*/ #[Locked] public array $serviceUnitIds = []; /** * The task's work type when editing, offered even if taken out of use. */ #[Locked] public ?int $storedWorkTypeId = null; public TaskForm $form; public function mount(CustomerJobQueries $jobQueries, TaskQueries $taskQueries, int $job, ?int $task = null): void { $details = $jobQueries->findDetails($job); abort_if($details === null, 404); $this->authorize('jobs.manage-tasks', $details->id); $this->jobId = $details->id; $this->jobTitle = $details->number.' '.$details->name; $this->serviceUnitIds = array_map(fn (NamedId $unit): int => $unit->id, $details->serviceUnits); if ($task === null) { abort_unless($details->status->allowsTasks(), 404); $this->form->assignee_user_id = (string) auth()->id(); return; } $summary = $taskQueries->findTask($details->id, $task); abort_if($summary === null, 404); $this->taskId = $summary->id; $this->storedWorkTypeId = $summary->workType->id; $this->form->fillFromSummary($summary); } /** * Work types of the job's service units and the shared ones, grouped * as "Unit – Service" for . * * @return array> */ #[Computed] public function workTypeGroups(): array { $catalog = app(CatalogQueries::class); $groups = []; $seen = []; foreach ($catalog->activeWorkTypesFor($this->serviceUnitIds) as $node) { if ($node->workTypes !== []) { $groups[$node->serviceUnit->name] = array_map(fn ($workType): array => ['id' => $workType->id, 'name' => $workType->name], $node->workTypes); } foreach ($node->services as $serviceNode) { if ($serviceNode->workTypes !== []) { $groups[$node->serviceUnit->name.' – '.$serviceNode->service->name] = array_map(fn ($workType): array => ['id' => $workType->id, 'name' => $workType->name], $serviceNode->workTypes); } } } foreach ($groups as $group) { foreach ($group as $workType) { $seen[$workType['id']] = true; } } if ($this->storedWorkTypeId !== null && ! isset($seen[$this->storedWorkTypeId]) && ($stored = $catalog->findWorkType($this->storedWorkTypeId)) !== null) { $groups[__('catalog.inactive')] = [['id' => $stored->id, 'name' => $stored->name]]; } return $groups; } /** * @return list */ #[Computed] public function userOptions(): array { return array_map(fn ($user): array => [ 'value' => $user->id, 'label' => $user->name, 'note' => $user->role === Role::Subcontractor ? __('users.roles.subcontractor') : null, ], app(UserAccountQueries::class)->activeUserOptions()); } public function save(AddTask $addTask, UpdateTask $updateTask): void { $this->authorize('jobs.manage-tasks', $this->jobId); $data = $this->form->toData(); try { if ($this->taskId === null) { $taskId = $addTask->execute($this->jobId, $data, (int) auth()->id()); $message = __('jobs.tasks.created', ['title' => trim($data->title)]); } else { $taskId = $this->taskId; $updateTask->execute($this->jobId, $taskId, $data, (int) auth()->id()); $message = __('jobs.tasks.updated', ['title' => trim($data->title)]); } } catch (CustomerJobNotFound|TaskNotFound) { abort(404); } catch (DomainException $exception) { $this->form->showDomainError($exception); return; } $plannedTo = app(TaskQueries::class)->findTask($this->jobId, $taskId)?->plannedTo; if ($data->plannedFrom !== null && $plannedTo !== null && $plannedTo !== ($data->plannedTo ?? $data->plannedFrom)) { $message .= ' '.__('jobs.tasks.extended', ['to' => CarbonImmutable::parse($plannedTo)->format('j.n.Y')]); } session()->flash('status', $message); $this->redirect(route('jobs.show', $this->jobId).'#tasks', navigate: true); } public function heading(): string { return __($this->taskId === null ? 'jobs.tasks.create_title' : 'jobs.tasks.edit_title'); } public function render(): mixed { return $this->view()->title($this->heading().' – '.$this->jobTitle); } }; ?>
{{ $this->heading() }}

{{ __('jobs.tasks.job_label') }}: {{ $jobTitle }}

{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}} @foreach ($this->workTypeGroups as $group => $workTypes) @foreach ($workTypes as $workType) @endforeach @endforeach @foreach ($this->userOptions as $user) @endforeach
@foreach (TaskStatus::cases() as $status) @endforeach
{{ __('jobs.tasks.schedule') }}

{{ __('jobs.tasks.fields.planned_hint') }}