# Academic Terms Improvements

This document outlines the enhancements and features implemented on top of the original `ACADEMIC_TERMS_MIGRATION_GUIDE.md` to better align the Educmac system with the nuances of the Nigerian Academic calendar.

## 1. Mid-Term Break & Holidays Management

The Nigerian academic calendar heavily features standardized Mid-Term breaks (usually lasting a week) and distinct public holidays. To accommodate this, the system's Session management interface has been upgraded.

### Feature Details:
- **Holidays Field:** A new input field has been added to the "Edit Term" modal (`application/views/sessions/index.php`).
- **Data Structure:** Holidays are securely stored as a JSON array within the `academic_terms` table (`holidays` column).
- **Backend Logic:** The `Sessions.php` controller (`edit_term` method) has been extended to parse comma-separated date strings (e.g., `2026-10-25, 2026-10-26`) and convert them into structured JSON arrays for safe database insertion.

### Benefit:
This allows school administrators to visually manage non-learning days, directly from the terms management modal. 

## 2. Automated Attendance "Total Days"

The system now dynamically calculates the total number of working days in a term instead of relying solely on the number of days attendance was physically taken.

### Feature Details:
- **Calculation Logic:** The system fetches the active academic term for the student's session and branch. It multiplies the `total_weeks` by 5 to get the standard working days. It then subtracts the exact number of dates defined in the `holidays` JSON array for that term.
- **Display:** This value is now displayed under the **Attendance Percentage** section of the report cards.
- **Fallback:** If a term isn't configured properly, it safely falls back to the previous behavior (counting the existing attendance records).

## 3. Third Term Cumulative Report Cards

Report cards generated for any exam tied to the 3rd Term will now automatically include cumulative data from the 1st and 2nd Terms.

### Feature Details:
- **Detection Logic:** `Exam_model::getStudentReportCard` automatically detects if the requested exam belongs to a term with `term_order == 3`.
- **Data Aggregation:** It queries the database for any previous exams within the same session that belong to `term_order == 1` or `term_order == 2`. It decodes the JSON mark distributions, aggregates the totals per subject, and calculates the cumulative averages across the terms.
- **Report Card Views:** The generated PDF and HTML report cards (`home/reportCard.php`, `home/reportCardWithTemplate.php`, `exam/reportCard.php`, `exam/reportCard_PDF.php`) automatically append `1st Term`, `2nd Term`, `Cum. Avg`, and `Cum. Grade` columns when a 3rd term exam is being viewed.

### Verification
You can verify the cumulative report cards by:
1. Creating a dummy student and assigning them to a class.
2. Creating three exams within the active session, one assigned to the 1st Term, one to the 2nd Term, and one to the 3rd Term.
3. Adding scores for the student in all three exams.
4. Generating the Report Card for the 3rd Term exam. You should instantly see the new cumulative columns reflecting the averages.

## 4. Admin Access to Session Settings
School Admin (`SchoolAdmin` role) can now access, edit, and view the session settings, previously restricted to Super Admin only.

## 5. Recommended Future Enhancements

The following features have been identified as highly impactful next steps for a complete Nigerian Academic Term experience:

1. **Term-Weighted Fee Invoicing:**
   - Extending the Fee Allocation module to strictly bind certain high-cost levies (e.g., Development Levy, Uniforms) to the First Term (`term_order == 1`), automatically generating segregated invoices for students.
