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" >