fix: target literal financial diagnostics and document V09 QA coverage

This commit is contained in:
2026-11-21 21:40:56 +02:00
parent b20feeb72e
commit 77f621b48d
34 changed files with 924 additions and 8 deletions
+17 -2
View File
@@ -1,5 +1,6 @@
import {
forecastBusinessPlan,
businessPlanNumberError,
type BusinessFinancialPlanInput,
} from './business-financial-plan.ts';
import {
@@ -272,11 +273,18 @@ export function buildComplementaryTables(
!r.responsible?.trim() ||
!r.department?.trim() ||
!date(r.start_date ?? '') ||
!date(r.due_date) ||
!date(r.due_date)
)
milestones.issues.push(
`Marco ${i + 1}: complete título, responsável, departamento e datas de início/término válidas.`,
);
if (
date(r.start_date ?? '') &&
date(r.due_date) &&
r.start_date! > r.due_date
)
milestones.issues.push(
`Marco ${i + 1}: complete título, responsável, departamento e datas de início/término válidas e ordenadas.`,
`Marcos / Marco ${i + 1} / «Prazo previsto»: A data de término não pode ser anterior à data de início.`,
);
milestones.rows.push([
r.title || unknown,
@@ -354,6 +362,13 @@ export function buildComplementaryTables(
try {
if (!r.competency.trim() || !r.department?.trim())
throw Error('Indique função e departamento.');
const quantityError = businessPlanNumberError(r.quantity ?? '', {
integer: true,
});
if (quantityError)
throw Error(
`«Quantidade de pessoas (inteiro)»: ${quantityError}`,
);
const count = integer(r.quantity, 0, 1000000),
salary = amount(r.monthly_salary),
start = integer(r.start_month, 1, periods),
+75 -2
View File
@@ -82,10 +82,82 @@ export function financialPlanWarningMetrics(
});
}
/** Presentation of already-calculated monthly values; never produces or changes amounts. */
function periodGuidance(
plan: BusinessFinancialPlanInput,
tables: InvestmentReportTable[],
) {
if (plan.reportSource === 'annual_example') return [];
const salesTable = tables.find((t) => t.id === 'sales');
const costsTable = tables.find((t) => t.id === 'profit-loss');
const read = (
table: InvestmentReportTable | undefined,
label: string,
col: number,
) => {
if (!table || table.issues.length) return undefined;
const value = table?.rows.find((row) => row[0] === label)?.[col];
return typeof value === 'string' && /^-?\d+\.\d{2}$/.test(value)
? BigInt(value.replace('.', ''))
: undefined;
};
const noContribution: string[] = [],
missingSales: string[] = [];
for (let col = 1; col <= (plan.periods ?? 12); col++) {
const sales = read(salesTable, 'Vendas totais', col),
cost = read(costsTable, 'Custo directo', col);
const period = (salesTable?.headers[col] ?? `Mês ${col}`).replace(
/^(\d{4})-(\d{2})$/,
'$2/$1',
);
if (
sales !== undefined &&
sales > 0n &&
cost !== undefined &&
cost >= sales
)
noContribution.push(period);
if (
sales === 0n &&
[
'Custo directo',
'Despesas operacionais',
'Pessoal',
'Depreciação',
'Juros',
'Imposto estimado',
].some((label) => {
const value = read(costsTable, label, col);
return value !== undefined && value > 0n;
})
)
missingSales.push(period);
}
return [
...(noContribution.length
? [
{
id: 'period-no-contribution',
message: `Com este custo variável não há margem para cobrir os custos fixos. Reveja o custo variável ou o preço. Períodos a rever: ${noContribution.join(', ')}.`,
},
]
: []),
...(missingSales.length
? [
{
id: 'period-sales-required',
message: `Indique as vendas previstas para calcular a margem e o ponto de equilíbrio. Períodos a rever: ${missingSales.join(', ')}.`,
},
]
: []),
];
}
export function financialPlanWarnings(
plan: BusinessFinancialPlanInput,
tables: InvestmentReportTable[],
) {
const periodWarnings = periodGuidance(plan, tables);
const annualWarnings = financialPlanWarningMetrics(plan, tables).flatMap(
({ year, metrics, count }) => {
// The warning helper compares a full year's sales to a monthly threshold.
@@ -121,7 +193,8 @@ export function financialPlanWarnings(
);
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;
if (!cashflow || cashflow.issues.length || !closing)
return [...annualWarnings, ...periodWarnings];
const months = [
'Janeiro',
'Fevereiro',
@@ -154,7 +227,7 @@ export function financialPlanWarnings(
},
];
});
return [...annualWarnings, ...monthlyWarnings];
return [...annualWarnings, ...periodWarnings, ...monthlyWarnings];
}
function inputCreditDays(value: string | undefined) {