Files
exchange-2.0/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php
T
2024-04-30 17:46:25 +08:00

67 lines
2.7 KiB
PHP

<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Classes\Modules\Bookings\DataTransferObjects\CalculationObject;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Http\Resources\BankResource;
use App\Models\Bank;
use Carbon\Carbon;
use Carbon\CarbonInterval;
class GeneratesBookingQuotation
{
public function execute(CalculationObject $calculationObject, ?int $paymentAttemptLimit = 0, ?CurrencyConversionObject $currencyConversionObject = null){
$date = Carbon::now();
$days = $date->diffInDays($date->copy()->addMinutes($paymentAttemptLimit));
$hours = $date->diffInHours($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)) ;
$minutes = $date->diffInMinutes($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)->subHours($hours));
// Initialize $receive_date to null by default
$receive_date = null;
if ($currencyConversionObject) {
$serviceId = $currencyConversionObject->getServiceId();
switch ($serviceId) {
case 3:
$daysToAdd = 3;
break;
case 5:
$daysToAdd = 7;
break;
default:
$daysToAdd = 1;
break;
}
$receive_date = Carbon::now()
->endOfDay()
->addWeekdays($daysToAdd)
->timezone('Asia/Singapore')
->format('4:00 PM, jS M, Y GMT T');
}
return [
'bank' => new BankResource(Bank::find($calculationObject->getConfigurations()->getBankId())),
'rate' => $calculationObject->getConfigurations()->getRate(),
'local_total' => $calculationObject->getLocalTotal(),
'foreign_total' => $calculationObject->getForeignTotal(),
'conversion_amount' => $calculationObject->getConversionTotal(),
'service_charge' => $calculationObject->getServiceCharge(),
'tax_total' => $calculationObject->getTax(),
'tax' => $calculationObject->getConfigurations()->getTax(),
'sub_total' => $calculationObject->getSubTotal(),
'total' => $calculationObject->getTotal(),
'date' => Carbon::now()->timezone('Asia/Singapore')->format('h:i a, jS M, Y \G\M\T T'),
'receive_date' => $receive_date,
'payment_attempt_limit' => CarbonInterval::days($days)->hours($hours)->minutes($minutes)->forHumans(),
'voucher_discount_amount' => $calculationObject->getVoucherDiscountAmount(),
'voucher_code' => $calculationObject->getVoucherCode(),
];
}
}