fix enrollment for the new school-year
Tests / PHPUnit (push) Successful in 1m26s

This commit is contained in:
root
2026-08-07 23:43:31 -04:00
parent b6f3b14e7b
commit 1ef2800f12
66 changed files with 8997 additions and 498 deletions
@@ -151,6 +151,13 @@ class PaymentController extends ResourceController
}
}
private function assertSchoolYearNameWritable(string $schoolYear): void
{
service('schoolYearWriteGuard')->assertWritable(
service('schoolYearContext')->forYearName($schoolYear)
);
}
// View: Create a new payment plan
public function create()
{
@@ -160,6 +167,12 @@ class PaymentController extends ResourceController
// API: Update balance after payment
public function updateBalanceAPI($paymentId)
{
$payment = $this->paymentModel->find($paymentId);
if (!$payment) {
return $this->failNotFound('Payment not found.');
}
$this->assertSchoolYearNameWritable((string)($payment['school_year'] ?? ''));
$amountPaid = $this->request->getPost('paid_amount');
if ($this->paymentModel->updateBalance($paymentId, $amountPaid)) {
return $this->respond(['status' => 'success']);
@@ -171,6 +184,12 @@ class PaymentController extends ResourceController
// View: Update balance after payment
public function updateBalance($paymentId)
{
$payment = $this->paymentModel->find($paymentId);
if (!$payment) {
return redirect()->back()->with('error', 'Payment not found.');
}
$this->assertSchoolYearNameWritable((string)($payment['school_year'] ?? ''));
$amountPaid = $this->request->getPost('paid_amount');
if ($this->paymentModel->updateBalance($paymentId, $amountPaid)) {
return redirect()->to('/payments');
@@ -879,6 +898,7 @@ class PaymentController extends ResourceController
if (!$invoice) {
return redirect()->back()->with('error', 'Invoice not found.');
}
$this->assertSchoolYearNameWritable((string)($invoice['school_year'] ?? ''));
// Snapshot pre-payment balance
$initialPreBalance = $this->getCurrentInvoiceBalance($invoiceId);
@@ -1142,6 +1162,7 @@ class PaymentController extends ResourceController
if (!$invoice) {
return redirect()->back()->with('error', 'Linked invoice not found.');
}
$this->assertSchoolYearNameWritable((string)($invoice['school_year'] ?? ($payment['school_year'] ?? '')));
//$schoolYear = (new ConfigurationModel())->getConfig('school_year');
$checkFile = $payment['check_file']; // default keep old file
@@ -1280,6 +1301,7 @@ class PaymentController extends ResourceController
}
$schoolYear = (string)($invoice['school_year'] ?? $this->schoolYear);
$this->assertSchoolYearNameWritable($schoolYear);
$this->recalculateInvoice((int)$invoice['id'], $schoolYear);
return redirect()->back()->with('success', 'Invoice recalculated.');