feat(webstatement): tambahkan hubungan branch dan account di model

Perubahan yang dilakukan:
- Menambahkan relasi branch di model Account berdasarkan kolom branch_code.
- Menambahkan relasi account di model PrintStatementLog untuk akses data account dari log.
- Memperbaiki referensi branch_name di PrintStatementController agar menggunakan relasi dari model Account.
- Menonaktifkan eager loading pada query di PrintStatementController untuk optimasi performa.

Tujuan perubahan:
- Memastikan data branch dan account dapat diakses langsung melalui relasi antar model.
- Menghindari potensi masalah N+1 query saat mengambil data terkait branch.
- Meningkatkan efisiensi kode dan menjaga konsistensi data dalam proses statement.
This commit is contained in:
Daeng Deni Mardaeni
2025-07-10 19:30:58 +07:00
parent 5b235def37
commit 011f749786
4 changed files with 15 additions and 12 deletions

View File

@@ -584,7 +584,7 @@ ini_set('max_execution_time', 300000);
$filteredRecords = $query->count(); $filteredRecords = $query->count();
// Eager load relationships to avoid N+1 query problems // Eager load relationships to avoid N+1 query problems
$query->with(['user', 'branch', 'authorizer']); //$query->with(['user', 'branch', 'authorizer']);
// Get the data for the current page // Get the data for the current page
$data = $query->get()->map(function ($item) { $data = $query->get()->map(function ($item) {
@@ -592,7 +592,7 @@ ini_set('max_execution_time', 300000);
return [ return [
'id' => $item->id, 'id' => $item->id,
'branch_code' => $item->branch_code, 'branch_code' => $item->branch_code,
'branch_name' => $item->branch->name ?? 'N/A', 'branch_name' => $item->account->branch->name ?? 'N/A',
'account_number' => $item->account_number, 'account_number' => $item->account_number,
'period_from' => $item->period_from, 'period_from' => $item->period_from,
'period_to' => $item->is_period_range ? $item->period_to : null, 'period_to' => $item->is_period_range ? $item->period_to : null,

View File

@@ -4,6 +4,7 @@ namespace Modules\Webstatement\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Basicdata\Models\Branch;
// use Modules\Webstatement\Database\Factories\AccountFactory; // use Modules\Webstatement\Database\Factories\AccountFactory;
class Account extends Model class Account extends Model
@@ -34,7 +35,7 @@ class Account extends Model
{ {
return $this->belongsTo(Customer::class, 'customer_code', 'customer_code'); return $this->belongsTo(Customer::class, 'customer_code', 'customer_code');
} }
/** /**
* Get all balances for this account. * Get all balances for this account.
*/ */
@@ -42,10 +43,10 @@ class Account extends Model
{ {
return $this->hasMany(AccountBalance::class, 'account_number', 'account_number'); return $this->hasMany(AccountBalance::class, 'account_number', 'account_number');
} }
/** /**
* Get balance for a specific period. * Get balance for a specific period.
* *
* @param string $period Format: YYYY-MM * @param string $period Format: YYYY-MM
* @return AccountBalance|null * @return AccountBalance|null
*/ */
@@ -53,4 +54,8 @@ class Account extends Model
{ {
return $this->balances()->where('period', $period)->first(); return $this->balances()->where('period', $period)->first();
} }
public function branch(){
return $this->belongsTo(Branch::class, 'branch_code','code');
}
} }

View File

@@ -293,4 +293,8 @@ class PrintStatementLog extends Model
{ {
return $query->where('request_type', 'single_account'); return $query->where('request_type', 'single_account');
} }
public function account(){
return $this->belongsTo(Account::class, 'account_number','account_number');
}
} }

View File

@@ -388,13 +388,7 @@
title: 'Branch', title: 'Branch',
}, },
account_number: { account_number: {
title: 'Account Number', title: 'Account Number'
render: (item, data) => {
if (data.request_type == "multi_account") {
return data.stmt_sent_type ?? 'N/A';
}
return data.account_number ?? '';
},
}, },
period: { period: {
title: 'Period', title: 'Period',