fix: complete V09 financial diagnostic coverage in isolated QA
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
forecastBusinessPlan,
|
||||
monthlyProjectedSales,
|
||||
businessPlanNumberError,
|
||||
type BusinessFinancialPlanInput,
|
||||
} from './business-financial-plan.ts';
|
||||
import { calculateStartupAssetRequirements } from './startup-asset-requirements.ts';
|
||||
@@ -50,6 +51,16 @@ const cents = (value: string): bigint => {
|
||||
const amount = BigInt(whole) * 100n + BigInt(fraction.padEnd(2, '0'));
|
||||
return negative ? -amount : amount;
|
||||
};
|
||||
/** Diagnostic wrapper only: preserve the report's signed parser and precision. */
|
||||
const fieldCents = (value: string, field: string): bigint => {
|
||||
try {
|
||||
return cents(value);
|
||||
} catch {
|
||||
throw new Error(
|
||||
`«${field}»: ${businessPlanNumberError(value, { allowNegative: true }) || 'Introduza um montante com até duas casas decimais.'}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
export const reportMoney = (amount: bigint): string => {
|
||||
const abs = amount < 0n ? -amount : amount;
|
||||
return `${amount < 0n ? '-' : ''}${abs / 100n}.${String(abs % 100n).padStart(2, '0')}`;
|
||||
@@ -151,21 +162,30 @@ export function buildIntegralFinancialTables(
|
||||
Number(a.startYear) < 1900 ||
|
||||
Number(a.startYear) > 9999
|
||||
)
|
||||
throw new Error('Indique o ano inicial do relatório (1900–9999).');
|
||||
throw new Error(
|
||||
`«Ano inicial»: ${businessPlanNumberError(a.startYear) || 'Indique o ano inicial do relatório (1900–9999).'}`,
|
||||
);
|
||||
const needs = plan.startupAssetRequirements
|
||||
? calculateStartupAssetRequirements(plan)
|
||||
: undefined;
|
||||
const openingFixed = cents(a.openingFixedAssets),
|
||||
const openingFixed = fieldCents(
|
||||
a.openingFixedAssets,
|
||||
'Activos fixos anteriores (valor líquido)',
|
||||
),
|
||||
otherAssets =
|
||||
cents(a.openingOtherAssets) + (needs?.currentAcquisition ?? 0n),
|
||||
openingEquity = cents(a.openingEquity);
|
||||
fieldCents(a.openingOtherAssets, 'Outros activos anteriores') +
|
||||
(needs?.currentAcquisition ?? 0n),
|
||||
openingEquity = fieldCents(
|
||||
a.openingEquity,
|
||||
'Capital e resultados anteriores',
|
||||
);
|
||||
if (
|
||||
[openingFixed, otherAssets, openingEquity].some(
|
||||
(value) => value < 0n,
|
||||
)
|
||||
)
|
||||
throw new Error(
|
||||
'Os saldos iniciais complementares não podem ser negativos.',
|
||||
`Saldos de abertura / «${openingFixed < 0n ? 'Activos fixos anteriores (valor líquido)' : otherAssets < 0n ? 'Outros activos anteriores' : 'Capital e resultados anteriores'}»: Este valor não pode ser negativo.`,
|
||||
);
|
||||
if (
|
||||
!Array.isArray(a.startupExpenses) ||
|
||||
@@ -175,16 +195,23 @@ export function buildIntegralFinancialTables(
|
||||
throw new Error(
|
||||
'Declare as despesas de arranque, incluindo uma linha de zero quando não existirem.',
|
||||
);
|
||||
const startup = a.startupExpenses.reduce((total, row) => {
|
||||
const startup = a.startupExpenses.reduce((total, row, index) => {
|
||||
if (
|
||||
!row.label.trim() ||
|
||||
row.label.length > 160 ||
|
||||
cents(row.amount) < 0n
|
||||
fieldCents(row.amount, `Montante de arranque ${index + 1}`) < 0n
|
||||
)
|
||||
throw new Error(
|
||||
'Cada despesa de arranque exige designação e montante não negativo.',
|
||||
!row.label.trim()
|
||||
? `«Despesa ${index + 1}»: Preencha este campo para continuar.`
|
||||
: row.label.length > 160
|
||||
? `«Despesa ${index + 1}»: Reduza a designação para até 160 caracteres.`
|
||||
: `«Montante de arranque ${index + 1}»: Este valor não pode ser negativo.`,
|
||||
);
|
||||
return total + cents(row.amount);
|
||||
return (
|
||||
total +
|
||||
fieldCents(row.amount, `Montante de arranque ${index + 1}`)
|
||||
);
|
||||
}, 0n);
|
||||
const count = result.rows.length;
|
||||
const schedule = (values: string[], field: string) => {
|
||||
@@ -198,12 +225,12 @@ export function buildIntegralFinancialTables(
|
||||
amount = cents(value);
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Impostos por mês — ${field}, mês ${month + 1}: preencha este campo com um montante até duas casas decimais; indique zero apenas quando aplicável.`,
|
||||
`Impostos por mês / «${field} — mês ${month + 1}»: ${businessPlanNumberError(value, { allowNegative: true }) || 'Introduza um montante com até duas casas decimais.'} Indique zero apenas quando aplicável.`,
|
||||
);
|
||||
}
|
||||
if (amount < 0n)
|
||||
throw new Error(
|
||||
`Impostos por mês — ${field}, mês ${month + 1}: o montante não pode ser negativo. Corrija este campo.`,
|
||||
`Impostos por mês / «${field} — mês ${month + 1}»: Este valor não pode ser negativo. Corrija este campo.`,
|
||||
);
|
||||
return amount;
|
||||
});
|
||||
@@ -218,7 +245,7 @@ export function buildIntegralFinancialTables(
|
||||
);
|
||||
if (!a.taxSource.trim())
|
||||
throw new Error(
|
||||
'Indique a fonte ou o pressuposto fiscal, incluindo quando não prevê imposto.',
|
||||
'«Fonte ou pressuposto dos impostos estimados»: Preencha este campo para continuar. Identifique a fonte ou o pressuposto fiscal, incluindo quando não prevê imposto.',
|
||||
);
|
||||
if (
|
||||
cents(plan.grants) > 0n &&
|
||||
|
||||
Reference in New Issue
Block a user