Files
exchange-2.0/app/Classes/Modules/Transactions/Services/CalculatesBillGroupPaymentAmount.php
T
2023-12-22 18:16:04 +08:00

22 lines
830 B
PHP

<?php
namespace App\Classes\Modules\Transactions\Services;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\BillGroup;
class CalculatesBillGroupPaymentAmount
{
public function execute(BillGroup $billGroup){
$floating_amount = floatval($billGroup->transactions()->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION])->sum('amount'));
$paid_amount = floatval($billGroup->transactions()->where('status', ApprovalStatus::APPROVED)->sum('amount'));
$outstanding_amount = $billGroup->amount - $paid_amount - $floating_amount + $billGroup->service_charge;
return [
'floating_amount' => $floating_amount,
'paid_amount' => $paid_amount,
'outstanding_amount' => $outstanding_amount,
];
}
}