fix event issues

This commit is contained in:
root
2026-04-19 12:05:10 -04:00
parent 35988e9ce1
commit 596d368b1d
7 changed files with 239 additions and 29 deletions
+53
View File
@@ -220,6 +220,59 @@ class EventController extends ResourceController
]);
if ($updated) {
if ($this->request->getPost('add_to_calendar')) {
$calendarModel = new CalendarModel();
$title = trim((string) $this->request->getPost('event_name'));
$date = (string) $this->request->getPost('expiration_date');
$schoolYear = (string) $this->request->getPost('school_year');
$semester = (string) $this->request->getPost('semester');
if ($title !== '' && $date !== '' && $schoolYear !== '') {
$data = [
'title' => $title,
'description' => (string) $this->request->getPost('description'),
'event_type' => 'Event',
'date' => $date,
'notify_parent' => $this->request->getPost('notify_parent') ? 1 : 0,
'notify_teacher' => $this->request->getPost('notify_teacher') ? 1 : 0,
'notify_admin' => $this->request->getPost('notify_admin') ? 1 : 0,
'no_school' => 0,
'school_year' => $schoolYear,
'semester' => $semester ?: $this->semester,
];
if (!$calendarModel->supportsEventType()) {
unset($data['event_type']);
}
$existingByPreviousEvent = $calendarModel
->where('school_year', (string) ($event['school_year'] ?? ''))
->where('date', (string) ($event['expiration_date'] ?? ''))
->where('title', (string) ($event['event_name'] ?? ''));
if ($calendarModel->supportsEventType() && isset($data['event_type'])) {
$existingByPreviousEvent = $existingByPreviousEvent->where('event_type', $data['event_type']);
}
$existingCalendar = $existingByPreviousEvent->first();
if ($existingCalendar) {
$calendarModel->update($existingCalendar['id'], $data);
} else {
$dupQuery = $calendarModel
->where('school_year', $data['school_year'])
->where('date', $data['date'])
->where('title', $data['title']);
if ($calendarModel->supportsEventType() && isset($data['event_type'])) {
$dupQuery = $dupQuery->where('event_type', $data['event_type']);
}
$duplicate = $dupQuery->first();
if (!$duplicate) {
$calendarModel->save($data);
}
}
}
}
$redirect = redirect()->to('/administrator/events')->with('success', 'Event updated successfully');
if ($this->request->getPost('send_email_parent')) {
$emailStatus = $this->broadcastEventToParents((int) $id);
+25 -6
View File
@@ -1797,16 +1797,34 @@ $existing = $this->studentModel
$activeEventCount = is_array($activeEvents) ? count($activeEvents) : 0;
// Get charges (participation info)
$chargesList = $this->chargesModel->getChargesWithEventInfo($parentId, $schoolYear);
$chargesList = $this->chargesModel->getChargesWithEventInfo($parentId, $schoolYear, $semester);
// Build a map: "studentId:eventId" => [ 'participation' => ..., 'date' => ... ]
$charges = [];
$externalParticipantsByEvent = [];
foreach ($chargesList as $charge) {
$key = $charge['student_id'] . ':' . $charge['event_id'];
$charges[$key] = [
'participation' => $charge['participation'],
'date' => $charge['updated_at'] ?? $charge['created_at'] // Use updated_at if available
];
$studentId = $charge['student_id'] ?? null;
$eventId = (int) ($charge['event_id'] ?? 0);
if (!empty($studentId)) {
$key = $studentId . ':' . $eventId;
$charges[$key] = [
'participation' => $charge['participation'],
'date' => $charge['updated_at'] ?? $charge['created_at'], // Use updated_at if available
];
continue;
}
$externalName = trim((string) ($charge['external_firstname'] ?? '') . ' ' . (string) ($charge['external_lastname'] ?? ''));
if ($eventId > 0 && $externalName !== '') {
$externalParticipantsByEvent[$eventId][] = [
'name' => $externalName,
'note' => (string) ($charge['external_note'] ?? ''),
'participation' => (string) ($charge['participation'] ?? ''),
'event_paid' => !empty($charge['event_paid']),
'charged' => (float) ($charge['charged'] ?? ($charge['event_amount'] ?? 0)),
];
}
}
// Get enrolled students
@@ -1815,6 +1833,7 @@ $existing = $this->studentModel
return view('parent/event_participation', [
'activeEvents' => $activeEvents,
'charges' => $charges,
'externalParticipantsByEvent' => $externalParticipantsByEvent,
'yourStudents' => $students,
'activeEventCount' => $activeEventCount,
]);