diff --git a/resources/js/components/financial-plan-details.tsx b/resources/js/components/financial-plan-details.tsx
index c9a268ac..ff784fd0 100644
--- a/resources/js/components/financial-plan-details.tsx
+++ b/resources/js/components/financial-plan-details.tsx
@@ -30,6 +30,26 @@ export function FinancialPlanDetails({
Crescimento, despesas discriminadas, capital e dividendos
+
+ Prazo de recebimento a crédito (dias, quando conhecido)
+
+ onChange({ ...plan, creditTermDays: e.target.value })
+ }
+ />
+
+
+ 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.
+
Fonte do relatório financeiro consolidado
typeof v === 'string' && v.length <= 160;
+ if (
+ plan.creditTermDays !== undefined &&
+ !shortText(plan.creditTermDays)
+ )
+ return null;
const amounts = (v: unknown) =>
Array.isArray(v) && v.length <= 60 && v.every(shortText);
if (
@@ -1406,6 +1414,12 @@ export function compareBusinessScenarios(input: BusinessFinancialPlanInput) {
/** Forecast separates invoiced sales, collections, accounting expenses and cash payments. */
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) {
const f = input.fundingBreakdown;
const total =
diff --git a/resources/js/lib/financial-plan-warnings.ts b/resources/js/lib/financial-plan-warnings.ts
index d2d21f0a..21a54a44 100644
--- a/resources/js/lib/financial-plan-warnings.ts
+++ b/resources/js/lib/financial-plan-warnings.ts
@@ -38,6 +38,7 @@ export function financialPlanWarningMetrics(
: undefined;
const metrics: PlanWarningMetrics = {
currency: plan.currency,
+ creditDays: inputCreditDays(plan.creditTermDays),
fundingGap:
year === 0
? read('funding', 'Diferença por financiar', 1)
@@ -97,7 +98,10 @@ export function financialPlanWarnings(
id: `${year}-${w.id}`,
message: `${year}: ${w.message}`,
}));
- if ((plan.salesCollectionLagMonths ?? 0) > 3)
+ if (
+ inputCreditDays(plan.creditTermDays) === undefined &&
+ (plan.salesCollectionLagMonths ?? 0) > 3
+ )
warnings.push({
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.`,
@@ -106,3 +110,9 @@ export function financialPlanWarnings(
},
);
}
+
+function inputCreditDays(value: string | undefined) {
+ return value && /^\d+$/.test(value) && Number(value) <= 365
+ ? Number(value)
+ : undefined;
+}
diff --git a/tests/frontend/financial-plan-pending-requirements.test.mjs b/tests/frontend/financial-plan-pending-requirements.test.mjs
index 6496f738..a062f05b 100644
--- a/tests/frontend/financial-plan-pending-requirements.test.mjs
+++ b/tests/frontend/financial-plan-pending-requirements.test.mjs
@@ -398,6 +398,10 @@ void test('actual editor controls preserve declarations through snapshot reload
target: { checked: 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('Dividendos, mês 1').props.onChange({ target: { value: '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.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/,
+ );
+ }
+});