From ef695e675ff52f38f9e54ea5738d2cdb9fd19e3a Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Mon, 17 Feb 2025 14:33:30 +0800 Subject: [PATCH] Add tabbable views in billplz transaction summary logic --- .../BillplzTransactionSummaryController.php | 47 ++++++++++++++----- .../index.blade.php | 28 +++++------ 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/BillplzTransactionSummaryController.php b/app/Http/Controllers/BillplzTransactionSummaryController.php index c85783d..bab9287 100644 --- a/app/Http/Controllers/BillplzTransactionSummaryController.php +++ b/app/Http/Controllers/BillplzTransactionSummaryController.php @@ -14,7 +14,24 @@ class BillplzTransactionSummaryController extends Controller $transactionDataPKB = collect( Http::arrahn()->get('/api/transaction/online/query', ['date' => $date, 'status' => 'paid'])->json() ); $transactionDataKOOP = collect( Http::arrahn_koop()->get('/api/transaction/online/query', ['date' => $date, 'status' => 'paid'])->json() ); $transactionData = $transactionDataPKB->merge($transactionDataKOOP); - + + $transactionDataPKB = $this->processArrahnTransactions($transactionDataPKB); + $transactionDataKOOP = $this->processArrahnTransactions($transactionDataKOOP); + $transactionData = $this->processArrahnTransactions($transactionData); + + $billIds = $transactionData->keys(); + $billIds = $billIds->toArray(); + $billplzBills = Http::get(config('api.url_arrahn_portal') . '/api/billplz', ['bill_ids' => json_encode($billIds)])->json(); + + $data = array_map(fn($x, $y) => $this->processBillplzBills($x, $y), $billplzBills, [$transactionDataKOOP, $transactionDataPKB]); + + [$billPlzTransactionSummaryPKB, $billPlzTransactionSummaryKOOP] = $data; + + return view('online.billplz-transaction-summary.index', compact('billPlzTransactionSummaryPKB' ,'billPlzTransactionSummaryKOOP', 'date')); + } + + public function processArrahnTransactions($transactionData) + { // Group transactionData by bill_id $transactionData = $transactionData->groupBy(function($transaction) { return $transaction['billplz_id']; @@ -23,15 +40,18 @@ class BillplzTransactionSummaryController extends Controller $transactionData = array_map(fn($x) => ['arrahn_transactions' => $x], $transactionData); $transactionData = collect($transactionData); - $billIds = $transactionData->keys(); - $billplzBills = Http::get(config('api.url_arrahn_portal') . '/api/billplz', ['bill_ids' => json_encode($billIds)])->json(); - $billplzBills = collect($billplzBills)->map(function($bill) { + return $transactionData; + } + + public function processBillplzBills($bills_group, $transactionData) + { + $bills_group = collect($bills_group)->map(function($bill) { $bill['paid_amount_formatted'] = floatval($bill['paid_amount']['amount']) / 100; return $bill; }); $sumOfArrahnTransactions = $transactionData->sum(fn($x) => array_reduce($x['arrahn_transactions'], fn($carry, $item) => $carry + $item['total_payment'], 0)); - $sumOfBillplzTransactions = collect($billplzBills)->sum(fn($x) => $x['paid_amount_formatted']); + $sumOfBillplzTransactions = collect($bills_group)->sum(fn($x) => $x['paid_amount_formatted']); $numberOfArrahnTransactions = $transactionData->count(); $paymentGatewayCost = 'RM ' . number_format($sumOfBillplzTransactions - $sumOfArrahnTransactions, 2); @@ -39,20 +59,25 @@ class BillplzTransactionSummaryController extends Controller $sumOfBillplzTransactions = 'RM ' . number_format($sumOfBillplzTransactions, 2); - if ($transactionData->count() !== count($billplzBills)) { - throw new \Exception("The number of items in transactionData and billplzBills must be the same."); + if ($transactionData->count() !== count($bills_group)) { + throw new \Exception("The number of items in transactionData and bills_group must be the same."); } - $billPlzTransactionSummary = $transactionData->zip($billplzBills)->map(function ($zippedItem) { + $billPlzTransactionSummary = $transactionData->zip($bills_group)->map(function ($zippedItem) { [$transactionData, $billplzBill] = $zippedItem; $transactionData['billplz_bill'] = $billplzBill; return $transactionData; }); - - - return view('online.billplz-transaction-summary.index', compact( 'billPlzTransactionSummary', 'sumOfArrahnTransactions', 'sumOfBillplzTransactions', 'paymentGatewayCost', 'numberOfArrahnTransactions', 'date')); + + return[ + 'billPlzTransactionSummary' => $billPlzTransactionSummary, + 'sumOfArrahnTransactions' => $sumOfArrahnTransactions, + 'sumOfBillplzTransactions' => $sumOfBillplzTransactions, + 'paymentGatewayCost' => $paymentGatewayCost, + 'numberOfArrahnTransactions' => $numberOfArrahnTransactions, + ]; } } diff --git a/resources/views/online/billplz-transaction-summary/index.blade.php b/resources/views/online/billplz-transaction-summary/index.blade.php index aabe4b5..0a4276d 100644 --- a/resources/views/online/billplz-transaction-summary/index.blade.php +++ b/resources/views/online/billplz-transaction-summary/index.blade.php @@ -10,8 +10,8 @@ -
-
+
+
@@ -27,20 +27,20 @@
- +
-
- +
=
- +

- +
x
=
+ subtitle="RM {{ number_format(($billPlzTransactionSummaryPKB['numberOfArrahnTransactions'] * 100) / 100, 2) }}">
@@ -52,7 +52,7 @@ - @forelse ($billPlzTransactionSummary as $data) + @forelse ($billPlzTransactionSummaryPKB['billPlzTransactionSummary'] as $data) @@ -118,20 +118,20 @@
- +
-
- +
=
- +

- +
x
=
+ subtitle="RM {{ number_format(($billPlzTransactionSummaryKOOP['numberOfArrahnTransactions'] * 100) / 100, 2) }}">
@@ -143,7 +143,7 @@
- @forelse ($billPlzTransactionSummary as $data) + @forelse ($billPlzTransactionSummaryKOOP['billPlzTransactionSummary'] as $data)