From 778f3b1e2f76e2ac5de4cb3a74775f1704dd8766 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 27 Mar 2025 14:53:18 +0800 Subject: [PATCH] Fix transaction summary not showing --- app/Http/Controllers/BillplzController.php | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/BillplzController.php b/app/Http/Controllers/BillplzController.php index 443b6d8..8a154cf 100644 --- a/app/Http/Controllers/BillplzController.php +++ b/app/Http/Controllers/BillplzController.php @@ -11,23 +11,30 @@ class BillplzController extends Controller { public function __invoke(Request $request) { - $companyMapping = [ - 'PKB', - 'KOPKB', - ]; - $bills = array_reduce($companyMapping, function($carry, $company_code) use($request){ + $billplz_ids = json_decode($request->bill_ids, true); + + $account_own_by_PKB = array_filter($billplz_ids, fn($x) => $x['account_own_by'] == 'PKB'); + $account_own_by_KOPKB = array_filter($billplz_ids, fn($x) => $x['account_own_by'] == 'KOOP'); + + $bill_ids_PKB = array_map(fn($x) => $x['bill_id'], $account_own_by_PKB); + $bill_ids_PKB = array_values($bill_ids_PKB); + + $bill_ids_KOPKB = array_map(fn($x) => $x['bill_id'], $account_own_by_KOPKB); + $bill_ids_KOPKB = array_values($bill_ids_KOPKB); + + $getBillDetailFromBillplz = function($company_code, $bill_ids) { $billplzService = new BillplzService($company_code); - $billIdArray = json_decode($request->bill_ids); - $billIdArray = $billplzService->getBills($billIdArray); - $carry[$company_code] = array_filter($billIdArray, function($bill) { - return $bill !== []; - }); - return $carry; - }, []); - - return $bills; - - + return $billplzService->getBills($bill_ids); + }; + + $billDetailsKOPKB = $getBillDetailFromBillplz('KOPKB', $bill_ids_KOPKB); + $billDetailsPKB = $getBillDetailFromBillplz('PKB', $bill_ids_PKB); + + return [ + 'KOPKB' => $billDetailsKOPKB, + 'PKB' => $billDetailsPKB, + ]; + } }