fix(v12): complete currency schedule and import diagnostics

This commit is contained in:
2026-11-21 08:58:00 +02:00
parent 64601256d5
commit 4bb2fd670a
9 changed files with 411 additions and 10 deletions
+16 -3
View File
@@ -1651,7 +1651,7 @@ export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
throw new Error('A agenda de recuperação deve ter até 60 parcelas.');
const recoveryMonths = new Set<number>();
const salesRecoveryRates = new Map<number, bigint>();
salesRecoverySchedule.forEach((entry) => {
salesRecoverySchedule.forEach((entry, index) => {
if (
!Number.isSafeInteger(entry.month) ||
entry.month < 1 ||
@@ -1659,7 +1659,11 @@ export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
recoveryMonths.has(entry.month)
)
throw new Error(
'Cada recuperação deve ter um mês único dentro do horizonte.',
Number.isSafeInteger(entry.month) &&
entry.month >= 1 &&
entry.month <= periods
? 'Cada recuperação deve ter um mês único dentro do horizonte.'
: `Fluxo de Caixa / Recuperação de vendas vencidas, linha ${index + 1} / Mês (${entry.month}): seleccione um mês inteiro entre 1 e ${periods}, dentro do horizonte do plano. Corrija este campo ou remova a linha inválida.`,
);
recoveryMonths.add(entry.month);
const rate = percentMicro(
@@ -1770,7 +1774,15 @@ export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
);
return {
units:
unitsByPeriod?.map(quantity) ??
unitsByPeriod?.map((value, month) => {
try {
return quantity(value);
} catch {
throw new Error(
`Previsão de Vendas / Unidades do produto ${index + 1}, mês ${month + 1}: preencha uma quantidade não negativa com até três casas decimais; indique zero apenas quando aplicável.`,
);
}
}) ??
Array.from({ length: periods }, (_, month) =>
projectedUnits(input, product, month),
),
@@ -3487,3 +3499,4 @@ export function exportBusinessPlanCsv(
.map((row) => row.map(csvCell).join(','))
.join('\r\n')}`;
}
export { financialPlanImportMessage } from './financial-plan-import-message.ts';