From 68898ee685841322a05fb558647628df0d345eca Mon Sep 17 00:00:00 2001 From: Edmond Lang Date: Tue, 17 Jun 2025 21:29:27 +0800 Subject: [PATCH] fix fully refund bug --- .../ControllersLogic/CreateBookingRefundLogic.php | 8 ++++---- .../ControllersLogic/UpdateBookingAmountLogic.php | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 2e8a34b2..49541b35 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -100,6 +100,10 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); $refund = $transaction->transactions()->refunds()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->sum('original_amount'); + $isFullyRefund = round($refund + $request->input('amount'), 2) == round((float) $transaction->original_amount, 2); + if ($isFullyRefund) { + $request->merge(['amount' => $transaction->original_amount]); + } $refundInPending = $transaction->transactions()->refunds()->where('status', ApprovalStatus::PENDING_VERIFICATION)->sum('original_amount'); @@ -120,10 +124,6 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $bookingAmountAfterRefunded = $booking->fix_amount - $refundInPending - $request->input('amount'); - $refundAmount = round($refund + $request->input('amount'), 2); - $originalAmount = round((float) $transaction->original_amount, 2); - $isFullyRefund = $refundAmount == $originalAmount; - $voucherCode = null; $redemptionId = null; diff --git a/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingAmountLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingAmountLogic.php index e40a947d..fd4af7f8 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingAmountLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingAmountLogic.php @@ -21,6 +21,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Classes\Exceptions\MalformedRequestException; +use Illuminate\Support\Facades\Log; class UpdateBookingAmountLogic extends AbstractControllerLogic { @@ -82,7 +83,9 @@ class UpdateBookingAmountLogic extends AbstractControllerLogic $minimum_amount = $booking->fix_amount - $this->calculatesBookingOutstanding->execute($booking); if (((float)$input_amount + 0.01) < (float)$minimum_amount) { - throw new MalformedRequestException('Booking Amount cannot be less than '. $minimum_amount .'.'); + $input_amount = 0; + // throw new MalformedRequestException('Booking Amount cannot be less than '. $minimum_amount .'.'); + Log::warning('Booking ID: '. $booking->id .'. Booking Marking: '. $booking->marking .'. Booking Amount cannot be less than '. $minimum_amount .'.'); } $poTransaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first();