fix(qa): identify every negative cash month in V11 warnings

This commit is contained in:
2026-11-20 21:38:39 +02:00
parent 63e211a36b
commit fe615e5572
4 changed files with 278 additions and 3 deletions
+41 -2
View File
@@ -3,7 +3,10 @@ import {
businessPlanWarnings,
type PlanWarningMetrics,
} from './business-plan-guidance.ts';
import type { InvestmentReportTable } from './integral-financial-report.ts';
import {
displayReportMoney,
type InvestmentReportTable,
} from './integral-financial-report.ts';
/** Only use determined values from the same tables/version, never replace missing amounts by zero. */
export function financialPlanWarningMetrics(
@@ -83,7 +86,7 @@ export function financialPlanWarnings(
plan: BusinessFinancialPlanInput,
tables: InvestmentReportTable[],
) {
return financialPlanWarningMetrics(plan, tables).flatMap(
const annualWarnings = financialPlanWarningMetrics(plan, tables).flatMap(
({ year, metrics, count }) => {
// The warning helper compares a full year's sales to a monthly threshold.
const adjusted = {
@@ -113,6 +116,42 @@ export function financialPlanWarnings(
return warnings;
},
);
const cashflow = tables.find((table) => table.id === 'cashflow');
const closing = cashflow?.rows.find((row) => row[0] === 'Caixa final');
if (!cashflow || cashflow.issues.length || !closing) return annualWarnings;
const months = [
'Janeiro',
'Fevereiro',
'Março',
'Abril',
'Maio',
'Junho',
'Julho',
'Agosto',
'Setembro',
'Outubro',
'Novembro',
'Dezembro',
];
const monthlyWarnings = closing
.slice(1, (plan.periods ?? 12) + 1)
.flatMap((value, index) => {
const period = cashflow.headers[index + 1];
const calendar = /^(\d{4})-(0[1-9]|1[0-2])$/.exec(period ?? '');
if (
!calendar ||
!/^-\d+\.\d{2}$/.test(value) ||
BigInt(value.replace('.', '')) >= 0n
)
return [];
return [
{
id: `cash-negative-${period}`,
message: `O saldo de caixa fica negativo em ${months[Number(calendar[2]) - 1]} de ${calendar[1]}: ${displayReportMoney(value)} ${plan.currency}. Reveja os pagamentos, os prazos de crédito ou o financiamento.`,
},
];
});
return [...annualWarnings, ...monthlyWarnings];
}
function inputCreditDays(value: string | undefined) {