mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 20:43:56 +00:00
49 lines
1.8 KiB
PHP
49 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Milestones\Processors;
|
|
|
|
|
|
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\Milestones;
|
|
use App\Models\Booking;
|
|
use App\Models\Transaction;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class MilestoneRewardByTransactionProcessor
|
|
{
|
|
/** @var CheckMilestonesForRewardProcessor */
|
|
private $checkMilestonesForRewardProcessor;
|
|
|
|
/**
|
|
* MilestoneRewardByTransactionProcessor constructor.
|
|
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
|
*/
|
|
public function __construct(CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor)
|
|
{
|
|
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Transaction $transaction
|
|
* @param array $milestones
|
|
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
*/
|
|
public function execute(Transaction $transaction, array $milestones)
|
|
{
|
|
$company = $transaction->owner instanceof Booking ? $transaction->owner()->first()->company : null;
|
|
if($company){
|
|
$completedBookingCount = count($company->bookings()->where('status', ApprovalStatus::COMPLETED)->get());
|
|
Log::info("Number of completed bookings completed for company ".$company->reference. ": " .$completedBookingCount);
|
|
if (in_array(Milestones::MILESTONE_1, $milestones)) {
|
|
if($completedBookingCount === 2){
|
|
$user = $company->employees()->first();
|
|
$this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_1]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|