mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Merge branch 'dillon/90-e-invoice-e' into vapor/production
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CalculatesBookingOutstanding
|
||||
{
|
||||
@@ -31,10 +32,17 @@ class CalculatesBookingOutstanding
|
||||
|
||||
|
||||
public function execute(Booking $booking){
|
||||
return $booking->fix_amount - $this->calculatesBookingFloatingAmount->execute($booking, $booking->fix_currency_id) - $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) + $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id);
|
||||
$originalBookingAmount = $booking->fix_amount;
|
||||
$refundedAmount = $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id);
|
||||
if($originalBookingAmount === $refundedAmount){
|
||||
return $originalBookingAmount - $this->calculatesBookingFloatingAmount->execute($booking, $booking->fix_currency_id) - $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id);
|
||||
}
|
||||
else{
|
||||
return $originalBookingAmount - $this->calculatesBookingFloatingAmount->execute($booking, $booking->fix_currency_id) - $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) + $refundedAmount;
|
||||
}
|
||||
}
|
||||
|
||||
public function executeWithoutFloatingAmount(Booking $booking){
|
||||
return $booking->fix_amount - $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) + $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CalculatesBookingPayableAmount
|
||||
{
|
||||
@@ -19,10 +20,21 @@ class CalculatesBookingPayableAmount
|
||||
->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');
|
||||
else{
|
||||
$returnAmount = $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');
|
||||
|
||||
if($returnAmount === 0){
|
||||
$returnAmount = $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 $returnAmount;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ class CalculatesBookingRefundAmount
|
||||
return $this->calculateRefundAmount($payment, $type);
|
||||
});
|
||||
|
||||
if ($refundAmounts->isEmpty()) {
|
||||
$refundAmounts = $booking->transactions()->payments()->whereIn('status', [ApprovalStatus::REFUNDED])->get()->map(function ($payment) use ($type) {
|
||||
return $this->calculateRefundAmount($payment, $type);
|
||||
});
|
||||
}
|
||||
|
||||
$totalRefundAmount = $refundAmounts->sum();
|
||||
|
||||
return $totalRefundAmount;
|
||||
|
||||
Reference in New Issue
Block a user