diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php index e00ab114..235d897a 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingCurrencyAverageRate.php @@ -12,16 +12,24 @@ class CalculatesBookingCurrencyAverageRate public function execute(Booking $booking, $type){ if ($type == TransactionType::PAYMENT) { - return $booking->transactions() + + $amount_without_service = $booking->transactions() ->where('type', TransactionType::PAYMENT) ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) - ->avg('currency_rate'); + ->selectRaw('ROUND(amount,2)-ROUND(service_charge,2) AS amount_without_service') + ->get()->sum('amount_without_service'); + + return number_format($booking->fix_amount/$amount_without_service,2); } else if ($type == TransactionType::BILL) { - return $booking->transactions() + + $amount_without_service = $booking->transactions() ->where('type', TransactionType::BILL) ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) - ->avg('currency_rate'); + ->selectRaw('ROUND(amount,2)-ROUND(service_charge,2) AS amount_without_service') + ->get()->sum('amount_without_service'); + + return number_format($booking->fix_amount/$amount_without_service,2); } } diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index c45d27f7..e7256b1f 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -77,18 +77,22 @@