816 lines
40 KiB
PHP
816 lines
40 KiB
PHP
<?= $this->extend('layout/management_layout') ?>
|
|
<?= $this->section('content') ?>
|
|
|
|
<?php
|
|
$source = $preview['source'] ?? [];
|
|
$target = $preview['target'] ?? null;
|
|
$overview = $preview['overview'] ?? [];
|
|
$finance = $preview['finance'] ?? [];
|
|
$promotion = $preview['promotion'] ?? ['summary' => [], 'rows' => []];
|
|
$promotionSummary = $promotion['summary'] ?? [];
|
|
$promotionRows = $promotion['rows'] ?? [];
|
|
$promotionTotal = count($promotionRows);
|
|
$blockers = $preview['blockers'] ?? [];
|
|
$warnings = $preview['warnings'] ?? [];
|
|
$carryForward = $preview['carry_forward'] ?? [];
|
|
$inventory = $preview['inventory'] ?? ['rows' => [], 'summary' => []];
|
|
$inventoryRows = $inventory['rows'] ?? [];
|
|
$carryForwardTotal = array_reduce(
|
|
$carryForward,
|
|
static fn (float $total, array $row): float => $total + (float) ($row['carry_forward_amount'] ?? 0),
|
|
0.0
|
|
);
|
|
$status = (string) ($source['status'] ?? '');
|
|
$batchStatus = (string) ($latestBatch['status'] ?? '');
|
|
$missingCarryForwardInvoices = (int) ($missingCarryForwardInvoices ?? 0);
|
|
$money = static fn ($value): string => '$' . number_format((float) $value, 2);
|
|
$score = static fn ($value): string => is_numeric($value) ? number_format((float) $value, 2) : '-';
|
|
$sourceId = (int) ($source['id'] ?? 0);
|
|
$targetId = (int) ($target['id'] ?? 0);
|
|
$flowStep = 1;
|
|
if ($status === 'closing' && $batchStatus === 'started') {
|
|
$flowStep = 3;
|
|
} elseif ($status === 'closing' && $batchStatus === 'executed') {
|
|
$flowStep = 4;
|
|
} elseif ($status === 'closed' || $batchStatus === 'completed') {
|
|
$flowStep = 5;
|
|
} elseif ($status === 'active') {
|
|
$flowStep = $blockers === [] && $target ? 2 : 1;
|
|
}
|
|
$initialModalStep = $flowStep === 2 ? 1 : $flowStep;
|
|
$flowSteps = [
|
|
1 => [
|
|
'title' => 'Review checklist',
|
|
'description' => 'Confirm promotion decisions, blocking issues, warnings, and financial totals before the year is locked.',
|
|
],
|
|
2 => [
|
|
'title' => 'Start close',
|
|
'description' => 'Lock the current year into end-year review and connect it to the selected next school year.',
|
|
],
|
|
3 => [
|
|
'title' => 'Carry forward',
|
|
'description' => 'Create or update target-year balances from the family balances shown in this checklist.',
|
|
],
|
|
4 => [
|
|
'title' => 'Finish close',
|
|
'description' => 'Mark the current school year closed and activate the next school year.',
|
|
],
|
|
5 => [
|
|
'title' => 'Closed',
|
|
'description' => 'The end-year process is complete. The closed year remains available for reporting and audit review.',
|
|
],
|
|
];
|
|
$ageBySchoolYearSecondSeptember = static function (array $row) use ($source): string {
|
|
$dob = trim((string) ($row['dob'] ?? ''));
|
|
$schoolYear = (string) ($source['name'] ?? '');
|
|
if ($dob === '' || preg_match('/^\d{4}-(\d{4})$/', $schoolYear, $matches) !== 1) {
|
|
return '';
|
|
}
|
|
|
|
try {
|
|
$birthDate = new DateTimeImmutable($dob);
|
|
$cutoff = new DateTimeImmutable($matches[1] . '-09-01');
|
|
} catch (Throwable) {
|
|
return '';
|
|
}
|
|
|
|
if ($birthDate > $cutoff) {
|
|
return '';
|
|
}
|
|
|
|
return (string) $birthDate->diff($cutoff)->y;
|
|
};
|
|
$kgPlacementFallback = static function (array $row) use ($target): string {
|
|
$classText = strtoupper(trim(
|
|
(string) ($row['class_name'] ?? '') . ' '
|
|
. (string) ($row['class_section_name'] ?? '')
|
|
));
|
|
if (preg_match('/(^|[^A-Z0-9])KG([^A-Z0-9]|$)/', $classText) !== 1 && ! str_contains($classText, 'KINDERGARTEN')) {
|
|
return '';
|
|
}
|
|
|
|
$dob = trim((string) ($row['dob'] ?? ''));
|
|
if ($dob === '') {
|
|
return '';
|
|
}
|
|
|
|
try {
|
|
$targetName = (string) ($target['name'] ?? '');
|
|
if (preg_match('/^(\d{4})-\d{4}$/', $targetName, $matches) === 1) {
|
|
$cutoff = new DateTimeImmutable($matches[1] . '-09-01');
|
|
} else {
|
|
$today = new DateTimeImmutable('today');
|
|
$cutoff = new DateTimeImmutable($today->format('Y') . '-09-01');
|
|
if ($today > $cutoff) {
|
|
$cutoff = $cutoff->modify('+1 year');
|
|
}
|
|
}
|
|
$birthDate = new DateTimeImmutable($dob);
|
|
} catch (Throwable) {
|
|
return '';
|
|
}
|
|
|
|
if ($birthDate > $cutoff) {
|
|
return '';
|
|
}
|
|
|
|
return $birthDate->diff($cutoff)->y >= 6 ? '1' : 'KG';
|
|
};
|
|
?>
|
|
|
|
<?php if (session()->getFlashdata('success')): ?>
|
|
<div class="alert alert-success"><?= esc(session()->getFlashdata('success')) ?></div>
|
|
<?php elseif (session()->getFlashdata('error')): ?>
|
|
<div class="alert alert-danger"><?= esc(session()->getFlashdata('error')) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="container-fluid py-3">
|
|
<div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-3">
|
|
<div>
|
|
<h2 class="mb-1">End-Year Checklist: <?= esc($source['name'] ?? '') ?></h2>
|
|
<div class="text-muted">
|
|
Status: <span class="fw-semibold"><?= esc(ucfirst($status)) ?></span>
|
|
<?php if ($target): ?>
|
|
<span class="mx-2">Next year: <span class="fw-semibold"><?= esc($target['name'] ?? '') ?></span></span>
|
|
<?php endif; ?>
|
|
<span>Generated: <?= esc($preview['generated_at'] ?? '') ?></span>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex flex-wrap gap-2">
|
|
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#closeSchoolYearFlowModal">
|
|
Continue End-Year Flow
|
|
</button>
|
|
<a class="btn btn-outline-secondary" href="<?= site_url('administrator/school-years') ?>">Back to School Years</a>
|
|
</div>
|
|
</div>
|
|
|
|
<form class="row g-2 align-items-end mb-4" method="get" action="<?= site_url('administrator/school-years/' . (int) ($source['id'] ?? 0) . '/closing/preview') ?>">
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="target_school_year_id">Next school year</label>
|
|
<select class="form-select" id="target_school_year_id" name="target_school_year_id">
|
|
<option value="">Auto-select next draft year</option>
|
|
<?php foreach (($schoolYears ?? []) as $year): ?>
|
|
<?php if ((int) ($year['id'] ?? 0) !== (int) ($source['id'] ?? 0)): ?>
|
|
<option value="<?= (int) $year['id'] ?>" <?= $target && (int) $target['id'] === (int) $year['id'] ? 'selected' : '' ?>>
|
|
<?= esc($year['name'] ?? '') ?> (<?= esc($year['status'] ?? '') ?>)
|
|
</option>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<button class="btn btn-primary" type="submit">Refresh Checklist</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-3">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<div class="text-muted small">Students</div>
|
|
<div class="fs-5 fw-semibold"><?= esc((string) ($overview['students'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<div class="text-muted small">Families</div>
|
|
<div class="fs-5 fw-semibold"><?= esc((string) ($overview['families'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<div class="text-muted small">Invoices</div>
|
|
<div class="fs-5 fw-semibold"><?= esc((string) ($overview['invoices'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<div class="text-muted small">Outstanding</div>
|
|
<div class="fs-5 fw-semibold"><?= esc($money($overview['total_outstanding'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-lg-6">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<h5>Blocking Issues</h5>
|
|
<?php if ($blockers === []): ?>
|
|
<p class="text-muted mb-0">No blocking issues found.</p>
|
|
<?php else: ?>
|
|
<ul class="mb-0">
|
|
<?php foreach ($blockers as $finding): ?>
|
|
<li><strong><?= esc($finding['title']) ?>:</strong> <?= esc($finding['detail']) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-6">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<h5>Warnings</h5>
|
|
<?php if ($warnings === []): ?>
|
|
<p class="text-muted mb-0">No warnings found.</p>
|
|
<?php else: ?>
|
|
<ul class="mb-0">
|
|
<?php foreach ($warnings as $finding): ?>
|
|
<li><strong><?= esc($finding['title']) ?>:</strong> <?= esc($finding['detail']) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-lg-5">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<h5>Finance Summary</h5>
|
|
<dl class="row mb-0">
|
|
<dt class="col-7">Total invoiced</dt>
|
|
<dd class="col-5 text-end"><?= esc($money($finance['total_invoiced'] ?? 0)) ?></dd>
|
|
<dt class="col-7">Total paid</dt>
|
|
<dd class="col-5 text-end"><?= esc($money($finance['total_paid'] ?? 0)) ?></dd>
|
|
<dt class="col-7">Positive balances</dt>
|
|
<dd class="col-5 text-end"><?= esc($money($finance['positive_balance'] ?? 0)) ?></dd>
|
|
<dt class="col-7">Credits</dt>
|
|
<dd class="col-5 text-end"><?= esc($money($finance['credit_balance'] ?? 0)) ?></dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-7">
|
|
<div class="border rounded bg-white p-3 h-100">
|
|
<h5>End-Year Progress</h5>
|
|
<ol class="mb-0">
|
|
<li>Checklist generated</li>
|
|
<li class="<?= $blockers === [] ? '' : 'text-muted' ?>">Validation <?= $blockers === [] ? 'passed' : 'has blockers' ?></li>
|
|
<li class="<?= $batchStatus !== '' ? '' : 'text-muted' ?>">End-year process <?= $batchStatus !== '' ? esc($batchStatus) : 'not started' ?></li>
|
|
<li class="<?= in_array($batchStatus, ['executed', 'completed'], true) ? '' : 'text-muted' ?>">Carry-forward completed</li>
|
|
<li class="<?= $status === 'closed' ? '' : 'text-muted' ?>">Year closed</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="border rounded bg-white p-3 mb-4" id="promotion-table">
|
|
<div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-3">
|
|
<div>
|
|
<h5 class="mb-1">Student Promotion Preview</h5>
|
|
<div class="text-muted small">Promotion decisions must be generated and resolved before this school year can end.</div>
|
|
</div>
|
|
<a class="btn btn-outline-primary btn-sm" href="<?= site_url('grading/below-60/decisions') ?>">
|
|
Manage Promotion Decisions
|
|
</a>
|
|
</div>
|
|
|
|
<div class="row g-3 mb-3">
|
|
<div class="col-lg-2 col-md-3 col-6">
|
|
<div class="border rounded p-2 h-100">
|
|
<div class="text-muted small">Students</div>
|
|
<div class="fw-semibold"><?= esc((string) ($promotionSummary['total_students'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-2 col-md-3 col-6">
|
|
<div class="border rounded p-2 h-100">
|
|
<div class="text-muted small">Decided</div>
|
|
<div class="fw-semibold"><?= esc((string) ($promotionSummary['with_decision'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-2 col-md-3 col-6">
|
|
<div class="border rounded p-2 h-100">
|
|
<div class="text-muted small">Pass</div>
|
|
<div class="fw-semibold"><?= esc((string) ($promotionSummary['pass'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-2 col-md-3 col-6">
|
|
<div class="border rounded p-2 h-100">
|
|
<div class="text-muted small">Pending</div>
|
|
<div class="fw-semibold text-danger"><?= esc((string) ($promotionSummary['pending_decision'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-2 col-md-3 col-6">
|
|
<div class="border rounded p-2 h-100">
|
|
<div class="text-muted small">Other</div>
|
|
<div class="fw-semibold"><?= esc((string) ($promotionSummary['other_decision'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table id="promotionPreviewTable" class="table table-sm align-middle no-mgmt-sticky" data-no-mgmt-sticky>
|
|
<thead>
|
|
<tr>
|
|
<th>Student</th>
|
|
<th>School ID</th>
|
|
<th>Class</th>
|
|
<th class="text-end">Age Sep 1</th>
|
|
<th class="text-end">Year Score</th>
|
|
<th>Decision</th>
|
|
<th>Source</th>
|
|
<th>Next Year Placement</th>
|
|
<th>Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($promotionRows as $row): ?>
|
|
<?php
|
|
$rowStatus = (string) ($row['status'] ?? 'missing');
|
|
$statusClass = $rowStatus === 'decided' ? 'success' : 'danger';
|
|
$sourceLabel = (string) ($row['source'] ?? '');
|
|
if ($sourceLabel === 'automatic_kg_age') {
|
|
$sourceLabel = 'Auto KG age';
|
|
}
|
|
$targetLabel = trim((string) ($row['target_section'] ?? ''));
|
|
if ($targetLabel === '') {
|
|
$targetLabel = trim((string) ($row['target_class'] ?? ''));
|
|
}
|
|
if ($targetLabel === '') {
|
|
$targetLabel = $kgPlacementFallback($row);
|
|
}
|
|
$ageSepOne = $ageBySchoolYearSecondSeptember($row);
|
|
?>
|
|
<tr>
|
|
<td><?= esc($row['student_name'] ?? ('Student #' . (int) ($row['student_id'] ?? 0))) ?></td>
|
|
<td><?= esc($row['school_id'] ?? '') ?></td>
|
|
<td><?= esc($row['class_section_name'] ?? '') ?></td>
|
|
<td class="text-end" data-order="<?= esc($ageSepOne, 'attr') ?>"><?= esc($ageSepOne !== '' ? $ageSepOne : '-') ?></td>
|
|
<td class="text-end" data-order="<?= esc(is_numeric($row['year_score'] ?? null) ? (string) $row['year_score'] : '', 'attr') ?>"><?= esc($score($row['year_score'] ?? null)) ?></td>
|
|
<td><?= esc(($row['decision'] ?? '') !== '' ? $row['decision'] : '-') ?></td>
|
|
<td><?= esc($sourceLabel) ?></td>
|
|
<td data-order="<?= esc($targetLabel, 'attr') ?>"><?= esc($targetLabel !== '' ? $targetLabel : '-') ?></td>
|
|
<td data-order="<?= esc($rowStatus, 'attr') ?>"><span class="badge bg-<?= esc($statusClass) ?>"><?= esc(ucfirst($rowStatus)) ?></span></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="border rounded bg-white p-3 mb-4" id="carry-forward-table">
|
|
<h5>Book Inventory Reconciliation</h5>
|
|
<div class="table-responsive mb-4">
|
|
<table class="table table-sm align-middle no-mgmt-sticky" data-no-mgmt-sticky>
|
|
<thead>
|
|
<tr>
|
|
<th>Book</th>
|
|
<th class="text-end">Opening</th>
|
|
<th class="text-end">Net Movements</th>
|
|
<th class="text-end">System Closing</th>
|
|
<th class="text-end">Physical Count</th>
|
|
<th class="text-end">Variance</th>
|
|
<th class="text-end">Charge Price</th>
|
|
<th class="text-end">Target Opening</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($inventoryRows as $row): ?>
|
|
<tr>
|
|
<td>
|
|
<div><?= esc($row['item_name'] ?? '') ?></div>
|
|
<div class="text-muted small"><?= esc(trim((string)($row['isbn'] ?? '') . ' ' . (string)($row['edition'] ?? ''))) ?></div>
|
|
</td>
|
|
<td class="text-end"><?= (int) ($row['opening_quantity'] ?? 0) ?></td>
|
|
<td class="text-end"><?= (int) ($row['movement_total'] ?? 0) ?></td>
|
|
<td class="text-end"><?= (int) ($row['system_closing_quantity'] ?? 0) ?></td>
|
|
<td class="text-end"><?= ($row['counted_closing_quantity'] ?? null) === null ? 'Missing' : (int) $row['counted_closing_quantity'] ?></td>
|
|
<td class="text-end"><?= ($row['variance_quantity'] ?? null) === null ? '-' : (int) $row['variance_quantity'] ?></td>
|
|
<td class="text-end">$<?= number_format(((int) ($row['charge_price_cents'] ?? 0)) / 100, 2) ?></td>
|
|
<td class="text-end"><?= (int) ($row['target_opening_quantity'] ?? 0) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if ($inventoryRows === []): ?>
|
|
<tr><td colspan="8" class="text-muted">No book inventory item-year rows found for this source year.</td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h5>Carry-Forward Families</h5>
|
|
<div class="table-responsive">
|
|
<table id="carryForwardFamiliesTable" class="table table-sm align-middle no-mgmt-sticky" data-no-mgmt-sticky>
|
|
<thead>
|
|
<tr>
|
|
<th>Family</th>
|
|
<th>Parent</th>
|
|
<th class="text-end">Source Balance</th>
|
|
<th class="text-end">Credits</th>
|
|
<th class="text-end">Adjustments</th>
|
|
<th class="text-end">Net Carry-Forward</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($carryForward as $row): ?>
|
|
<tr>
|
|
<td><?= esc($row['family']) ?></td>
|
|
<td>
|
|
<div><?= esc($row['parent'] ?? ('Parent #' . (int) ($row['family_id'] ?? 0))) ?></div>
|
|
<?php if (! empty($row['parent_email'])): ?>
|
|
<div class="text-muted small"><?= esc($row['parent_email']) ?></div>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="text-end" data-order="<?= esc((string) (float) ($row['source_balance'] ?? 0), 'attr') ?>"><?= esc($money($row['source_balance'])) ?></td>
|
|
<td class="text-end" data-order="<?= esc((string) (float) ($row['credit_amount'] ?? 0), 'attr') ?>"><?= esc($money($row['credit_amount'])) ?></td>
|
|
<td class="text-end" data-order="<?= esc((string) (float) ($row['adjustment_amount'] ?? 0), 'attr') ?>"><?= esc($money($row['adjustment_amount'])) ?></td>
|
|
<td class="text-end" data-order="<?= esc((string) (float) ($row['carry_forward_amount'] ?? 0), 'attr') ?>"><?= esc($money($row['carry_forward_amount'])) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div
|
|
class="modal fade"
|
|
id="closeSchoolYearFlowModal"
|
|
tabindex="-1"
|
|
aria-labelledby="closeSchoolYearFlowModalLabel"
|
|
aria-hidden="true"
|
|
data-initial-step="<?= esc((string) $initialModalStep, 'attr') ?>"
|
|
data-max-step="<?= esc((string) $flowStep, 'attr') ?>"
|
|
>
|
|
<div class="modal-dialog modal-xl modal-dialog-scrollable">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<div>
|
|
<h5 class="modal-title" id="closeSchoolYearFlowModalLabel">Close <?= esc($source['name'] ?? '') ?></h5>
|
|
<div class="text-muted small">
|
|
<?php if ($target): ?>
|
|
Next school year: <span class="fw-semibold"><?= esc($target['name'] ?? '') ?></span>
|
|
<?php else: ?>
|
|
Select or create a next school year before closing can start.
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="row g-3 mb-4">
|
|
<?php foreach ($flowSteps as $stepNumber => $step): ?>
|
|
<?php
|
|
$stepClass = $stepNumber < $flowStep
|
|
? 'border-success bg-light'
|
|
: ($stepNumber === $flowStep ? 'border-primary' : 'border-light bg-light');
|
|
$badgeClass = $stepNumber < $flowStep
|
|
? 'bg-success'
|
|
: ($stepNumber === $flowStep ? 'bg-primary' : 'bg-secondary');
|
|
?>
|
|
<div class="col-lg col-md-4 col-sm-6">
|
|
<div class="border rounded p-3 h-100 <?= esc($stepClass) ?>" data-step-indicator="<?= esc((string) $stepNumber, 'attr') ?>">
|
|
<span class="badge <?= esc($badgeClass) ?> mb-2"><?= esc((string) $stepNumber) ?></span>
|
|
<div class="fw-semibold"><?= esc($step['title']) ?></div>
|
|
<div class="text-muted small"><?= esc($step['description']) ?></div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<div class="close-school-year-step" data-step-pane="1">
|
|
<h6 class="mb-3">Review checklist details</h6>
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-3">
|
|
<div class="border rounded p-3 h-100">
|
|
<div class="text-muted small">Students reviewed</div>
|
|
<div class="fs-5 fw-semibold"><?= esc((string) ($overview['students'] ?? 0)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="border rounded p-3 h-100">
|
|
<div class="text-muted small">Pending decisions</div>
|
|
<div class="fs-5 fw-semibold <?= (int) ($promotionSummary['pending_decision'] ?? 0) > 0 ? 'text-danger' : '' ?>">
|
|
<?= esc((string) ($promotionSummary['pending_decision'] ?? 0)) ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="border rounded p-3 h-100">
|
|
<div class="text-muted small">Blocking issues</div>
|
|
<div class="fs-5 fw-semibold <?= $blockers === [] ? 'text-success' : 'text-danger' ?>"><?= esc((string) count($blockers)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="border rounded p-3 h-100">
|
|
<div class="text-muted small">Net carry-forward</div>
|
|
<div class="fs-5 fw-semibold"><?= esc($money($carryForwardTotal)) ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($blockers !== []): ?>
|
|
<div class="alert alert-danger">
|
|
<div class="fw-semibold mb-2">Resolve these blockers before the year can be closed.</div>
|
|
<ul class="mb-0">
|
|
<?php foreach ($blockers as $finding): ?>
|
|
<li><strong><?= esc($finding['title']) ?>:</strong> <?= esc($finding['detail']) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php elseif (! $target && $status === 'active'): ?>
|
|
<div class="alert alert-warning mb-0">
|
|
A next school year is required. Use the selector on this page to choose a target year, then refresh the checklist.
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="alert alert-success mb-0">
|
|
Checklist review is ready. Continue to the next step to start closing this school year.
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($warnings !== []): ?>
|
|
<div class="border rounded p-3 mt-3">
|
|
<div class="fw-semibold mb-2">Warnings to review</div>
|
|
<ul class="mb-0">
|
|
<?php foreach ($warnings as $finding): ?>
|
|
<li><strong><?= esc($finding['title']) ?>:</strong> <?= esc($finding['detail']) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="close-school-year-step d-none" data-step-pane="2">
|
|
<h6 class="mb-3">Start the close</h6>
|
|
<div class="alert alert-warning mb-3">
|
|
Starting the close locks <?= esc($source['name'] ?? 'this school year') ?> into end-year review. Normal edits for this year stop while carry-forward is prepared.
|
|
</div>
|
|
<dl class="row mb-0">
|
|
<dt class="col-sm-4">Current school year</dt>
|
|
<dd class="col-sm-8"><?= esc($source['name'] ?? '') ?></dd>
|
|
<dt class="col-sm-4">Next school year</dt>
|
|
<dd class="col-sm-8"><?= esc($target['name'] ?? 'Not selected') ?></dd>
|
|
<dt class="col-sm-4">Blocking issues</dt>
|
|
<dd class="col-sm-8"><?= esc((string) count($blockers)) ?></dd>
|
|
</dl>
|
|
</div>
|
|
|
|
<div class="close-school-year-step d-none" data-step-pane="3">
|
|
<h6 class="mb-3">Confirm carry-forward</h6>
|
|
<div class="alert alert-primary mb-3">
|
|
Carry-forward will create or update next-year invoices from the balances shown in the Carry-Forward Families table.
|
|
</div>
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="border rounded p-3 h-100">
|
|
<div class="text-muted small">Families with carry-forward rows</div>
|
|
<div class="fs-5 fw-semibold"><?= esc((string) count($carryForward)) ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="border rounded p-3 h-100">
|
|
<div class="text-muted small">Net carry-forward</div>
|
|
<div class="fs-5 fw-semibold"><?= esc($money($carryForwardTotal)) ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="close-school-year-step d-none" data-step-pane="4">
|
|
<h6 class="mb-3">Finish the close</h6>
|
|
<div class="alert alert-success mb-0">
|
|
Carry-forward is complete. Finishing the close will mark <?= esc($source['name'] ?? 'this school year') ?> closed and activate <?= esc($target['name'] ?? 'the next school year') ?>.
|
|
</div>
|
|
</div>
|
|
|
|
<div class="close-school-year-step d-none" data-step-pane="5">
|
|
<h6 class="mb-3">Closed</h6>
|
|
<div class="alert alert-secondary mb-0">
|
|
This close flow is complete. Use the report tables on this page for audit review.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer justify-content-between">
|
|
<div>
|
|
<?php if ($status === 'closing' && ! in_array($batchStatus, ['executed', 'completed'], true)): ?>
|
|
<form action="<?= site_url('administrator/school-years/' . $sourceId . '/closing/cancel') ?>" method="post" data-action-step="3">
|
|
<?= csrf_field() ?>
|
|
<button class="btn btn-outline-secondary" type="submit">Cancel End-Year Process</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="d-flex flex-wrap gap-2">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Review Page</button>
|
|
<button type="button" class="btn btn-outline-primary" data-step-back>Back</button>
|
|
<button type="button" class="btn btn-primary" data-step-next>Next</button>
|
|
|
|
<?php if ($status === 'active' && $target && $blockers === []): ?>
|
|
<form action="<?= site_url('administrator/school-years/' . $sourceId . '/closing/start') ?>" method="post" data-action-step="2">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="target_school_year_id" value="<?= $targetId ?>">
|
|
<button class="btn btn-warning" type="submit">Next</button>
|
|
</form>
|
|
<?php elseif ($status === 'active'): ?>
|
|
<button class="btn btn-warning" type="button" disabled data-action-step="1">Next</button>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($status === 'closing' && $batchStatus === 'started'): ?>
|
|
<form action="<?= site_url('administrator/school-years/' . $sourceId . '/closing/execute') ?>" method="post" data-action-step="3">
|
|
<?= csrf_field() ?>
|
|
<button class="btn btn-primary" type="submit">Next</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($status === 'closing' && $batchStatus === 'executed'): ?>
|
|
<form action="<?= site_url('administrator/school-years/' . $sourceId . '/closing/complete') ?>" method="post" data-action-step="4">
|
|
<?= csrf_field() ?>
|
|
<button class="btn btn-success" type="submit">Finish Close</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($status === 'closed' || $batchStatus === 'completed'): ?>
|
|
<a class="btn btn-success" href="<?= site_url('administrator/school-years') ?>" data-action-step="5">Finish</a>
|
|
<?php elseif ($batchStatus === 'executed'): ?>
|
|
<form action="<?= site_url('administrator/school-years/' . $sourceId . '/closing/execute') ?>" method="post" data-action-step="4">
|
|
<?= csrf_field() ?>
|
|
<button class="btn btn-outline-primary" type="submit">
|
|
<?= $missingCarryForwardInvoices > 0
|
|
? 'Repair Carry-Forward Invoices (' . $missingCarryForwardInvoices . ')'
|
|
: 'Re-run Carry-Forward Sync' ?>
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?= $this->endSection() ?>
|
|
|
|
<?= $this->section('scripts') ?>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
var closeFlowModal = document.getElementById('closeSchoolYearFlowModal');
|
|
var setupCloseFlowModal = function () {
|
|
if (!closeFlowModal) {
|
|
return;
|
|
}
|
|
|
|
var currentStep = parseInt(closeFlowModal.getAttribute('data-initial-step') || '1', 10);
|
|
var maxStep = parseInt(closeFlowModal.getAttribute('data-max-step') || '1', 10);
|
|
var backButton = closeFlowModal.querySelector('[data-step-back]');
|
|
var nextButton = closeFlowModal.querySelector('[data-step-next]');
|
|
var panes = Array.prototype.slice.call(closeFlowModal.querySelectorAll('[data-step-pane]'));
|
|
var indicators = Array.prototype.slice.call(closeFlowModal.querySelectorAll('[data-step-indicator]'));
|
|
var actions = Array.prototype.slice.call(closeFlowModal.querySelectorAll('[data-action-step]'));
|
|
var actionForms = actions.filter(function (action) {
|
|
return action.tagName && action.tagName.toLowerCase() === 'form';
|
|
});
|
|
|
|
var showStep = function (step) {
|
|
currentStep = Math.max(1, Math.min(maxStep, step));
|
|
|
|
panes.forEach(function (pane) {
|
|
pane.classList.toggle('d-none', parseInt(pane.getAttribute('data-step-pane') || '0', 10) !== currentStep);
|
|
});
|
|
|
|
indicators.forEach(function (indicator) {
|
|
var indicatorStep = parseInt(indicator.getAttribute('data-step-indicator') || '0', 10);
|
|
var badge = indicator.querySelector('.badge');
|
|
indicator.classList.remove('border-success', 'border-primary', 'border-light', 'bg-light');
|
|
if (badge) {
|
|
badge.classList.remove('bg-success', 'bg-primary', 'bg-secondary');
|
|
}
|
|
|
|
if (indicatorStep < currentStep) {
|
|
indicator.classList.add('border-success', 'bg-light');
|
|
if (badge) badge.classList.add('bg-success');
|
|
} else if (indicatorStep === currentStep) {
|
|
indicator.classList.add('border-primary');
|
|
if (badge) badge.classList.add('bg-primary');
|
|
} else {
|
|
indicator.classList.add('border-light', 'bg-light');
|
|
if (badge) badge.classList.add('bg-secondary');
|
|
}
|
|
});
|
|
|
|
actions.forEach(function (action) {
|
|
action.classList.toggle('d-none', parseInt(action.getAttribute('data-action-step') || '0', 10) !== currentStep);
|
|
});
|
|
|
|
if (backButton) {
|
|
backButton.classList.toggle('d-none', currentStep <= 1);
|
|
}
|
|
if (nextButton) {
|
|
nextButton.classList.toggle('d-none', currentStep >= maxStep);
|
|
}
|
|
};
|
|
|
|
if (backButton) {
|
|
backButton.addEventListener('click', function () {
|
|
showStep(currentStep - 1);
|
|
});
|
|
}
|
|
if (nextButton) {
|
|
nextButton.addEventListener('click', function () {
|
|
showStep(currentStep + 1);
|
|
});
|
|
}
|
|
|
|
actionForms.forEach(function (form) {
|
|
form.addEventListener('submit', function (event) {
|
|
var submitButton = form.querySelector('button[type="submit"]');
|
|
event.preventDefault();
|
|
|
|
if (submitButton) {
|
|
submitButton.disabled = true;
|
|
}
|
|
|
|
fetch(form.action, {
|
|
method: form.method || 'POST',
|
|
body: new FormData(form),
|
|
credentials: 'same-origin',
|
|
headers: {
|
|
'X-Requested-With': 'XMLHttpRequest'
|
|
}
|
|
})
|
|
.then(function (response) {
|
|
return response.text();
|
|
})
|
|
.then(function (html) {
|
|
var parsed = new DOMParser().parseFromString(html, 'text/html');
|
|
var updatedModal = parsed.getElementById('closeSchoolYearFlowModal');
|
|
|
|
if (!updatedModal) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
|
|
closeFlowModal.setAttribute('data-initial-step', updatedModal.getAttribute('data-initial-step') || '1');
|
|
closeFlowModal.setAttribute('data-max-step', updatedModal.getAttribute('data-max-step') || '1');
|
|
closeFlowModal.querySelector('.modal-content').innerHTML = updatedModal.querySelector('.modal-content').innerHTML;
|
|
setupCloseFlowModal();
|
|
})
|
|
.catch(function () {
|
|
form.submit();
|
|
})
|
|
.finally(function () {
|
|
if (submitButton) {
|
|
submitButton.disabled = false;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
showStep(currentStep);
|
|
};
|
|
|
|
if (closeFlowModal) {
|
|
setupCloseFlowModal();
|
|
if (new URLSearchParams(window.location.search).get('close_flow') === '1' && window.bootstrap && window.bootstrap.Modal) {
|
|
window.bootstrap.Modal.getOrCreateInstance(closeFlowModal).show();
|
|
}
|
|
}
|
|
|
|
if (!window.jQuery || !window.jQuery.fn || !window.jQuery.fn.DataTable) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
Object.keys(window.localStorage || {}).forEach(function (key) {
|
|
if (key.indexOf('DataTables_promotionPreviewTable_') === 0 || key.indexOf('DataTables_carryForwardFamiliesTable_') === 0) {
|
|
window.localStorage.removeItem(key);
|
|
}
|
|
});
|
|
} catch (error) {
|
|
// Ignore storage restrictions; DataTables can still initialize without saved state.
|
|
}
|
|
|
|
var baseOptions = {
|
|
paging: true,
|
|
pageLength: 25,
|
|
lengthMenu: [[25, 50, 100, 200, -1], [25, 50, 100, 200, 'All']],
|
|
pagingType: 'full_numbers',
|
|
stateSave: false,
|
|
autoWidth: false,
|
|
dom: "<'row mb-2'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" +
|
|
"t" +
|
|
"<'row mt-2'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
|
|
language: {
|
|
lengthMenu: 'Show _MENU_ entries',
|
|
paginate: {
|
|
first: 'First',
|
|
previous: 'Previous',
|
|
next: 'Next',
|
|
last: 'Last'
|
|
}
|
|
}
|
|
};
|
|
|
|
window.jQuery('#promotionPreviewTable').DataTable(Object.assign({}, baseOptions, {
|
|
order: [[2, 'asc'], [0, 'asc']],
|
|
language: {
|
|
lengthMenu: 'Show _MENU_ entries',
|
|
emptyTable: 'No active class assignments found for this school year.'
|
|
}
|
|
}));
|
|
|
|
window.jQuery('#carryForwardFamiliesTable').DataTable(Object.assign({}, baseOptions, {
|
|
order: [[0, 'asc']],
|
|
language: {
|
|
lengthMenu: 'Show _MENU_ entries',
|
|
emptyTable: 'No carry-forward balances found.'
|
|
}
|
|
}));
|
|
});
|
|
</script>
|
|
<?= $this->endSection() ?>
|