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
@@ -119,6 +119,7 @@ export type BusinessFinancialPlanInput = {
annualGrowthPercent?: string;
/** Explicit opt-in; saved forecasts without this choice retain their values. */
applyAnnualGrowth?: boolean;
creditTermDays?: string;
dividendsByPeriod?: string[];
operatingExpenseLines?: {
label: string;
@@ -196,6 +197,7 @@ export function serializeBusinessPlanSnapshot(
const snapshot = JSON.stringify({
version: [
'applyAnnualGrowth',
'creditTermDays',
'dividendsByPeriod',
'operatingExpenseLines',
'fundingBreakdown',
@@ -298,6 +300,7 @@ export function restoreBusinessPlanSnapshot(
decoded.version < 18 &&
[
'applyAnnualGrowth',
'creditTermDays',
'dividendsByPeriod',
'operatingExpenseLines',
'fundingBreakdown',
@@ -307,6 +310,11 @@ export function restoreBusinessPlanSnapshot(
return null;
const shortText = (v: unknown) =>
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 =
+11 -1
View File
@@ -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;
}