authorize('time.use'); $bookable = $tasks->bookableTask($task); abort_if($bookable === null, 404); $this->authorize('time.book', $bookable->jobId); $this->taskId = $bookable->taskId; $this->workedOn = $clock->today()->format('Y-m-d'); } #[Computed] public function task(): BookableTask { return app(TaskQueries::class)->bookableTask($this->taskId) ?? abort(404); } /** * @return list */ #[Computed] public function entries(): array { return app(TimeEntryQueries::class)->entriesForTask($this->taskId, (int) auth()->id()); } public function save(AddTaskHours $addHours): void { $this->authorize('time.book', $this->task->jobId); $this->validate( ['workedOn' => ['required', 'date_format:Y-m-d'], 'hours' => ['required', 'string', 'max:10'], 'note' => ['nullable', 'string', 'max:2000']], ['workedOn.required' => __('time.errors.date_required'), 'workedOn.date_format' => __('time.errors.invalid_date'), 'hours.required' => __('time.errors.invalid_hours'), 'hours.max' => __('time.errors.invalid_hours')], ); try { $total = $addHours->execute((int) auth()->id(), $this->taskId, $this->workedOn, $this->hours, $this->note); } catch (DomainException $exception) { $this->addError('hours', $this->messageFor($exception)); return; } $this->statusMessage = __('time.task_page.saved', [ 'hours' => WorkedHours::parse($this->hours)?->format() ?? $this->hours, 'day' => $this->dayLabel($this->workedOn), 'total' => $total, ]); $this->reset('hours', 'note'); unset($this->entries); } public function editEntry(int $entryId): void { $entry = collect($this->entries)->firstWhere('id', $entryId); if ($entry === null) { return; } $this->editingEntryId = $entry->id; $this->editHours = WorkedHours::formatQuarters($entry->quarters); $this->editNote = $entry->note ?? ''; $this->resetErrorBag('editHours'); $this->js("document.getElementById('edit-hours-{$entryId}')?.focus()"); } public function cancelEdit(): void { $entryId = $this->editingEntryId; $this->reset('editingEntryId', 'editHours', 'editNote'); $this->js("document.getElementById('edit-entry-{$entryId}')?.focus()"); } public function updateEntry(UpdateTimeEntry $updateEntry): void { $this->authorize('time.book', $this->task->jobId); $entry = collect($this->entries)->firstWhere('id', $this->editingEntryId); if ($entry === null) { return; } try { $updateEntry->execute((int) auth()->id(), $entry->id, $this->editHours, $this->editNote); } catch (DomainException $exception) { $this->addError('editHours', $this->messageFor($exception)); return; } $this->statusMessage = __('time.task_page.updated', ['day' => $this->dayLabel($entry->workedOn)]); $this->reset('editingEntryId', 'editHours', 'editNote'); unset($this->entries); $this->js("document.getElementById('edit-entry-{$entry->id}')?.focus()"); } public function confirmRemoval(int $entryId): void { if (collect($this->entries)->firstWhere('id', $entryId) === null) { return; } $this->removalEntryId = $entryId; $this->js("document.getElementById('remove-entry-dialog').showModal()"); } public function removeEntry(RemoveTimeEntry $removeEntry): void { $this->authorize('time.book', $this->task->jobId); $entry = collect($this->entries)->firstWhere('id', $this->removalEntryId); if ($entry !== null) { try { $removeEntry->execute((int) auth()->id(), $entry->id); $this->statusMessage = __('time.task_page.entry_removed', ['day' => $this->dayLabel($entry->workedOn)]); } catch (DomainException $exception) { $this->statusMessage = $this->messageFor($exception); } } $this->reset('removalEntryId'); unset($this->entries); $this->js("document.getElementById('remove-entry-dialog').close(); document.getElementById('entries-heading').focus()"); } public function dayLabel(string $day): string { $date = CarbonImmutable::parse($day); return __('time.days')[$date->dayOfWeekIso - 1].' '.$date->format('j.n.Y'); } public function render(): mixed { return $this->view()->title(__('time.task_page.title', ['task' => $this->task->taskTitle])); } private function messageFor(DomainException $exception): string { return __(match (true) { $exception instanceof InvalidWorkedHours => 'time.errors.invalid_hours', $exception instanceof DailyHoursExceeded => 'time.errors.day_full', $exception instanceof TimeLocked => 'time.errors.locked', default => 'time.errors.not_found', }); } }; ?> @php($task = $this->task)

{{ __('time.task_page.title', ['task' => $task->taskTitle]) }}

{{ __('time.task_page.job') }}
{{ $task->jobNumber }} {{ $task->jobName }}
{{ __('time.task_page.work_type') }}
{{ $task->workTypeName }}
{{ __('time.task_page.back_to_week') }}

{{ $statusMessage }}

@if ($task->isLocked())

@else
@endif

{{ __('time.task_page.own_entries') }}

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

{{ __('time.task_page.no_entries') }}

@else
    @foreach ($this->entries as $entry)
  • @if ($editingEntryId === $entry->id)

    {{ $this->dayLabel($entry->workedOn) }}

    @else

    {{ $this->dayLabel($entry->workedOn) }}: {{ __('time.hours_suffix', ['hours' => WorkedHours::formatQuarters($entry->quarters)]) }}

    @if ($entry->note !== null)

    {{ $entry->note }}

    @endif
    @unless ($task->isLocked())
    @endunless
    @endif
  • @endforeach
@endif

@php($removal = collect($this->entries)->firstWhere('id', $removalEntryId)) @if ($removal !== null) {{ __('time.task_page.remove_question', ['day' => $this->dayLabel($removal->workedOn), 'hours' => WorkedHours::formatQuarters($removal->quarters)]) }} @endif