fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -1,20 +1,143 @@
|
||||
import {acquisitionOperationChoices,createAcquisitionRightLink,linkedOperationRight,linkedBeverageDeductionRight,type AcquisitionRightLink} from '@/lib/iva-acquisition-right';
|
||||
import type {Acquisition} from '@/lib/iva-acquisitions';
|
||||
import {
|
||||
acquisitionOperationChoices,
|
||||
createAcquisitionRightLink,
|
||||
linkedOperationRight,
|
||||
linkedBeverageDeductionRight,
|
||||
type AcquisitionRightLink,
|
||||
} from '@/lib/iva-acquisition-right';
|
||||
import type { Acquisition } from '@/lib/iva-acquisitions';
|
||||
|
||||
export function AcquisitionOperationLink({draft,row,onChange}:{draft:Record<string,unknown>;row:Acquisition;onChange:(patch:Partial<Acquisition>)=>void}){
|
||||
const choices=acquisitionOperationChoices(draft),link=row.deductionLink;
|
||||
const adopt=(id:string)=>onChange({deductionLink:createAcquisitionRightLink(draft,id)});
|
||||
const patch=(value:Partial<AcquisitionRightLink>)=>{if(link)onChange({deductionLink:{...link,...value}});};
|
||||
const result=link?(row.bc?.expense==='beverages'&&row.bc.facts.beverageSpecial==='yes'&&['deduction','refund'].includes(row.bc.beveragePath)?linkedBeverageDeductionRight(draft,link,row.bc.facts.notCoastalFishing==='yes'):linkedOperationRight(draft,link)):null;
|
||||
return <fieldset className="space-y-2 rounded border p-3"><legend>Aquisição → direito à dedução — L2-A</legend>
|
||||
<p>Reutilize a classificação existente. A ligação conserva montantes, documento e escolhas da aquisição; não cria outra compra. Importações, despesas especiais e afectação parcial conservam enquadramento próprio.</p>
|
||||
{choices.length===1&&!link?<button type="button" onClick={()=>adopt(choices[0].id)}>Reutilizar operação existente: {choices[0].label}</button>:<label>Operação de destino<select value={link?.operationId??''} onChange={e=>e.target.value?adopt(e.target.value):onChange({deductionLink:undefined})}><option value="">Sem vínculo L2-A</option>{choices.map(c=><option key={c.id} value={c.id}>{c.label}</option>)}</select></label>}
|
||||
{!choices.length&&<p>Não há operação classificada nesta oportunidade. A compra e o histórico permanecem disponíveis.</p>}
|
||||
{link&&<><p>{row.bc?.beveragePath==='refund'&&result?.status==='eligible'?'Condições da operação13(2) identificadas;via de restituição escolhida,sem dedução desta parcela.':result?.reason}</p><small>{result?.source}</small>
|
||||
<label className="block">Afectação exclusiva à operação ligada<select value={link.scopeConfirmed} onChange={e=>patch({scopeConfirmed:e.target.value as AcquisitionRightLink['scopeConfirmed']})}><option value="">Por confirmar</option><option value="yes">Sim</option><option value="no">Não / por rever</option></select></label>
|
||||
<label className="block">Motivo ou referência da afectação<input value={link.allocationRef} onChange={e=>patch({allocationRef:e.target.value})}/></label>
|
||||
{result?.status==='eligible'&&<label className="block">Aquisição fora dos pagamentos excluídos15(6)(c)/19(2)<select value={link.noExcludedPayments} onChange={e=>patch({noExcludedPayments:e.target.value as AcquisitionRightLink['noExcludedPayments']})}><option value="">Por indicar</option><option value="yes">Sim</option><option value="no">Não</option></select></label>}
|
||||
{result?.status==='indeterminate'&&choices.some(c=>c.id===link.operationId)&&<button type="button" onClick={()=>adopt(link.operationId)}>Adoptar explicitamente a classificação actual e rever afectação</button>}
|
||||
</>}
|
||||
</fieldset>;
|
||||
export function AcquisitionOperationLink({
|
||||
draft,
|
||||
row,
|
||||
onChange,
|
||||
}: {
|
||||
draft: Record<string, unknown>;
|
||||
row: Acquisition;
|
||||
onChange: (patch: Partial<Acquisition>) => void;
|
||||
}) {
|
||||
const choices = acquisitionOperationChoices(draft),
|
||||
link = row.deductionLink;
|
||||
const adopt = (id: string) =>
|
||||
onChange({ deductionLink: createAcquisitionRightLink(draft, id) });
|
||||
const patch = (value: Partial<AcquisitionRightLink>) => {
|
||||
if (link) onChange({ deductionLink: { ...link, ...value } });
|
||||
};
|
||||
const result = link
|
||||
? row.bc?.expense === 'beverages' &&
|
||||
row.bc.facts.beverageSpecial === 'yes' &&
|
||||
['deduction', 'refund'].includes(row.bc.beveragePath)
|
||||
? linkedBeverageDeductionRight(
|
||||
draft,
|
||||
link,
|
||||
row.bc.facts.notCoastalFishing === 'yes',
|
||||
)
|
||||
: linkedOperationRight(draft, link)
|
||||
: null;
|
||||
return (
|
||||
<fieldset className="space-y-2 rounded border p-3">
|
||||
<legend>Aquisição → direito à dedução — L2-A</legend>
|
||||
<p>
|
||||
Reutilize a classificação existente. A ligação conserva
|
||||
montantes, documento e escolhas da aquisição; não cria outra
|
||||
compra. Importações, despesas especiais e afectação parcial
|
||||
conservam enquadramento próprio.
|
||||
</p>
|
||||
{choices.length === 1 && !link ? (
|
||||
<button type="button" onClick={() => adopt(choices[0].id)}>
|
||||
Reutilizar operação existente: {choices[0].label}
|
||||
</button>
|
||||
) : (
|
||||
<label>
|
||||
Operação de destino
|
||||
<select
|
||||
value={link?.operationId ?? ''}
|
||||
onChange={(e) =>
|
||||
e.target.value
|
||||
? adopt(e.target.value)
|
||||
: onChange({ deductionLink: undefined })
|
||||
}
|
||||
>
|
||||
<option value="">Sem vínculo L2-A</option>
|
||||
{choices.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{!choices.length && (
|
||||
<p>
|
||||
Não há operação classificada nesta oportunidade. A compra e
|
||||
o histórico permanecem disponíveis.
|
||||
</p>
|
||||
)}
|
||||
{link && (
|
||||
<>
|
||||
<p>
|
||||
{row.bc?.beveragePath === 'refund' &&
|
||||
result?.status === 'eligible'
|
||||
? 'Condições da operação13(2) identificadas;via de restituição escolhida,sem dedução desta parcela.'
|
||||
: result?.reason}
|
||||
</p>
|
||||
<small>{result?.source}</small>
|
||||
<label className="block">
|
||||
Afectação exclusiva à operação ligada
|
||||
<select
|
||||
value={link.scopeConfirmed}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
scopeConfirmed: e.target
|
||||
.value as AcquisitionRightLink['scopeConfirmed'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por confirmar</option>
|
||||
<option value="yes">Sim</option>
|
||||
<option value="no">Não / por rever</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
Motivo ou referência da afectação
|
||||
<input
|
||||
value={link.allocationRef}
|
||||
onChange={(e) =>
|
||||
patch({ allocationRef: e.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
{result?.status === 'eligible' && (
|
||||
<label className="block">
|
||||
Aquisição fora dos pagamentos
|
||||
excluídos15(6)(c)/19(2)
|
||||
<select
|
||||
value={link.noExcludedPayments}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
noExcludedPayments: e.target
|
||||
.value as AcquisitionRightLink['noExcludedPayments'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por indicar</option>
|
||||
<option value="yes">Sim</option>
|
||||
<option value="no">Não</option>
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{result?.status === 'indeterminate' &&
|
||||
choices.some((c) => c.id === link.operationId) && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => adopt(link.operationId)}
|
||||
>
|
||||
Adoptar explicitamente a classificação actual e
|
||||
rever afectação
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user