invoicing
Invoicing: numbered VAT invoices, corrections and a PDF
An invoicing module issues a document, numbers it, lets it be corrected, and prints it. The idea the design turns on: an issued invoice is a fact, not a record. It is numbered once, by the database, inside the write that creates it; it carries its own copy of both parties; and from then on nothing edits it. A mistake is answered with another document. Everything else in the module follows from holding that.
Written by the engineer who has shipped this module. The earlier implementation it was audited against was an invoicing section in a multi-tenant business application on Postgres. The facts and rules below are what the suites and the database checks verify; provenance.md has the record.
When to use
A Next.js App Router app that sells something and must hand the buyer a VAT invoice: issued by staff in an admin area, standalone or from a sale, order or booking the app already holds; corrected when wrong; downloaded or e-mailed as PDF; and, in Poland, sent to KSeF.