fix school year and enrollment steps
Tests / PHPUnit (push) Failing after 58s

This commit is contained in:
root
2026-08-15 21:15:05 -04:00
parent 4603d9ced2
commit 3cbfc40934
18 changed files with 1142 additions and 163 deletions
+376 -55
View File
@@ -13,11 +13,51 @@
$blockers = $preview['blockers'] ?? [];
$warnings = $preview['warnings'] ?? [];
$carryForward = $preview['carry_forward'] ?? [];
$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'] ?? '');
@@ -94,16 +134,12 @@
<span>Generated: <?= esc($preview['generated_at'] ?? '') ?></span>
</div>
</div>
<a class="btn btn-outline-secondary" href="<?= site_url('administrator/school-years') ?>">Back to School Years</a>
</div>
<div class="border rounded bg-white p-3 mb-4">
<h5 class="mb-2">How to End This Year</h5>
<ol class="mb-0">
<li>Clear all blocking issues below.</li>
<li>Start the end-year process to lock the checklist.</li>
<li>Confirm carry-forward balances, then mark this school year closed.</li>
</ol>
<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') ?>">
@@ -342,55 +378,218 @@
</div>
</div>
<div class="d-flex flex-wrap gap-2 mb-4">
<?php if ($status === 'active' && $target && $blockers === []): ?>
<form action="<?= site_url('administrator/school-years/' . (int) $source['id'] . '/closing/start') ?>" method="post">
<?= csrf_field() ?>
<input type="hidden" name="target_school_year_id" value="<?= (int) $target['id'] ?>">
<button class="btn btn-warning" type="submit">Close Year</button>
</form>
<?php elseif ($status === 'active'): ?>
<button class="btn btn-warning" type="button" disabled>Close Year</button>
<span class="align-self-center text-muted small">
<?php if (! $target): ?>
Create or select the next school year first.
<?php elseif ($blockers !== []): ?>
Resolve the blocking issues above first.
<?php endif; ?>
</span>
<?php endif; ?>
</div>
<?php if ($status === 'closing' && $batchStatus === 'started'): ?>
<form action="<?= site_url('administrator/school-years/' . (int) $source['id'] . '/closing/execute') ?>" method="post">
<?= csrf_field() ?>
<button class="btn btn-primary" type="submit">Confirm Carry-Forward</button>
</form>
<?php endif; ?>
<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>
<?php if ($status === 'closing' && $batchStatus === 'executed'): ?>
<form action="<?= site_url('administrator/school-years/' . (int) $source['id'] . '/closing/complete') ?>" method="post">
<?= csrf_field() ?>
<button class="btn btn-success" type="submit">Close Year</button>
</form>
<?php endif; ?>
<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 (in_array($batchStatus, ['executed', 'completed'], true)): ?>
<form action="<?= site_url('administrator/school-years/' . (int) $source['id'] . '/closing/execute') ?>" method="post">
<?= csrf_field() ?>
<button class="btn btn-primary" type="submit">
<?= $missingCarryForwardInvoices > 0
? 'Repair Carry-Forward Invoices (' . $missingCarryForwardInvoices . ')'
: 'Re-run Carry-Forward Sync' ?>
</button>
</form>
<?php endif; ?>
<?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 ($status === 'closing' && ! in_array($batchStatus, ['executed', 'completed'], true)): ?>
<form action="<?= site_url('administrator/school-years/' . (int) $source['id'] . '/closing/cancel') ?>" method="post">
<?= csrf_field() ?>
<button class="btn btn-outline-secondary" type="submit">Cancel End-Year Process</button>
</form>
<?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>
@@ -399,6 +598,128 @@
<?= $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;
}