fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
@@ -27,7 +27,7 @@ export function SimulationCashflowPlanner({
const restored = restoreCashflowDraftSnapshot(snapshot);
const [confirmedCurrency, setConfirmedCurrency] = useState('');
const originCurrency = restored?.version === 2 ? restored.currency : null;
const calculationCurrency = snapshot ? originCurrency ?? '' : currency;
const calculationCurrency = snapshot ? (originCurrency ?? '') : currency;
const [taxMode, setTaxMode] = useState<'fixed' | 'schedule'>(
restored?.taxMode ?? 'fixed',
);
@@ -45,7 +45,13 @@ export function SimulationCashflowPlanner({
) {
setInputs(next);
setTaxMode(mode);
onSnapshotChange?.(serializeCashflowDraftSnapshot(mode, next, snapshot ? originCurrency ?? null : currency || null));
onSnapshotChange?.(
serializeCashflowDraftSnapshot(
mode,
next,
snapshot ? (originCurrency ?? null) : currency || null,
),
);
}
const set = (
key: Exclude<keyof typeof inputs, 'monthlyTaxSchedule'>,
@@ -68,7 +74,10 @@ export function SimulationCashflowPlanner({
'Não foi possível recuperar os pressupostos guardados de tesouraria. Reveja os campos antes de voltar a guardar; nenhum resultado foi calculado com dados alternativos.',
);
if (restored) cashflowCurrency(restored, currency);
projection = projectMonthlyCashflow({ ...cashflowInput, currency: calculationCurrency });
projection = projectMonthlyCashflow({
...cashflowInput,
currency: calculationCurrency,
});
} catch (cause) {
error =
cause instanceof Error
@@ -108,16 +117,67 @@ export function SimulationCashflowPlanner({
<h3 id="cashflow-title" className="text-lg font-semibold">
Projecção de tesouraria — 12 meses
</h3>
{restored && !originCurrency && <div className="space-y-2 rounded border border-amber-600 p-3">
<p>A moeda de origem dos montantes guardados não foi registada. Os valores foram conservados. Confirme apenas essa moeda; não é necessário preencher os montantes novamente.</p>
<label>Moeda de origem da tesouraria guardada<select className="ml-2 rounded border p-2" value={confirmedCurrency} onChange={event => setConfirmedCurrency(event.target.value)}><option value="">Por confirmar</option>{simulationCurrencyOptions.map(code => <option key={code} value={code}>{code}</option>)}</select></label>
<button type="button" className="block underline" disabled={!isSimulationCurrency(confirmedCurrency)} onClick={() => onSnapshotChange?.(serializeCashflowDraftSnapshot(taxMode, inputs, confirmedCurrency))}>Confirmar moeda de origem e conservar montantes</button>
</div>}
{originCurrency && originCurrency !== currency && <div role="alert" className="rounded border border-amber-600 p-3">
<p>{cashflowCurrency(restored!, currency).notice}</p>
<button type="button" className="underline" onClick={() => onCurrencyChange(originCurrency)}>Usar {originCurrency} no projecto e conservar montantes</button>
</div>}
{originCurrency && <p>Moeda de origem dos pressupostos: {originCurrency}.</p>}
{restored && !originCurrency && (
<div className="space-y-2 rounded border border-amber-600 p-3">
<p>
A moeda de origem dos montantes guardados não foi
registada. Os valores foram conservados. Confirme apenas
essa moeda; não é necessário preencher os montantes
novamente.
</p>
<label>
Moeda de origem da tesouraria guardada
<select
className="ml-2 rounded border p-2"
value={confirmedCurrency}
onChange={(event) =>
setConfirmedCurrency(event.target.value)
}
>
<option value="">Por confirmar</option>
{simulationCurrencyOptions.map((code) => (
<option key={code} value={code}>
{code}
</option>
))}
</select>
</label>
<button
type="button"
className="block underline"
disabled={!isSimulationCurrency(confirmedCurrency)}
onClick={() =>
onSnapshotChange?.(
serializeCashflowDraftSnapshot(
taxMode,
inputs,
confirmedCurrency,
),
)
}
>
Confirmar moeda de origem e conservar montantes
</button>
</div>
)}
{originCurrency && originCurrency !== currency && (
<div
role="alert"
className="rounded border border-amber-600 p-3"
>
<p>{cashflowCurrency(restored!, currency).notice}</p>
<button
type="button"
className="underline"
onClick={() => onCurrencyChange(originCurrency)}
>
Usar {originCurrency} no projecto e conservar montantes
</button>
</div>
)}
{originCurrency && (
<p>Moeda de origem dos pressupostos: {originCurrency}.</p>
)}
<p className="text-sm text-slate-700">
Introduza pressupostos na mesma moeda. O imposto indicado é um
pressuposto do utilizador; esta ferramenta não calcula nem
@@ -190,7 +250,8 @@ export function SimulationCashflowPlanner({
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
{inputs.monthlyTaxSchedule.map((value, index) => (
<label key={index} className="text-sm font-medium">
Imposto manual do cenário personalizado — mês {index + 1}
Imposto manual do cenário personalizado — mês{' '}
{index + 1}
<input
type="number"
min="0"