From 1c4669a8576b1525a7652d2a12d4c8479603d2cd Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Mon, 6 Sep 2021 09:21:56 +0800 Subject: [PATCH] add partial refund credit note flow --- .../Bookings/ControllersLogic/CreateBookingRefundLogic.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 0e31eed0..22f2b95f 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -102,13 +102,17 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); + if((int) $transaction->type === TransactionType::BILL){ + $customerBooking = $booking->transactions()->payments()->complete()->where('original_amount', '=', $transaction->original_amount)->where('id', '<', $transaction->id)->orderByDesc('id')->first(); + } + $unrequestedAmount = $this->calculateTransactionRefundOriginalAmount->execute($transaction, $request->input('amount')); $conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $unrequestedAmount)), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1); $configurations = $this->fetchBookingQuotation->execute($booking->company, $conversionObject); - $totalRefundAmount = $this->calculateTransactionRefundAmount->execute($transaction, $configurations->getTotal()); + $totalRefundAmount = $this->calculateTransactionRefundAmount->execute(((int) $transaction->type === TransactionType::BILL) ? $customerBooking : $transaction, $configurations->getTotal()); $object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id, $configurations->getConfigurations()->getBankId(), $configurations->getConversionObject()->getPaymentMethod(),