Hoan thien core finance v2

This commit is contained in:
2026-04-25 04:04:14 +00:00
parent 86216ef872
commit 002c9a8b99
39 changed files with 1308 additions and 89 deletions

View File

@@ -20,6 +20,21 @@ class PaymentScheduleItem extends Model
'due_date' => 'date',
];
public function getPaidAmountAttribute(): float
{
// Nếu đã eager load payments, dùng collection sum để tránh query thêm
if ($this->relationLoaded('payments')) {
return (float) $this->payments->sum('amount');
}
return (float) $this->payments()->sum('amount');
}
public function getRemainingAmountAttribute(): float
{
return (float) $this->amount - $this->paid_amount;
}
public function template()
{
return $this->belongsTo(PaymentTemplate::class);