fix the enrollement-carryover balance
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 49s
Tests / PHPUnit (push) Successful in 1m21s

This commit is contained in:
root
2026-09-09 21:40:01 -04:00
parent 2d5b151234
commit 36e8ffe56d
12 changed files with 1365 additions and 39 deletions
@@ -57,11 +57,13 @@ public function buildRoster(string $selectedYear, string $semester): array
$students = $this->studentModel->getStudentsWithClassAndEnrollment($selectedYear);
$removedPriorStatuses = $this->removedPriorYearStudentStatuses($selectedYear);
$makeUpExamStudentIds = array_fill_keys($this->makeUpExamStudentIds($selectedYear), true);
service('studentYearStatus')->attachToStudents($students, $selectedYear);
foreach ($students as &$s) {
// ===== Ensure IDs needed by the modal =====
$s['student_id'] = (int)($s['id'] ?? 0);
$s['make_up_exam'] = isset($makeUpExamStudentIds[$s['student_id']]) ? 'Yes' : 'No';
$priorRemovedStatus = $removedPriorStatuses[$s['student_id']] ?? null;
$s['removed_previous_year'] = $priorRemovedStatus !== null ? 'Yes' : 'No';
$s['prior_removed_status'] = $priorRemovedStatus;
@@ -528,6 +530,54 @@ private function getPreviousSchoolYear(string $schoolYear): string
return '';
}
/**
* Return students whose latest deliberation decision for the source school year
* requires a make-up exam.
*/
private function makeUpExamStudentIds(string $selectedYear): array
{
$sourceYear = $this->getPreviousSchoolYear($selectedYear);
if ($sourceYear === '' || ! $this->db->tableExists('student_decisions')) {
return [];
}
$select = ['student_id', 'decision'];
$hasStandardDecision = $this->db->fieldExists('deliberation_decision_standard', 'student_decisions');
if ($hasStandardDecision) {
$select[] = 'deliberation_decision_standard';
}
$rows = $this->db->table('student_decisions')
->select($select)
->where('school_year', $sourceYear)
->orderBy('updated_at', 'DESC')
->orderBy('id', 'DESC')
->get()
->getResultArray();
$latestDecisionSeen = [];
$studentIds = [];
foreach ($rows as $row) {
$studentId = (int) ($row['student_id'] ?? 0);
if ($studentId <= 0 || isset($latestDecisionSeen[$studentId])) {
continue;
}
$latestDecisionSeen[$studentId] = true;
$decision = $hasStandardDecision
? DeliberationDecision::normalize($row['deliberation_decision_standard'] ?? null)
: null;
$decision ??= DeliberationDecision::normalize($row['decision'] ?? null);
if ($decision === DeliberationDecision::MAKE_UP_EXAM) {
$studentIds[] = $studentId;
}
}
return $studentIds;
}
private function getSchoolYearStartYear(string $schoolYear): ?int
{
$schoolYear = trim($schoolYear);