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
+23 -3
View File
@@ -86,11 +86,16 @@ function assertForecastReconciles(forecast: Forecast): void {
);
previousOpeningReceivables = openingReceivablesBalance;
totalOpeningReceivablesCollections += openingReceivablesCollections;
const advanceRefund = cents(
forecast.supplierAdvanceLedger?.monthly[row.month - 1].refunded ??
'0',
);
const otherCollections =
row.otherCollections === null
? cents(String(row.cashCollections)) -
salesCollections -
openingReceivablesCollections
openingReceivablesCollections -
advanceRefund
: cents(String(row.otherCollections));
if (otherCollections < 0n)
throw new Error(
@@ -100,7 +105,10 @@ function assertForecastReconciles(forecast: Forecast): void {
const collections = cents(String(row.cashCollections));
if (
collections !==
salesCollections + openingReceivablesCollections + otherCollections
salesCollections +
openingReceivablesCollections +
otherCollections +
advanceRefund
)
throw new Error(
'As cobranças mensais não reconciliam com as suas origens.',
@@ -260,8 +268,20 @@ export function buildFinancialFiscalBridge(forecast: Forecast) {
(row.salesCollections === null
? 0n
: cents(row.salesCollections)) -
cents(row.openingReceivablesCollections),
cents(row.openingReceivablesCollections) -
cents(
forecast.supplierAdvanceLedger?.monthly[
row.month - 1
].refunded ?? '0',
),
),
...(forecast.supplierAdvanceLedger
? {
supplierAdvanceRefunds:
forecast.supplierAdvanceLedger.monthly[row.month - 1]
.refunded,
}
: {}),
collections: row.cashCollections,
collectionsTotal: row.cashCollections,
salesReceivablesBalance: row.salesReceivablesClosing,