Attendance Management
Two attendance systems run side by side today: a class-section-based daily attendance system (DailyAttendance) that powers leave requests, chronic-absence detection, locking, and the admin school-wide overview, and an older course-level attendance system (Attendance) still used by the teacher's per-course marking screens and student self-check-in. Both feed parent notifications and downstream analytics.
Basic Tier Features
BasicClass-Section Daily Attendance
- DailyAttendance model: school → class → section → student → date, with 8 status values (present, absent, late, half_day, medical_leave, approved_leave, holiday, excused)
- Bulk mark a whole class-section for a date in one request; unique compound index prevents duplicate records
- A class with no sections is marked as a whole: omit sectionId and the record has no section (DailyAttendance.section is optional). A class that has sections still needs one chosen, otherwise the request is rejected with 400
- Admin school-wide overview: per-class/section totals and percentage, aggregated in a single pipeline
- Parent notification created automatically for absent/late/half-day marks
- Web: /dashboard/admin/attendance (overview) · /dashboard/parent/attendance, /dashboard/student/attendance
Legacy Course-Level Attendance
- Original Attendance model: one record per student per course per date (present/absent/late/excused)
- Teacher bulk-marks a course roster via a single MongoDB bulkWrite upsert — used by the course-scoped teacher UI
- Course-level attendance analytics: per-student present/absent counts and percentage via aggregation
- Student self-check-in (studentMarkToday / studentToday) when a school enables self-marking
- Web: /dashboard/teacher/attendance/[courseId]/today, /[date], /calendar
Leave Requests
- Parent submits a leave request for a child: type (medical/personal/emergency/sports/school_activity/other), date range, reason, supporting documents
- Teacher or admin reviews and approves/rejects with remarks
- On approval, attendance records for every day in the range are bulk-written as medical_leave or approved_leave and linked back to the leave request
- Web: /dashboard/parent/leave-requests (submit) · /dashboard/admin/attendance (review queue)
Chronic Absence Detection
- Aggregation over a rolling window (default 30 days) flags students at or above an absence-count threshold (default 3)
- Threshold and window are query-parameter configurable per request
- Surfaces on the admin "At-Risk Students" tab with student name, admission number, and absence count
Attendance Corrections & Locking
- Every DailyAttendance record carries a lockExpiry (default 48 hours after marking) and an isLocked flag
- Marking is blocked outright if any targeted record is already locked
- Correcting a locked record requires the super_admin role; the previous status, reason, and approver are stored on the record
- Every correction is written to AuditLog with actor, old value, new value, and IP
Teacher & Staff Attendance
- TeacherAttendance model: present/absent/late/half_day/on_leave, with check-in/check-out time strings
- Teacher self-marks their own daily attendance; admin views school-wide teacher attendance for any date
- Monthly self-summary with present/absent counts and percentage
- This dataset is shared with the Chapter 19 HR & Payroll module for staff attendance reporting
Attendance Analytics
- Monthly per-student analytics for a class-section: total, present, absent, late, leave counts and percentage
- Results sorted ascending by percentage so the lowest-attendance students surface first
- Attendance percentage is consumed downstream by Chapter 12 report cards (attendance summary block) and promotion eligibility checks
Staff Check-In / Check-Out with Location — New
- POST /api/hr/attendance/check-in and /check-out: every staff role records its own day. The date and HH:MM time come from the server clock (IST), never from the phone
- Status is set at check-in: present, or late when the time is past the assigned shift's start plus its grace period (15 minutes by default). Staff without a shift are always present
- TeacherAttendance gains checkInLocation and checkOutLocation ({ lat, lng, accuracy in metres, address, capturedAt }). Both are optional on the API and range-checked (lat ±90, lng ±180)
- Mobile requires a location: it asks for foreground location permission, reads a high-accuracy fix (15 s timeout, then the last known position) and reverse-geocodes an address when it can. If permission is denied or GPS is off, check-in is blocked with an instruction. Web asks the browser and carries on without a location if it is refused
- Check-in is idempotent for a day. A day already marked on_leave returns 409. Check-out needs a check-in first and is never earlier than the check-in time
- Admin register: GET /api/hr/attendance/register lists every HR-enrolled staff member for a date with status, times, both locations, remarks and a selfMarked flag. Staff with no record show as not_marked; staff on approved leave as on_leave
- POST /api/hr/attendance/bulk saves only the rows an admin changed (max 500). Marking a row absent or on_leave clears its times and its locations
- Locations are recorded, not verified: nothing compares them with the school's address and a mock-GPS app can fake them. Approved regularization requests change the times but keep the original locations
- Mobile: (admin)/my-hr.tsx (check in/out + own history), (admin)/hr-attendance.tsx (register). Web: /dashboard/my-hr, /dashboard/admin/hr/attendance
Staff Attendance Export — New
- Mobile exports the filtered register as a real .xlsx file (Staff_Attendance_<date>.xlsx) and opens the share sheet
- Columns: Date, Employee Name, Email, Role, Status, Check-In, Check-In Location, Check-In Map Link, Check-Out, Check-Out Location, Check-Out Map Link
- Location columns carry the street address (or coordinates when no address could be found) and a Google Maps link. Absent and on-leave rows export blank times and locations
- Web exports the same columns plus Remarks as CSV (Staff_Attendance_Register_<date>.csv)
- Free-text cells (names, emails, addresses) are escaped against spreadsheet formula injection
Subject-Teacher Access Control — New
- A teacher can mark, view, correct and analyse course attendance only for subjects they teach (as main teacher or co-teacher). Anyone else gets 403 "You are not the teacher of this subject"
- Applies to POST /api/attendance/mark, GET /api/attendance/course/:courseId, PUT /api/attendance/:attendanceId and GET /api/attendance/analytics/:courseId. Admins and super admins are unaffected
- Checked on every request through utils/courseAccess.teachesCourse, so when an admin gives a subject to another teacher (Chapter 11) the previous teacher loses access immediately
Planned — Not Yet Implemented
Not Yet Implemented
- Biometric and RFID attendance check-in — marking is manual only today
- Excel/CSV/PDF export of class attendance reports (daily, monthly, student history) — only the staff attendance register exports today
- Morning/afternoon sub-tracking within a Half-Day record — currently a single half_day status, not a split object
- Bulk correction of multiple records in one request, and bulk leave approval
- Attendance-driven exam hall-ticket blocking (attendance % currently feeds report cards and promotion checks, but does not yet gate exam registration directly)
API Reference — Chapter 10
Class Daily Attendance
/api/class-attendance/markBulk-mark a class-section for a date (teacher, admin, super_admin)
/api/class-attendanceFetch records filtered by classId, sectionId, date
/api/class-attendance/school-overviewAdmin: school-wide daily summary grouped by class-section
/api/class-attendance/analyticsMonthly per-student analytics for a class-section
/api/class-attendance/chronic-absenteesList students flagged for chronic absence
/api/class-attendance/student/:studentId/summaryStudent/parent-facing attendance summary + records
/api/class-attendance/:id/correctCorrect a record (audited); super_admin required if locked
/api/class-attendance/lockLock all records for a class-section-date
Leave Requests
/api/class-attendance/leave-requestsParent (or admin) submits a leave request for a student
/api/class-attendance/leave-requestsList leave requests, filterable by studentId/status
/api/class-attendance/leave-requests/:id/reviewTeacher/admin approves or rejects; approval bulk-updates attendance
Teacher Attendance
/api/class-attendance/teacher/markTeacher self-marks attendance with check-in/check-out
/api/class-attendance/teacher/myTeacher's own monthly attendance + summary
/api/class-attendance/teacher/schoolAdmin: school-wide teacher attendance for a date
Legacy Course Attendance
/api/attendance/markBulk-mark attendance for a course and date (teacher, admin)
/api/attendance/course/:courseIdList attendance for a course, optional ?date=
/api/attendance/student/:studentIdList a student's attendance records
/api/attendance/:attendanceIdUpdate a single attendance record
/api/attendance/analytics/:courseIdPer-student present/absent counts and percentage for a course
/api/attendance/student/markStudent self-marks today's attendance
/api/attendance/student/todayStudent views today's own attendance record
Staff Check-In & Register (HR module)
/api/hr/attendance/check-inSigned-in staff member checks in; server sets date and time, optional location in the body
/api/hr/attendance/check-outCheck out; optional location. Requires a check-in for the day
/api/hr/attendance/registerHR: every enrolled staff member for ?date= with times, locations and not_marked / on_leave
/api/hr/attendance/bulkHR: save the changed register rows (max 500)
/api/hr/attendanceHR: attendance records filtered by employee, date range and status
/api/hr/attendance/todayToday records: HR sees everyone, other staff only their own
Frontend Pages
| Path | Role | Description | Tier |
|---|---|---|---|
| /dashboard/admin/attendance | Admin | School overview, teacher attendance, leave review, chronic-absence tab | Basic |
| /dashboard/admin/analytics/attendance | Admin | Attendance analytics dashboard | Basic |
| /dashboard/teacher/attendance | Teacher | Course list for attendance marking | Basic |
| /dashboard/teacher/attendance/[courseId]/today | Teacher | Mark today's attendance for a course | Basic |
| /dashboard/teacher/attendance/[courseId]/[date] | Teacher | Mark/edit attendance for a specific date | Basic |
| /dashboard/teacher/attendance/[courseId]/calendar | Teacher | Calendar view of a course's marked dates | Basic |
| /dashboard/student/attendance | Student | Own attendance record view | Basic |
| /dashboard/parent/attendance | Parent | Child's daily attendance summary (class-section based) | Basic |
| /dashboard/parent/leave-requests | Parent | Submit and track leave requests for a child | Basic |
| /dashboard/my-hr | Every staff role | Check in / check out with location and own attendance history | Basic |
| /dashboard/admin/hr/attendance | Admin | Staff register with check-in and check-out locations, CSV export | Basic |
Mobile Screens
(student)/attendance.tsx(parent)/attendance.tsx(teacher)/attendance.tsx(admin)/attendance.tsx(admin)/my-hr.tsx(admin)/hr-attendance.tsx