mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-21 13:33:57 +00:00
28 lines
828 B
PHP
28 lines
828 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Bookings\Services;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Models\Booking;
|
|
|
|
class CalculatesBookingRefundServiceCharge
|
|
{
|
|
public function execute(Booking $booking, int $type, ?string $payment_reference = null): float
|
|
{
|
|
$refundAmounts = $booking->transactions()->payments()->complete()->get()->map(function ($payment) use ($type) {
|
|
return $this->calculateRefundAmount($payment, $type);
|
|
});
|
|
|
|
$totalRefundAmount = $refundAmounts->sum();
|
|
|
|
return $totalRefundAmount;
|
|
}
|
|
|
|
public function calculateRefundAmount($payment): float
|
|
{
|
|
$refundTransactions = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::APPROVED]);
|
|
|
|
return $refundTransactions->sum('service_charge');
|
|
}
|
|
}
|