mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
fix invoice amount not tally when voucher is apply for booking
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user