From 0bf3b1b3539a03e83182480efe4d16ba8cbd04fa Mon Sep 17 00:00:00 2001 From: glovetleong Date: Mon, 11 Apr 2022 23:50:15 +0800 Subject: [PATCH] refund bug --- .../ControllersLogic/CreateBookingRefundLogic.php | 6 ++++-- app/Http/Resources/BookingResource.php | 1 + .../bookings/elements/PaymentHistoryComponent.vue | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 74e92fa6..d31ee2ce 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -84,12 +84,14 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); - $refund = $transaction->transactions()->refunds()->sum('amount'); if($refund + $request->input('amount') > $transaction->original_amount) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.'); - $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount')); + $amount = $transaction->booking->fix_currency_id == 1 ? $request->input('amount') : $request->input('amount') / $transaction->currency_rate; + + + $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $amount); $transactionRefundCalculationObject->init(); $object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id, diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index 0eeb9670..0adfa65d 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -31,6 +31,7 @@ class BookingResource extends JsonResource 'service' => new ServiceTypeResource($this->service), 'marking' => $this->marking, 'amount' => $this->fix_amount, + 'amount' => $this->fix_amount, 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), 'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index b73081b9..de39dfb0 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -219,7 +219,7 @@ -
+
@@ -249,12 +249,25 @@ }, computed: { totalRequestedRefund() { + let vm = this; var TotalRequestedRefund = 0; this.data.transaction_refunds.forEach(function(refunds) { TotalRequestedRefund += refunds.status === 1 ? refunds.original_amount : 0; }); + return TotalRequestedRefund; }, + totalRequestedConvertRefund() { + let vm = this; + var TotalRequestedRefund = 0; + this.data.transaction_refunds.forEach(function(refunds) { + TotalRequestedRefund += refunds.status === 1 ? refunds.original_amount : 0; + }); + if (vm.data.booking.fixed_currency.id != 1 && this.data.transaction_refunds[0]) { + TotalRequestedRefund = (TotalRequestedRefund * this.data.transaction_refunds[0].currency_rate); + } + return ((Math.round((TotalRequestedRefund + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); + }, totalRefunds() { var TotalRequestedRefund = 0; this.data.transaction_refunds.forEach(function(refunds) {