fix payments
This commit is contained in:
@@ -150,10 +150,12 @@ class FamilyAdminController extends BaseController
|
||||
}
|
||||
|
||||
// Recent payments (limit 10)
|
||||
$payRows = $db->table('payments')
|
||||
->select('id, parent_id, invoice_id, paid_amount, balance, payment_method, payment_date, status')
|
||||
->whereIn('parent_id', $parentIds)
|
||||
->orderBy('payment_date', 'DESC')
|
||||
$payRows = $db->table('payments p')
|
||||
->select('p.id, p.parent_id, p.invoice_id, p.paid_amount, p.payment_method, p.payment_date, p.status AS payment_status, p.installment_seq, p.number_of_installments, i.invoice_number, i.balance AS invoice_current_balance, i.status AS invoice_status, i.school_year')
|
||||
->join('invoices i', 'i.id = p.invoice_id', 'inner')
|
||||
->whereIn('p.parent_id', $parentIds)
|
||||
->orderBy('p.payment_date', 'DESC')
|
||||
->orderBy('p.id', 'DESC')
|
||||
->limit(10)
|
||||
->get()->getResultArray();
|
||||
$fam['payments'] = $payRows;
|
||||
@@ -395,10 +397,12 @@ class FamilyAdminController extends BaseController
|
||||
}
|
||||
|
||||
// Payments
|
||||
$payRows = $db->table('payments')
|
||||
->select('id, parent_id, invoice_id, paid_amount, balance, payment_method, payment_date, status')
|
||||
->whereIn('parent_id', $parentIds)
|
||||
->orderBy('payment_date', 'DESC')
|
||||
$payRows = $db->table('payments p')
|
||||
->select('p.id, p.parent_id, p.invoice_id, p.paid_amount, p.payment_method, p.payment_date, p.status AS payment_status, p.installment_seq, p.number_of_installments, i.invoice_number, i.balance AS invoice_current_balance, i.status AS invoice_status, i.school_year')
|
||||
->join('invoices i', 'i.id = p.invoice_id', 'inner')
|
||||
->whereIn('p.parent_id', $parentIds)
|
||||
->orderBy('p.payment_date', 'DESC')
|
||||
->orderBy('p.id', 'DESC')
|
||||
->limit(10)
|
||||
->get()->getResultArray();
|
||||
$family['payments'] = $payRows;
|
||||
|
||||
@@ -658,10 +658,10 @@ public function financialReport()
|
||||
}, $discountDetailsBuilder->orderBy('du.id', 'ASC')->get()->getResultArray());
|
||||
|
||||
$paymentDetailsBuilder = $db->table('payments p')
|
||||
->select("p.id, p.invoice_id, p.parent_id, p.paid_amount, p.payment_method, p.payment_date, p.status, p.transaction_id, p.check_number, i.invoice_number, CONCAT(COALESCE(u.firstname, ''), ' ', COALESCE(u.lastname, '')) AS parent_name")
|
||||
->join('invoices i', 'i.id = p.invoice_id', 'left')
|
||||
->select("p.id, p.invoice_id, p.parent_id, p.paid_amount, p.payment_method, p.payment_date, p.status AS payment_status, p.transaction_id, p.check_number, i.invoice_number, i.balance AS invoice_current_balance, i.status AS invoice_status, i.school_year, CONCAT(COALESCE(u.firstname, ''), ' ', COALESCE(u.lastname, '')) AS parent_name")
|
||||
->join('invoices i', 'i.id = p.invoice_id', 'inner')
|
||||
->join('users u', 'u.id = p.parent_id', 'left')
|
||||
->where('p.school_year', $schoolYear)
|
||||
->where('i.school_year', $schoolYear)
|
||||
->groupStart()
|
||||
->whereNotIn('p.status', $paymentExclude)
|
||||
->orWhere('p.status IS NULL', null, false)
|
||||
@@ -677,9 +677,12 @@ public function financialReport()
|
||||
'Parent' => trim((string)($row['parent_name'] ?? '')),
|
||||
'Invoice #' => (string)($row['invoice_number'] ?? ''),
|
||||
'Paid Amount' => (float)($row['paid_amount'] ?? 0),
|
||||
'Invoice Balance' => (float)($row['invoice_current_balance'] ?? 0),
|
||||
'Payment Method' => (string)($row['payment_method'] ?? ''),
|
||||
'Payment Date' => (string)($row['payment_date'] ?? ''),
|
||||
'Status' => (string)($row['status'] ?? ''),
|
||||
'Payment Status' => (string)($row['payment_status'] ?? ''),
|
||||
'Invoice Status' => (string)($row['invoice_status'] ?? ''),
|
||||
'School Year' => (string)($row['school_year'] ?? ''),
|
||||
'Transaction ID' => (string)($row['transaction_id'] ?? ''),
|
||||
'Check Number' => (string)($row['check_number'] ?? ''),
|
||||
];
|
||||
|
||||
@@ -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