From 2353c637d74e8a10e9b5b8eab2e87f975d2f253c Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sun, 12 Mar 2023 23:13:03 +0800 Subject: [PATCH] multi payment final - finish top up and trsanction history --- .../ControllersLogic/CallbackBillplzLogic.php | 13 +++- ...chWalletByCompanyModuleControllerLogic.php | 8 ++- .../CustomerPaymentBillingInnerComponent.vue | 8 +-- .../elements/PaymentsBillingComponents.vue | 8 ++- .../CustomerTransactionSectionComponent.vue | 41 ++++++------ .../wallets/elements/WalletComponent.vue | 65 +++++++++++-------- resources/views/layouts/base_portal.blade.php | 2 +- .../views/pages/wallet/transactions.blade.php | 3 +- routes/web.php | 29 ++++++++- 9 files changed, 117 insertions(+), 60 deletions(-) diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index ae8ae28f..e9daa5f1 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -44,6 +44,9 @@ class CallbackBillplzLogic /** @var UpdateDoFromYDPortalProcessor */ private $updateDoFromYDPortalProcessor ; + /** @var UpdatesWalletBalance */ + private $updatesWalletBalance; + /** * CallbackBillplzLogic constructor. * @param GetBillplzBill $getBillplzBill @@ -52,13 +55,14 @@ class CallbackBillplzLogic * @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor * @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor */ - public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor) + public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance) { $this->getBillplzBill = $getBillplzBill; $this->fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; + $this->updatesWalletBalance = $updatesWalletBalance; } @@ -101,9 +105,14 @@ class CallbackBillplzLogic $token = Auth::fromUser(User::find(1)); $request->headers->set('Authorization', 'Bearer '.$token); + // check if is wallet top up + if($transaction->owner instanceof Wallet && $transaction->status !== ApprovalStatus::APPROVED) { + $this->updatesWalletBalance->execute($transaction->owner, $transaction->amount); + } + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED); - if(($invoice->amount - $transaction->amount) < 0.01) { + if(($invoice->amount - $transaction->amount) < 0.01 && !$transaction->owner instanceof Wallet) { $this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED); $packingList->status = ApprovalStatus::APPROVED; diff --git a/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php index 8a97929c..6a7c9515 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php @@ -24,7 +24,7 @@ class FetchWalletByCompanyModuleControllerLogic extends AbstractControllerLogic protected function notification():array { return [ 'title' => 'Retrieved Wallet', - 'message' => 'You have successfully created a wallet' + 'message' => 'You have successfully retrieved a wallet' ]; } @@ -78,7 +78,11 @@ class FetchWalletByCompanyModuleControllerLogic extends AbstractControllerLogic return $this->resourceResponse(new WalletResource($wallet)); } - $query = $this->fetchesWallet->execute(['owner_id' => $request->route('company_module_id')]); + $filters = $this->fetchesWallet->deserializeFilters($request->input('filters')); + + $filters['owner_id'] = $request->route('company_module_id'); + + $query = $this->fetchesWallet->execute($filters); return $this->resourceResponse(new WalletResource($query)); } diff --git a/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue b/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue index 1bbf3d5d..8ec98df2 100644 --- a/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue +++ b/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue @@ -6,7 +6,7 @@
@@ -59,10 +59,10 @@ -
+
-
Make Payment
-
Generate Summary Invoice
+
Make Payment
+
Generate Summary Invoice
diff --git a/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue b/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue index 4c27be29..b3c896b7 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue @@ -28,7 +28,7 @@
@@ -54,7 +54,11 @@ selectedInvoice: { type: Array, required: false, - } + }, + section:{ + type: String, + default: null + }, }, data(){ return { diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue index 25577b5c..4f41552c 100644 --- a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue @@ -2,14 +2,14 @@
-
-
-
+
+
+
Transaction History
-
+
Date
@@ -19,7 +19,7 @@
Balance
-
+
{{item.created_at}}
{{[5, 9].includes(parseFloat(item.type)) ? (Math.round((parseFloat(item.amount) + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : ''}}
@@ -29,8 +29,8 @@
-
-
+
+
@@ -51,8 +51,8 @@
-
- +
+
@@ -60,12 +60,12 @@
Top Up Records
-
+
- +
-
+
@@ -99,13 +99,13 @@ export default { id: { type: Number, required: true - } + }, }, data(){ return { section: 'customerTransactionSection', isLoading: true, - company: null, + wallet: null, attention: false } }, @@ -117,7 +117,7 @@ export default { watch: { pendingQueue(inComplete){ if(inComplete){ - this.fetchCompany(); + this.fetchWallet(); } } }, @@ -125,15 +125,16 @@ export default { this.$store.dispatch('updateListQueue', {'name': this.section}); }, methods: { - fetchCompany(){ + fetchWallet(){ this.isLoading = true; - this.submit(route('api.company.show', this.id), 'get', this.section, false, false) + var filters = {with_transactions: true}; + this.submit(route('api.wallet.company_module.show', this.id) + '?filters=' + JSON.stringify(filters), 'get', this.section, false, false); }, remainingBalance(index) { let tempBalance = 0; - if(this.company.wallet){ - let transactions = this.company.wallet.transactions.slice().reverse(); + if(this.wallet){ + let transactions = this.wallet.transactions.slice().reverse(); transactions.slice(0, transactions.length - index).map(function(transaction) { [1, 11].includes(transaction.type) ? tempBalance -= (transaction.amount) : tempBalance += (transaction.amount); return tempBalance @@ -144,7 +145,7 @@ export default { }, successHandler(response){ this.isLoading = false; - this.company = response.payload.data; + this.wallet = response.payload.data; } } } diff --git a/resources/assets/vue/components/wallets/elements/WalletComponent.vue b/resources/assets/vue/components/wallets/elements/WalletComponent.vue index f36f865f..e3d61d0d 100644 --- a/resources/assets/vue/components/wallets/elements/WalletComponent.vue +++ b/resources/assets/vue/components/wallets/elements/WalletComponent.vue @@ -1,35 +1,41 @@