fix is_active student flag logic and make moving with enrollment status
This commit is contained in:
@@ -509,6 +509,7 @@ class ParentController extends BaseController
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
$enrollmentStatusService = \Config\Services::enrollmentStatus(false);
|
||||
foreach ($enroll as $studentId) {
|
||||
$studentId = (int) $studentId;
|
||||
if (! isset($evaluations[$studentId])) {
|
||||
@@ -548,7 +549,13 @@ class ParentController extends BaseController
|
||||
|
||||
if ($existingEnrollment['is_withdrawn'] == 1) {
|
||||
// Reactivate the enrollment if the student was previously withdrawn
|
||||
$this->enrollmentModel->update((int) $existingEnrollment['id'], $update);
|
||||
$enrollmentStatusService->upsertStatus(array_merge($update, [
|
||||
'id' => (int) $existingEnrollment['id'],
|
||||
'student_id' => $studentId,
|
||||
'parent_id' => $parentId,
|
||||
'school_year' => $selectedYear,
|
||||
'semester' => $this->semester,
|
||||
]), (int) $parentId, 'parent_re_enrollment_submitted');
|
||||
log_message('info', "{$studentData[$studentId]['firstname']} {$studentData[$studentId]['lastname']} (ID $studentId) has been re-enrolled in enrollment ID {$existingEnrollment['id']}.");
|
||||
// Apply promotion-based class placement for the upcoming year
|
||||
$this->applyPromotionAssignment((int)$studentId, $selectedYear, $isReturningReEnrollment);
|
||||
@@ -557,7 +564,13 @@ class ParentController extends BaseController
|
||||
if ($currentStatus === 'enrolled') {
|
||||
$update['admission_status'] = 'accepted';
|
||||
}
|
||||
$this->enrollmentModel->update((int) $existingEnrollment['id'], $update);
|
||||
$enrollmentStatusService->upsertStatus(array_merge($update, [
|
||||
'id' => (int) $existingEnrollment['id'],
|
||||
'student_id' => $studentId,
|
||||
'parent_id' => $parentId,
|
||||
'school_year' => $selectedYear,
|
||||
'semester' => $this->semester,
|
||||
]), (int) $parentId, 'parent_enrollment_submitted');
|
||||
log_message('info', "{$studentData[$studentId]['firstname']} {$studentData[$studentId]['lastname']} (ID $studentId) is already actively enrolled.");
|
||||
$this->applyPromotionAssignment((int)$studentId, $selectedYear, $isReturningReEnrollment);
|
||||
}
|
||||
@@ -592,9 +605,9 @@ class ParentController extends BaseController
|
||||
'admission_status' => $targetAdmissionStatus,
|
||||
'created_at' => utc_now()
|
||||
]);
|
||||
$result = $this->enrollmentModel->insert($payload, true);
|
||||
$result = $enrollmentStatusService->upsertStatus($payload, (int) $parentId, 'parent_enrollment_submitted');
|
||||
|
||||
if (!$result) {
|
||||
if ((int) ($result['id'] ?? 0) <= 0) {
|
||||
$this->db->transRollback();
|
||||
return redirect()->back()->withInput()->with('error', $studentName . ': Unable to save enrollment.');
|
||||
} else {
|
||||
@@ -603,7 +616,7 @@ class ParentController extends BaseController
|
||||
$this->applyPromotionAssignment((int)$studentId, $selectedYear, $isReturningReEnrollment);
|
||||
}
|
||||
|
||||
$enrollmentId = (int) $result;
|
||||
$enrollmentId = (int) $result['id'];
|
||||
if (! empty($evaluation['admin_exception']['id'])) {
|
||||
$transitionService->markExceptionUsed((int) $evaluation['admin_exception']['id'], $enrollmentId);
|
||||
}
|
||||
@@ -642,11 +655,17 @@ class ParentController extends BaseController
|
||||
|
||||
if ($enrollment !== null) {
|
||||
// Update enrollment as withdrawn
|
||||
$this->enrollmentModel->update((int) $enrollment['id'], [
|
||||
$enrollmentStatusService = \Config\Services::enrollmentStatus(false);
|
||||
$enrollmentStatusService->upsertStatus([
|
||||
'id' => (int) $enrollment['id'],
|
||||
'student_id' => (int) $studentId,
|
||||
'parent_id' => (int) ($enrollment['parent_id'] ?? $parentId),
|
||||
'school_year' => (string) $this->schoolYear,
|
||||
'semester' => (string) ($enrollment['semester'] ?? $this->semester),
|
||||
'withdrawal_date' => local_date(utc_now(), 'Y-m-d'),
|
||||
'enrollment_status' => 'withdraw under review', // Withdrawal needs review
|
||||
'updated_at' => utc_now()
|
||||
]);
|
||||
], (int) $parentId, 'parent_withdrawal_requested');
|
||||
log_message('info', "Student ID $studentId has been withdrawn from enrollment ID {$enrollment['id']}.");
|
||||
|
||||
// === Trigger refund process ===
|
||||
|
||||
Reference in New Issue
Block a user