From b000c25e668c1afe9a368ceac532c67cb3183362 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 9 Jun 2024 12:00:19 +0800 Subject: [PATCH] 'Your Payment Proof' feature missing for order with storage invoices through group payment --- .../TransactionWithStorageResource.php | 34 ++++++++++++++----- .../elements/PaymentHistoryComponent.vue | 17 ++++++++-- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/app/Http/Resources/TransactionWithStorageResource.php b/app/Http/Resources/TransactionWithStorageResource.php index 3831ba37..66ea152c 100644 --- a/app/Http/Resources/TransactionWithStorageResource.php +++ b/app/Http/Resources/TransactionWithStorageResource.php @@ -28,7 +28,9 @@ class TransactionWithStorageResource extends JsonResource $groupPaymentAttemptsFiltered = []; $group_payment_expired = null; $group_payment_history = null; + $group_payment_history_query = null; $groupTotalAmount = 0; + $payment_history = null; if ($this->owner instanceof Transaction) { if ($this->owner) { @@ -44,7 +46,8 @@ class TransactionWithStorageResource extends JsonResource if($this->groups){ $group_payment_attempts = GroupForOrderV2Resource::collection($this->groups->whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])); $group_payment_expired = GroupForOrderV2Resource::collection($this->groupsWithTrashed->whereIn('status', [ApprovalStatus::EXPIRED])); - $group_payment_history = GroupForOrderV2Resource::collection($this->groups->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED])); + $group_payment_history_query = $this->groups->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED]); + $group_payment_history = GroupForOrderV2Resource::collection($group_payment_history_query); } } else { @@ -61,7 +64,7 @@ class TransactionWithStorageResource extends JsonResource } $ts = $this->groups->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION])->last(); - if ($ts) { + if ($ts && $group_payment_history && $group_payment_attempts) { $paymentTransaction = Transaction::where('payment_reference', $ts->reference)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION])->first(); if($paymentTransaction){ $groupTotalAmount = (double) $this->amount; @@ -81,6 +84,18 @@ class TransactionWithStorageResource extends JsonResource } + $payment_history = TransactionResource::collection($this->transactions() + ->payments() + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]) + ->get()); + + //For 'Your Payment Proof' at frontend + if($group_payment_history_query){ + foreach ($payment_history as $item) { + $item['payment_reference'] = $this->getReferenceForGroupPayment($group_payment_history_query); + } + } + return [ 'id' => $this->id, 'owner_type' => $this->owner_type, @@ -117,12 +132,7 @@ class TransactionWithStorageResource extends JsonResource ->payments()->where('status', ApprovalStatus::EXPIRED) ->get() ), - 'payment_history' => TransactionResource::collection( - $this->transactions() - ->payments() - ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]) - ->get() - ), + 'payment_history' => $payment_history, 'remarks' => RemarkResource::collection($this->remarks), 'packing_list_reference' => $packingListReference, 'storages' => $this->storages ? $this->storages : null, //from middleware @@ -132,4 +142,12 @@ class TransactionWithStorageResource extends JsonResource 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y') ]; } + + private function getReferenceForGroupPayment($groups){ + if(count($groups)){ + $firstGroup = $groups[0]; + return $firstGroup['reference']; + } + return null; + } } diff --git a/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue index 8d5dee0f..94f23bc5 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue @@ -157,6 +157,13 @@ +
+ +
+ +
+
+
@@ -181,9 +188,13 @@ }, methods: { clickExpand(){ - if(this.item - && ((this.item.payment_method !== 5 && this. item.documents.length) - || (this.item.payment_method === 5 && (this.item.status === 2 || this.item.status === 3)))){ + // if(this.item + // && ((this.item.payment_method !== 5 && this. item.documents.length) + // || (this.item.payment_method === 5 && (this.item.status === 2 || this.item.status === 3)))){ + // this.expandPaymentDetails = !this.expandPaymentDetails; + // } + + if(this.item){ this.expandPaymentDetails = !this.expandPaymentDetails; } },