authorize('machines.use'); $summary = $machines->findMachine($machine) ?? abort(404); $this->machineId = $summary->id; $this->day = $this->validDay($this->day) ?? $clock->today()->format('Y-m-d'); $this->dayInput = $this->day; $this->message = (string) session('status', ''); } #[Computed] public function machine(): MachineSummary { return app(MachineQueries::class)->findMachine($this->machineId) ?? abort(404); } #[Computed] public function today(): string { return app(Clock::class)->today()->format('Y-m-d'); } /** * @return list */ #[Computed] public function rows(): array { return app(MachineQueries::class)->rowsOn($this->machineId, $this->day, $this->today); } /** * @return list */ #[Computed] public function load(): array { return app(MachineQueries::class)->load($this->machineId, $this->today, self::LOAD_DAYS); } /** * Machines a row's task could move to. * * @return list */ public function machinesFor(QueueRow $row): array { return $row->task === null ? [] : app(MachineQueries::class)->machinesFor($row->task->allowedServiceUnitIds); } public function showDay(string $which): void { $this->authorize('machines.use'); $current = CarbonImmutable::createFromFormat('!Y-m-d', $this->day); $this->day = match ($which) { 'previous' => $current->subDay()->format('Y-m-d'), 'next' => $current->addDay()->format('Y-m-d'), 'chosen' => $this->validDay($this->dayInput) ?? $this->day, default => $this->today, }; $this->dayInput = $this->day; $this->editingEntryId = null; $this->message = ''; unset($this->rows); } public function showDate(string $date): void { $this->dayInput = $date; $this->showDay('chosen'); } public function move(int $entryId, string $direction, MachineWorkList $workList): void { $this->authorize('machines.use'); $row = $this->row($entryId); $up = $direction === 'up'; try { $moved = $workList->move($entryId, $up); } catch (QueueEntryNotFound|QueueEntryCompleted) { $this->message = __('machines.errors.not_found'); unset($this->rows); return; } $title = $this->rowTitle($row); $this->message = __('machines.show.'.($moved ? ($up ? 'moved_up' : 'moved_down') : ($up ? 'first' : 'last')), ['title' => $title]); unset($this->rows); $this->js("document.getElementById('row-{$entryId}-{$direction}')?.focus()"); } public function startEdit(int $entryId): void { $this->authorize('machines.use'); $row = $this->row($entryId); $this->editingEntryId = $entryId; $this->editMachineId = (string) $row->machineId; $this->editDay = $row->isLate ? $this->today : $row->plannedOn; $this->resetErrorBag(); $this->js("setTimeout(() => document.getElementById('edit-day')?.focus())"); } public function cancelEdit(): void { $entryId = $this->editingEntryId; $this->editingEntryId = null; $this->js("document.getElementById('row-{$entryId}-edit')?.focus()"); } public function reschedule(MachineWorkList $workList): void { $this->authorize('machines.use'); $row = $this->row((int) $this->editingEntryId); abort_if($row->taskId === null, 404); try { $workList->planTask($row->taskId, (int) $this->editMachineId, $this->editDay); } catch (InvalidPlannedDay) { $this->addError('editDay', __('machines.errors.day')); return; } catch (MachineNotFound|MachineInactive|MachineNotForTask) { $this->addError('editMachineId', __('machines.errors.machine')); return; } catch (MachineTaskNotFound) { $this->message = __('machines.errors.task_done'); return; } $machine = app(MachineQueries::class)->findMachine((int) $this->editMachineId); $this->message = __('machines.task.moved', ['machine' => $machine->name ?? '', 'date' => $this->dateLabel($this->editDay)]); $this->editingEntryId = null; unset($this->rows, $this->load); $this->js("document.getElementById('work-list-status')?.focus()"); } public function remove(int $entryId, MachineWorkList $workList): void { $this->authorize('machines.use'); $row = $this->row($entryId); abort_if($row->taskId === null, 404); $workList->removeTask($row->taskId); $this->message = __('machines.task.removed'); unset($this->rows, $this->load); $this->js("document.getElementById('work-list-status')?.focus()"); } public function rowTitle(QueueRow $row): string { return $row->task === null ? __('machines.show.order') : $row->task->title; } public function render(): mixed { return $this->view()->title($this->machine->name); } private function row(int $entryId): QueueRow { return collect($this->rows)->firstWhere('entryId', $entryId) ?? abort(404); } private function validDay(string $value): ?string { if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) !== 1) { return null; } $date = CarbonImmutable::createFromFormat('!Y-m-d', $value); return $date !== null && $date->format('Y-m-d') === $value ? $value : null; } }; ?>
@php($machine = $this->machine)

{{ __('machines.show.back') }}

{{ $machine->name }}

{{ __('machines.types.'.$machine->type->value) }} · {{ __('machines.show.units', ['units' => implode(', ', $machine->serviceUnitNames)]) }} @if ($machine->responsibleName !== null) · {{ __('machines.index.responsible', ['name' => $machine->responsibleName]) }} @endif @unless ($machine->isActive) · {{ __('machines.index.inactive') }} @endunless

@if ($machine->description !== null)

{{ $machine->description }}

@endif
@can('machines.manage') @endcan

{{ $message }}

{{ __('machines.show.work_list') }}

{{ __('machines.show.load') }}

    @foreach ($this->load as $dayLoad)
  • @endforeach

{{ __('machines.show.day_heading', ['date' => $this->dateLabel($day)]) }}

{{ trans_choice('machines.show.row_count', count($this->rows), ['count' => count($this->rows)]) }}

@if ($this->rows === [])

{{ __('machines.show.none') }}

@else
    @foreach ($this->rows as $row) @php($task = $row->task)
  1. {{ $this->rowTitle($row) }}

    @if ($task !== null)

    {{ $task->jobNumber }} {{ $task->jobName }} · {{ $task->customerName }}

    @if ($task->dueOn !== null) {{ __('machines.show.due', ['date' => $this->dateLabel($task->dueOn)]) }} @endif {{ __('machines.show.priority', ['priority' => __('jobs.priorities.'.$task->priority)]) }} {{ __('machines.show.status', ['status' => __('jobs.tasks.statuses.'.$task->status)]) }}

    @endif @if ($row->isLate)

    @endif @if ($task !== null && $task->isOutsidePlan($row->isLate ? $this->today : $row->plannedOn))

    @endif
    @if ($task !== null) {{ __('machines.show.open_task') }} @endif
    @if ($task !== null && ($task->instructions !== null || $task->description !== null))
    @if ($task->instructions !== null)
    {{ __('machines.show.instructions') }}

    {{ $task->instructions }}

    @endif @if ($task->description !== null)
    {{ __('machines.show.description') }}

    {{ $task->description }}

    @endif
    @endif @if ($editingEntryId === $row->entryId)
    @foreach ($this->machinesFor($row) as $option) @endforeach
    @else
    @unless ($row->isLate || $row->isOrder()) @endunless @if ($task !== null) @endif
    @endif
  2. @endforeach
@endif