33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Tasks;
|
|
|
|
use App\Domains\CostUnit\Actions\ChangeCostUnitState\ChangeCostUnitStateCommand;
|
|
use App\Domains\CostUnit\Actions\ChangeCostUnitState\ChangeCostUnitStateRequest;
|
|
use App\Models\CostUnit;
|
|
use App\Repositories\CostUnitRepository;
|
|
|
|
class CloseCostUnit implements CronTask {
|
|
public function handle(): void
|
|
{
|
|
$now = now();
|
|
$costUnitRepository = new CostUnitRepository();
|
|
/** @var CostUnit $costUnit */
|
|
foreach ($costUnitRepository->getCurrentEvents() as $costUnit) {
|
|
$billingEndTime = \DateTime::createFromFormat('Y-m-d H:i:s', $costUnit['billing_deadline']);
|
|
$billingEndTime->setTime(0,0,0);
|
|
$billingEndTime->add(new \DateInterval('P1D'));
|
|
|
|
$now = now();
|
|
|
|
if ($billingEndTime < $now) {
|
|
new ChangeCostUnitStateCommand(
|
|
new ChangeCostUnitStateRequest(
|
|
CostUnit::where('id', $costUnit['id'])->first(),false, false
|
|
)
|
|
)->execute();
|
|
}
|
|
}
|
|
}
|
|
}
|