fix: recover simulator cashflow and verify QA continuity and report assumptions
This commit is contained in:
@@ -834,8 +834,10 @@ export function SimulationForm() {
|
||||
}, [openedTool, step]);
|
||||
function openDraftTool(tool: 'calculation' | 'fiscal') {
|
||||
setToolError('');
|
||||
const index = journeySections.findIndex(
|
||||
(section) => section.id === 'tax',
|
||||
const index = journeySections.findIndex((section) =>
|
||||
tool === 'calculation'
|
||||
? ['financial', 'tax'].includes(section.id)
|
||||
: section.id === 'tax',
|
||||
);
|
||||
if (index < 0) {
|
||||
setToolError(
|
||||
@@ -927,6 +929,7 @@ export function SimulationForm() {
|
||||
const [businessLinkError, setBusinessLinkError] = useState('');
|
||||
const [businessLinkBusy, setBusinessLinkBusy] = useState(false);
|
||||
const [continueLaterSaved, setContinueLaterSaved] = useState(false);
|
||||
const [saveAttempt, setSaveAttempt] = useState(0);
|
||||
const calculationInFlightRef = useRef(false);
|
||||
const draftIdRef = useRef<string | null>(null);
|
||||
const draftEtagRef = useRef<string | null>(null);
|
||||
@@ -1322,6 +1325,7 @@ export function SimulationForm() {
|
||||
setSaveStatus('A guardar o rascunho no servidor…');
|
||||
saveQueueRef.current = saveQueueRef.current
|
||||
.then(async () => {
|
||||
if (fingerprint === lastSavedFingerprintRef.current) return;
|
||||
const headers = {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
@@ -1476,6 +1480,7 @@ export function SimulationForm() {
|
||||
draftCreateKey,
|
||||
draftIdKey,
|
||||
draftKey,
|
||||
saveAttempt,
|
||||
]);
|
||||
|
||||
async function returnToInvestment() {
|
||||
@@ -1700,6 +1705,7 @@ export function SimulationForm() {
|
||||
async function saveAndContinueLater() {
|
||||
if (!draft.purpose) return;
|
||||
setContinueLaterSaved(false);
|
||||
setSaveAttempt((attempt) => attempt + 1);
|
||||
await new Promise((resolve) => window.setTimeout(resolve, 550));
|
||||
await saveQueueRef.current;
|
||||
const target = canSavePersonalData ? draft : getAutosaveSnapshot(draft);
|
||||
@@ -3449,6 +3455,10 @@ export function SimulationForm() {
|
||||
(draft.purpose === 'simulate_only' &&
|
||||
current.id === 'tax')) && (
|
||||
<SimulationCashflowPlanner
|
||||
snapshot={String(draft.cashflow_snapshot ?? '')}
|
||||
onSnapshotChange={(value) =>
|
||||
change('cashflow_snapshot', value)
|
||||
}
|
||||
currency={String(draft.currency ?? '')}
|
||||
onCurrencyChange={(value) => change('currency', value)}
|
||||
/>
|
||||
@@ -3692,36 +3702,49 @@ export function SimulationForm() {
|
||||
documentos nesta simulação exploratória.
|
||||
</p>
|
||||
)}
|
||||
{current.id === 'tax' && (
|
||||
{(current.id === 'tax' || result) && (
|
||||
<div className="space-y-3 border-t pt-4">
|
||||
<h4 className="font-semibold">
|
||||
Cenário personalizado de planeamento
|
||||
{current.id === 'tax'
|
||||
? 'Cenário personalizado de planeamento'
|
||||
: 'Resultado histórico seleccionado'}
|
||||
</h4>
|
||||
{draft.fiscal_scenario_mode === 'custom_planning' && (
|
||||
<p
|
||||
role="note"
|
||||
className="rounded bg-slate-50 p-3 text-sm"
|
||||
>
|
||||
Os valores abaixo são pressupostos que
|
||||
introduziu para planeamento. O resultado é uma
|
||||
operação percentual genérica, não uma taxa
|
||||
legal, imposto devido nem confirmação de
|
||||
elegibilidade.
|
||||
{current.id !== 'tax' && result && (
|
||||
<p>
|
||||
Este resultado conserva os pressupostos e a
|
||||
versão da execução seleccionada. Não substitui
|
||||
as entradas deste dossier.
|
||||
</p>
|
||||
)}
|
||||
{draft.fiscal_scenario_mode === 'custom_planning' && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={isCalculating}
|
||||
aria-busy={isCalculating}
|
||||
className="rounded-lg bg-emerald-800 px-4 py-3 font-semibold text-white focus-visible:outline-2 disabled:cursor-wait disabled:opacity-60"
|
||||
onClick={() => void runSimulation()}
|
||||
>
|
||||
{isCalculating
|
||||
? 'A calcular…'
|
||||
: 'Validar e calcular no servidor'}
|
||||
</button>
|
||||
)}
|
||||
{current.id === 'tax' &&
|
||||
draft.fiscal_scenario_mode ===
|
||||
'custom_planning' && (
|
||||
<p
|
||||
role="note"
|
||||
className="rounded bg-slate-50 p-3 text-sm"
|
||||
>
|
||||
Os valores abaixo são pressupostos que
|
||||
introduziu para planeamento. O resultado é
|
||||
uma operação percentual genérica, não uma
|
||||
taxa legal, imposto devido nem confirmação
|
||||
de elegibilidade.
|
||||
</p>
|
||||
)}
|
||||
{current.id === 'tax' &&
|
||||
draft.fiscal_scenario_mode ===
|
||||
'custom_planning' && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={isCalculating}
|
||||
aria-busy={isCalculating}
|
||||
className="rounded-lg bg-emerald-800 px-4 py-3 font-semibold text-white focus-visible:outline-2 disabled:cursor-wait disabled:opacity-60"
|
||||
onClick={() => void runSimulation()}
|
||||
>
|
||||
{isCalculating
|
||||
? 'A calcular…'
|
||||
: 'Validar e calcular no servidor'}
|
||||
</button>
|
||||
)}
|
||||
{serverError && (
|
||||
<p role="alert" className="text-red-800">
|
||||
{serverError}
|
||||
|
||||
Reference in New Issue
Block a user