mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-23 22:44:03 +00:00
fix booking rate average bug
This commit is contained in:
@@ -9,27 +9,29 @@ use Carbon\Carbon;
|
||||
|
||||
class CalculatesBookingCurrencyAverageRate
|
||||
{
|
||||
/** @var CalculatesBookingPayableAmount */
|
||||
private $calculatesBookingPayableAmount;
|
||||
|
||||
/**
|
||||
* CalculatesBookingCurrencyAverageRate constructor.
|
||||
* @param CalculatesBookingPayableAmount $calculatesBookingPayableAmount
|
||||
*/
|
||||
public function __construct(CalculatesBookingPayableAmount $calculatesBookingPayableAmount)
|
||||
{
|
||||
$this->calculatesBookingPayableAmount = $calculatesBookingPayableAmount;
|
||||
}
|
||||
|
||||
|
||||
public function execute(Booking $booking, $type){
|
||||
|
||||
if ($type == TransactionType::PAYMENT) {
|
||||
|
||||
$amount_without_service = $booking->transactions()
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->selectRaw('ROUND(amount,2)-ROUND(service_charge,2) AS amount_without_service')
|
||||
->get()->sum('amount_without_service');
|
||||
$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 number_format($booking->fix_amount/$amount_without_service,2);
|
||||
}
|
||||
else if ($type == TransactionType::BILL) {
|
||||
|
||||
$amount_without_service = $booking->transactions()
|
||||
->where('type', TransactionType::BILL)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->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);
|
||||
return $booking->transactions()->bills()->complete()->sum('original_amount') / $booking->transactions()->bills()->complete()->sum('amount');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user