Hub 2.0 step 4: billing per customer

- One invoice per customer per period for all its products; the schedule
  moves from Licence to Customer (migration copies it, so billing carries
  on unchanged); licences get billedFrom / billedUntil
- Website (R99, 5 GB) and App (on active members) prices next to the
  Events tiers; founding prices per product, then bundles (15% two, 25%
  three); extra website storage R20 per 5 GB, never discounted
- A product added to a billed customer starts after its free month; days
  before its first full period are prorated, never charged twice
- Annual review per product (Events income, App members), one notice of
  licence change per product; invoices, PDFs and emails name products
- Customer page: schedule, per-product billing, next-invoice preview
- Invoices from before 2.0 kept as they were (still recalculable)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 16:18:23 +02:00
co-authored by Claude Opus 5.5
parent 937c1fa38e
commit 7478e84e9d
21 changed files with 1081 additions and 316 deletions
+20 -11
View File
@@ -70,15 +70,24 @@ 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
2. **Per church** (customer page → Billing; Hub 2.0: **one invoice per church for all its products**):
founding church (35% off every tier), billing email and postal address, the **billing schedule**
(monthly or yearly — 10 months' price for 12 —, the date billing started, whose day of the month
is the billing day, the next invoice date and the next annual tier review), and for each product
the date it's **charged from** (blank = not charged, e.g. a trial; Accounts is always free) and an
optional custom monthly price (e.g. a Network tier). **Next invoice** shows the next draft as it
would be made today.
3. **The job** (every 15 minutes): **14 days** before a church's next invoice date it drafts the
invoice and emails it to you with the draft PDF. Each product is a line at its price; a founding
church gets the founding price as a line under each; **bundles** take 15% off two products and 25%
off three (after founding); **extra website storage** (R20 per 5 GB above 5 GB, from the website's
heartbeat) is added last and never discounted (12 months' price on a yearly invoice). A product
added to a church that's billed already gets its **free month**, then the days before its first
full period are charged by the day (a year's price over 365 days). At the yearly **review** the
draft uses what each product reports — Cross Events its 12-month event-income band (2.0.2+), the
App its active-member band — and can move each tier up or down; drafts in between keep the tiers.
**Approve** it on Billing (you can change its lines, dates, recipient and notes first); each 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.
@@ -89,8 +98,8 @@ the emails, `index.js` the job and actions) and `backend/src/routes/billing.js`.
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>`
included. The prices of every product 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