Files
Investidor-V2/resources/js/components/simulation-irpc-pec.tsx
T

201 lines
8.5 KiB
TypeScript

import { FiscalProofParcelFields } from './fiscal-proof-parcel';
import { newPecPayment, pecSource, type PecPayment } from '@/lib/irpc-pec';
import type { AnnualBook } from '@/lib/irpc-annual-settlement';
export function SimulationIrpcPec({
book,
save,
}: {
book: AnnualBook;
save: (book: AnnualBook) => void;
}) {
const detail = book.pecPayments;
if (!detail)
return (
<fieldset className="rounded border p-3">
<legend>PEC — comprovativos do próprio exercício</legend>
<p>
O resumo anterior fica conservado. Preparar o detalhe
permite reconciliar os pagamentos efectivos e deduzi-los até
à colecta disponível, sem reembolso do excedente PEC.
</p>
<button
type="button"
onClick={() =>
save({
...book,
pecPayments: {
version: 1,
state: book.pec.state,
reference: book.pec.reference,
rows: [],
},
})
}
>
Preparar detalhe PEC
</button>
</fieldset>
);
const update = (next: typeof detail) =>
save({ ...book, pecPayments: next });
return (
<fieldset className="space-y-2 rounded border p-3">
<legend>PEC — pagamentos efectivamente comprovados</legend>
<p>{pecSource}</p>
<p>
Identifique a natureza PEC no comprovativo. As utilizações
anteriores exigem valor e suporte; zero conhecido é diferente de
informação em falta. A parcela seleccionada não pode exceder o
comprovado menos o já utilizado. Saldos de anos anteriores,
cálculo da obrigação e créditos próprios permanecem separados.
</p>
<label className="block">
Estado dos PEC
<select
aria-label="Estado dos PEC comprovados L8"
value={detail.state}
onChange={(e) =>
update({
...detail,
state: e.target.value as typeof detail.state,
})
}
>
<option value="">Informação em falta</option>
<option value="known">Pagamentos conhecidos</option>
<option value="absent">
Ausência declarada com suporte
</option>
</select>
</label>
<label className="block">
Suporte do inventário PEC
<input
aria-label="Suporte do inventário PEC L8"
value={detail.reference}
onChange={(e) =>
update({ ...detail, reference: e.target.value })
}
/>
</label>
<button
type="button"
onClick={() =>
update({
...detail,
state: 'known',
rows: [
...detail.rows,
{
...newPecPayment(crypto.randomUUID()),
subjectNuit: book.subjectNuit,
year: book.year,
},
],
})
}
>
Registar comprovativo PEC
</button>
{detail.rows.map((r, index) => {
const change = (p: Partial<PecPayment>) =>
update({
...detail,
rows: detail.rows.map((x) =>
x.id === r.id ? { ...x, ...p } : x,
),
});
return (
<fieldset key={r.id} className="rounded border p-2">
<legend>PEC {index + 1}</legend>
{(
[
['document', 'Comprovativo PEC'],
['issuer', 'Emitente'],
['date', 'Data (AAAA-MM-DD)'],
['subjectNuit', 'NUIT beneficiário'],
['year', 'Exercício de origem'],
['currency', 'Moeda'],
['proofAmount', 'Montante comprovado'],
[
'previouslyUsed',
'Já utilizado fora destas parcelas',
],
[
'priorUseReference',
'Suporte das utilizações anteriores ou do zero conhecido',
],
['amount', 'Parcela disponível seleccionada'],
[
'reference',
'Suporte do pagamento PEC e afectação',
],
] as const
).map(([key, label]) => (
<label key={key} className="block">
{label}
<input
aria-label={
'PEC L8 ' + (index + 1) + ' — ' + label
}
value={r[key]}
onChange={(e) =>
change({ [key]: e.target.value })
}
/>
</label>
))}
<label className="block">
Pagamento PEC efectivamente comprovado
<select
aria-label={
'PEC L8 ' + (index + 1) + ' — Efectivo'
}
value={r.effective}
onChange={(e) =>
change({
effective: e.target
.value as PecPayment['effective'],
})
}
>
<option value="">Informação em falta</option>
<option value="yes">
Sim — natureza PEC e pagamento reconciliados
</option>
<option value="no">
Não — previsão ou outra natureza
</option>
</select>
</label>
<FiscalProofParcelFields
value={r}
change={change}
label={'PEC L8 ' + (index + 1)}
/>
<button
type="button"
onClick={() =>
update({
...detail,
rows: detail.rows.filter(
(x) => x.id !== r.id,
),
})
}
>
Retirar selecção PEC {index + 1}
</button>
</fieldset>
);
})}
<p>
O detalhe substitui o resumo PEC apenas nesta execução. Os
comprovativos e resultados de execuções anteriores permanecem no
histórico; não há consumo automático de saldos oficiais.
</p>
</fieldset>
);
}