feat(finance): project PGC-PE supplier advances by operation in QA

This commit is contained in:
2026-11-21 10:42:41 +02:00
parent d1fcdcd947
commit c2a985dc6b
23 changed files with 2380 additions and 83 deletions
+60 -5
View File
@@ -4,6 +4,7 @@ import {
type BusinessFinancialPlanInput,
} from './business-financial-plan.ts';
import { calculateStartupAssetRequirements } from './startup-asset-requirements.ts';
import { advanceEventLabels } from './supplier-advances.ts';
export type InvestmentReportTable = {
id: string;
@@ -518,7 +519,10 @@ export function buildIntegralFinancialTables(
const opening = cash;
cash += netCash;
receivables +=
cents(row.revenue) - cents(row.cashCollections) + otherIncome;
cents(row.revenue) -
cents(row.cashCollections) +
otherIncome +
cents(result.supplierAdvanceLedger?.monthly[i].refunded ?? '0');
const purchases =
row.inventoryReceipts === null
? null
@@ -538,6 +542,13 @@ export function buildIntegralFinancialTables(
cents(row.payrollPayments) -
cents(row.interestPayment) -
cents(row.openingPayablesPayments);
const advance = cents(
result.supplierAdvanceLedger?.monthly[i].advance ?? '0',
);
obligations += cents(
result.supplierAdvanceLedger?.monthly[i].refunded ?? '0',
);
const grossObligations = obligations + advance;
taxDue += taxExpenses[i] - taxPayments[i];
depreciation += cents(row.depreciation);
principal += cents(row.principalRepayment);
@@ -566,11 +577,12 @@ export function buildIntegralFinancialTables(
fixed -
depreciation +
otherAssets +
positive(-obligations) +
positive(-grossObligations) +
advance +
positive(-taxDue);
const liabilities =
positive(-receivables) +
positive(obligations) +
positive(grossObligations) +
positive(taxDue) +
loans -
principal +
@@ -581,7 +593,8 @@ export function buildIntegralFinancialTables(
opening,
cash,
receivables,
obligations: obligationsKnown ? obligations : null,
obligations: obligationsKnown ? grossObligations : null,
advance,
taxDue,
profit,
netCash,
@@ -679,7 +692,12 @@ export function buildIntegralFinancialTables(
for (const [key, label] of [
['cash', 'Caixa líquida'],
['receivables', 'Recebíveis líquidos'],
['obligations', 'Obrigações operacionais líquidas'],
[
'obligations',
result.supplierAdvanceLedger
? 'Obrigações operacionais brutas'
: 'Obrigações operacionais líquidas',
],
['taxDue', 'Saldo fiscal estimado'],
['fixed', 'Activos fixos líquidos'],
['loans', 'Empréstimos e suprimentos por reembolsar'],
@@ -694,6 +712,43 @@ export function buildIntegralFinancialTables(
label,
ledger.map((row) => row[key]),
);
if (result.supplierAdvanceLedger) {
stocks(
'balance',
'Adiantamentos identificados a fornecedores',
ledger.map((row) => row.advance),
);
stocks(
'balance',
'Líquido por liquidar — operações identificadas',
result.supplierAdvanceLedger.monthly.map((row) =>
cents(row.netDue),
),
);
for (const [key, label] of [
['paid', 'Adiantamentos pagos'],
['applied', 'Aplicações sem movimento de caixa'],
['refunded', 'Devoluções de adiantamentos'],
['settled', 'Remanescentes pagos'],
] as const)
flows(
'cashflow',
label + ' (discriminação)',
result.supplierAdvanceLedger.monthly.map((row) =>
cents(row[key]),
),
);
table('balance').notes.push(
'PGC-PE: adiantamentos identificados apresentados no activo, separados das obrigações brutas. Líquido por liquidar é calculado por operação/parcela, sem compensação entre operações. Devoluções não são receita; aplicações não movimentam caixa.',
);
table('cashflow').notes.push(
'Adiantamentos, aplicações, devoluções e remanescentes são projecções discriminadas, já incluídas nos totais de caixa quando aplicável; não somar novamente. Sem automatização de IVA, câmbio, perdas, penalizações ou contratos especiais.',
...result.supplierAdvanceLedger.operations.map(
(o) =>
`${o.originId}/${o.parcelId} — ${o.supplier}: reconhecimento ${o.recognitionDate || 'por confirmar'}; factura ${o.invoiceDate || 'por confirmar'}. ${o.events.map((e) => `${advanceEventLabels[e.kind]}: ${e.date}, ${e.amount} ${plan.currency}${e.outsideHorizon ? ' (fora do horizonte)' : ''}`).join('; ')}.`,
),
);
}
table('balance').rows.push([
'Existências',
...ledger.map((row) =>