2.5 KiB
2.5 KiB
Phase 11: Monthly Report Generation + Email
Status: Not started Depends on: Phase 9 (Email), Phase 12 (On-Prem Data Pull)
Goal
On the 1st of each month, automatically generate and email a comprehensive report to each active school summarising their SMS usage, credit consumption, and invoice for the period. Super admin can manually trigger reports. School portal shows report history.
Planned Scope
Backend
Enhance reports.send_monthly_reports Celery task (currently a stub)
- For each active school:
- Fetch SMS stats for prior month (sent, failed, delivery rate, credit burn)
- Fetch attendance data from
school_monthly_stats(populated by Phase 12) - Fetch invoice for the period (if exists)
- Render
monthly_report.htmlJinja2 template - Send email to
school.billing_email - Store report record in
monthly_reportstable
monthly_reports table (new model)
id,school_id,report_month(YYYY-MM),email_sent_at,report_data(JSON),created_at
Manual trigger endpoint
POST /api/reports/send/{school_id}— super admin triggers report for a specific school
School portal: report history
GET /api/portal/reports— school admin lists their past reportsGET /api/portal/reports/{id}— view report detail (JSON data rendered as HTML)
monthly_report.html Jinja2 email template
- School name + period header
- SMS stats: sent, failed, delivery rate, credit burn
- Attendance summary (if available from Phase 12, else "data unavailable")
- Invoice summary for the period
- Credit balance as of report date
Frontend
PortalReportsPage.vue (new portal page)
- List of past monthly reports (month, email sent date, SMS count, status)
- Click to view report detail
Super admin — manual report trigger button in SchoolDetailPage
Router + sidebar — add /portal/reports route and nav item
Key Files to Create/Modify
backend/app/models/report.py(new — monthly_reports table)backend/app/tasks/reports.py— enhance from stubbackend/app/routers/reports.py(new)backend/app/templates/email/monthly_report.html(new)backend/app/main.py— include reports routerbackend/migrations/versions/003_monthly_reports.py(new)frontend/src/pages/portal/PortalReportsPage.vue(new)frontend/src/router/index.ts— add /portal/reportsfrontend/src/components/sidebar/PortalSidebar.vue— add Reports nav itemfrontend/src/lib/api.ts— portal report functions