Fixed cronjobs

This commit is contained in:
2026-05-14 16:58:41 +02:00
parent 30cc0b79c5
commit 454d83de2e
4 changed files with 34 additions and 18 deletions
+14 -3
View File
@@ -2,6 +2,8 @@
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;
@@ -12,9 +14,18 @@ class CloseCostUnit implements CronTask {
$costUnitRepository = new CostUnitRepository();
/** @var CostUnit $costUnit */
foreach ($costUnitRepository->getCurrentEvents() as $costUnit) {
if (\DateTime::createFromFormat('Y-m-d', $costUnit->billing_deadline) < $now ) {
$costUnit->allow_new = false;
$costUnit->save();
$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();
}
}
}