Backend:
- app/services/invoice_pdf.py: Jinja2+WeasyPrint PDF generation, saves to
/app/data/invoices/{id}.pdf, updates Invoice.pdf_path
- app/templates/invoice.html: professional branded A4 invoice template with
school details, line items table, totals, payment instructions, paid receipt
- routers/billing.py: GET /invoices/{id}/pdf (auto-generate on demand, FileResponse),
POST /invoices/{id}/mark-paid (payment_method + reference → status=paid),
POST /trigger-generate-invoices (manual trigger), school_name in invoice list
- tasks/billing.py: fix missing func import in generate_monthly_invoices,
new billing.generate_invoice_pdf Celery task, auto-send email after
invoice creation, check_overdue upgraded with 7-day warning emails and
30-day school suspension + suspension email
Frontend:
- BillingPage.vue: full rewrite — status filter tabs, school names (not UUIDs),
PDF download button, mail icon, Mark Paid modal with method/reference fields,
overdue rows highlighted, pagination, Generate Invoices trigger button
- api.ts: markInvoicePaid, downloadInvoicePdf, triggerGenerateInvoices
1.8 KiB
1.8 KiB
Phase 08: Billing Engine + Invoice PDF
Status: Complete Completed: 2026-03-16
Goal
Automated monthly invoice generation, PDF export, mark-as-paid workflow, and overdue escalation.
What was built
Backend
billing/invoice_pdf.py (new service)
generate_invoice_pdf(invoice_id)— renders Jinja2 HTML template → WeasyPrint PDF- Stores at
/app/data/invoices/{invoice_id}.pdf - Sets
Invoice.pdf_pathin DB
templates/invoice.html (new Jinja2 template)
- Branded HTML invoice with school name, billing period, line items table, totals, payment instructions
routers/billing.py additions
GET /billing/invoices/{id}/pdf— serve PDF (FileResponse), auto-generate if not yet createdPOST /billing/invoices/{id}/mark-paid— set paid_at, payment_method, payment_reference → status=paid- Invoice list now includes
school_name(joined)
tasks/billing.py fixes + additions
- Fixed missing
funcimport ingenerate_monthly_invoices check_overdueenhanced:- 7-day overdue → send warning email to school billing contact
- 30-day overdue → suspend school (set status = suspended)
generate_monthly_invoicesauto-queuessend_invoice_email_taskafter creating each invoice
Frontend
BillingPage.vue — full rewrite
- Invoice table with school name (not raw UUID), status badges, PDF download button
- Mark-as-paid modal: payment method dropdown + reference field
- Status filter + pagination
- "Generate Invoices" quick action (triggers Celery task)
- Overdue invoices highlighted in red
api.ts additions
downloadInvoicePdf(id)— opens PDF in new tabmarkInvoicePaid(id, data)— PATCH to mark-paid endpointtriggerGenerateInvoices()— POST to trigger monthly invoice generation