/** * Writes sample billing PDFs (invoice, receipt, statement, licence change) with made-up data, to * check the layout after changing utils/billing/pdf.js: `node scripts/sample-billing-pdfs.js [dir]`. * Needs no database. */ const fs = require('fs'); const path = require('path'); const { DEFAULTS } = require('../src/utils/settings'); const pdf = require('../src/utils/billing/pdf'); const { draftCustomerInvoice, invoiceState, statement } = require('../src/utils/billing/compute'); const out = path.resolve(process.argv[2] || 'billing-samples'); fs.mkdirSync(out, { recursive: true }); const settings = { ...DEFAULTS, bank_name: 'Sample Bank', bank_account_name: 'Cross Code', bank_account_number: '1234 567 890', bank_branch_code: '250655', bank_account_type: 'Cheque' }; // A founding church with all three products at its annual review: Events moves up a tier, the App // joined part-way through December, and the website uses 7 GB. const customer = { id: 'c1', name: 'Cedarwood Community Church', contactName: 'Thandi Nkosi', billingAddress: '12 Oak Street, Meyerton, 1961', email: 'office@cedarwood.example', founding: true, billingCycle: 'monthly', billingStart: new Date('2026-01-01'), nextInvoiceDate: new Date('2027-01-01'), reviewDate: new Date('2027-01-01'), }; const GB = 1024 ** 3; const licences = [ { id: 'l1', product: 'events', status: 'active', plan: 'Sprout', customMonthlyCents: null, billedFrom: new Date('2026-01-01'), billedUntil: new Date('2026-12-31'), install: { product: 'events', adminContact: { email: 'admin@cedarwood.example' }, stats: { income: { eventIncome12m: 'R250 001–R400 000' } } } }, { id: 'l2', product: 'website', status: 'active', plan: 'Website', customMonthlyCents: null, billedFrom: new Date('2026-06-01'), billedUntil: new Date('2026-12-31'), install: { product: 'website', stats: { storage: { usedBytes: 7 * GB, includedBytes: 5 * GB } } } }, { id: 'l3', product: 'app', status: 'active', plan: 'Mustard Seed', customMonthlyCents: null, billedFrom: new Date('2026-12-15'), billedUntil: null, install: { product: 'app', stats: { activeMembers90d: '0–100' } } }, ]; (async () => { const { invoice: draft } = draftCustomerInvoice({ customer, licences, settings }); const invoice = { ...draft, id: 'i1', number: 'INV-2027-0001', status: 'sent', notes: null }; const payment = { id: 'p1', receiptNumber: 'REC-2027-0001', amountCents: 30000, paidOn: new Date('2027-01-05'), method: 'eft', reference: 'INV-2027-0001' }; const state = invoiceState({ ...invoice, payments: [payment] }, '2027-01-06'); fs.writeFileSync(path.join(out, 'invoice.pdf'), await pdf.invoicePdf({ invoice, customer, settings, state })); fs.writeFileSync(path.join(out, 'invoice-draft.pdf'), await pdf.invoicePdf({ invoice: { ...invoice, status: 'draft' }, customer, settings, state: invoiceState({ ...invoice, payments: [] }, '2027-01-06') })); fs.writeFileSync(path.join(out, 'receipt.pdf'), await pdf.receiptPdf({ payment, customer, invoice, state, settings, recipientEmail: invoice.recipientEmail })); const older = { ...invoice, number: 'INV-2026-0012', issueDate: new Date('2026-12-01'), dueDate: new Date('2026-12-08'), periodStart: new Date('2026-12-01'), periodEnd: new Date('2026-12-31'), totalCents: 36000, payments: [] }; const st = statement({ invoices: [older, { ...invoice, payments: [payment] }], payments: [{ ...payment, invoice }], from: '2026-12-15', to: '2027-01-31' }); fs.writeFileSync(path.join(out, 'statement.pdf'), await pdf.statementPdf({ statement: st, customer, settings, recipientEmail: invoice.recipientEmail })); const change = { number: 'LC-2026-0001', fromPlan: 'Sprout', toPlan: 'Grow', fromMonthlyCents: 55000, toMonthlyCents: 85000, effectiveDate: new Date('2027-01-01'), incomeBand: 'R250 001–R400 000', createdAt: new Date('2026-12-18') }; fs.writeFileSync(path.join(out, 'licence-change.pdf'), await pdf.licenceChangePdf({ change, customer, settings, founding: true, recipientEmail: invoice.recipientEmail, cycle: 'monthly', product: 'events' })); console.log(`samples in ${out}`); })();