authorize('jobs.view'); abort_if($jobQueries->findDetails($job) === null, 404); $this->authorize('jobs.view-job', $job); $this->jobId = $job; } #[Computed] public function job(): CustomerJobDetails { return app(CustomerJobQueries::class)->findDetails($this->jobId) ?? abort(404); } /** * @return list */ #[Computed] public function changes(): array { return app(CustomerJobQueries::class)->changes($this->jobId); } public function formatDate(?string $date): string { return $date === null ? __('jobs.not_set') : CarbonImmutable::parse($date)->format('j.n.Y'); } /** * A history value as text: names for ids, labels for enum keys, * Finnish dates. */ public function historyValue(string $field, ?string $value): string { if ($value === null || $value === '') { return __('jobs.not_set'); } $ids = array_map('intval', explode(',', $value)); $named = fn (array $names): string => implode(', ', array_map( fn (int $id): string => $names[$id] ?? __('jobs.history.unknown', ['id' => $id]), $ids, )); return match ($field) { 'starts_on', 'due_on', 'planned_from', 'planned_to' => $this->formatDate($value), 'kind' => __('jobs.kinds.'.$value), 'status' => __('jobs.statuses.'.$value), 'priority' => __('jobs.priorities.'.$value), 'payment_basis' => __('jobs.payment_bases.'.$value), 'customer' => $named(app(CustomerQueries::class)->namesByIds($ids)), 'service_units' => $named(app(CatalogQueries::class)->serviceUnitNames($ids)), 'responsible_user', 'contact_user', 'biller_user', 'members' => $named(app(UserAccountQueries::class)->namesByIds($ids)), 'customer_contact' => app(CustomerQueries::class)->findContact($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]), 'billing_unit' => app(CustomerQueries::class)->findBillingUnit($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]), default => $value, }; } public function render(): mixed { return $this->view()->title($this->job->number.' '.$this->job->name); } }; ?> @php($job = $this->job)

{{ $job->number }} {{ $job->name }}

@can('jobs.manage') @endcan
@if (session('status')) @endif
{{ __('jobs.fields.status') }}:
{{ __('jobs.statuses.'.$job->status->value) }}
{{ __('jobs.fields.priority') }}:
{{ __('jobs.fields.due_on') }}:

{{ __('jobs.sections.basics') }}

{{ __('jobs.fields.customer') }}
@can('customers.use') {{ $job->customer->name }} @else {{ $job->customer->name }} @endcan
{{ __('jobs.fields.service_units') }}
{{ collect($job->serviceUnits)->pluck('name')->join(', ') }}
{{ __('jobs.fields.kind') }}
{{ __('jobs.kinds.'.$job->kind->value) }}
{{ __('jobs.fields.payment_basis') }}
{{ $job->paymentBasis === null ? __('jobs.not_set') : __('jobs.payment_bases.'.$job->paymentBasis->value) }}
{{ __('jobs.fields.estimated_hours') }}
{{ $job->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $job->estimatedHours).' h' }}
{{ __('jobs.fields.customer_reference') }}
{{ $job->customerReference ?? __('jobs.not_set') }}
{{ __('jobs.fields.tags') }}
{{ $job->tags === [] ? __('jobs.tags.none') : implode(', ', $job->tags) }}
{{ __('jobs.fields.created_at') }}
{{ CarbonImmutable::parse($job->createdAt)->format('j.n.Y H.i') }}, {{ $job->createdByName }}
@if ($job->description !== null)

{{ __('jobs.fields.description') }}

{{ $job->description }}

@endif

{{ __('jobs.sections.schedule') }}

{{ __('jobs.fields.starts_on') }}
{{ $this->formatDate($job->startsOn) }}
{{ __('jobs.fields.due_on') }}
{{ __('jobs.fields.planned_from') }}
{{ $this->formatDate($job->plannedFrom) }}
{{ __('jobs.fields.planned_to') }}
{{ $this->formatDate($job->plannedTo) }}

{{ __('jobs.sections.members') }}

{{ __('jobs.fields.responsible_user') }}
{{ $job->responsible->name }}
{{ __('jobs.fields.contact_user') }}
{{ $job->contactUser->name ?? __('jobs.not_set') }}
{{ __('jobs.fields.customer_contact') }}
{{ $job->customerContact->name ?? __('jobs.not_set') }}
{{ __('jobs.fields.biller_user') }}
{{ $job->biller->name ?? __('jobs.not_set') }}
{{ __('jobs.fields.billing_unit') }}
{{ $job->billingUnit->name ?? __('jobs.not_set') }}
{{ __('jobs.fields.members') }}
{{ $job->members === [] ? __('jobs.not_set') : collect($job->members)->pluck('name')->join(', ') }}
@if ($job->links === [])

{{ __('jobs.links.none') }}

@else
    @foreach ($job->links as $link)
  • {{ $link['title'] }} ({{ __('jobs.opens_in_new_tab') }})
  • @endforeach
@endif

{{ __('jobs.sections.instructions') }}

{{ $job->instructions ?? __('jobs.not_set') }}

{{ __('jobs.sections.history') }}

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

{{ __('jobs.history.empty') }}

@else
    @foreach ($this->changes as $change)
  1. @if ($change->field === 'created') {{ __('jobs.history.created', ['user' => $change->userName, 'number' => $change->newValue]) }} @else {{ __('jobs.history.changed', [ 'field' => __('jobs.fields.'.$change->field), 'old' => $this->historyValue($change->field, $change->oldValue), 'new' => $this->historyValue($change->field, $change->newValue), ]) }} @endif {{ __('jobs.history.by', ['user' => $change->userName, 'time' => CarbonImmutable::parse($change->changedAt)->format('j.n.Y H.i')]) }}
  2. @endforeach
@endif