fix: retain editable investment plans and record partial QA continuity evidence

This commit is contained in:
2026-11-20 09:25:49 +02:00
parent bae996e10d
commit 04d8db6c1b
17 changed files with 1011 additions and 290 deletions
+24
View File
@@ -3,6 +3,10 @@ import { landStatusVisible } from './investment-land-preparation.ts';
import { csvCell } from './csv.js';
import { fiscalQaRows } from './fiscal-qa-preview.ts';
import { isApiSimulationResultSnapshotV1 } from './simulation-contract.ts';
import {
forecastBusinessPlan,
restoreBusinessPlanSnapshot,
} from './business-financial-plan.ts';
export type SimulationDraft = Record<string, string | string[]>;
export const projectQuestionnaireVersion =
@@ -1801,6 +1805,26 @@ export function validateSimulationDraft(
errors.total_investment =
'A soma do capital, dívida e subvenções deve corresponder ao investimento total.';
}
if (
sectionId === 'financial' &&
typeof draft.business_plan_snapshot === 'string' &&
draft.business_plan_snapshot
) {
const plan = restoreBusinessPlanSnapshot(draft.business_plan_snapshot);
if (!plan)
errors.business_plan_snapshot =
'Não foi possível recuperar o plano financeiro. Reveja os dados guardados.';
else {
try {
forecastBusinessPlan(plan);
} catch (cause) {
errors.business_plan_snapshot =
cause instanceof Error
? cause.message
: 'Reveja os dados do plano financeiro antes de continuar.';
}
}
}
return errors;
}