fix school year for all tables
Tests / PHPUnit (push) Failing after 1m20s

This commit is contained in:
root
2026-07-18 14:45:38 -04:00
parent 4db8334a3c
commit 716cc8b8d3
125 changed files with 2315 additions and 81 deletions
@@ -14,11 +14,13 @@ class SchoolYearClosingController extends BaseController
$targetId = $this->normalizeInt($this->request->getGet('target_school_year_id'));
$preview = service('schoolYearClosing')->preview($id, $targetId);
$promotionTable = $this->promotionTablePayload($preview['promotion']['rows'] ?? []);
$latestBatch = service('schoolYearClosing')->latestBatch($id);
return view('school_years/closing_preview', [
'preview' => $preview,
'promotionTable' => $promotionTable,
'latestBatch' => service('schoolYearClosing')->latestBatch($id),
'latestBatch' => $latestBatch,
'missingCarryForwardInvoices' => $this->missingCarryForwardInvoiceCount($latestBatch),
'schoolYears' => (new SchoolYearModel())->orderBy('name', 'DESC')->findAll(),
]);
} catch (Throwable $e) {
@@ -26,6 +28,23 @@ class SchoolYearClosingController extends BaseController
}
}
public function previewByName(string $name)
{
try {
$year = (new SchoolYearModel())
->where('name', rawurldecode($name))
->first();
if ($year === null) {
return redirect()->to('/administrator/school-years')->with('error', 'School year was not found.');
}
return $this->preview((int) $year['id']);
} catch (Throwable $e) {
return redirect()->to('/administrator/school-years')->with('error', $e->getMessage());
}
}
public function start(int $id)
{
try {
@@ -76,6 +95,26 @@ class SchoolYearClosingController extends BaseController
return is_numeric($value) && (int) $value > 0 ? (int) $value : null;
}
private function missingCarryForwardInvoiceCount(?array $batch): int
{
if ($batch === null || ! in_array((string) ($batch['status'] ?? ''), ['executed', 'completed'], true)) {
return 0;
}
$db = \Config\Database::connect();
if (! $db->tableExists('school_year_closing_items')) {
return 0;
}
return $db->table('school_year_closing_items')
->where('closing_batch_id', (int) $batch['id'])
->groupStart()
->where('target_invoice_id', null)
->orWhere('target_invoice_id', 0)
->groupEnd()
->countAllResults();
}
private function promotionTablePayload(array $rows): array
{
$allowedSorts = ['student', 'school_id', 'class', 'year_score', 'decision', 'source', 'queue', 'target', 'status'];