fix parent pages and teachers and admin
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped

This commit is contained in:
root
2026-07-09 13:56:22 -04:00
parent 21c9322127
commit 02ba2fe6b6
34 changed files with 2306 additions and 99 deletions
+47 -22
View File
@@ -8,13 +8,23 @@ class Payment extends BaseModel
{
protected $table = 'payments';
/**
* legacy: useTimestamps = false because DB handles created_at/updated_at (defaults/triggers).
* Keep OFF in Laravel too.
*/
public $timestamps = true;
protected $fillable = ['parent_id', 'invoice_id', 'total_amount', 'paid_amount', 'balance', 'number_of_installments', 'transaction_id', 'check_file', 'check_number', 'payment_method', 'payment_date', 'semester', 'school_year', 'status', 'updated_by', 'created_at', 'updated_at'];
protected $fillable = [
'parent_id',
'invoice_id',
'total_amount',
'paid_amount',
'balance',
'number_of_installments',
'transaction_id',
'check_file',
'check_number',
'payment_method',
'payment_date',
'semester',
'school_year',
'status',
'updated_by',
];
protected $casts = [
'parent_id' => 'integer',
@@ -26,10 +36,20 @@ class Payment extends BaseModel
'paid_amount' => 'decimal:2',
'balance' => 'decimal:2',
'payment_date' => 'datetime',
'payment_date' => 'date',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
protected $attributes = [
'paid_amount' => '0.00',
'balance' => '0.00',
'payment_method' => 'Unknown',
'status' => 'Pending',
];
/* Optional relationships */
public function invoice()
{
return $this->belongsTo(Invoice::class, 'invoice_id');
@@ -67,19 +87,18 @@ class Payment extends BaseModel
{
/** @var self|null $payment */
$payment = static::query()->find($paymentId);
if (! $payment) {
return false;
}
$newBalance = (float) $payment->balance - (float) $amountPaid;
// keep precision stable
$paidAmount = (float) $payment->paid_amount + (float) $amountPaid;
$newPaidAmount = round((float) $payment->paid_amount + $amountPaid, 2);
$newBalance = round((float) $payment->balance - $amountPaid, 2);
$affected = static::query()
->whereKey($paymentId)
->update([
'paid_amount' => $paidAmount,
'paid_amount' => $newPaidAmount,
'balance' => $newBalance,
]);
@@ -101,10 +120,10 @@ class Payment extends BaseModel
public static function generateNewTransactionId(): string
{
$currentYear = date('Y');
$prefix = $currentYear.'-';
$prefix = $currentYear . '-';
$latest = static::query()
->where('transaction_id', 'like', $prefix.'%')
->where('transaction_id', 'like', $prefix . '%')
->orderByDesc('transaction_id')
->first();
@@ -115,30 +134,34 @@ class Payment extends BaseModel
$newNumber = 1;
}
return $prefix.str_pad((string) $newNumber, 6, '0', STR_PAD_LEFT);
return $prefix . str_pad((string) $newNumber, 6, '0', STR_PAD_LEFT);
}
/**
* Get latest payment (date/amount/status) per invoice for given invoice IDs.
* Matches your legacy logic: statuses in ['Full','Paid','Partially Paid'].
* Get latest payment date/amount/status per invoice for given invoice IDs.
* Statuses included: Full, Paid, Partially Paid.
*/
public static function getPaymentsByInvoice($invoiceIds): array
{
if (! is_array($invoiceIds)) {
$invoiceIds = [$invoiceIds];
}
$invoiceIds = array_values(array_unique(array_map('intval', array_filter($invoiceIds))));
$invoiceIds = array_values(array_unique(array_map(
'intval',
array_filter($invoiceIds)
)));
if (empty($invoiceIds)) {
return [];
}
// Subquery: latest payment_date per invoice (Full/Partial only)
$latestSub = DB::table('payments')
->selectRaw('invoice_id, MAX(payment_date) AS max_date')
->whereIn('invoice_id', $invoiceIds)
->whereIn('status', ['Full', 'Paid', 'Partially Paid'])
->groupBy('invoice_id');
// Main query: join payments to the latest per invoice
$rows = DB::table('payments as p')
->joinSub($latestSub, 'latest', function ($join) {
$join->on('latest.invoice_id', '=', 'p.invoice_id')
@@ -149,11 +172,13 @@ class Payment extends BaseModel
->select([
'p.invoice_id',
DB::raw('p.paid_amount AS last_paid_amount'),
DB::raw('p.balance AS balance'),
DB::raw('p.balance AS balance_after_payment'),
DB::raw('p.payment_date AS last_payment_date'),
DB::raw('p.status AS last_payment_status'),
])
->get();
return $rows->map(fn ($r) => (array) $r)->all();
return $rows->map(fn ($row) => (array) $row)->all();
}
}