Files
TapTrack-Hub/.paul/phases/08-billing-engine/README.md
kevin-asprec 0e0803e417 feat(phase-8): billing engine + invoice PDF + mark-paid + overdue escalation
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
2026-03-16 13:46:33 +08:00

47 lines
1.8 KiB
Markdown

# 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_path` in 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 created
- `POST /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 `func` import in `generate_monthly_invoices`
- `check_overdue` enhanced:
- 7-day overdue → send warning email to school billing contact
- 30-day overdue → suspend school (set status = suspended)
- `generate_monthly_invoices` auto-queues `send_invoice_email_task` after 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 tab
- `markInvoicePaid(id, data)` — PATCH to mark-paid endpoint
- `triggerGenerateInvoices()` — POST to trigger monthly invoice generation