From 5bd7943ff46740a0acc82e3d256963f006d38b50 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 13 Sep 2024 16:44:05 +0800 Subject: [PATCH] Load pembiayaan detail modal whenever user clicks. not loaded it all at page startup --- app/Services/BayaranHistoryService.php | 22 ++----- app/Services/MarhunService.php | 18 +++--- app/Services/PembiayaanService.php | 64 ++++++------------- .../table-pembiayaan-akan-dilelong.blade.php | 3 +- .../partials/table-pembiayaan.blade.php | 3 +- resources/views/modal/marhun.blade.php | 41 ++++++------ routes/api.php | 3 + 7 files changed, 63 insertions(+), 91 deletions(-) diff --git a/app/Services/BayaranHistoryService.php b/app/Services/BayaranHistoryService.php index f34a67e..03a3cf2 100644 --- a/app/Services/BayaranHistoryService.php +++ b/app/Services/BayaranHistoryService.php @@ -8,23 +8,15 @@ use Illuminate\Support\Facades\Http; class BayaranHistoryService { - public $norujukanList; + public $norujukan; - public function __construct($norujukanList) { - $this->norujukanList = $norujukanList; + public function __construct($norujukan) { + $this->norujukan = $norujukan; } public function getBayaranHistory() { - $getBayaranHistory = function () { - return Http::pool(function (Pool $pool){ - foreach ($this->norujukanList as $norujukan) { - $pool->get(config('api.url') . '/api/transaction/' . $norujukan); - } - }); - }; - - $bayaranHistoryResponse = array_map(fn($x) => $x->json(), $getBayaranHistory()); + $bayaranHistory = Http::arrahn()->get('/api/transaction/online/query', ['date' => $this->norujukan])->json(); $formatBayaranHistoryData = function ($x) { if (sizeof($x) === 0) { @@ -41,12 +33,12 @@ class BayaranHistoryService }, $x); }; - return array_map($formatBayaranHistoryData, $bayaranHistoryResponse); + return $formatBayaranHistoryData($bayaranHistory); } - public static function from($norujukanList) + public static function from($norujukan) { - return new static($norujukanList); + return new static($norujukan); } } diff --git a/app/Services/MarhunService.php b/app/Services/MarhunService.php index b114851..c86ccdb 100644 --- a/app/Services/MarhunService.php +++ b/app/Services/MarhunService.php @@ -6,10 +6,10 @@ use Illuminate\Support\Facades\Http; class MarhunService { - public $norujukanList; + public $norujukan; - public function __construct($norujukanList) { - $this->norujukanList = $norujukanList; + public function __construct($norujukan) { + $this->norujukan = $norujukan; } public function getMarhunDetails() @@ -30,18 +30,18 @@ class MarhunService }; $marhunDetailPipelines = [ - fn($x) => array_map($getMarhunDetails, $x), - fn($x) => array_map(fn($y) => $x == null ? [] : $y, $x), + fn($x) => $getMarhunDetails($x), + fn($x) => $x == null ? [] : $x, fn($x) => array_map(fn($y) => array_merge([], ...$y), $x), - fn($x) => array_map($formatMarhunDetailData, $x), + fn($x) => $formatMarhunDetailData($x), ]; - return array_reduce($marhunDetailPipelines, fn($x, $y) => $y($x), $this->norujukanList); + return array_reduce($marhunDetailPipelines, fn($x, $y) => $y($x), $this->norujukan); } - public static function from($norujukanList) + public static function from($norujukan) { - return new static($norujukanList); + return new static($norujukan); } } diff --git a/app/Services/PembiayaanService.php b/app/Services/PembiayaanService.php index 00346a2..fcd3d58 100644 --- a/app/Services/PembiayaanService.php +++ b/app/Services/PembiayaanService.php @@ -25,7 +25,6 @@ class PembiayaanService $pembiayaan = array_filter($getPembiayaan(), fn($x) => $x->hargajualan != null || $x->hargajualan != 0); $pembiayaan = $this->setUpahTawarruq($pembiayaan); $pembiayaan = $this->formatPembiayaanData($pembiayaan); - $pembiayaan = $this->attachMarhunModalData($pembiayaan); $pembiayaan = $this->checkPembiayaanPaymentDisabled($pembiayaan); return $pembiayaan; @@ -101,51 +100,28 @@ class PembiayaanService return $formatted; } - private function attachMarhunModalData($pembiayaan) + public function getMarhunModalData($norujukan) { - $marhunModalData = $this->getMarhunModalData($pembiayaan); - - return array_map( - function ($x, $y) { - $x->marhunModalData = $y; - return $x; - }, - $pembiayaan, - $marhunModalData, - ); - } - - public function getMarhunModalData($pembiayaan) - { - $norujukanList = array_map(fn($x) => $x->norujukan, $pembiayaan); - - $marhunDetails = MarhunService::from($norujukanList)->getMarhunDetails(); - - $bayaranHistoryDetails = BayaranHistoryService::from($norujukanList)->getBayaranHistory(); - - return array_map( - fn($x, $y, $z) => [ - 'nilaimarhun' => $x->nilaimarhun, - 'berat' => $x->berat, - 'bakiupah' => $x->bakiupah, - 'pinjaman' => $x->pinjaman, - 'bakipjm' => $x->bakipjm, - 'taglel' => $x->taglel, - 'marhun' => $x->marhun, - 'pinjaman' => $x->pinjaman, - 'norujukan' => $x->norujukan, - 'hargajualan' => $x->hargajualan, - 'kodcaw' => $x->kodcaw, - 'tempoh' => $x->tempoh, - 'cawangan_name' => $x->cawangan_name, - 'marhun_details' => $y, - 'bayaran_history' => $z, - ], - $pembiayaan, - $marhunDetails, - $bayaranHistoryDetails, - ); + $gadaianDetails = Http::arrahn()->get('/api/gadai/norujukan/' . $norujukan)->json()[0][0]; + + $attachCawanganName = function ($x) use ($gadaianDetails) { + $x['cawangan_name'] = Http::arrahn()->get('/api/cawangan/detail/' . $gadaianDetails['kodcaw'])->json()[0]['cawangan']; + return $x; + }; + + $gadaianDetails = $attachCawanganName($gadaianDetails); + + $marhunDetails = MarhunService::from($norujukan)->getMarhunDetails(); + + $bayaranHistoryDetails = BayaranHistoryService::from($norujukan)->getBayaranHistory(); + + + return [ + 'gadaianDetails' => $gadaianDetails, + 'marhunDetails' => $marhunDetails, + 'bayaranHistoryDetails' => $bayaranHistoryDetails, + ]; } private function getNorujukanRecentlyAttemptPayment($norujukanList) diff --git a/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php b/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php index b4c6648..228bea0 100644 --- a/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php +++ b/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php @@ -18,8 +18,7 @@ - {{ $data->norujukan }} + {{ $data->norujukan }} {{ $data->t_lelong_formatted }} diff --git a/resources/views/includes/partials/table-pembiayaan.blade.php b/resources/views/includes/partials/table-pembiayaan.blade.php index c059049..42aaaab 100644 --- a/resources/views/includes/partials/table-pembiayaan.blade.php +++ b/resources/views/includes/partials/table-pembiayaan.blade.php @@ -20,8 +20,7 @@ - {{ $data->norujukan }} + {{ $data->norujukan }} {{ $data->tempoh }} diff --git a/resources/views/modal/marhun.blade.php b/resources/views/modal/marhun.blade.php index 321c937..e2c6acf 100644 --- a/resources/views/modal/marhun.blade.php +++ b/resources/views/modal/marhun.blade.php @@ -169,30 +169,33 @@ @push('additional_js_scripts')