fix: complete V09 financial diagnostic coverage in isolated QA
This commit is contained in:
@@ -1040,7 +1040,7 @@ function cents(value: string, label: string, signed = false): bigint {
|
||||
).exec(value.trim());
|
||||
if (!match || value.length > 40)
|
||||
throw new Error(
|
||||
`${label}: use um montante${signed ? '' : ' não negativo'} com até duas casas decimais.`,
|
||||
`${label}: ${businessPlanNumberError(value, { allowNegative: signed }) || `Introduza um montante${signed ? '' : ' não negativo'} com até duas casas decimais.`}`,
|
||||
);
|
||||
const sign = match[1].startsWith('-') ? -1n : 1n;
|
||||
return (
|
||||
@@ -1054,7 +1054,7 @@ function quantity(value: string): bigint {
|
||||
const match = /^(\d+)(?:\.(\d{1,3}))?$/.exec(value.trim());
|
||||
if (!match || value.length > 40)
|
||||
throw new Error(
|
||||
'Quantidade: use um valor não negativo com até três casas decimais.',
|
||||
`Quantidade: ${businessPlanNumberError(value) || 'Introduza um valor não negativo com até três casas decimais.'}`,
|
||||
);
|
||||
return (
|
||||
BigInt(match[1]) * 1000n +
|
||||
@@ -1195,7 +1195,7 @@ function percentMicro(value: string, label: string): bigint {
|
||||
const match = /^(-?\d+)(?:\.(\d{1,6}))?$/.exec(value.trim());
|
||||
if (!match || value.length > 40)
|
||||
throw new Error(
|
||||
`${label}: indique uma percentagem com até seis casas.`,
|
||||
`${label}: ${businessPlanNumberError(value, { allowNegative: true }) || 'Introduza uma percentagem com até seis casas.'}`,
|
||||
);
|
||||
const sign = match[1].startsWith('-') ? -1n : 1n;
|
||||
return (
|
||||
@@ -1558,6 +1558,26 @@ type ActiveDayTerms = ReturnType<typeof buildDayTermSchedule> & {
|
||||
};
|
||||
|
||||
export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
|
||||
try {
|
||||
return forecastBusinessPlanChecked(input);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
[
|
||||
'Movimentos por período — Ano inicial: preencha o ano do relatório entre 1900 e 9993.',
|
||||
'Prazos em dias — Ano inicial: indique o ano do relatório entre 1900 e 9993.',
|
||||
'Adiantamentos: preencha o ano inicial do relatório entre 1900 e 9993.',
|
||||
].includes(error.message)
|
||||
) {
|
||||
throw new Error(
|
||||
`«Ano inicial»: ${businessPlanNumberError(input.reportAssumptions?.startYear ?? '') || 'Indique o ano do relatório entre 1900 e 9993.'}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function forecastBusinessPlanChecked(input: BusinessFinancialPlanInput) {
|
||||
const config = input.dayTerms;
|
||||
const advances = input.supplierAdvances;
|
||||
if (
|
||||
@@ -1768,7 +1788,9 @@ function forecastBusinessPlanBase(
|
||||
'Percentagem de cobrança',
|
||||
);
|
||||
if (salesCollectionRate < 0n || salesCollectionRate > 100_000_000n)
|
||||
throw new Error('A percentagem de cobrança deve estar entre 0 e 100.');
|
||||
throw new Error(
|
||||
'Percentagem de cobrança: Introduza uma percentagem entre 0% e 100%.',
|
||||
);
|
||||
const openingReceivablesCollectionMonth =
|
||||
input.openingReceivablesCollectionMonth ?? null;
|
||||
if (
|
||||
@@ -1791,7 +1813,7 @@ function forecastBusinessPlanBase(
|
||||
openingReceivablesCollectionRate > 100_000_000n
|
||||
)
|
||||
throw new Error(
|
||||
'A percentagem de cobrança dos valores a receber deve estar entre 0 e 100.',
|
||||
'Percentagem de cobrança dos valores a receber: Introduza uma percentagem entre 0% e 100%.',
|
||||
);
|
||||
const openingReceivablesInstallments =
|
||||
input.openingReceivablesInstallments ?? [];
|
||||
@@ -1820,7 +1842,7 @@ function forecastBusinessPlanBase(
|
||||
);
|
||||
if (rate < 0n || rate > 100_000_000n)
|
||||
throw new Error(
|
||||
'A percentagem de cada parcela deve estar entre 0 e 100.',
|
||||
'Percentagem de cada parcela: Introduza uma percentagem entre 0% e 100%.',
|
||||
);
|
||||
openingReceivablesScheduledRate += rate;
|
||||
return rate;
|
||||
@@ -1854,7 +1876,7 @@ function forecastBusinessPlanBase(
|
||||
);
|
||||
if (rate < 0n || rate > 100_000_000n)
|
||||
throw new Error(
|
||||
'A percentagem de cada liquidação deve estar entre 0 e 100.',
|
||||
'Percentagem de cada liquidação: Introduza uma percentagem entre 0% e 100%.',
|
||||
);
|
||||
openingPayablesScheduledRate += rate;
|
||||
return rate;
|
||||
@@ -1893,7 +1915,7 @@ function forecastBusinessPlanBase(
|
||||
);
|
||||
if (rate < 0n || rate > 100_000_000n)
|
||||
throw new Error(
|
||||
'A percentagem de recuperação deve estar entre 0 e 100.',
|
||||
'Percentagem de recuperação: Introduza uma percentagem entre 0% e 100%.',
|
||||
);
|
||||
salesRecoveryRates.set(entry.month, rate);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user