From 8e67c219a9cb807948625870b4622dc8f584deb7 Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Fri, 20 Oct 2023 14:56:35 +0800 Subject: [PATCH] fix wallet pagination --- .../ListWalletTransactionsLogic.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php index 0b70b484..649b3309 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListWalletTransactionsLogic.php @@ -44,7 +44,19 @@ class ListWalletTransactionsLogic extends AbstractControllerLogic $query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters'))); if (str_contains($request->input('filters'), "owner_id") && $query->count() > 0) { - $currentWalletBalance = Wallet::find($query->first()->owner_id)->amount; + $wallet_total_incoming = Transaction::where('owner_type', $query->first()->owner_type) + ->where('owner_id', $query->first()->owner_id) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE]) + ->sum('amount'); + + $wallet_total_outgoing = Transaction::where('owner_type', $query->first()->owner_type) + ->where('owner_id', $query->first()->owner_id) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->whereIn('type', [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE]) + ->sum('amount'); + + $currentWalletBalance = $wallet_total_incoming - $wallet_total_outgoing; $incoming = Transaction::where('owner_type', $query->first()->owner_type) ->where('owner_id', $query->first()->owner_id) ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])