mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
29 lines
1.0 KiB
PHP
29 lines
1.0 KiB
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 CalculatesBookingPayableAmount
|
|
{
|
|
|
|
public function execute(Booking $booking, int $type, bool $generateEInvoiceRefund = false){
|
|
|
|
if($generateEInvoiceRefund){
|
|
return $type === 1 ?
|
|
$booking->transactions()->payments()->where('status', ApprovalStatus::REFUNDED)
|
|
->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total') :
|
|
$booking->transactions()->payments()->where('status', ApprovalStatus::REFUNDED)->sum('original_amount');
|
|
}
|
|
return $type === 1 ?
|
|
$booking->transactions()->payments()->complete()
|
|
->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total') :
|
|
$booking->transactions()->payments()->complete()->sum('original_amount');
|
|
}
|
|
|
|
}
|