From f57f2da1c44f1c2f5d5fcef6273ba0d41d32e270 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Tue, 16 Jul 2024 16:01:53 +0800 Subject: [PATCH] Handle erors on marhun service, and pembiayaan service --- app/Services/MarhunService.php | 3 ++- app/Services/PembiayaanService.php | 11 ++++++++++- resources/views/modal/marhun.blade.php | 23 ++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/Services/MarhunService.php b/app/Services/MarhunService.php index f3e3bd5..223b4a5 100644 --- a/app/Services/MarhunService.php +++ b/app/Services/MarhunService.php @@ -23,7 +23,8 @@ class MarhunService }); }; - $marhunDetailsResponse = array_map(fn($x) => array_merge([], ...$x->json()), $getMarhunDetails()); + $marhunDetailsResponse = array_map(fn($x) => $x->json() == null ? [] : $x->Json(), $getMarhunDetails()); + $marhunDetailsResponse = array_map(fn($x) => array_merge([], ...$x), $marhunDetailsResponse); $formatMarhunDetailData = function ($x) { $getMarhunTypeFullName = function ($code) { diff --git a/app/Services/PembiayaanService.php b/app/Services/PembiayaanService.php index ee37acf..5398c20 100644 --- a/app/Services/PembiayaanService.php +++ b/app/Services/PembiayaanService.php @@ -165,9 +165,18 @@ class PembiayaanService }; $pembiayaanAkanDilelong = array_filter($getPembiayaanAkanDilelong(), $isCurrentDateGreaterThanEqual3DaysBeforeLelong); + $norujukanAkanDilelong = array_map(fn($x) => $x->norujukan, $pembiayaanAkanDilelong); - $pembiayaanInFasa2 = array_filter($getPembiayaanAkanDilelong(), fn($x) => $x->fasa == 2); + $setDefaultFasaIfNotAvailable = function($x){ + if(! isset($x->fasa)){ + $x->fasa = 1; + } + return $x; + }; + + $pembiayaanWithFasa = array_map($setDefaultFasaIfNotAvailable, $getPembiayaanAkanDilelong()); + $pembiayaanInFasa2 = array_filter($pembiayaanWithFasa, fn($x) => $x->fasa == 2); $norujukanInFasa2 = array_map(fn($x) => $x->norujukan, $pembiayaanInFasa2); $getPayableUjrahBranches = fn() => Http::arrahn()->get('/api/payable-ujrah-branches')->json(); diff --git a/resources/views/modal/marhun.blade.php b/resources/views/modal/marhun.blade.php index f338d72..321c937 100644 --- a/resources/views/modal/marhun.blade.php +++ b/resources/views/modal/marhun.blade.php @@ -193,10 +193,10 @@ $('#norujukan_modal').val(data.norujukan); $('#pinjaman_modal').val(data.pinjaman); $('#marhunModal').modal('show'); - + $('#tablehistorybayaran').DataTable().clear().destroy(); let table_bayaran_history = $('#tablehistorybayaran').DataTable(); - + $('#biasa').DataTable().clear().destroy(); let table_marhun = $('#biasa').DataTable(); @@ -207,7 +207,7 @@ `RM ${x.duit_masuk} `, ]).draw(false) }); - + data.marhun_details.forEach((x, index) => { table_marhun.row.add([ index + 1, @@ -222,20 +222,21 @@ }; document.addEventListener('DOMContentLoaded', function() { - - document.querySelectorAll('a.marhun-detail-link').forEach(x => x.addEventListener('click', showMarhunDetailModal)) - + + + $('#main-table').on('click', 'a.marhun-detail-link', function(e) { + showMarhunDetailModal(e) + }); + }); - + document.querySelector('#marhunModal .modal-footer button').addEventListener('click', function(e) { e.preventDefault(); $('#marhunModal').modal('hide'); - }); - + }); + document.querySelector('#marhunModal').addEventListener('hidden.bs.modal', function(e) { document.querySelector('#marhunModal .modal-header a[aria-controls="pills-marhun"]').click(); }); - - ') @endpush