update event charge at the invoice

This commit is contained in:
root
2026-04-13 01:38:40 -04:00
parent 4e2d12e524
commit 821e9cdc81
11 changed files with 537 additions and 32 deletions
+118 -20
View File
@@ -12,6 +12,14 @@
<?php endif; ?>
<?php
$classSectionNames = $classSectionNames ?? [];
$semesterOptions = $semesterOptions ?? [];
$schoolYearOptions = $schoolYearOptions ?? [];
?>
<?php
$filterParentId = $filterParentId ?? 0;
$parentBalances = $parentBalances ?? [];
$selectedEvent = null;
if (!empty($filterEventId)) {
foreach ($events as $event) {
@@ -22,10 +30,48 @@
}
}
?>
<div class="card mb-4">
<div class="card-body">
<form method="get" action="<?= site_url('administrator/event-charges') ?>" class="row g-3 align-items-end">
<?php if ($filterEventId > 0): ?>
<input type="hidden" name="event_id" value="<?= esc($filterEventId) ?>">
<?php endif; ?>
<?php if ($filterParentId > 0): ?>
<input type="hidden" name="parent_id" value="<?= esc($filterParentId) ?>">
<?php endif; ?>
<div class="col-md-4">
<label for="semester_filter" class="form-label">Semester</label>
<select id="semester_filter" name="semester" class="form-select">
<option value="">-- All semesters --</option>
<?php foreach ($semesterOptions as $option): ?>
<option value="<?= esc($option) ?>" <?= $semester === $option ? 'selected' : '' ?>>
<?= esc($option) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-4">
<label for="school_year_filter" class="form-label">School Year</label>
<select id="school_year_filter" name="school_year" class="form-select">
<option value="">-- All school years --</option>
<?php foreach ($schoolYearOptions as $option): ?>
<option value="<?= esc($option) ?>" <?= $school_year === $option ? 'selected' : '' ?>>
<?= esc($option) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-outline-primary">Filter</button>
</div>
</form>
</div>
</div>
<!-- Add New Charge Form -->
<div class="card mb-4">
<div class="card-body">
<form action="<?= site_url('payment/event_charges') ?>" method="post">
<form id="event-participant-form" action="<?= site_url('payment/event_charges') ?>" method="post">
<?= csrf_field() ?>
<div class="row g-3">
<div class="col-md-4">
@@ -60,16 +106,13 @@
</div>
</div>
<?php endif; ?>
</div>
<div class="row g-3 mt-2">
<div class="col-md-4">
<label for="parent_id" class="form-label">Parents List</label>
<select id="parent_id" name="parent_id" class="form-select" required>
<option value="">-- Select Parent --</option>
<?php foreach ($parents as $parent): ?>
<option value="<?= $parent['id'] ?>">
<option value="<?= esc($parent['id']) ?>" <?= $filterParentId && $filterParentId == $parent['id'] ? 'selected' : '' ?>>
<?= esc($parent['firstname'] . ' ' . $parent['lastname']) ?> (<?= esc($parent['school_id']) ?>)
</option>
<?php endforeach; ?>
@@ -89,7 +132,6 @@
</form>
</div>
</div>
<!-- Charge Tables grouped by event -->
<?php
$grouped = [];
@@ -108,6 +150,10 @@
<?= esc($eventLabel) ?>
</div>
<div class="card-body p-0">
<?php
$totalParticipants = 0;
$totalCharged = 0.0;
?>
<div class="table-responsive">
<table class="table table-bordered table-striped mb-0 no-mgmt-sticky">
<thead class="table-light">
@@ -115,17 +161,20 @@
<th>ID</th>
<th>Parent Name</th>
<th>Student Name</th>
<th>Class Section</th>
<th>Charged Amount</th>
<th>Is Participating</th>
<th>Semester</th>
<th>Year</th>
<th>Created</th>
<th>Description</th>
<th>Event Fees</th>
<th>Fees Paid</th>
<th>Payment</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $charge): ?>
<?php
$isParticipating = ($charge['participation'] === 'yes');
$isEventPaid = !empty($charge['event_paid']);
?>
<tr>
<td><?= esc($charge['id']) ?></td>
<td><?= esc($charge['parent_firstname'] . ' ' . $charge['parent_lastname']) ?></td>
@@ -134,20 +183,65 @@
? esc($charge['student_firstname'] . ' ' . $charge['student_lastname'])
: '-' ?>
</td>
<td>$<?= esc(number_format($charge['charged'] ?? 0, 2)) ?></td>
<td>
<?= $charge['participation']
? '<span class="badge bg-success">Yes</span>'
: '<span class="badge bg-warning">No</span>' ?>
<?= esc($classSectionNames[$charge['class_section_id'] ?? ''] ?? '—') ?>
</td>
<td><?= esc($charge['semester'] ?? '-') ?></td>
<td><?= esc($charge['school_year'] ?? '-') ?></td>
<td><?= esc(!empty($charge['created_at']) ? local_datetime($charge['created_at'], 'm-d-Y H:i') : '') ?></td>
<td><?= esc($charge['event_description'] ?? '—') ?></td>
<td>$<?= esc(number_format($charge['event_amount'] ?? 0, 2)) ?></td>
<td><?= esc(!empty($charge['created_at']) ? local_datetime($charge['created_at'], 'm-d-Y H:i') : '') ?></td>
<?php
$feeAmount = (float) ($charge['event_amount'] ?? 0);
$hasBalanceRecord = array_key_exists((int)$charge['parent_id'], $parentBalances);
$parentBalance = $hasBalanceRecord ? (float)$parentBalances[$charge['parent_id']] : null;
$feeIsPaid = $isParticipating && ($isEventPaid || ($hasBalanceRecord && $parentBalance <= 0));
?>
<td class="text-center">
<?php if ($feeIsPaid): ?>
<span class="badge bg-success">Paid</span>
<?php else: ?>
<span class="badge bg-danger">Unpaid</span>
<?php endif; ?>
</td>
<td class="text-center">
<form method="post" action="<?= site_url('administrator/event-charges/payment/' . esc($charge['id'])) ?>" class="d-inline-flex align-items-center">
<?= csrf_field() ?>
<input type="hidden" name="paid" value="<?= $feeIsPaid ? '1' : '0' ?>">
<input type="checkbox" class="form-check-input" id="eventPayment_<?= esc($charge['id']) ?>"
<?= $isEventPaid ? 'checked' : '' ?>
onchange="this.form.paid.value = this.checked ? 1 : 0; this.form.submit();">
<label class="form-check-label ms-2" for="eventPayment_<?= esc($charge['id']) ?>" aria-hidden="true">Paid</label>
</form>
</td>
<td class="text-nowrap">
<div class="d-flex gap-1 align-items-center">
<a href="<?= site_url('administrator/event-charges') ?>?event_id=<?= esc($charge['event_id']) ?>&parent_id=<?= esc($charge['parent_id']) ?>#event-participant-form" class="btn btn-outline-primary btn-sm">
Edit
</a>
<form action="<?= site_url('administrator/event-charges/remove/' . esc($charge['id'])) ?>" method="post" onsubmit="return confirm('Remove this participation and update the charge?');">
<?= csrf_field() ?>
<button type="submit" class="btn btn-outline-danger btn-sm">Remove</button>
</form>
</div>
</td>
</tr>
<?php
if ($isParticipating) {
$totalParticipants++;
$totalCharged += (float) ($charge['event_amount'] ?? 0);
}
?>
<?php endforeach; ?>
</tbody>
<tfoot class="table-light">
<tr>
<th colspan="4">Totals</th>
<th>$<?= esc(number_format($totalCharged, 2)) ?></th>
<th colspan="5">
<span class="badge bg-secondary">
<?= esc($totalParticipants) ?> participating
</span>
</th>
</tr>
</tfoot>
</table>
</div>
</div>
@@ -214,6 +308,10 @@ $(function() {
}
window.location.href = url.toString();
});
if ($('#event_id').val() && $('#parent_id').val()) {
loadStudentsWithCharges();
}
});
</script>
<?= $this->endSection() ?>