detailsFactory->build($data); $year = (int) $this->clock->today()->format('Y'); return $this->transactions->run(function () use ($details, $year, $actorUserId): int { $job = CustomerJob::open($this->numbers->next($year), $details, $actorUserId); $job->recordCompletion($this->clock->now()); $job = $this->jobs->save($job); $jobId = (int) $job->id(); $this->jobs->recordChanges($jobId, $actorUserId, [new FieldChange('created', null, $job->number()->format())]); $added = PeopleAddedToJob::between(null, $job, $actorUserId); if ($added !== null) { $this->events->dispatch($added); } return $jobId; }); } }