30 lines
718 B
PHP
30 lines
718 B
PHP
<?php
|
|
|
|
namespace Modules\Accounting\Entities;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class AccountingBankLoan extends Model
|
|
{
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
'disbursement_date' => 'date',
|
|
'maturity_date' => 'date',
|
|
'principal_amount' => 'float',
|
|
'interest_rate' => 'float',
|
|
'paid_principal' => 'float',
|
|
];
|
|
|
|
public function payments(): HasMany
|
|
{
|
|
return $this->hasMany(AccountingBankLoanPayment::class, 'bank_loan_id');
|
|
}
|
|
|
|
public function remainingPrincipal(): float
|
|
{
|
|
return max(0, (float) $this->principal_amount - (float) $this->paid_principal);
|
|
}
|
|
}
|