fix(qa): evaluate credit warnings from declared contractual days

This commit is contained in:
2026-11-20 15:03:55 +02:00
parent 9c34af0406
commit 19f06ddfe1
4 changed files with 74 additions and 1 deletions
@@ -30,6 +30,26 @@ export function FinancialPlanDetails({
<summary className="font-semibold"> <summary className="font-semibold">
Crescimento, despesas discriminadas, capital e dividendos Crescimento, despesas discriminadas, capital e dividendos
</summary> </summary>
<label className="grid gap-1 text-sm">
Prazo de recebimento a crédito (dias, quando conhecido)
<input
type="number"
min="0"
max="365"
step="1"
className="min-w-0 rounded border p-2"
value={plan.creditTermDays ?? ''}
onChange={(e) =>
onChange({ ...plan, creditTermDays: e.target.value })
}
/>
</label>
<p className="text-sm">
O prazo contratual declarado permite avaliar o aviso acima de 90
dias. As cobranças de caixa conservam a agenda mensal
introduzida; não se presume que um mês tenha 30 dias. Confira a
compatibilidade entre contrato e cobranças previstas.
</p>
<label className="grid gap-1"> <label className="grid gap-1">
Fonte do relatório financeiro consolidado Fonte do relatório financeiro consolidado
<select <select
@@ -119,6 +119,7 @@ export type BusinessFinancialPlanInput = {
annualGrowthPercent?: string; annualGrowthPercent?: string;
/** Explicit opt-in; saved forecasts without this choice retain their values. */ /** Explicit opt-in; saved forecasts without this choice retain their values. */
applyAnnualGrowth?: boolean; applyAnnualGrowth?: boolean;
creditTermDays?: string;
dividendsByPeriod?: string[]; dividendsByPeriod?: string[];
operatingExpenseLines?: { operatingExpenseLines?: {
label: string; label: string;
@@ -196,6 +197,7 @@ export function serializeBusinessPlanSnapshot(
const snapshot = JSON.stringify({ const snapshot = JSON.stringify({
version: [ version: [
'applyAnnualGrowth', 'applyAnnualGrowth',
'creditTermDays',
'dividendsByPeriod', 'dividendsByPeriod',
'operatingExpenseLines', 'operatingExpenseLines',
'fundingBreakdown', 'fundingBreakdown',
@@ -298,6 +300,7 @@ export function restoreBusinessPlanSnapshot(
decoded.version < 18 && decoded.version < 18 &&
[ [
'applyAnnualGrowth', 'applyAnnualGrowth',
'creditTermDays',
'dividendsByPeriod', 'dividendsByPeriod',
'operatingExpenseLines', 'operatingExpenseLines',
'fundingBreakdown', 'fundingBreakdown',
@@ -307,6 +310,11 @@ export function restoreBusinessPlanSnapshot(
return null; return null;
const shortText = (v: unknown) => const shortText = (v: unknown) =>
typeof v === 'string' && v.length <= 160; typeof v === 'string' && v.length <= 160;
if (
plan.creditTermDays !== undefined &&
!shortText(plan.creditTermDays)
)
return null;
const amounts = (v: unknown) => const amounts = (v: unknown) =>
Array.isArray(v) && v.length <= 60 && v.every(shortText); Array.isArray(v) && v.length <= 60 && v.every(shortText);
if ( if (
@@ -1406,6 +1414,12 @@ export function compareBusinessScenarios(input: BusinessFinancialPlanInput) {
/** Forecast separates invoiced sales, collections, accounting expenses and cash payments. */ /** Forecast separates invoiced sales, collections, accounting expenses and cash payments. */
export function forecastBusinessPlan(input: BusinessFinancialPlanInput) { export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
if (
input.creditTermDays?.trim() &&
(!/^\d+$/.test(input.creditTermDays) ||
Number(input.creditTermDays) > 365)
)
throw new Error('Indique um prazo entre 0 e 365 dias.');
if (input.fundingBreakdown) { if (input.fundingBreakdown) {
const f = input.fundingBreakdown; const f = input.fundingBreakdown;
const total = const total =
+11 -1
View File
@@ -38,6 +38,7 @@ export function financialPlanWarningMetrics(
: undefined; : undefined;
const metrics: PlanWarningMetrics = { const metrics: PlanWarningMetrics = {
currency: plan.currency, currency: plan.currency,
creditDays: inputCreditDays(plan.creditTermDays),
fundingGap: fundingGap:
year === 0 year === 0
? read('funding', 'Diferença por financiar', 1) ? read('funding', 'Diferença por financiar', 1)
@@ -97,7 +98,10 @@ export function financialPlanWarnings(
id: `${year}-${w.id}`, id: `${year}-${w.id}`,
message: `${year}: ${w.message}`, message: `${year}: ${w.message}`,
})); }));
if ((plan.salesCollectionLagMonths ?? 0) > 3) if (
inputCreditDays(plan.creditTermDays) === undefined &&
(plan.salesCollectionLagMonths ?? 0) > 3
)
warnings.push({ warnings.push({
id: `${year}-credit`, id: `${year}-credit`,
message: `${year}: O prazo de recebimento é superior a três meses no modelo mensal e pressiona a caixa. Confirme o prazo indicado.`, message: `${year}: O prazo de recebimento é superior a três meses no modelo mensal e pressiona a caixa. Confirme o prazo indicado.`,
@@ -106,3 +110,9 @@ export function financialPlanWarnings(
}, },
); );
} }
function inputCreditDays(value: string | undefined) {
return value && /^\d+$/.test(value) && Number(value) <= 365
? Number(value)
: undefined;
}
@@ -398,6 +398,10 @@ void test('actual editor controls preserve declarations through snapshot reload
target: { checked: true }, target: { checked: true },
}); });
assert.equal(plan.applyAnnualGrowth, true); assert.equal(plan.applyAnnualGrowth, true);
field('Prazo de recebimento a crédito').props.onChange({
target: { value: '91' },
});
assert.equal(plan.creditTermDays, '91');
field('Planear dividendos').props.onChange({ target: { checked: true } }); field('Planear dividendos').props.onChange({ target: { checked: true } });
field('Dividendos, mês 1').props.onChange({ target: { value: '12.25' } }); field('Dividendos, mês 1').props.onChange({ target: { value: '12.25' } });
assert.equal(plan.dividendsByPeriod[0], '12.25'); assert.equal(plan.dividendsByPeriod[0], '12.25');
@@ -411,3 +415,28 @@ void test('actual editor controls preserve declarations through snapshot reload
assert.equal(plan.dividendsByPeriod[0], '12.25'); assert.equal(plan.dividendsByPeriod[0], '12.25');
assert.equal(plan.products[0].monthlyUnits, '10'); assert.equal(plan.products[0].monthlyUnits, '10');
}); });
void test('the credit warning uses the declared 90-day boundary without converting or changing monthly cash flows', () => {
const p = financialReportFixture(12),
baseline = forecastBusinessPlan(p);
for (const days of ['0', '30', '90', '91', '365']) {
p.creditTermDays = days;
const restored = reload(p);
assert.equal(restored.creditTermDays, days);
assert.deepEqual(forecastBusinessPlan(restored), baseline);
assert.equal(
financialPlanWarnings(
restored,
buildIntegralFinancialTables(restored),
).some((w) => w.id.endsWith('-credit')),
Number(days) > 90,
);
}
for (const invalid of ['-1', '366', '30.5', 'abc']) {
p.creditTermDays = invalid;
assert.throws(
() => forecastBusinessPlan(p),
/prazo entre 0 e 365 dias/,
);
}
});