This commit is contained in:
@@ -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'];
|
||||
|
||||
Reference in New Issue
Block a user