From 65b87819a0629f79f415788a6aa1a16fe031e37e Mon Sep 17 00:00:00 2001 From: nala Date: Sat, 24 Oct 2026 11:29:15 +0200 Subject: [PATCH] fix: preserve cashflow currency and recover admitted monthly IVA executions in QA --- .../simulation-cashflow-planner.tsx | 29 ++++++-- .../js/components/simulation-monthly-iva.tsx | 33 +++++---- resources/js/lib/monthly-cashflow.ts | 19 ++++-- resources/js/lib/monthly-iva.ts | 11 ++- resources/js/lib/project-dossier.ts | 5 +- .../Feature/SimulatorClosureRecoveryTest.php | 67 +++++++++++++++++++ .../fixtures/simulator-closure-fixture.mjs | 13 ++++ .../frontend/simulator-closure-scope.test.mjs | 55 +++++++++++++++ .../simulator-independent-review.test.mjs | 4 +- 9 files changed, 207 insertions(+), 29 deletions(-) create mode 100644 tests/Feature/SimulatorClosureRecoveryTest.php create mode 100644 tests/frontend/fixtures/simulator-closure-fixture.mjs create mode 100644 tests/frontend/simulator-closure-scope.test.mjs diff --git a/resources/js/components/simulation-cashflow-planner.tsx b/resources/js/components/simulation-cashflow-planner.tsx index 94760cfd..4f23c4fe 100644 --- a/resources/js/components/simulation-cashflow-planner.tsx +++ b/resources/js/components/simulation-cashflow-planner.tsx @@ -5,6 +5,7 @@ import { defaultCashflowDraftInputs, restoreCashflowDraftSnapshot, serializeCashflowDraftSnapshot, + cashflowCurrency, type CashflowDraftSnapshot, } from '@/lib/monthly-cashflow'; import { @@ -24,6 +25,9 @@ export function SimulationCashflowPlanner({ onSnapshotChange?: (snapshot: string) => void; }) { const restored = restoreCashflowDraftSnapshot(snapshot); + const [confirmedCurrency, setConfirmedCurrency] = useState(''); + const originCurrency = restored?.version === 2 ? restored.currency : null; + const calculationCurrency = snapshot ? originCurrency ?? '' : currency; const [taxMode, setTaxMode] = useState<'fixed' | 'schedule'>( restored?.taxMode ?? 'fixed', ); @@ -41,7 +45,7 @@ export function SimulationCashflowPlanner({ ) { setInputs(next); setTaxMode(mode); - onSnapshotChange?.(serializeCashflowDraftSnapshot(mode, next)); + onSnapshotChange?.(serializeCashflowDraftSnapshot(mode, next, snapshot ? originCurrency ?? null : currency || null)); } const set = ( key: Exclude, @@ -63,7 +67,8 @@ export function SimulationCashflowPlanner({ throw new Error( '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.', ); - projection = projectMonthlyCashflow({ ...cashflowInput, currency }); + if (restored) cashflowCurrency(restored, currency); + projection = projectMonthlyCashflow({ ...cashflowInput, currency: calculationCurrency }); } catch (cause) { error = cause instanceof Error @@ -76,7 +81,7 @@ export function SimulationCashflowPlanner({ aria-labelledby="cashflow-title" >