mega-plant/lib/invoice-booking-policy.json

7 lines
861 B
JSON
Raw Normal View History

Invoices: line-item extraction, booking to plant items, VAT-inclusive income Adds an Invoices sub-menu under /income with a summary table (one row per invoice, click to expand the full detail) and the data model behind it. Data: - invoices + invoice_lines PocketBase collections, created idempotently by scripts/setup-invoice-collections.mjs - line items transcribed from PHI 166/167/171 with per-invoice arithmetic validation in the seed; a bad invoice is refused without blocking the rest - invoice-*.json in data/source are auto-imported, so adding an invoice is one file Booking: - manual book-in per line (Booked to), grouped by category - POST /api/invoice-lines/:id/book moves the income row rather than adding a second one, so a booking can be changed freely - scripts/book-invoice.mjs is idempotent: rows are stamped with monthly_income.invoice_line and replaced on re-run - booked amount follows lib/invoice-booking-policy.json (bookInclusiveVat), read by both the app and the CLI so they cannot disagree Money: - the R24,205.13 column on these invoices is PLUS VAT, not escalation. The seed now rejects VAT that disagrees with the stated rate. - booked amounts are VAT-inclusive per the client ruling of 2026-10-01; the VAT stays visible rather than hidden. Uploads: - drag-and-drop PDF attached to invoices.source_pdf - GET /api/invoices/:id/document proxies it — the collection is rule-locked, so a direct PocketBase /api/files link 404s in a browser Fixes a month-aggregation bug this introduced: buildIncomeRows assigned into months[i], so a machine with two income rows in one month (one per invoice, which is normal multi-site use) showed only the last. SS01 September read R20,700 instead of R35,305 while its own YTD included both. Months now accumulate, per-month profit is computed once after accumulation, and lib/rows.test.ts pins it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-10-01 13:59:30 +00:00
{
"_comment": "SINGLE SOURCE OF TRUTH for how invoice line amounts are treated when booked. Read by BOTH the Next.js app (lib/invoice-booking.ts) and the CLI scripts (scripts/book-invoice.mjs) so the two can never drift apart. To flip, change bookInclusiveVat and re-run: npm run seed && node scripts/book-invoice.mjs",
"_ruling": "Client decision 2026-10-01: invoice amounts are booked to a machine VAT-INCLUSIVE. This is the amount the debtor actually pays and it is what the overview totals show as booked income.",
"_consequence": "Booked income now includes SARS output VAT. On the September 2026 set that is R29,935.13 of VAT inside R229,502.63. If a VAT-excl. P&L is ever needed, set bookInclusiveVat back to false and re-run the booking — the VAT is still stored per line in invoice_lines.vat, so nothing is lost.",
"bookInclusiveVat": true
}