fix is_active student flag logic and make moving with enrollment status
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 47s
Tests / PHPUnit (push) Successful in 1m16s

This commit is contained in:
root
2026-08-20 03:11:37 -04:00
parent 6f722795c5
commit 0a31aa1393
20 changed files with 588 additions and 489 deletions
@@ -2656,13 +2656,16 @@ class AdministratorController extends BaseController
$payload = $this->filterEnrollmentPayloadByColumns($payload);
if ($existing !== null) {
$this->db->table('enrollments')
->where('id', (int) $existing['id'])
->update($payload);
$payload['id'] = (int) $existing['id'];
} else {
$payload['created_at'] = $now;
$this->db->table('enrollments')->insert($this->filterEnrollmentPayloadByColumns($payload));
}
\Config\Services::enrollmentStatus(false)->upsertStatus(
$this->filterEnrollmentPayloadByColumns($payload),
(int) (session()->get('user_id') ?? 0) ?: null,
'admin_review_decision_enrollment'
);
}
}
@@ -2961,6 +2964,8 @@ class AdministratorController extends BaseController
public function adminEnrollmentWithdrawalHandler()
{
$refundService = new FeeCalculationService();
$enrollmentStatusService = \Config\Services::enrollmentStatus(false);
$performedBy = (int) (session()->get('user_id') ?? 0) ?: null;
$this->db->transStart();
try {
@@ -3023,7 +3028,7 @@ class AdministratorController extends BaseController
$isWithdrawn = in_array($newEnrollmentStatus, ['withdrawn', 'refund pending', 'withdraw under review'], true) ? 1 : 0;
$ok = $this->db->table('enrollments')->insert([
$result = $enrollmentStatusService->upsertStatus([
'student_id' => (int)$studentId,
'parent_id' => $parentId,
'school_year' => (string)$this->schoolYear,
@@ -3034,9 +3039,9 @@ class AdministratorController extends BaseController
'admission_status' => $admissionStatus,
'created_at' => utc_now(),
'updated_at' => utc_now(),
]);
], $performedBy, 'admin_enrollment_withdrawal_handler');
if (!$ok) {
if ((int) ($result['id'] ?? 0) <= 0) {
$errors[] = "Failed to create enrollment for student ID $studentId.";
continue;
}
@@ -3080,26 +3085,36 @@ class AdministratorController extends BaseController
// admissionStatus computed above
// Skip if no actual change
if ($oldStatus === $newEnrollmentStatus) {
log_message('debug', "No status change for student {$studentId} ({$oldStatus}) — skipping.");
$enrollmentStatusService->upsertStatus([
'id' => (int) $enrollmentRow['id'],
'student_id' => (int) $studentId,
'parent_id' => (int) $parentId,
'school_year' => (string) $this->schoolYear,
'semester' => (string) ($enrollmentRow['semester'] ?? $this->semester),
'enrollment_status' => $newEnrollmentStatus,
'admission_status' => $admissionStatus,
'updated_at' => utc_now(),
], $performedBy, 'admin_enrollment_status_repair');
log_message('debug', "No status change for student {$studentId} ({$oldStatus}); repaired activity flag.");
if (in_array($newEnrollmentStatus, ['payment pending', 'enrolled'], true)) {
$this->applyDistributionDraftToStudentClass((int)$studentId, (string)$this->schoolYear);
}
continue;
}
// Update enrollment
$updated = $this->db->table('enrollments')
->where('student_id', $studentId)
->where('school_year', $this->schoolYear)
->update([
'enrollment_status' => $newEnrollmentStatus,
'admission_status' => $admissionStatus,
'updated_at' => utc_now(),
]);
$result = $enrollmentStatusService->upsertStatus([
'id' => (int) $enrollmentRow['id'],
'student_id' => (int) $studentId,
'parent_id' => (int) $parentId,
'school_year' => (string) $this->schoolYear,
'semester' => (string) ($enrollmentRow['semester'] ?? $this->semester),
'enrollment_status' => $newEnrollmentStatus,
'admission_status' => $admissionStatus,
'updated_at' => utc_now(),
], $performedBy, 'admin_enrollment_withdrawal_handler');
if (!$updated) {
if ((int) ($result['id'] ?? 0) <= 0) {
$errors[] = "Failed to update enrollment for student ID $studentId.";
continue;
}