Billing: invoices, approval, receipts, statements, licence changes (1.7.0)

- Invoices drafted 14 days before each licence's invoice date and emailed
  to the alert email for approval; approved ones go out on their date from
  08:00 SA time. Drafts can be edited, recalculated, sent early, put back
  to draft or voided; one-off invoices too.
- Annual tier review from the 12-month event-income band; approving a tier
  change emails a notice of licence change, applied when the invoice goes out.
  Notices can also be sent by hand.
- Founding churches (35% off as its own line), payments with receipts,
  statements for any dates.
- Every billing email is styled HTML with a PDF (invoice / tax invoice,
  receipt, statement, licence change) and logged per customer.
- Settings -> Billing: business and bank details, VAT (off: plain invoices;
  on: VAT-inclusive tax invoices), timing and numbering.
- Migration 20261103111645_invoicing; pdfkit 0.17.2; tests/billing.test.js;
  scripts/sample-billing-pdfs.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-03 13:42:45 +02:00
co-authored by Claude Opus 5.5
parent cc7d62690b
commit 6fce0fe90e
33 changed files with 3579 additions and 53 deletions
+31
View File
@@ -62,6 +62,37 @@ optional markup override, on the customer's page. The cap counts what the church
Use per site (real cost, charged, profit) is on Settings → AI and on each install's page. No prompt
or response text is stored.
## Billing (1.7.0)
Invoices, receipts, statements and notices of licence change, each emailed (styled HTML) with a PDF.
The code is in `backend/src/utils/billing/` (`compute.js` the rules, `pdf.js` the documents, `email.js`
the emails, `index.js` the job and actions) and `backend/src/routes/billing.js`.
1. **Set up** Settings → **Billing**: business and banking details, VAT, timing and numbering. Set the
**alert email** (Settings → Alerts): approval requests go there. SMTP must work.
2. **Per church** (customer page → Billing): founding church (35% off every tier), billing email and
postal address, and for each licence: monthly or yearly (10 months' price for 12), the date billing
started (its day of the month is the billing day), the next invoice date, the next annual tier
review and an optional custom monthly price (e.g. the Network tier).
3. **The job** (every 15 minutes): **14 days** before a licence's next invoice date it drafts the
invoice and emails it to you with the draft PDF. At the yearly **review** the draft uses the site's
12-month event-income band (Cross Events 2.0.2+) and can move the tier up or down; drafts in between
keep the tier. **Approve** it on Billing (you can change its lines, dates, recipient and notes
first); a tier change sends the church a notice of licence change at once. Approved invoices go out
**on their date from 08:00** (South African time) to the billing email, else the site's admin
contact, else the customer's email; the tier change takes effect when that invoice goes out. If a
date comes and it isn't approved, you're emailed once and it waits.
4. **Payments**: Billing → Record payment (or on an invoice or customer). A receipt is emailed with
its PDF unless you untick it. **Statements**: customer page → Billing → Statement (any dates;
open the PDF or email it). One-off invoices (e.g. standby support): Billing → One-off invoice.
Invoices are **in advance** (the invoice dated the 1st covers that month). **VAT**: not registered →
plain invoices with no VAT; once registered, tick it in Settings → Billing: prices are then
VAT-inclusive (totals unchanged), documents become tax invoices with the VAT number and the VAT
included. The tiers are in `backend/src/utils/billing/tiers.js` and `frontend/src/lib/tiers.ts` (a test
checks they match) and on crosscode-site `src/data/pricing.mjs`. `node backend/scripts/sample-billing-pdfs.js <dir>`
writes sample PDFs (no database needed) to check the layout.
## The licence signing key
Licences are tokens signed with an Ed25519 key. **The private key exists only on the Hub server**;