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