From 596d368b1db2de8c9f2cabffa83239affd8ed0ba Mon Sep 17 00:00:00 2001 From: root Date: Sun, 19 Apr 2026 12:05:10 -0400 Subject: [PATCH] fix event issues --- app/Controllers/View/EventController.php | 53 +++++++++++++ app/Controllers/View/ParentController.php | 31 ++++++-- .../administrator/events/create_event.php | 32 ++++++-- app/Views/administrator/events/edit_event.php | 79 ++++++++++++++++++- .../administrator/events/event_charges.php | 13 +-- app/Views/emails/event_broadcast.php | 2 +- app/Views/parent/event_participation.php | 58 ++++++++++++-- 7 files changed, 239 insertions(+), 29 deletions(-) diff --git a/app/Controllers/View/EventController.php b/app/Controllers/View/EventController.php index fafa6bc..9bb09a1 100644 --- a/app/Controllers/View/EventController.php +++ b/app/Controllers/View/EventController.php @@ -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); diff --git a/app/Controllers/View/ParentController.php b/app/Controllers/View/ParentController.php index 027d08f..4f91788 100644 --- a/app/Controllers/View/ParentController.php +++ b/app/Controllers/View/ParentController.php @@ -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, ]); diff --git a/app/Views/administrator/events/create_event.php b/app/Views/administrator/events/create_event.php index 6e9bf3f..62d9193 100644 --- a/app/Views/administrator/events/create_event.php +++ b/app/Views/administrator/events/create_event.php @@ -28,7 +28,7 @@
- +
@@ -108,17 +108,37 @@ endSection() ?> section('scripts') ?> + endSection() ?> diff --git a/app/Views/administrator/events/edit_event.php b/app/Views/administrator/events/edit_event.php index 98b59e0..e86b8f3 100644 --- a/app/Views/administrator/events/edit_event.php +++ b/app/Views/administrator/events/edit_event.php @@ -4,6 +4,12 @@

Edit Event

+ + getFlashdata('error')): ?>
getFlashdata('error') ?>
@@ -23,7 +29,7 @@ +
@@ -44,7 +50,7 @@

- +
No flyer uploaded.
@@ -70,6 +76,37 @@
+
+
School Calendar
+
+
+ + +
+ + +
+
+
Parent Email Broadcast
@@ -89,3 +126,39 @@
endSection() ?> + +section('scripts') ?> + + +endSection() ?> diff --git a/app/Views/administrator/events/event_charges.php b/app/Views/administrator/events/event_charges.php index db72985..a9f9c17 100644 --- a/app/Views/administrator/events/event_charges.php +++ b/app/Views/administrator/events/event_charges.php @@ -427,6 +427,7 @@ function loadStudentsWithCharges() { } const $externalHidden = $('#externalParticipantsHidden'); + const $externalSaveButton = $('#externalParticipantSave'); const storageKey = 'eventChargesExternalParticipants'; let externalDrafts = []; let editingKey = null; @@ -497,13 +498,12 @@ function loadStudentsWithCharges() { $${amountDisplay} ${createdDisplay} - Pending - ${isPaid ? 'Paid on save' : 'Paid on save'} + ${isPaid ? 'Paid' : 'Unpaid'}
- On save + Paid
@@ -575,6 +575,7 @@ function loadStudentsWithCharges() { return; } editingKey = key; + $externalSaveButton.text('Save'); $('#modalExternalFirstName').val(entry.firstname); $('#modalExternalLastName').val(entry.lastname); $('#modalExternalNote').val(entry.note); @@ -592,6 +593,7 @@ function loadStudentsWithCharges() { if (modalElement) { modalElement.addEventListener('hidden.bs.modal', () => { editingKey = null; + $externalSaveButton.text('Add to list'); }); } function clearModalInputs() { @@ -651,6 +653,7 @@ function loadStudentsWithCharges() { } saveExternalDraft(entry); editingKey = null; + $externalSaveButton.text('Add to list'); clearModalInputs(); if (modalInstance) { modalInstance.hide(); @@ -687,9 +690,9 @@ function loadStudentsWithCharges() { .val(paid ? '1' : '0'); const $badge = $(`tr.external-preview[data-key="${key}"] .external-paid-badge`); if (paid) { - $badge.removeClass('d-none').addClass('bg-success').text('Paid on save'); + $badge.removeClass('bg-danger').addClass('bg-success').text('Paid'); } else { - $badge.addClass('d-none'); + $badge.removeClass('bg-success').addClass('bg-danger').text('Unpaid'); } }); $('#event-participant-form').on('submit', function() { diff --git a/app/Views/emails/event_broadcast.php b/app/Views/emails/event_broadcast.php index a424f56..3e96bdf 100644 --- a/app/Views/emails/event_broadcast.php +++ b/app/Views/emails/event_broadcast.php @@ -16,7 +16,7 @@ $amount = ($amountRaw !== null && $amountRaw !== '') ? number_format((float) $am

Amount: $

-

+
diff --git a/app/Views/parent/event_participation.php b/app/Views/parent/event_participation.php index 8781ce0..7ac509d 100644 --- a/app/Views/parent/event_participation.php +++ b/app/Views/parent/event_participation.php @@ -24,6 +24,7 @@
+
@@ -42,6 +43,53 @@
+
+
Description
+ +
+ +

No description

+ +
+ + +
+
External Participants
+
+ + + + + + + + + + + + + + + + + + +
Student NameStatusFee
+ (external) + + + + + + + + $
+
+
+ +
@@ -51,11 +99,8 @@ - - + - - @@ -65,8 +110,7 @@ $current = $charges[$key]['participation'] ?? ''; ?> - - + - -
Student First NameStudent Last NameStudent Name ParticipateDescriptionEvent Fees
@@ -83,8 +127,6 @@
$