- 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>
57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
// use Modules\Webstatement\Database\Factories\AccountFactory;
|
|
|
|
class Account extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected $fillable = [
|
|
'account_number',
|
|
'customer_code',
|
|
'currency',
|
|
'opening_date',
|
|
'branch_code',
|
|
'open_category',
|
|
'start_year_bal',
|
|
'closure_date',
|
|
'account_type',
|
|
'stmt_email',
|
|
'stmt_sent_type',
|
|
'open_actual_bal',
|
|
'open_cleared_bal'
|
|
];
|
|
|
|
// Relationships
|
|
public function customer()
|
|
{
|
|
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();
|
|
}
|
|
}
|