transactions->run(function () use ($userId, $taskId, $date, $parsed): void { $task = $this->booking->openTask($taskId); $entry = $this->entries->findForDay($userId, $taskId, $date); if ($parsed === null) { if ($entry !== null) { $this->entries->delete($entry); } return; } $this->booking->ensureDayFits($userId, $date, $parsed, $entry?->id()); if ($entry === null) { $entry = TimeEntry::create($userId, $taskId, $task->jobId, $task->workTypeId, $date, $parsed); } else { $entry->changeHours($parsed, $entry->note()); } $this->entries->save($entry); }); } }