Merged in izzati-hotfix-uum (pull request #390)
update code outstanding
This commit is contained in:
@@ -186,6 +186,9 @@ public function getSummaryLaporanPelangganAktif(Request $request)
|
|||||||
return response()->json(['error' => 'Sila pilih tahun'], 400);
|
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');
|
Carbon::setLocale('ms');
|
||||||
|
|
||||||
// 1️⃣ Ambil semua pelanggan tahun ini
|
// 1️⃣ Ambil semua pelanggan tahun ini
|
||||||
@@ -207,12 +210,23 @@ public function getSummaryLaporanPelangganAktif(Request $request)
|
|||||||
$allTransaksi = collect();
|
$allTransaksi = collect();
|
||||||
foreach ($connections as $conn) {
|
foreach ($connections as $conn) {
|
||||||
$data = DB::connection($conn->mysql)
|
$data = DB::connection($conn->mysql)
|
||||||
->table('gadai as g')
|
->table('gadai as g')
|
||||||
->leftJoin('tebus as t', 'g.norujukan', '=', 't.norujukan')
|
->leftJoin('tebus as t', 'g.norujukan', '=', 't.norujukan')
|
||||||
->leftJoin('lelong as l', 'g.norujukan', '=', 'l.norujukan')
|
->leftJoin('lelong as l', 'g.norujukan', '=', 'l.norujukan')
|
||||||
->whereIn('g.nokp', $nokps)
|
->whereIn('g.nokp', $nokps)
|
||||||
->select('g.nokp','g.norujukan','g.t_gadai','t.t_tebus','g.pinjaman','g.upah12','g.tempoh','l.t_lelong')
|
->whereBetween('g.t_gadai', [$startOfYear, $endOfYear]) // ⬅️ dalam tahun sahaja
|
||||||
->get();
|
->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);
|
$allTransaksi = $allTransaksi->concat($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +260,21 @@ public function getSummaryLaporanPelangganAktif(Request $request)
|
|||||||
// Bilangan transaksi
|
// Bilangan transaksi
|
||||||
$bilTransaksi = $tempohData->count();
|
$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
|
// Bilangan tebus
|
||||||
$bilTebus = $tempohData->whereNotNull('t_tebus')->count();
|
$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,
|
'tarikh_tamat' => $tarikhTamat ? Carbon::parse($tarikhTamat)->format('d-m-Y') : null,
|
||||||
'hari_sejak_transaksi' => $hariTempohPajakan,
|
'hari_sejak_transaksi' => $hariTempohPajakan,
|
||||||
'bil_transaksi' => $bilTransaksi,
|
'bil_transaksi' => $bilTransaksi,
|
||||||
|
'bil_outstanding' => $bilOutstanding,
|
||||||
'bil_tebus' => $bilTebus,
|
'bil_tebus' => $bilTebus,
|
||||||
'jumlah_pinjaman' => $jumlahPinjaman,
|
'jumlah_pinjaman' => $jumlahPinjaman,
|
||||||
'norujukan' => $norujukanPelanggan,
|
'norujukan' => $norujukanPelanggan,
|
||||||
|
|||||||
Reference in New Issue
Block a user