mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
28 lines
897 B
PHP
28 lines
897 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Bookings\Services;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Models\Booking;
|
|
use Carbon\Carbon;
|
|
|
|
class CalculatesBookingCurrencyAverageRate
|
|
{
|
|
public function execute(Booking $booking, $type){
|
|
|
|
if ($type == TransactionType::PAYMENT) {
|
|
return $booking->transactions()
|
|
->where('type', TransactionType::PAYMENT)
|
|
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
|
->avg('currency_rate');
|
|
}
|
|
else if ($type == TransactionType::BILL) {
|
|
return $booking->transactions()
|
|
->where('type', TransactionType::BILL)
|
|
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
|
->avg('currency_rate');
|
|
}
|
|
}
|
|
|
|
} |