Add time tracking on tasks with a weekly sheet

Phase 1, item 8 (last of phase 1). New TimeTracking module:
- One entry per user, task and day (0.25-24 h in quarters, with a note);
  the job and work type are copied from the task. A user's day cannot
  exceed 24 h, and hours on a done, invoiced, billed or archived job
  cannot be added or changed.
- Weekly sheet /time: tasks as rows (own open tasks, tasks with hours
  that week, tasks added by search), days as columns, row, day and week
  totals, week navigation. A cell saves on change and an empty cell
  removes the entry; on phones one day at a time. Saves and errors are
  announced, errors are tied to their cell.
- Task booking page /time/tasks/{task}: date, hours and note, added to
  the day's entry; own entries with edit and remove.
- Anyone but subcontractors may book on any unlocked task;
  subcontractors only on jobs they are attached to.

Jobs module:
- JobStatus::locksTime(), BookableTask and task queries for booking.
- A task with time entries cannot be removed (TaskUsage contract,
  provided by TimeTracking); the job page links tasks to booking.
- The "involved in a job" rule is shared in JobInvolvement.

Spec and CLAUDE.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 05:52:45 +02:00
co-authored by Claude Opus 5.5
parent 02a62eb16e
commit 3922c744a7
53 changed files with 2496 additions and 19 deletions
@@ -0,0 +1,312 @@
<?php
use App\Modules\Jobs\Application\Contracts\TaskQueries;
use App\Modules\Jobs\Application\DTOs\BookableTask;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\TimeTracking\Application\Contracts\TimeEntryQueries;
use App\Modules\TimeTracking\Application\DTOs\TimeEntrySummary;
use App\Modules\TimeTracking\Application\UseCases\AddTaskHours;
use App\Modules\TimeTracking\Application\UseCases\RemoveTimeEntry;
use App\Modules\TimeTracking\Application\UseCases\UpdateTimeEntry;
use App\Modules\TimeTracking\Domain\Exceptions\DailyHoursExceeded;
use App\Modules\TimeTracking\Domain\Exceptions\InvalidWorkedHours;
use App\Modules\TimeTracking\Domain\Exceptions\TimeLocked;
use App\Modules\TimeTracking\Domain\ValueObjects\WorkedHours;
use App\Modules\Users\Application\Contracts\Clock;
use Carbon\CarbonImmutable;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Hours on one task: a date, hours and a note, and the user's own entries
* on the task with edit and remove.
*/
new class extends Component
{
#[Locked]
public int $taskId;
public string $workedOn = '';
public string $hours = '';
public string $note = '';
#[Locked]
public ?int $editingEntryId = null;
public string $editHours = '';
public string $editNote = '';
#[Locked]
public ?int $removalEntryId = null;
public string $statusMessage = '';
public function mount(TaskQueries $tasks, Clock $clock, int $task): void
{
$this->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<TimeEntrySummary>
*/
#[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)
<div class="mx-auto max-w-2xl space-y-6 p-4 sm:p-6">
<div class="space-y-2">
<h1 class="text-2xl font-semibold break-words">{{ __('time.task_page.title', ['task' => $task->taskTitle]) }}</h1>
<dl class="grid gap-x-6 gap-y-1 text-sm sm:grid-cols-[max-content_1fr]">
<dt class="font-medium">{{ __('time.task_page.job') }}</dt>
<dd><x-link :href="route('jobs.show', $task->jobId)" navigate>{{ $task->jobNumber }} {{ $task->jobName }}</x-link></dd>
<dt class="font-medium">{{ __('time.task_page.work_type') }}</dt>
<dd>{{ $task->workTypeName }}</dd>
</dl>
<x-link :href="route('time.week')" navigate class="text-sm">{{ __('time.task_page.back_to_week') }}</x-link>
</div>
<p role="status" aria-live="polite" class="min-h-5 text-sm">{{ $statusMessage }}</p>
@if ($task->isLocked())
<p class="flex items-start gap-2 rounded-lg border border-zinc-300 p-3 text-sm dark:border-zinc-600">
<x-icon name="lock-closed" class="size-5 shrink-0" aria-hidden="true" />
{{ __('time.task_page.locked') }}
</p>
@else
<form wire:submit="save" class="space-y-6" novalidate>
<div class="grid gap-6 sm:grid-cols-2">
<x-input wire:model="workedOn" type="date" :label="__('time.task_page.worked_on')" required />
<x-input wire:model="hours" inputmode="decimal" :label="__('time.task_page.hours')" :hint="__('time.task_page.hours_description')" autocomplete="off" required />
</div>
<x-textarea wire:model="note" :label="__('time.task_page.note')" resize-auto />
<x-button submit :text="__('time.task_page.save')" />
</form>
@endif
<section aria-labelledby="entries-heading" class="space-y-3">
<h2 id="entries-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">{{ __('time.task_page.own_entries') }}</h2>
@if ($this->entries === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('time.task_page.no_entries') }}</p>
@else
<ul class="divide-y divide-zinc-200 rounded-lg border border-zinc-200 text-sm dark:divide-zinc-700 dark:border-zinc-700">
@foreach ($this->entries as $entry)
<li wire:key="entry-{{ $entry->id }}" class="space-y-2 p-3">
@if ($editingEntryId === $entry->id)
<form wire:submit="updateEntry" class="space-y-3" novalidate>
<p class="font-medium">{{ $this->dayLabel($entry->workedOn) }}</p>
<x-input id="edit-hours-{{ $entry->id }}" wire:model="editHours" inputmode="decimal" :label="__('time.task_page.hours')" autocomplete="off" required />
<x-textarea id="edit-note-{{ $entry->id }}" wire:model="editNote" :label="__('time.task_page.note')" resize-auto />
<div class="flex flex-wrap gap-2">
<x-button submit sm :text="__('jobs.save')" />
<x-button wire:click="cancelEdit" subtle color="black" sm :text="__('jobs.cancel')" />
</div>
</form>
@else
<div class="flex flex-wrap items-start justify-between gap-3">
<div>
<p class="font-medium">{{ $this->dayLabel($entry->workedOn) }}: {{ __('time.hours_suffix', ['hours' => WorkedHours::formatQuarters($entry->quarters)]) }}</p>
@if ($entry->note !== null)
<p class="whitespace-pre-line text-zinc-700 dark:text-zinc-300">{{ $entry->note }}</p>
@endif
</div>
@unless ($task->isLocked())
<div class="flex flex-wrap gap-2">
<x-button
id="edit-entry-{{ $entry->id }}"
wire:click="editEntry({{ $entry->id }})"
subtle
color="black"
sm
icon="pencil"
:text="__('time.task_page.edit')"
:aria-label="__('time.task_page.edit_named', ['day' => $this->dayLabel($entry->workedOn)])"
/>
<x-button
wire:click="confirmRemoval({{ $entry->id }})"
subtle
color="black"
sm
icon="trash"
:text="__('time.task_page.remove')"
:aria-label="__('time.task_page.remove_named', ['day' => $this->dayLabel($entry->workedOn)])"
/>
</div>
@endunless
</div>
@endif
</li>
@endforeach
</ul>
@endif
</section>
<x-confirm-dialog id="remove-entry-dialog" :title="__('customers.removal.title')">
<p>
@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
</p>
<x-slot:actions>
<x-button wire:click="removeEntry" color="red" icon="trash" :text="__('time.task_page.remove')" />
</x-slot:actions>
</x-confirm-dialog>
</div>
@@ -0,0 +1,428 @@
<?php
use App\Modules\Jobs\Application\Contracts\TaskQueries;
use App\Modules\Jobs\Application\DTOs\BookableTask;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\TimeTracking\Application\Contracts\TimeEntryQueries;
use App\Modules\TimeTracking\Application\DTOs\WeekSheet;
use App\Modules\TimeTracking\Application\UseCases\SetDayHours;
use App\Modules\TimeTracking\Domain\Exceptions\DailyHoursExceeded;
use App\Modules\TimeTracking\Domain\Exceptions\InvalidWorkedHours;
use App\Modules\TimeTracking\Domain\Exceptions\TimeLocked;
use App\Modules\TimeTracking\Domain\ValueObjects\WorkedHours;
use App\Modules\Users\Application\Contracts\Clock;
use App\Modules\Users\Domain\Enums\Role;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Gate;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Url;
use Livewire\Component;
/**
* The weekly time sheet: tasks as rows, days as columns. A cell saves when
* focus leaves it; an empty cell removes the day's entry. On a phone one
* day is shown at a time.
*/
new class extends Component
{
/**
* The Monday of the week shown (Y-m-d).
*/
#[Url(as: 'viikko', except: '')]
public string $week = '';
/**
* Stored hours as shown, by task id and day: [taskId => [Y-m-d => "2,5"]].
* The cells send their value with wire:change; the desktop grid and the
* phone list both have an input for the same cell.
*
* @var array<int|string, array<string, string>>
*/
#[Locked]
public array $cells = [];
/**
* Tasks added to this week by search, besides the user's own.
*
* @var list<int>
*/
#[Locked]
public array $extraTaskIds = [];
/**
* Values that were not saved, shown back in their cell with the error.
*
* @var array<string, string>
*/
#[Locked]
public array $rejected = [];
public string $selectedDay = '';
public string $taskSearch = '';
public string $statusMessage = '';
public string $errorMessage = '';
public function mount(Clock $clock): void
{
$this->authorize('time.use');
$this->week = $this->mondayOf($this->week !== '' ? $this->week : $clock->today()->format('Y-m-d'));
$today = $clock->today()->format('Y-m-d');
$this->selectedDay = in_array($today, $this->sheet->days, true) ? $today : $this->week;
$this->loadCells();
}
#[Computed]
public function sheet(): WeekSheet
{
return app(TimeEntryQueries::class)->week((int) auth()->id(), $this->week, $this->extraTaskIds);
}
/**
* @return list<BookableTask>
*/
#[Computed]
public function searchResults(): array
{
$term = trim($this->taskSearch);
if (mb_strlen($term) < 2) {
return [];
}
$shown = array_map(fn ($row): int => $row->task->taskId, $this->sheet->rows);
return array_values(array_filter(
app(TaskQueries::class)->searchBookableTasks($term, $this->isSubcontractor() ? (int) auth()->id() : null),
fn (BookableTask $task): bool => ! in_array($task->taskId, $shown, true),
));
}
public function saveCell(int $taskId, string $day, string $value): void
{
$this->authorize('time.use');
$row = collect($this->sheet->rows)->first(fn ($row): bool => $row->task->taskId === $taskId);
if ($row === null || ! in_array($day, $this->sheet->days, true)) {
return;
}
$this->authorize('time.book', $row->task->jobId);
$this->resetErrorBag("cells.{$taskId}.{$day}");
unset($this->rejected["{$taskId}.{$day}"]);
$this->errorMessage = '';
try {
app(SetDayHours::class)->execute((int) auth()->id(), $taskId, $day, $value);
} catch (DomainException $exception) {
$message = __(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',
});
$this->addError("cells.{$taskId}.{$day}", $message);
$this->errorMessage = $row->task->taskTitle.', '.$this->dayLabel($day).': '.$message;
$this->rejected["{$taskId}.{$day}"] = $value;
return;
}
unset($this->sheet);
$this->loadCells();
$hours = $this->cells[$taskId][$day] ?? '';
$this->statusMessage = $hours === ''
? __('time.removed', ['task' => $row->task->taskTitle, 'day' => $this->dayLabel($day)])
: __('time.saved', ['task' => $row->task->taskTitle, 'day' => $this->dayLabel($day), 'hours' => $hours]);
}
public function addTask(int $taskId): void
{
$this->authorize('time.use');
$task = app(TaskQueries::class)->bookableTask($taskId);
if ($task === null || $task->isLocked() || Gate::denies('time.book', $task->jobId)) {
return;
}
if (! in_array($taskId, $this->extraTaskIds, true)) {
$this->extraTaskIds[] = $taskId;
}
$this->taskSearch = '';
unset($this->sheet);
$this->loadCells();
$this->statusMessage = __('time.add.added', ['task' => $task->label()]);
$this->js("(document.getElementById('cell-{$taskId}-{$this->selectedDay}')?.offsetParent ? document.getElementById('cell-{$taskId}-{$this->selectedDay}') : document.getElementById('mcell-{$taskId}-{$this->selectedDay}'))?.focus()");
}
public function selectDay(string $day): void
{
if (in_array($day, $this->sheet->days, true)) {
$this->selectedDay = $day;
}
}
public function showWeek(string $which, Clock $clock): void
{
$this->week = match ($which) {
'previous' => CarbonImmutable::parse($this->week)->subWeek()->toDateString(),
'next' => CarbonImmutable::parse($this->week)->addWeek()->toDateString(),
default => $this->mondayOf($clock->today()->format('Y-m-d')),
};
unset($this->sheet);
$this->selectedDay = $this->week;
$this->statusMessage = $this->weekHeading();
$this->errorMessage = '';
$this->resetErrorBag();
$this->rejected = [];
$this->loadCells();
}
public function weekHeading(): string
{
$monday = CarbonImmutable::parse($this->week);
return __('time.week_heading', [
'number' => $monday->isoWeek(),
'from' => $monday->format('j.n.'),
'to' => $monday->addDays(6)->format('j.n.Y'),
]);
}
public function dayLabel(string $day): string
{
$date = CarbonImmutable::parse($day);
return __('time.days')[$date->dayOfWeekIso - 1].' '.$date->format('j.n.');
}
public function hours(int $quarters): string
{
return WorkedHours::formatQuarters($quarters);
}
public function isSubcontractor(): bool
{
return auth()->user()?->role === Role::Subcontractor;
}
public function render(): mixed
{
return $this->view()->title(__('time.title'));
}
private function loadCells(): void
{
$cells = [];
foreach ($this->sheet->rows as $row) {
foreach ($this->sheet->days as $day) {
$quarters = $row->quartersByDay[$day] ?? 0;
$cells[$row->task->taskId][$day] = $quarters === 0 ? '' : WorkedHours::formatQuarters($quarters);
}
}
$this->cells = $cells;
}
private function mondayOf(string $date): string
{
try {
return CarbonImmutable::parse($date)->startOfWeek()->toDateString();
} catch (\Throwable) {
return CarbonImmutable::now()->startOfWeek()->toDateString();
}
}
};
?>
@php($sheet = $this->sheet)
<div class="mx-auto max-w-7xl space-y-6 p-4 sm:p-6">
<div class="space-y-2">
<h1 class="text-2xl font-semibold">{{ __('time.title') }}</h1>
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('time.intro') }}</p>
</div>
<div class="flex flex-wrap items-center justify-between gap-3">
<h2 class="text-xl font-semibold">{{ $this->weekHeading() }}</h2>
<div class="flex flex-wrap gap-2">
<x-button wire:click="showWeek('previous')" subtle color="black" sm icon="chevron-left" :text="__('time.previous_week')" />
<x-button wire:click="showWeek('this')" subtle color="black" sm :text="__('time.this_week')" />
<x-button wire:click="showWeek('next')" subtle color="black" sm icon="chevron-right" position="right" :text="__('time.next_week')" />
</div>
</div>
<p role="status" aria-live="polite" class="min-h-5 text-sm">{{ $statusMessage }}</p>
<p role="alert" class="text-sm font-medium text-red-700 dark:text-red-400">{{ $errorMessage }}</p>
@if ($sheet->rows === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('time.no_rows') }}</p>
@else
{{-- Desktop: the whole week as an input grid (a form, so a native table rather than <x-table>). --}}
<div class="hidden lg:block">
<table class="w-full border-collapse text-sm">
<caption class="sr-only">{{ __('time.table_caption') }}</caption>
<thead>
<tr class="border-b border-zinc-300 dark:border-zinc-600">
<th scope="col" class="py-2 pr-3 text-left font-semibold">{{ __('time.task') }}</th>
@foreach ($sheet->days as $day)
<th scope="col" class="w-20 px-1 py-2 text-center font-semibold">{{ $this->dayLabel($day) }}</th>
@endforeach
<th scope="col" class="w-20 py-2 pl-3 text-right font-semibold">{{ __('time.total') }}</th>
</tr>
</thead>
<tbody>
@foreach ($sheet->rows as $row)
<tr wire:key="row-{{ $row->task->taskId }}" class="border-b border-zinc-200 align-top dark:border-zinc-700">
<th scope="row" class="py-2 pr-3 text-left font-normal">
<x-link :href="route('time.task', $row->task->taskId)" navigate class="font-medium">{{ $row->task->label() }}</x-link>
<span class="block text-zinc-600 dark:text-zinc-300">{{ $row->task->workTypeName }}</span>
@if ($row->task->isLocked())
<span class="mt-1 inline-flex items-center gap-1 text-zinc-700 dark:text-zinc-300">
<x-icon name="lock-closed" class="size-4" aria-hidden="true" /> {{ __('time.locked') }}
</span>
@endif
</th>
@foreach ($sheet->days as $day)
<td class="px-1 py-2 text-center">
@if ($row->task->isLocked())
{{ isset($row->quartersByDay[$day]) ? $this->hours($row->quartersByDay[$day]) : '' }}
@else
<input
id="cell-{{ $row->task->taskId }}-{{ $day }}"
type="text"
inputmode="decimal"
autocomplete="off"
value="{{ $rejected[$row->task->taskId.'.'.$day] ?? $cells[$row->task->taskId][$day] ?? '' }}"
wire:change="saveCell({{ $row->task->taskId }}, '{{ $day }}', $event.target.value)"
aria-label="{{ __('time.cell_label', ['task' => $row->task->taskTitle, 'day' => $this->dayLabel($day)]) }}"
@error('cells.'.$row->task->taskId.'.'.$day) aria-invalid="true" aria-describedby="cell-{{ $row->task->taskId }}-{{ $day }}-error" @enderror
class="w-16 rounded-md border border-zinc-400 bg-white px-2 py-1.5 text-center text-zinc-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 aria-invalid:border-red-700 dark:border-zinc-500 dark:bg-zinc-900 dark:text-zinc-100 dark:aria-invalid:border-red-400"
/>
@error('cells.'.$row->task->taskId.'.'.$day)
<p id="cell-{{ $row->task->taskId }}-{{ $day }}-error" class="mt-1 text-xs text-red-700 dark:text-red-400">{{ $message }}</p>
@enderror
@endif
</td>
@endforeach
<td class="py-2 pl-3 text-right font-medium">{{ $this->hours($row->totalQuarters) }}</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th scope="row" class="py-2 pr-3 text-left font-semibold">{{ __('time.day_total') }}</th>
@foreach ($sheet->days as $day)
<td class="px-1 py-2 text-center font-semibold">{{ $this->hours($sheet->dayTotals[$day]) }}</td>
@endforeach
<td class="py-2 pl-3 text-right font-semibold">{{ $this->hours($sheet->totalQuarters) }}</td>
</tr>
</tfoot>
</table>
</div>
{{-- Phone: one day at a time. --}}
<div class="space-y-4 lg:hidden">
<div role="group" aria-label="{{ __('time.choose_day') }}" class="grid grid-cols-4 gap-2 sm:grid-cols-7">
@foreach ($sheet->days as $day)
<button
type="button"
wire:click="selectDay('{{ $day }}')"
aria-pressed="{{ $day === $selectedDay ? 'true' : 'false' }}"
aria-label="{{ __('time.day_button', ['day' => $this->dayLabel($day), 'hours' => $this->hours($sheet->dayTotals[$day])]) }}"
@class([
'rounded-md border px-2 py-2 text-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700',
'border-primary-700 bg-primary-700 font-semibold text-white' => $day === $selectedDay,
'border-zinc-300 bg-white text-zinc-900 dark:border-zinc-600 dark:bg-zinc-900 dark:text-zinc-100' => $day !== $selectedDay,
])
>
<span class="block">{{ $this->dayLabel($day) }}</span>
<span class="block text-xs">{{ __('time.hours_suffix', ['hours' => $this->hours($sheet->dayTotals[$day])]) }}</span>
</button>
@endforeach
</div>
<ul class="space-y-3">
@foreach ($sheet->rows as $row)
<li wire:key="mrow-{{ $row->task->taskId }}" class="rounded-lg border border-zinc-200 p-3 text-sm dark:border-zinc-700">
<x-link :href="route('time.task', $row->task->taskId)" navigate class="font-medium break-words">{{ $row->task->label() }}</x-link>
<span class="block text-zinc-600 dark:text-zinc-300">{{ $row->task->workTypeName }}</span>
@if ($row->task->isLocked())
<p class="mt-2 inline-flex items-center gap-1">
<x-icon name="lock-closed" class="size-4" aria-hidden="true" /> {{ __('time.locked') }}
@isset($row->quartersByDay[$selectedDay])
– {{ __('time.hours_suffix', ['hours' => $this->hours($row->quartersByDay[$selectedDay])]) }}
@endisset
</p>
@else
<label for="mcell-{{ $row->task->taskId }}-{{ $selectedDay }}" class="mt-2 block font-medium">
{{ __('time.cell_label', ['task' => $row->task->taskTitle, 'day' => $this->dayLabel($selectedDay)]) }}
</label>
<input
id="mcell-{{ $row->task->taskId }}-{{ $selectedDay }}"
type="text"
inputmode="decimal"
autocomplete="off"
value="{{ $rejected[$row->task->taskId.'.'.$selectedDay] ?? $cells[$row->task->taskId][$selectedDay] ?? '' }}"
wire:change="saveCell({{ $row->task->taskId }}, '{{ $selectedDay }}', $event.target.value)"
@error('cells.'.$row->task->taskId.'.'.$selectedDay) aria-invalid="true" aria-describedby="mcell-{{ $row->task->taskId }}-{{ $selectedDay }}-error" @enderror
class="mt-1 w-24 rounded-md border border-zinc-400 bg-white px-2 py-2 text-zinc-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 aria-invalid:border-red-700 dark:border-zinc-500 dark:bg-zinc-900 dark:text-zinc-100 dark:aria-invalid:border-red-400"
/>
@error('cells.'.$row->task->taskId.'.'.$selectedDay)
<p id="mcell-{{ $row->task->taskId }}-{{ $selectedDay }}-error" class="mt-1 text-xs text-red-700 dark:text-red-400">{{ $message }}</p>
@enderror
@endif
</li>
@endforeach
</ul>
</div>
<p class="text-sm font-semibold">{{ __('time.week_total', ['hours' => $this->hours($sheet->totalQuarters)]) }}</p>
@endif
<section aria-labelledby="add-task-heading" class="space-y-2">
<h2 id="add-task-heading" class="sr-only">{{ __('time.add.search') }}</h2>
<x-input
id="task-search"
wire:model.live.debounce.300ms="taskSearch"
type="search"
icon="magnifying-glass"
:label="__('time.add.search')"
:hint="__('time.add.search_description')"
autocomplete="off"
/>
@if (mb_strlen(trim($taskSearch)) >= 2)
<p role="status" aria-live="polite" class="text-sm text-zinc-600 dark:text-zinc-300">
{{ trans_choice('time.add.results', count($this->searchResults), ['count' => count($this->searchResults)]) }}
</p>
<ul class="space-y-1">
@foreach ($this->searchResults as $task)
<li wire:key="result-{{ $task->taskId }}">
<button
type="button"
wire:click="addTask({{ $task->taskId }})"
aria-label="{{ __('time.add.choose', ['task' => $task->label()]) }}"
class="w-full rounded-md px-3 py-2 text-left text-sm hover:bg-zinc-100 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:hover:bg-zinc-700"
>
<span class="font-medium">{{ $task->label() }}</span>
<span class="text-zinc-600 dark:text-zinc-300">{{ $task->workTypeName }}</span>
</button>
</li>
@endforeach
</ul>
@endif
</section>
</div>
@@ -0,0 +1,11 @@
<?php
use Illuminate\Support\Facades\Route;
Route::middleware(['web', 'auth', 'can:time.use'])
->prefix('time')
->name('time.')
->group(function () {
Route::livewire('/', 'time::week')->name('week');
Route::livewire('/tasks/{task}', 'time::task')->whereNumber('task')->name('task');
});