What it's for
A quote or invoice gets rebuilt every time in a word processor, with the risk of a calculation error or a forgotten VAT. This script produces the document from a small JSON file: lines, discounts, VAT, total, validity or due date. You keep the data (the JSON) and generate the layout whenever you like.
Before you start
- A JSON file describing the document (see
samples/devis.json). - The currency (
XOF,EUR…): amounts are rounded to its decimals (0 for the CFA franc, 2 for the euro).
Step by step
- Copy the example and adapt seller, client and lines:
cp samples/devis.json my-quote.json - Generate a Markdown document, or an HTML page you can print to PDF from the browser:
node scripts/26-quote-invoice.mjs my-quote.json --format html --out quote.html - For an invoice, set
"type": "facture": the heading becomes "FACTURE" and the validity date becomes a due date.
Reading the output
Each line = quantity × price, minus the discount in %. The subtotal is the sum of lines; VAT applies to the subtotal; the amount due is their sum. The deadline is date + dueDays.
Automating it
Connect it to your entry tool: one line per service in a spreadsheet → JSON → document. Numbering (number) stays your responsibility: keep an unbroken sequence.
Pitfalls
- Mandatory legal mentions (tax ID, payment terms) depend on your country: add them in
notesandseller. - The script calculates, it does not store anything: archive the documents you issue.
- The document text itself is in French.