fix payments
This commit is contained in:
@@ -85,7 +85,6 @@ class PaymentController extends ResourceController
|
||||
'payment_date' => $this->request->getPost('payment_date'),
|
||||
'payment_type' => $this->request->getPost('payment_type'),
|
||||
'status' => 'Pending',
|
||||
'semester' => $this->request->getPost('semester'),
|
||||
'school_year' => $this->request->getPost('school_year'),
|
||||
];
|
||||
|
||||
@@ -99,7 +98,8 @@ class PaymentController extends ResourceController
|
||||
// API: Get payments by parent ID
|
||||
public function getByParentAPI($parentId)
|
||||
{
|
||||
$payments = $this->paymentModel->getPaymentsByParentId($parentId);
|
||||
$selectedYear = $this->getSelectedPaymentHistoryYear();
|
||||
$payments = $this->paymentModel->getPaymentsByParentId((int) $parentId, $selectedYear);
|
||||
if ($payments) {
|
||||
return $this->respond($payments);
|
||||
} else {
|
||||
@@ -110,13 +110,8 @@ class PaymentController extends ResourceController
|
||||
// View: Get payments by parent ID (for web views)
|
||||
public function getByParent($parentId)
|
||||
{
|
||||
// Fetch payments with invoice number (if available)
|
||||
$payments = $this->paymentModel
|
||||
->select('payments.*, invoices.invoice_number')
|
||||
->join('invoices', 'invoices.id = payments.invoice_id', 'left')
|
||||
->where('payments.parent_id', (int)$parentId)
|
||||
->orderBy('payments.payment_date', 'DESC')
|
||||
->findAll();
|
||||
$selectedYear = $this->getSelectedPaymentHistoryYear();
|
||||
$payments = $this->paymentModel->getPaymentsByParentId((int) $parentId, $selectedYear);
|
||||
|
||||
// Parent display name
|
||||
$parent = $this->userModel->select('firstname, lastname')->find((int)$parentId) ?: [];
|
||||
@@ -140,6 +135,13 @@ class PaymentController extends ResourceController
|
||||
]);
|
||||
}
|
||||
|
||||
private function getSelectedPaymentHistoryYear(): ?string
|
||||
{
|
||||
$selectedYear = $this->request->getGet('school_year') ?? $this->schoolYear;
|
||||
|
||||
return $selectedYear !== '' ? $selectedYear : null;
|
||||
}
|
||||
|
||||
// View: Create a new payment plan
|
||||
public function create()
|
||||
{
|
||||
@@ -346,12 +348,12 @@ class PaymentController extends ResourceController
|
||||
->where('parent_id', $parentId)
|
||||
->findAll();
|
||||
|
||||
// Payments (paginated)
|
||||
$payments = $this->paymentModel
|
||||
->where('parent_id', $parentId)
|
||||
->orderBy('payment_date', 'DESC')
|
||||
->paginate(10);
|
||||
$pager = $this->paymentModel->pager;
|
||||
// Payments (paginated). Join invoices so history is filtered by invoice term
|
||||
// and displays current invoice state instead of stale payment snapshots.
|
||||
$selectedYear = $this->getSelectedPaymentHistoryYear();
|
||||
$paymentHistory = $this->paymentModel->parentPaymentHistoryQuery($parentId, $selectedYear);
|
||||
$payments = $paymentHistory->paginate(10);
|
||||
$pager = $paymentHistory->pager;
|
||||
|
||||
// Invoices
|
||||
$rawInvoices = $this->invoiceModel
|
||||
@@ -972,8 +974,7 @@ class PaymentController extends ResourceController
|
||||
$checkFile,
|
||||
$transactionId,
|
||||
$paymentDate,
|
||||
$this->schoolYear,
|
||||
$this->semester,
|
||||
$invYear,
|
||||
$checkNumber,
|
||||
$installmentSeq,
|
||||
(array) $this->invoiceModel->find($invoiceId),
|
||||
@@ -1015,7 +1016,7 @@ class PaymentController extends ResourceController
|
||||
$rowParentDisc = $this->db->table('discount_usages')
|
||||
->selectSum('discount_amount', 'sum_disc')
|
||||
->where('parent_id', $parentId)
|
||||
->where('school_year', $this->schoolYear)
|
||||
->where('school_year', $invYear)
|
||||
->get()->getRowArray();
|
||||
if ($rowParentDisc && isset($rowParentDisc['sum_disc'])) {
|
||||
$parentYearDiscountTotal = (float)$rowParentDisc['sum_disc'];
|
||||
@@ -1270,7 +1271,6 @@ class PaymentController extends ResourceController
|
||||
$transactionId = null,
|
||||
$paymentDate = null,
|
||||
$schoolYear = null,
|
||||
$semester = null,
|
||||
$checkNumber = null,
|
||||
?int $installmentSeq = null,
|
||||
?array $invoice = null,
|
||||
@@ -1315,8 +1315,7 @@ class PaymentController extends ResourceController
|
||||
'check_file' => $checkFile,
|
||||
'check_number' => (strtolower($paymentMethod) === 'check') ? $checkNumber : null,
|
||||
'updated_by' => session()->get('user_id'),
|
||||
'school_year' => $schoolYear ?? $this->schoolYear,
|
||||
'semester' => $semester ?? $this->semester,
|
||||
'school_year' => $schoolYear ?? ($invoice['school_year'] ?? $this->schoolYear),
|
||||
];
|
||||
|
||||
if (!$this->paymentModel->insert($paymentData)) {
|
||||
|
||||
Reference in New Issue
Block a user