From 02d28f8fba43548b9e1c00865981d751cd8cdc54 Mon Sep 17 00:00:00 2001 From: JiaSheng Date: Mon, 8 Apr 2024 21:17:37 +0800 Subject: [PATCH] fix invoice amount not tally when voucher is apply for booking --- .../CalculatesBookingCurrencyAverageRate.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php index da3fe0b4..9cb7717e 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php @@ -24,10 +24,22 @@ class CalculatesBookingCurrencyAverageRate public function execute(Booking $booking, $type){ + $transaction = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->latest()->get()[0]; + + $voucherRedemption = $transaction->voucherRedemption; + + $discount = 0; + + if ($voucherRedemption) { + $discount = $voucherRedemption->value; + } + if ($type == TransactionType::PAYMENT) { $totalPayment = $booking->fix_currency_id === 1 ? $booking->transactions()->payments()->complete()->sum('original_amount') : $booking->transactions()->payments()->complete()->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total'); - return $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) / $totalPayment; + return $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) / ($totalPayment + $discount); } else if ($type == TransactionType::BILL) {