fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -739,7 +739,8 @@ export const simulationFieldGroups: Record<
|
||||
label: 'Situação do terreno',
|
||||
options: 'land_status',
|
||||
showWhen: (d) =>
|
||||
landStatusVisible(d) && (d.purpose !== 'simulate_only' || isInvestorProjectJourney(d)),
|
||||
landStatusVisible(d) &&
|
||||
(d.purpose !== 'simulate_only' || isInvestorProjectJourney(d)),
|
||||
},
|
||||
{
|
||||
key: 'area_required',
|
||||
@@ -971,7 +972,9 @@ export const simulationFieldGroups: Record<
|
||||
key: 'fiscal_currency',
|
||||
label: 'Moeda da operação fiscal (sem conversão automática)',
|
||||
options: 'currency',
|
||||
showWhen: (d) => d.fiscal_component === 'iva' && d.fiscal_scenario_mode !== 'custom_planning',
|
||||
showWhen: (d) =>
|
||||
d.fiscal_component === 'iva' &&
|
||||
d.fiscal_scenario_mode !== 'custom_planning',
|
||||
},
|
||||
{
|
||||
key: 'fiscal_period',
|
||||
@@ -1683,18 +1686,42 @@ export function readArithmeticSnapshot(
|
||||
}
|
||||
const result = snapshot as Record<string, unknown>;
|
||||
const value = result.indicative_total;
|
||||
if (['fiscal_rule_qa_preview', 'fiscal_rule_published'].includes(String(result.scenario_kind))) {
|
||||
const presentation = result.presentation as Record<string, unknown> | undefined;
|
||||
if (isApiSimulationResultSnapshotV1(result) && fiscalQaRows(result).length > 0 &&
|
||||
result.result.value === value && presentation?.value === value &&
|
||||
presentation?.rounding_applied === false && result.context.currency === 'MZN' &&
|
||||
if (
|
||||
['fiscal_rule_qa_preview', 'fiscal_rule_published'].includes(
|
||||
String(result.scenario_kind),
|
||||
)
|
||||
) {
|
||||
const presentation = result.presentation as
|
||||
| Record<string, unknown>
|
||||
| undefined;
|
||||
if (
|
||||
isApiSimulationResultSnapshotV1(result) &&
|
||||
fiscalQaRows(result).length > 0 &&
|
||||
result.result.value === value &&
|
||||
presentation?.value === value &&
|
||||
presentation?.rounding_applied === false &&
|
||||
result.context.currency === 'MZN' &&
|
||||
result.result.unit === 'MZN' &&
|
||||
((result.result.status === 'calculated' && typeof value === 'string' && /^\d+(?:\.\d+)?$/.test(value)) ||
|
||||
(result.result.status === 'indeterminate' && value === null && result.result.missing_inputs.length > 0))) {
|
||||
return { integrity: 'versioned', value: value as string | null,
|
||||
context: result.context as unknown as Record<string, unknown>, explanation: result.result.explanation };
|
||||
((result.result.status === 'calculated' &&
|
||||
typeof value === 'string' &&
|
||||
/^\d+(?:\.\d+)?$/.test(value)) ||
|
||||
(result.result.status === 'indeterminate' &&
|
||||
value === null &&
|
||||
result.result.missing_inputs.length > 0))
|
||||
) {
|
||||
return {
|
||||
integrity: 'versioned',
|
||||
value: value as string | null,
|
||||
context: result.context as unknown as Record<string, unknown>,
|
||||
explanation: result.result.explanation,
|
||||
};
|
||||
}
|
||||
return { integrity: 'invalid', value: null, context: null, explanation: null };
|
||||
return {
|
||||
integrity: 'invalid',
|
||||
value: null,
|
||||
context: null,
|
||||
explanation: null,
|
||||
};
|
||||
}
|
||||
if (typeof value !== 'string' || !/^(?:\d+)(?:\.\d+)?$/.test(value)) {
|
||||
return {
|
||||
@@ -1870,12 +1897,25 @@ export function exportCompletedArithmeticCsv(
|
||||
);
|
||||
}
|
||||
const result = simulation.result_snapshot as Record<string, unknown>;
|
||||
if (['fiscal_rule_qa_preview', 'fiscal_rule_published'].includes(String(result.scenario_kind))) {
|
||||
if (
|
||||
['fiscal_rule_qa_preview', 'fiscal_rule_published'].includes(
|
||||
String(result.scenario_kind),
|
||||
)
|
||||
) {
|
||||
const rows = fiscalQaRows(result);
|
||||
const report = readVersionedArithmeticReportReference(simulation);
|
||||
if (!rows.length || !report) throw new Error('A pré-visualização fiscal não corresponde ao relatório preservado.');
|
||||
return `\uFEFF${[...rows, ['ID do relatório', report.id], ['Hash do relatório', report.report_sha256], ['Data de exportação', exportedAt]]
|
||||
.map((field) => field.map(csvCell).join(',')).join('\r\n')}`;
|
||||
if (!rows.length || !report)
|
||||
throw new Error(
|
||||
'A pré-visualização fiscal não corresponde ao relatório preservado.',
|
||||
);
|
||||
return `\uFEFF${[
|
||||
...rows,
|
||||
['ID do relatório', report.id],
|
||||
['Hash do relatório', report.report_sha256],
|
||||
['Data de exportação', exportedAt],
|
||||
]
|
||||
.map((field) => field.map(csvCell).join(','))
|
||||
.join('\r\n')}`;
|
||||
}
|
||||
const decimal = (value: unknown, label: string) => {
|
||||
if (typeof value !== 'string' || !/^(?:\d+)(?:\.\d+)?$/.test(value))
|
||||
|
||||
Reference in New Issue
Block a user