feat(webstatement): tambah model AccountBalance dan relasi balances pada Account
- Menambahkan model `AccountBalance` dengan fitur berikut: - Properti `fillable` meliputi: `account_number`, `period`, `actual_balance`, `cleared_balance`. - Relasi `belongsTo` dengan model `Account`. - Scope query untuk filter berdasarkan `account_number` (`scopeForAccount`) dan `period` (`scopeForPeriod`). - Fungsi statis `getBalance` untuk mendapatkan saldo berdasarkan `account_number` dan `period`. - Menambahkan method berikut pada model `Account`: - Relasi `hasMany` dengan `AccountBalance` untuk mendapatkan semua saldo terkait. - Method `getBalanceForPeriod` untuk mendapatkan saldo pada periode tertentu. - Membuat migrasi untuk tabel `account_balances` dengan spesifikasi berikut: - Kolom: `account_number`, `period` (format: YYYY-MM), `actual_balance` (decimal), `cleared_balance` (decimal), `timestamps`. - Konstrain unik untuk pasangan `account_number` dan `period`. - Indeks pada kolom `account_number`, `period`, dan `created_at`. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -34,4 +34,23 @@ class Account extends Model
|
||||
{
|
||||
return $this->belongsTo(Customer::class, 'customer_code', 'customer_code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all balances for this account.
|
||||
*/
|
||||
public function balances()
|
||||
{
|
||||
return $this->hasMany(AccountBalance::class, 'account_number', 'account_number');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get balance for a specific period.
|
||||
*
|
||||
* @param string $period Format: YYYY-MM
|
||||
* @return AccountBalance|null
|
||||
*/
|
||||
public function getBalanceForPeriod($period)
|
||||
{
|
||||
return $this->balances()->where('period', $period)->first();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user