Files
Toiminnanohjaus/resources/views/components/time/sheet-section.blade.php
T
2026-11-30 06:56:14 +02:00

329 lines
26 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{--
One part of the time sheet (docs/ui-timesheet.md 4): "Aikataulutettu"
or "Lukitut työt" as its own card, a native table (an input grid is a
form, not a data table) with customer → job → task rows. Every day cell
has −15 min, the HH:MM field, +15 min and the entry button; today's
column has the timer button on its left.
Props: `section` ('scheduled' or 'pinned'), `groups`, `days`, `today`
(Y-m-d or null when another week is shown), `readOnly`, `cells`
(shown HH:MM values by task and day), `rejected`, `labels` (day labels).
--}}
@props(['section', 'groups', 'days', 'today', 'readOnly' => false, 'cells' => [], 'rejected' => [], 'labels' => [], 'collapsible' => false])
@use('App\Modules\TimeTracking\Domain\ValueObjects\WorkedHours')
@use('App\Modules\Shared\Domain\ValueObjects\HexColor')
@php
$columnCount = 1 + count($days) + 2;
$pinned = $section === 'pinned';
$taskCount = array_sum(array_map(fn ($customer) => $customer->taskCount(), $groups));
$symbolClass = fn ($model) => match ($model->value) {
'fixed' => 'border-sky-600 bg-sky-100 text-sky-900 dark:border-sky-400/60 dark:bg-sky-500/20 dark:text-sky-100',
'hourly' => 'border-emerald-600 bg-emerald-100 text-emerald-900 dark:border-emerald-400/60 dark:bg-emerald-500/20 dark:text-emerald-100',
default => 'border-zinc-500 bg-zinc-100 text-zinc-800 dark:border-zinc-400/60 dark:bg-zinc-500/20 dark:text-zinc-100',
};
@endphp
<section
aria-labelledby="sheet-{{ $section }}-heading"
x-data="{ collapsed: false }"
class="overflow-hidden rounded-xl border border-slate-300 bg-white shadow-lg dark:border-[#36393f] dark:bg-[#16160e]"
>
<table class="w-full table-fixed border-collapse text-left">
<caption class="sr-only">{{ __('time.sheet.caption_'.$section) }}</caption>
<colgroup>
<col class="w-[340px]" />
@foreach ($days as $day)
<col @class(['w-[168px]' => $day === $today, 'w-[124px]' => $day !== $today]) />
@endforeach
<col class="w-[72px]" />
<col class="w-[76px]" />
</colgroup>
<thead>
<tr class="border-b-2 border-slate-900 bg-slate-800 text-sm font-bold tracking-wide text-white dark:border-[#3c4047] dark:bg-[#0b0c0e]">
<th scope="col" class="px-3 py-3">
<span class="flex items-center justify-between gap-2">
<span>{{ __('time.sheet.column_task') }}</span>
<span class="text-xs font-normal text-zinc-200" aria-hidden="true">{{ __('time.sheet.alphabetical') }}</span>
</span>
</th>
@foreach ($days as $day)
<th scope="col" @class([
'px-1.5 py-3 text-center',
'border-x-2 border-t-2 border-indigo-400 bg-indigo-950 text-white' => $day === $today,
'border-l border-zinc-700' => $day !== $today,
])>
<span class="inline-flex items-center justify-center gap-1.5">
@if ($day === $today)
<x-icon name="clock" class="size-4 text-emerald-300" aria-hidden="true" />
@endif
<span>{{ $labels[$day] ?? $day }}</span>
@if ($day === $today)
<span class="rounded bg-indigo-600 px-1.5 py-0.5 text-[10px] font-bold tracking-wider uppercase">{{ __('time.sheet.today') }}</span>
@endif
</span>
</th>
@endforeach
<th scope="col" class="border-l border-zinc-700 px-2 py-3 text-center">{{ __('time.sheet.column_total') }}</th>
<th scope="col" class="border-l border-zinc-700 px-2 py-3 text-center">{{ __('time.sheet.column_actions') }}</th>
</tr>
</thead>
<tbody class="text-xs">
{{-- Section header row --}}
<tr class="border-b border-slate-300 bg-slate-200/80 dark:border-[#3b3f47] dark:bg-[#23262b]">
<td colspan="{{ $columnCount }}" class="px-3 py-2.5">
<div class="flex flex-wrap items-center justify-between gap-2">
<h2 id="sheet-{{ $section }}-heading" class="m-0">
@if ($collapsible)
<button
type="button"
x-on:click="collapsed = ! collapsed"
x-bind:aria-expanded="(! collapsed).toString()"
aria-controls="sheet-{{ $section }}-rows"
class="flex min-h-6 items-center gap-2 rounded text-xs font-bold tracking-wider uppercase focus-visible:outline-2 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300"
>
<span class="flex size-6 items-center justify-center rounded-md border border-slate-300 bg-white transition-transform dark:border-[#3c4047] dark:bg-[#16160e]" x-bind:class="collapsed && '-rotate-90'" aria-hidden="true">
<x-icon name="chevron-down" class="size-3.5" />
</span>
<x-icon name="calendar-days" class="size-4 text-sky-700 dark:text-sky-300" aria-hidden="true" />
<span>{{ __('time.sheet.'.$section) }}</span>
<span class="rounded-full border border-sky-300 bg-sky-100 px-2 py-0.5 text-[11px] font-semibold tracking-normal text-sky-900 normal-case dark:border-sky-500/30 dark:bg-sky-500/20 dark:text-sky-100">{{ trans_choice('time.sheet.task_count', $taskCount, ['count' => $taskCount]) }}</span>
</button>
@else
<span class="flex items-center gap-2 text-xs font-bold tracking-wider uppercase">
<x-icon name="star" class="size-4 text-amber-700 dark:text-amber-300" aria-hidden="true" />
<span>{{ __('time.sheet.'.$section) }}</span>
<span class="rounded-full border border-amber-300 bg-amber-100 px-2 py-0.5 text-[11px] font-semibold tracking-normal text-amber-900 normal-case dark:border-amber-500/40 dark:bg-amber-500/20 dark:text-amber-100">{{ trans_choice('time.sheet.task_count', $taskCount, ['count' => $taskCount]) }}</span>
</span>
@endif
</h2>
<div class="flex items-center gap-2">
<span class="hidden text-[11px] sm:inline">{{ __('time.sheet.'.$section.'_hint') }}</span>
@if ($pinned && ! $readOnly)
<button
type="button"
id="open-add-to-list"
x-on:click="document.getElementById('add-to-list-dialog').showModal(); $nextTick(() => document.getElementById('pin-search')?.focus())"
class="min-h-6 rounded-lg bg-indigo-700 px-3 py-1 text-xs font-semibold text-white shadow-sm hover:bg-indigo-800 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300"
>{{ __('time.sheet.add_to_list') }}</button>
@endif
</div>
</div>
</td>
</tr>
</tbody>
<tbody id="sheet-{{ $section }}-rows" @if ($collapsible) x-show="! collapsed" @endif class="divide-y divide-zinc-200 text-xs dark:divide-zinc-800/70">
@if ($taskCount === 0)
<tr>
<td colspan="{{ $columnCount }}" class="px-4 py-4 text-center italic">{{ __('time.sheet.'.$section.'_empty') }}</td>
</tr>
@endif
@foreach ($groups as $customer)
@php
$color = new HexColor($customer->headerColor ?? '#374151');
@endphp
{{-- Level 1: customer --}}
<tr wire:key="{{ $section }}-customer-{{ $customer->customerId }}">
<td colspan="{{ $columnCount }}" class="p-0">
<div style="background-color: {{ $color->value }}; color: {{ $color->textColor() }}" class="flex items-center justify-between gap-3 px-3 py-1.5">
<span class="flex items-center gap-2 text-xs font-bold tracking-wide">
<x-icon name="building-office" class="size-3.5 shrink-0" aria-hidden="true" />
<span>{{ $customer->name }}</span>
<span class="rounded bg-black/15 px-1.5 text-[10px] font-medium">{{ __('time.sheet.customer') }}</span>
</span>
@if (! $readOnly && Gate::allows('customers.use'))
<button
type="button"
x-on:click="$dispatch('color-picker:open', {{ Js::from([
'id' => 'colour-picker',
'title' => __('time.sheet.color_title', ['customer' => $customer->name]),
'color' => $color->value,
'method' => 'setCustomerColor',
'args' => [$customer->customerId],
'resettable' => $customer->headerColor !== null,
]) }})"
aria-label="{{ __('time.sheet.color_label', ['customer' => $customer->name]) }}"
class="flex min-h-6 items-center gap-1.5 rounded bg-black/20 px-2 text-[11px] font-medium transition hover:bg-black/30 focus-visible:outline-2 focus-visible:outline-current"
>
<span class="size-2.5 rounded-full border border-current" style="background-color: {{ $color->value }}" aria-hidden="true"></span>
<span>{{ __('time.sheet.color') }}</span>
</button>
@endif
</div>
</td>
</tr>
@foreach ($customer->jobs as $job)
{{-- Level 2: customer job --}}
<tr wire:key="{{ $section }}-job-{{ $job->jobId }}">
<td colspan="{{ $columnCount }}" class="border-t border-zinc-200 bg-slate-100/90 py-1.5 pr-3 pl-7 text-slate-800 dark:border-zinc-800/60 dark:bg-[#1d1f23] dark:text-zinc-100">
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex flex-wrap items-center gap-2 text-xs font-semibold">
<span aria-hidden="true">└</span>
<span class="rounded border border-indigo-500/40 bg-indigo-100 px-1.5 font-mono text-[11px] text-indigo-900 dark:bg-indigo-500/15 dark:text-indigo-100">#{{ $job->number }}</span>
<span>{{ $job->name }}</span>
@if ($job->isContinuing())
<span class="rounded border border-purple-500/40 bg-purple-100 px-1.5 text-[10px] font-semibold text-purple-900 dark:bg-purple-500/20 dark:text-purple-100">{{ __('time.sheet.live') }}</span>
@endif
<span class="rounded border px-1.5 text-[10px] font-semibold {{ $symbolClass($job->billingModel()) }}">{{ __('time.sheet.models.'.$job->billingModel()->value) }}</span>
</div>
<div class="flex items-center gap-2">
<span class="font-mono text-[11px]">{{ __('time.sheet.accumulated', ['hours' => WorkedHours::formatClock($job->accumulatedQuarters)]) }}</span>
@if (! $pinned && ! $readOnly && ! $job->status->locksTime())
<button
type="button"
wire:click="pinJob({{ $job->jobId }})"
aria-label="{{ __('time.sheet.pin_job_label', ['job' => $job->number.' '.$job->name]) }}"
class="min-h-6 rounded border border-amber-600/50 bg-amber-100 px-2 text-[11px] font-medium text-amber-900 transition hover:bg-amber-200 focus-visible:outline-2 focus-visible:outline-primary-600 dark:bg-amber-500/15 dark:text-amber-100 dark:hover:bg-amber-500/25 dark:focus-visible:outline-primary-300"
>{{ __('time.sheet.pin_job') }}</button>
@endif
</div>
</div>
</td>
</tr>
@foreach ($job->rows as $row)
@php
$taskId = $row->task->taskId;
$locked = $row->task->isLocked();
$model = $row->defaultBillingModel();
@endphp
{{-- Level 3: task --}}
<tr wire:key="{{ $section }}-task-{{ $taskId }}">
<th scope="row" class="bg-white py-1.5 pr-3 pl-16 font-normal dark:bg-[#282a2e]">
<span class="flex min-w-0 items-center gap-2">
<span aria-hidden="true">└</span>
<span class="flex size-4 shrink-0 items-center justify-center rounded-full border text-[10px] font-bold {{ $symbolClass($model) }}" title="{{ __('time.sheet.models.'.$model->value) }}" aria-hidden="true">{{ $model->symbol() }}</span>
<span class="sr-only">{{ __('time.sheet.models.'.$model->value) }}:</span>
<x-link :href="route('time.task', $taskId)" navigate class="truncate text-xs font-medium" :title="$row->task->taskTitle">{{ $row->task->taskTitle }}</x-link>
</span>
@if ($locked)
<span class="mt-0.5 flex items-center gap-1 pl-6 text-[11px]"><x-icon name="lock-closed" class="size-3.5" aria-hidden="true" />{{ __('time.sheet.locked_row') }}</span>
@endif
</th>
@foreach ($days as $day)
@php
$cell = $row->cell($day);
$quarters = $cell?->quarters ?? 0;
$dayLabel = $labels[$day] ?? $day;
$editable = ! $readOnly && ! $locked && ! ($cell?->approved ?? false);
$fieldId = 'cell-'.$section.'-'.$taskId.'-'.$day;
$errorKey = 'cells.'.$taskId.'.'.$day;
@endphp
<td @class([
'px-1 py-1.5 align-middle',
'border-x-2 border-indigo-500 bg-indigo-50/90 dark:border-indigo-400/80 dark:bg-indigo-500/15' => $day === $today,
'border-l border-slate-200 bg-white dark:border-[#36393f] dark:bg-[#282a2e]' => $day !== $today,
])>
<div class="flex items-center justify-center gap-1">
@if ($day === $today && $editable)
<div class="mr-0.5 flex items-center border-r border-indigo-400/40 pr-1.5">
<button
type="button"
x-on:click="openTimer({{ $taskId }}, {{ Js::from($row->task->taskTitle) }}, {{ Js::from($row->task->customerName) }}, {{ Js::from('#'.$row->task->jobNumber.' '.$row->task->jobName) }})"
aria-label="{{ __('time.sheet.timer_open', ['task' => $row->task->taskTitle]) }}"
x-bind:class="timer.taskId === {{ $taskId }} ? 'animate-pulse border-emerald-500 bg-emerald-100 text-emerald-900 dark:bg-emerald-500/30 dark:text-emerald-100' : 'border-indigo-500 bg-indigo-100 text-indigo-800 hover:bg-indigo-200 dark:border-indigo-400/40 dark:bg-indigo-950/80 dark:text-indigo-100 dark:hover:bg-indigo-600/40'"
class="flex h-6 w-7 shrink-0 items-center justify-center rounded-md border transition focus-visible:outline-2 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300"
>
<x-icon name="clock" class="size-3.5" aria-hidden="true" />
</button>
</div>
@endif
@if ($editable)
<button
type="button"
wire:click="adjustCell({{ $taskId }}, '{{ $day }}', -1)"
@disabled($quarters === 0)
aria-label="{{ __('time.sheet.minus', ['task' => $row->task->taskTitle, 'day' => $dayLabel]) }}"
class="flex h-6 w-6 items-center justify-center rounded border border-slate-400 bg-slate-100 text-xs font-bold text-slate-800 transition select-none hover:bg-rose-100 focus-visible:outline-2 focus-visible:outline-primary-600 disabled:opacity-40 dark:border-[#5a5e66] dark:bg-[#1b1d20] dark:text-zinc-100 dark:hover:bg-rose-500/25 dark:focus-visible:outline-primary-300"
>−</button>
<label for="{{ $fieldId }}" class="sr-only">{{ __('time.sheet.cell', ['task' => $row->task->taskTitle, 'day' => $dayLabel]) }}</label>
<input
id="{{ $fieldId }}"
type="text"
inputmode="decimal"
autocomplete="off"
value="{{ $rejected[$taskId.'.'.$day] ?? ($cells[$taskId][$day] ?? '0:00') }}"
wire:change="saveCell({{ $taskId }}, '{{ $day }}', $event.target.value)"
@error($errorKey) aria-invalid="true" aria-describedby="{{ $fieldId }}-error" @enderror
@class([
'h-6 w-11 rounded border text-center font-mono text-[11px] focus-visible:outline-2 focus-visible:outline-primary-600 aria-invalid:border-red-700 dark:focus-visible:outline-primary-300 dark:aria-invalid:border-red-300',
'border-emerald-600 bg-emerald-50 font-semibold text-emerald-900 dark:border-emerald-500/50 dark:bg-emerald-950/50 dark:text-emerald-100' => $quarters > 0,
'border-slate-400 bg-slate-50 text-slate-700 dark:border-[#5a5e66] dark:bg-[#1b1d20] dark:text-zinc-200' => $quarters === 0,
])
/>
<button
type="button"
wire:click="adjustCell({{ $taskId }}, '{{ $day }}', 1)"
aria-label="{{ __('time.sheet.plus', ['task' => $row->task->taskTitle, 'day' => $dayLabel]) }}"
class="flex h-6 w-6 items-center justify-center rounded border border-slate-400 bg-slate-100 text-xs font-bold text-slate-800 transition select-none hover:bg-emerald-100 focus-visible:outline-2 focus-visible:outline-primary-600 dark:border-[#5a5e66] dark:bg-[#1b1d20] dark:text-zinc-100 dark:hover:bg-emerald-500/25 dark:focus-visible:outline-primary-300"
>+</button>
@else
<span class="font-mono text-[11px]">{{ WorkedHours::formatClock($quarters) }}</span>
@if ($cell?->approved)
<x-icon name="check-circle" class="size-3.5" aria-hidden="true" />
<span class="sr-only">{{ __('time.approval.cell_approved') }}</span>
@endif
@endif
@if ($quarters > 0)
<button
type="button"
wire:click="openEntry({{ $taskId }}, '{{ $day }}')"
aria-label="{{ __('time.sheet.note_button', ['task' => $row->task->taskTitle, 'day' => $dayLabel]) }} {{ $cell?->hasBillingNote() ? __('time.sheet.note_filled') : __('time.sheet.note_missing') }}"
@class([
'relative flex h-6 w-6 shrink-0 items-center justify-center rounded border transition focus-visible:outline-2 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300',
'border-sky-500 bg-sky-50 text-sky-800 dark:border-sky-400/60 dark:bg-sky-500/15 dark:text-sky-100' => $cell?->hasBillingNote(),
'border-amber-600 bg-amber-50 text-amber-900 dark:border-amber-400/60 dark:bg-amber-500/15 dark:text-amber-100' => ! $cell?->hasBillingNote(),
])
>
<x-icon name="pencil-square" class="size-3.5" aria-hidden="true" />
@if ($cell?->hasBillingNote())
<span class="absolute -top-0.5 -right-0.5 size-1.5 rounded-full bg-sky-500" aria-hidden="true"></span>
@else
<span class="absolute -top-0.5 -right-0.5 size-2 rounded-full bg-amber-500" aria-hidden="true"></span>
@endif
</button>
@endif
</div>
@error($errorKey)
<p id="{{ $fieldId }}-error" class="mt-1 text-center text-[10px] font-semibold text-red-700 dark:text-red-200">{{ $message }}</p>
@enderror
</td>
@endforeach
<td class="border-l border-slate-200 bg-white px-2 py-1.5 text-center font-mono text-xs font-bold dark:border-[#36393f] dark:bg-[#282a2e]">{{ WorkedHours::formatClock($row->totalQuarters) }}</td>
<td class="border-l border-slate-200 bg-white px-2 py-1.5 text-center dark:border-[#36393f] dark:bg-[#282a2e]">
@unless ($readOnly)
@if ($pinned)
<button
type="button"
wire:click="unpinTask({{ $taskId }})"
aria-label="{{ __('time.sheet.unpin_task_label', ['task' => $row->task->taskTitle]) }}"
class="min-h-6 rounded-md border border-rose-500/50 bg-rose-50 px-2 text-xs font-semibold text-rose-900 transition hover:bg-rose-100 focus-visible:outline-2 focus-visible:outline-primary-600 dark:bg-rose-500/15 dark:text-rose-100 dark:focus-visible:outline-primary-300"
>×</button>
@elseif (! $locked)
<button
type="button"
wire:click="pinTasks([{{ $taskId }}])"
aria-label="{{ __('time.sheet.pin_task_label', ['task' => $row->task->taskTitle]) }}"
class="min-h-6 rounded-md border border-amber-600/50 bg-amber-100 px-2 text-xs font-semibold text-amber-900 transition hover:bg-amber-200 focus-visible:outline-2 focus-visible:outline-primary-600 dark:bg-amber-500/15 dark:text-amber-100 dark:focus-visible:outline-primary-300"
>★</button>
@endif
@endunless
</td>
</tr>
@endforeach
@endforeach
@endforeach
</tbody>
</table>
</section>