fix enrollment and email send to parent
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 49s
Tests / PHPUnit (push) Failing after 1m20s

This commit is contained in:
root
2026-08-27 12:39:08 -04:00
parent 7b86cf5218
commit 0ae9993d82
19 changed files with 37831 additions and 1313 deletions
+66 -1
View File
@@ -514,6 +514,8 @@ class DiscountController extends BaseController
$affected = count($rowsToUpdate);
$db->transCommit();
$this->triggerStudentEnrolledNotification($parentId, $rowsToUpdate);
log_message(
'info',
'Enrollment status -> enrolled for {n} row(s). parent={p}, year={y}, sem={s}, ids=[{ids}]',
@@ -534,10 +536,60 @@ class DiscountController extends BaseController
}
}
private function triggerStudentEnrolledNotification(int $parentId, array $enrollmentRows): void
{
if ($parentId <= 0 || $enrollmentRows === []) {
return;
}
try {
$parent = $this->userModel->find($parentId) ?? [];
$studentIds = array_values(array_unique(array_filter(
array_map(static fn (array $row): int => (int) ($row['student_id'] ?? 0), $enrollmentRows),
static fn (int $studentId): bool => $studentId > 0
)));
if ($studentIds === []) {
return;
}
$students = [];
foreach ($this->db->table('students')->whereIn('id', $studentIds)->get()->getResultArray() as $student) {
$studentId = (int) ($student['id'] ?? 0);
if ($studentId <= 0) {
continue;
}
$students[] = [
'student_id' => $studentId,
'name' => trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? '')) ?: 'Student #' . $studentId,
];
}
if ($students === []) {
return;
}
Events::trigger('studentEnrolled', [
'user_id' => $parent['id'] ?? $parentId,
'email' => $parent['email'] ?? null,
'firstname' => $parent['firstname'] ?? '',
'lastname' => $parent['lastname'] ?? '',
'school_year' => (string) $this->schoolYear,
'portalLink' => base_url('/login'),
], $students);
} catch (\Throwable $e) {
log_message('error', 'Enrollment confirmation notification after discount failed for parent {parent_id}: {error}', [
'parent_id' => $parentId,
'error' => $e->getMessage(),
]);
}
}
public function listVouchers()
{
$this->schoolYear = $this->activeSchoolYearName();
$this->schoolYear = $this->currentSchoolYearName();
$vouchers = $this->voucherModel
->where('school_year', $this->schoolYear)
@@ -684,6 +736,19 @@ class DiscountController extends BaseController
}
}
protected function currentSchoolYearName(?string $fallback = null): string
{
try {
return service('schoolYearContext')->resolve($this->request)->yearName();
} catch (\Throwable) {
if ($fallback !== null && $fallback !== '') {
return $fallback;
}
return (string) ($this->configModel->getConfig('school_year') ?? '');
}
}
/**
* 🔄 Helper: Current invoice balance (school-year scoped) = total - payments - discounts - refundsPaid
*/