Merged in izzati-hotfix-uum (pull request #390)

update code outstanding
This commit is contained in:
izzati zulkifli
2026-01-18 00:48:34 +00:00
@@ -186,6 +186,9 @@ public function getSummaryLaporanPelangganAktif(Request $request)
return response()->json(['error' => 'Sila pilih tahun'], 400);
}
$startOfYear = Carbon::create($year, 1, 1)->startOfDay();
$endOfYear = Carbon::create($year, 12, 31)->endOfDay();
Carbon::setLocale('ms');
// 1️⃣ Ambil semua pelanggan tahun ini
@@ -207,12 +210,23 @@ public function getSummaryLaporanPelangganAktif(Request $request)
$allTransaksi = collect();
foreach ($connections as $conn) {
$data = DB::connection($conn->mysql)
->table('gadai as g')
->leftJoin('tebus as t', 'g.norujukan', '=', 't.norujukan')
->leftJoin('lelong as l', 'g.norujukan', '=', 'l.norujukan')
->whereIn('g.nokp', $nokps)
->select('g.nokp','g.norujukan','g.t_gadai','t.t_tebus','g.pinjaman','g.upah12','g.tempoh','l.t_lelong')
->get();
->table('gadai as g')
->leftJoin('tebus as t', 'g.norujukan', '=', 't.norujukan')
->leftJoin('lelong as l', 'g.norujukan', '=', 'l.norujukan')
->whereIn('g.nokp', $nokps)
->whereBetween('g.t_gadai', [$startOfYear, $endOfYear]) // ⬅️ dalam tahun sahaja
->select(
'g.nokp',
'g.norujukan',
'g.t_gadai',
't.t_tebus',
'g.pinjaman',
'g.upah12',
'g.tempoh',
'l.t_lelong',
'g.sttebus',
)
->get();
$allTransaksi = $allTransaksi->concat($data);
}
@@ -246,6 +260,21 @@ public function getSummaryLaporanPelangganAktif(Request $request)
// Bilangan transaksi
$bilTransaksi = $tempohData->count();
// Bilangan Belum tebus
$endOfYear = Carbon::create($year, 12, 31)->endOfDay();
$bilOutstanding = $tempohData
->filter(function ($row) use ($endOfYear) {
// masih belum tebus langsung
if (empty($row->sttebus)) {
return true;
}
// dah tebus, tapi tebus selepas hujung tahun
return Carbon::parse($row->t_tebus)->gt($endOfYear);
})
->count();
// Bilangan tebus
$bilTebus = $tempohData->whereNotNull('t_tebus')->count();
@@ -332,6 +361,7 @@ public function getSummaryLaporanPelangganAktif(Request $request)
'tarikh_tamat' => $tarikhTamat ? Carbon::parse($tarikhTamat)->format('d-m-Y') : null,
'hari_sejak_transaksi' => $hariTempohPajakan,
'bil_transaksi' => $bilTransaksi,
'bil_outstanding' => $bilOutstanding,
'bil_tebus' => $bilTebus,
'jumlah_pinjaman' => $jumlahPinjaman,
'norujukan' => $norujukanPelanggan,