From 5783382d7f1d9caddd1ef54de9639b6f8e17d127 Mon Sep 17 00:00:00 2001 From: Nur Izzati Date: Mon, 28 Jul 2025 15:47:35 +0800 Subject: [PATCH] update untuk paparan keuntungan arcc --- app/Http/Controllers/CallCenterController.php | 109 ++++++++++++------ resources/views/callcenter/v2/info.blade.php | 57 ++++----- resources/views/modal/historytebus.blade.php | 17 ++- 3 files changed, 115 insertions(+), 68 deletions(-) diff --git a/app/Http/Controllers/CallCenterController.php b/app/Http/Controllers/CallCenterController.php index fb61038..9522b9d 100644 --- a/app/Http/Controllers/CallCenterController.php +++ b/app/Http/Controllers/CallCenterController.php @@ -841,50 +841,83 @@ class CallCenterController extends Controller { $auth_user = Auth::user(); - $gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/gadai/norujukan/'. $request->norujukan)->json(); + $norujukan = $request->norujukan; + $gadai = Http::withOptions(['verify' => config('app.api_verify')]) + ->get(config('api.url') . '/api/gadai/norujukan/' . $norujukan) + ->json(); - if(sizeof($gadai) > 0) - { - $history = $gadai[0][0]['historygadaian']; - $dahtebus = $gadai[0][0]['sttebus']; - $norujukan = $gadai[0][0]['norujukan']; - - } - - $count = 0; $arrayhist = []; - while($history != "0" && $history != '' || $dahtebus == 'T') - { - if($history != "0" && $history != '') - { - $gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/gadai/norujukan/'. $history)->json(); - $tebus = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/listpenebusanhistory/'. $gadai[0][0]['kodcaw'],[ - "norujukan" => $history - ])->json(); + if (sizeof($gadai) > 0) { + $history = $gadai[0][0]['historygadaian']; + $dahtebus = $gadai[0][0]['sttebus']; + $kodcaw = $gadai[0][0]['kodcaw']; + // Kalau belum ada history, ambil rekod asal sahaja + if ($dahtebus == 'T') { + + $tebusList = Http::withOptions(['verify' => config('app.api_verify')]) + ->get(config('api.url') . '/api/listpenebusanhistory/' . $kodcaw, [ + 'norujukan' => $norujukan + ]) + ->json(); - if(sizeof($gadai) > 0) - { - if($history == $gadai[0][0]['historygadaian']) - $history = 0; - else{ - array_push($arrayhist,["tagbaru" => ((isset($gadai[0][0]['tagbaru'])) ? $gadai[0][0]['tagbaru'] : 0),"hargajualan" => ((isset($gadai[0][0]['hargajualan'])) ? $gadai[0][0]['hargajualan'] : ''), "pinjaman" => ((isset($tebus[0])) ? $tebus[0]['pinjaman'] : 0),"norujukan" => $history,"jenistebus" => ((isset($tebus[0])) ? $tebus[0]['jenistebus'] : 0),"jbg" => ((isset($tebus[0])) ? $tebus[0]['jbg'] : 0),"t_tebus" => ((isset($tebus[0])) ? $tebus[0]['t_tebus'] : 0)]); - $history = $gadai[0][0]['historygadaian']; + $tebus = collect($tebusList)->firstWhere('norujukan', $norujukan); + + $arrayhist[] = [ + "tagbaru" => $gadai[0][0]['tagbaru'] ?? 0, + "hargajualan" => $gadai[0][0]['hargajualan'] ?? '', + "pinjaman" => $tebus['pinjaman'] ?? 0, + "norujukan" => $norujukan, + "jenistebus" => $tebus['jenistebus'] ?? 0, + "jbg" => $tebus['jbg'] ?? 0, + "t_tebus" => $tebus['t_tebus'] ?? 0, + "bayaran_keuntungan" => $tebus['bayaran_keuntungan'] ?? 0, + "bayaran_pembiayaan" => $tebus['bayaran_pembiayaan'] ?? 0, + "duit_masuk" => $tebus['duit_masuk'] ?? 0, + "trans_type" => $tebus['trans_type'] ?? 0, + ]; + } else { + // Loop ke belakang (rekod lepas-lepas) + while ($history != "0" && $history != '') { + $prevGadai = Http::withOptions(['verify' => config('app.api_verify')]) + ->get(config('api.url') . '/api/gadai/norujukan/' . $history) + ->json(); + + $prevKodcaw = $prevGadai[0][0]['kodcaw'] ?? null; + + if (!$prevKodcaw) break; + + $tebusList = Http::withOptions(['verify' => config('app.api_verify')]) + ->get(config('api.url') . '/api/listpenebusanhistory/' . $prevKodcaw, [ + 'norujukan' => $history + ]) + ->json(); + + $tebus = collect($tebusList)->firstWhere('norujukan', $history); + + $arrayhist[] = [ + "tagbaru" => $prevGadai[0][0]['tagbaru'] ?? 0, + "hargajualan" => $prevGadai[0][0]['hargajualan'] ?? '', + "pinjaman" => $tebus['pinjaman'] ?? 0, + "norujukan" => $history, + "jenistebus" => $tebus['jenistebus'] ?? 0, + "jbg" => $tebus['jbg'] ?? 0, + "t_tebus" => $tebus['t_tebus'] ?? 0, + "bayaran_keuntungan" => $tebus['bayaran_keuntungan'] ?? 0, + "bayaran_pembiayaan" => $tebus['bayaran_pembiayaan'] ?? 0, + "duit_masuk" => $tebus['duit_masuk'] ?? 0, + "trans_type" => $tebus['trans_type'] ?? 0, + ]; + + $nextHistory = $prevGadai[0][0]['historygadaian'] ?? '0'; + + // Elakkan infinite loop + if ($nextHistory == $history) { + break; } + + $history = $nextHistory; } - - $count++; - - } - else{ - $gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/gadai/norujukan/'. $norujukan)->json(); - $tebus = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/listpenebusanhistory/'. $gadai[0][0]['kodcaw'],[ - "norujukan" => $norujukan - ])->json(); - - - array_push($arrayhist,["tagbaru" => ((isset($gadai[0][0]['tagbaru'])) ? $gadai[0][0]['tagbaru'] : 0), "hargajualan" => ((isset($gadai[0][0]['hargajualan'])) ? $gadai[0][0]['hargajualan'] : ''),"pinjaman" => ((isset($tebus[0])) ? $tebus[0]['pinjaman'] : 0),"norujukan" => $norujukan,"jenistebus" => ((isset($tebus[0])) ? $tebus[0]['jenistebus'] : 0),"jbg" => ((isset($tebus[0])) ? $tebus[0]['jbg'] : 0),"t_tebus" => ((isset($tebus[0])) ? $tebus[0]['t_tebus'] : 0)]); - break; } } diff --git a/resources/views/callcenter/v2/info.blade.php b/resources/views/callcenter/v2/info.blade.php index 6478bb8..0c0dfc4 100644 --- a/resources/views/callcenter/v2/info.blade.php +++ b/resources/views/callcenter/v2/info.blade.php @@ -1304,10 +1304,10 @@ $.ajax({ method:'get', - url:'{{ route("arcc.history") }}', + url: '{{ route("arcc.history", ":kodcaw") }}'.replace(':kodcaw', kodcaw), data:{ "norujukan" : histid}, success:function(data){ - historytebustable(data); + historytebustable(data,histid); $.ajax({ method: 'get', @@ -1386,7 +1386,10 @@ urlroute = urlroute.replace(':id', bayaran['id']); historybayarandatatable.row.add([ counter, + bayaran['norujukan'], bayaran['created_at'], + "RM " + bayaran['bayaran_pembiayaan'], + "RM " + bayaran['bayaran_keuntungan'], "RM " + bayaran['duit_masuk'], bayaranteller, bayaran['trans_type'], @@ -1400,54 +1403,54 @@ "ordering": false }); - function historytebustable(data){ + function historytebustable(data, histid) + { + console.log("Full data returned tebus:", histid); // Debug var counter = 1; historytebusbayaran.clear().draw(); - $.each(data,function(index,tebusaz){ + // TAPIS hanya entry yang sama dengan norujukan klik user + let filtered = data.filter(tebusaz => tebusaz.norujukan === histid); + $.each(filtered, function(index, tebusaz){ + console.log("Tebus untuk:", tebusaz.norujukan); + + var urlroute = ''; switch(tebusaz['jenistebus']) { case 'P': - var urlroute = '{{ route("resit.tambahpinjam", ":id") }}'; - urlroute = urlroute.replace(':id', tebusaz['norujukan']); + urlroute = '{{ route("resit.tambahpinjam", ":id") }}'.replace(':id', tebusaz['norujukan']); break; case 'T': - - if(tebusaz['hargajualan'] === '') - { - var urlroute = '{{ route("resit.belumtebus", ":id") }}'; - urlroute = urlroute.replace(':id', tebusaz['norujukan']); - - }else{ - var urlroute = '{{ route("resit.tebus", ":id") }}'; - urlroute = urlroute.replace(':id', tebusaz['norujukan']); - } - + urlroute = (tebusaz['hargajualan'] === '') + ? '{{ route("resit.belumtebus", ":id") }}'.replace(':id', tebusaz['norujukan']) + : '{{ route("resit.tebus", ":id") }}'.replace(':id', tebusaz['norujukan']); break; case 'A': - var urlroute = '{{ route("resit.belumansurans", ":id") }}'; - urlroute = urlroute.replace(':id', tebusaz['norujukan']); + urlroute = '{{ route("resit.belumansurans", ":id") }}'.replace(':id', tebusaz['norujukan']); break; case 'S': - var urlroute = '{{ route("resit.tebusseparuh", ":id") }}'; - urlroute = urlroute.replace(':id', tebusaz['norujukan']); - break; - } + urlroute = '{{ route("resit.tebusseparuh", ":id") }}'.replace(':id', tebusaz['id']); + break; + } historytebusbayaran.row.add([ counter, - tebusaz['norujukan'], - tebusaz['jenistebus'], - tebusaz['pinjaman'], + histid, + tebusaz['trans_type'], + "RM " + tebusaz['bayaran_pembiayaan'], + "RM " + tebusaz['bayaran_keuntungan'], + "RM " + tebusaz['duit_masuk'], tebusaz['jbg'], tebusaz['t_tebus'], '' ]).draw(); - counter = counter + 1; + + counter++; }); } + function daftarwakil() { let nopelanggan = $('#nopelangganwakil').val(); diff --git a/resources/views/modal/historytebus.blade.php b/resources/views/modal/historytebus.blade.php index eb5a3b2..5050b6e 100644 --- a/resources/views/modal/historytebus.blade.php +++ b/resources/views/modal/historytebus.blade.php @@ -1,6 +1,12 @@ +