38686-vm/docs/plans/2026-02-22-payslip-feature-design.md
Konrad du Plessis c8c78dd88e Add payslip feature: detail page, PDF generation, and email to Spark
- core/utils.py: render_to_pdf() wrapper for xhtml2pdf
- core/templates/core/pdf/payslip_pdf.html: A4 PDF payslip (matches V2 layout)
- core/templates/core/email/payslip_email.html: HTML email body for Spark
- core/templates/core/payslip.html: browser payslip detail page with print
- core/views.py: add payslip_detail view, wire email+PDF into process_payment
- core/urls.py: add payroll/payslip/<pk>/ route
- config/settings.py: add SPARK_RECEIPT_EMAIL setting
- payroll_dashboard.html: add "View" payslip link in Payment History tab

All templates show adjustments (bonuses, deductions, overtime, loan repayments)
as line items. Amounts always show 2 decimal places. Email failure does not
roll back payment — handled gracefully with warning message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 20:37:04 +02:00

24 lines
1022 B
Markdown

# Payslip Feature Design — 22 Feb 2026
## Goal
Complete the payment workflow: when "Pay" is clicked, generate a PDF payslip and email it to Spark. Also add a payslip detail page for viewing/printing past payslips.
## Files
1. `core/utils.py` — render_to_pdf() xhtml2pdf wrapper
2. `core/templates/core/pdf/payslip_pdf.html` — A4 PDF template
3. `core/templates/core/email/payslip_email.html` — HTML email body
4. `core/templates/core/payslip.html` — Browser payslip detail page
5. `core/views.py` — payslip_detail view + email in process_payment
6. `core/urls.py` — payroll/payslip/<pk>/
7. `config/settings.py` — SPARK_RECEIPT_EMAIL + DEFAULT_FROM_EMAIL
## Flow
process_payment → atomic(create record, link logs/adjs, update loans) → email PDF to Spark → redirect
## Key: V2 → V5 field mapping
- record.amount → record.amount_paid
- worker.id_no → worker.id_number
- worker.phone_no → worker.phone_number
- loan.balance → loan.remaining_balance
- loan.amount → loan.principal_amount