Files
Toiminnanohjaus/app/Modules/Dashboard/Presentation/Livewire/⚡management.blade.php
T
petriandClaude Opus 5.5 51b40b24fe Give the UI an indigo look with cards, status badges and empty states
- Dark indigo header and tinted page background; the mobile main menu gets
  its own row, in the same order as the keyboard reaches it.
- Page titles with an icon chip (x-page-title, x-page, x-page-header) and
  card sections (x-panel, the card utility); x-table styled as a card with
  an indigo header row in AppServiceProvider::styleTables().
- Job and task statuses, late work, unapproved hours and stock states as
  badges with icon and text (x-status-badge, x-jobs.status,
  x-jobs.task-status), never colour alone.
- Empty lists as x-empty-state; dashboard quick link tiles, week hour bars
  and trend arrows; Kanban columns and task cards edged by status; calendar
  today column and bar accents; quick sale, reports and machine console
  restyled; signed-out pages show the app name.
- Focus rings use the primary colour in both themes (white in the header).
- Document the components in CLAUDE.md; test the status badges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 10:53:10 +02:00

275 lines
16 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.
<?php
use App\Modules\Dashboard\Application\DTOs\ManagementOverview;
use App\Modules\Dashboard\Application\UseCases\ManagementOverviewQuery;
use App\Modules\Dashboard\Domain\ValueObjects\Change;
use App\Modules\Dashboard\Domain\ValueObjects\Workload;
use App\Modules\Dashboard\Presentation\Livewire\Concerns\FormatsDashboard;
use App\Modules\Users\Application\Contracts\Clock;
use Livewire\Attributes\Computed;
use Livewire\Component;
/**
* The management panel of the home page (admin and management): what
* needs doing, this month's key figures against the same days of the
* previous month, the jobs and late work, and everyone's workload. Loaded
* lazily after the rest of the home page.
*/
new class extends Component
{
use FormatsDashboard;
public function mount(): void
{
$this->authorize('dashboard.management');
}
#[Computed]
public function overview(): ManagementOverview
{
return app(ManagementOverviewQuery::class)->execute(app(Clock::class)->today());
}
public function placeholder(): string
{
return '<section class="rounded-xl border border-zinc-200 bg-white p-4 shadow-sm dark:border-zinc-700 dark:bg-zinc-900"><p role="status" class="text-sm">'.e(__('dashboard.management.loading')).'</p></section>';
}
/**
* E.g. "+12,5 % edelliseen", or "ei vertailukohtaa" when the earlier value was zero.
*/
public function change(int $current, int $previous): string
{
$ratio = (new Change($current, $previous))->ratio();
if ($ratio === null) {
return __('dashboard.management.no_comparison');
}
return __('dashboard.management.change', ['change' => ($ratio > 0 ? '+' : ($ratio < 0 ? '−' : '±')).$this->percent(abs($ratio))]);
}
public function load(Workload $load): string
{
$ratio = $load->ratio();
return $ratio === null ? '–' : $this->percent($ratio);
}
public function render(): mixed
{
return $this->view();
}
};
?>
<section aria-labelledby="management-heading" class="space-y-6">
@php($overview = $this->overview)
<h2 id="management-heading" class="flex items-center gap-2 border-t border-zinc-200 pt-6 text-xl font-semibold dark:border-zinc-700">
<x-icon name="presentation-chart-line" class="size-6 text-primary-700 dark:text-primary-300" aria-hidden="true" />
{{ __('dashboard.management.title') }}
</h2>
<div class="grid gap-6 lg:grid-cols-2">
<x-panel :title="__('dashboard.todo.title')" icon="inbox-stack" :level="3" heading-id="todo-heading">
<ul class="space-y-2 text-sm">
@can('time.approve-others')
<li>
<x-link :href="route('time.approvals')" navigate>
{{ trans_choice('dashboard.todo.approvals', count($overview->pendingApprovals), ['count' => count($overview->pendingApprovals)]) }}
</x-link>
@if ($overview->pendingApprovals !== [])
<ul class="mt-1 ml-4 list-disc">
@foreach ($overview->pendingApprovals as $pending)
<li>{{ __('dashboard.todo.approval_line', ['name' => $pending->name, 'hours' => $this->hours($pending->quarters), 'weeks' => $pending->weekCount]) }}</li>
@endforeach
</ul>
@endif
</li>
@endcan
@can('billing.manage')
<li>
<x-link :href="route('billing.index')" navigate>{{ trans_choice('dashboard.todo.done_jobs', $overview->doneJobCount, ['count' => $overview->doneJobCount]) }}</x-link>
</li>
@if ($overview->draftExportId !== null)
<li><x-link :href="route('billing.export', $overview->draftExportId)" navigate>{{ __('dashboard.todo.draft') }}</x-link></li>
@endif
@endcan
@can('sales.close-day')
@if ($overview->unclosedCashDays !== [])
<li>
<x-link :href="route('sales.index', ['paiva' => $overview->unclosedCashDays[0]])" navigate>
{{ trans_choice('dashboard.todo.cash_days', count($overview->unclosedCashDays), ['count' => count($overview->unclosedCashDays), 'first' => $this->dateLabel($overview->unclosedCashDays[0])]) }}
</x-link>
</li>
@endif
@endcan
@can('machines.use')
@if ($overview->lateMaintenance !== [])
<li>
<x-link :href="route('machines.show', $overview->lateMaintenance[0]['machineId']).'#maintenance-heading'" navigate>
{{ trans_choice('dashboard.todo.maintenance', count($overview->lateMaintenance), ['count' => count($overview->lateMaintenance)]) }}
</x-link>
<ul class="mt-1 ml-4 list-disc">
@foreach ($overview->lateMaintenance as $late)
<li>{{ __('dashboard.todo.maintenance_line', ['machine' => $late['machine'], 'item' => $late['item']]) }}</li>
@endforeach
</ul>
</li>
@endif
@endcan
@can('inventory.view')
@if ($overview->stockItemsToOrder > 0)
<li>
<x-link :href="route('inventory.index', ['tilattavat' => 1])" navigate>
{{ trans_choice('dashboard.todo.stock', $overview->stockItemsToOrder, ['count' => $overview->stockItemsToOrder]) }}
</x-link>
</li>
@endif
@endcan
@can('reports.view')
<li>
<x-link :href="route('reports.unbilled')" navigate>{{ __('dashboard.todo.unbilled', ['amount' => $this->money($overview->unbilledValueCents)]) }}</x-link>
</li>
@endcan
</ul>
</x-panel>
@can('reports.view')
<x-panel :title="__('dashboard.month.title')" icon="chart-bar" :level="3" heading-id="month-heading">
<p class="text-sm text-zinc-600 dark:text-zinc-300">
{{ __('dashboard.month.period', [
'from' => $this->dateLabel($overview->monthFrom), 'to' => $this->dateLabel($overview->monthTo),
'previous_from' => $this->dateLabel($overview->previousFrom), 'previous_to' => $this->dateLabel($overview->previousTo),
]) }}
</p>
@php($month = $overview->month)
@php($previous = $overview->previousMonth)
<dl class="grid gap-3 sm:grid-cols-2">
@foreach ([
['label' => 'customer_hours', 'value' => $this->hours($month->customerQuarters).' h', 'current' => $month->customerQuarters, 'previous' => $previous->customerQuarters, 'route' => 'reports.hours'],
['label' => 'internal_hours', 'value' => $this->hours($month->internalQuarters).' h', 'current' => $month->internalQuarters, 'previous' => $previous->internalQuarters, 'route' => 'reports.hours'],
['label' => 'billed', 'value' => $this->money($month->billedCents), 'current' => $month->billedCents, 'previous' => $previous->billedCents, 'route' => 'reports.profitability'],
['label' => 'margin', 'value' => $month->marginCents === null ? __('dashboard.month.no_cost') : $this->money($month->marginCents), 'current' => $month->marginCents, 'previous' => $previous->marginCents, 'route' => 'reports.profitability'],
['label' => 'sales', 'value' => $this->money($month->salesCents), 'current' => $month->salesCents, 'previous' => $previous->salesCents, 'route' => 'reports.sales'],
] as $figure)
@php($ratio = $figure['current'] !== null && $figure['previous'] !== null ? (new \App\Modules\Dashboard\Domain\ValueObjects\Change($figure['current'], $figure['previous']))->ratio() : null)
<div class="rounded-lg border border-zinc-200 bg-zinc-50 p-3 dark:border-zinc-700 dark:bg-zinc-800/60">
<dt class="text-sm">
<x-link :href="route($figure['route'])" navigate>{{ __('dashboard.month.'.$figure['label']) }}</x-link>
</dt>
<dd class="text-xl font-semibold tabular-nums">{{ $figure['value'] }}</dd>
@if ($figure['current'] !== null && $figure['previous'] !== null)
<dd class="flex items-center gap-1 text-sm text-zinc-700 dark:text-zinc-200">
@if ($ratio !== null && $ratio > 0)
<x-icon name="arrow-trending-up" class="size-4 text-emerald-700 dark:text-emerald-300" aria-hidden="true" />
@elseif ($ratio !== null && $ratio < 0)
<x-icon name="arrow-trending-down" class="size-4 text-red-700 dark:text-red-300" aria-hidden="true" />
@endif
{{ $this->change($figure['current'], $figure['previous']) }}
</dd>
@endif
</div>
@endforeach
</dl>
<p class="text-xs text-zinc-600 dark:text-zinc-300">{{ __('dashboard.month.billing_note') }}</p>
</x-panel>
@endcan
</div>
<div class="grid gap-6 lg:grid-cols-2">
<x-panel :title="__('dashboard.stock.title')" icon="briefcase" :level="3" heading-id="jobs-overview-heading">
<table class="w-full text-sm">
<caption class="sr-only">{{ __('dashboard.stock.caption') }}</caption>
<thead class="sr-only">
<tr>
<th scope="col">{{ __('dashboard.stock.status') }}</th>
<th scope="col">{{ __('dashboard.stock.count') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
@foreach ($overview->jobCounts as $status => $count)
<tr wire:key="status-{{ $status }}">
<th scope="row" class="py-1.5 text-left font-normal">
<a href="{{ route('jobs.index', ['status' => $status, 'mine' => 0]) }}" wire:navigate class="rounded-full focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300">
<x-jobs.status :status="$status" class="underline-offset-2 hover:underline" />
</a>
</th>
<td class="py-1.5 text-right font-semibold tabular-nums">{{ $count }}</td>
</tr>
@endforeach
</tbody>
</table>
<p class="flex items-center gap-2 text-sm">
@if ($overview->overdueJobCount > 0)
<x-icon name="exclamation-triangle" class="size-5 text-red-700 dark:text-red-400" aria-hidden="true" />
@endif
{{ trans_choice('dashboard.stock.overdue_jobs', $overview->overdueJobCount, ['count' => $overview->overdueJobCount]) }}
</p>
<p class="flex items-center gap-2 text-sm">
@if ($overview->overdueTaskCount > 0)
<x-icon name="exclamation-triangle" class="size-5 text-red-700 dark:text-red-400" aria-hidden="true" />
@endif
{{ trans_choice('dashboard.stock.overdue_tasks', $overview->overdueTaskCount, ['count' => $overview->overdueTaskCount]) }}
</p>
@if ($overview->oldestOverdueTasks !== [])
<h4 class="font-semibold">{{ __('dashboard.stock.oldest_overdue') }}</h4>
<ul class="divide-y divide-zinc-200 text-sm dark:divide-zinc-700">
@foreach ($overview->oldestOverdueTasks as $task)
<li wire:key="late-{{ $task->taskId }}" class="py-2">
<x-link :href="route('jobs.show', $task->jobId).'#task-'.$task->taskId" navigate class="font-medium">{{ $task->title }}</x-link>
<span class="block text-zinc-600 dark:text-zinc-300">
{{ $task->jobNumber }} {{ $task->jobName }} · {{ $task->assigneeName ?? __('dashboard.stock.no_assignee') }}
· {{ __('dashboard.tasks.due', ['date' => $this->dateLabel((string) $task->dueOn)]) }}
</span>
</li>
@endforeach
</ul>
@endif
</x-panel>
<x-panel :title="__('dashboard.load.title')" icon="users" :level="3" heading-id="load-heading">
@if ($overview->workloads === [])
<x-empty-state icon="users">{{ __('dashboard.load.none') }}</x-empty-state>
@else
<div class="overflow-x-auto rounded focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600" tabindex="0" role="region" aria-label="{{ __('dashboard.load.caption') }}">
<table class="w-full text-sm">
<caption class="sr-only">{{ __('dashboard.load.caption') }}</caption>
<thead>
<tr class="border-b border-zinc-300 text-left align-bottom dark:border-zinc-600">
<th scope="col" class="py-2 pr-3">{{ __('dashboard.load.person') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('dashboard.load.week', ['from' => $this->dateLabel($overview->thisMonday)]) }}</th>
<th scope="col" class="py-2 text-right">{{ __('dashboard.load.week', ['from' => $this->dateLabel($overview->nextMonday)]) }}</th>
</tr>
</thead>
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
@foreach ($overview->workloads as $person)
<tr wire:key="load-{{ $person->userId }}">
<th scope="row" class="py-2 pr-3 text-left font-normal">{{ $person->name }}</th>
@foreach ([$person->thisWeek, $person->nextWeek] as $index => $load)
<td class="py-2 text-right {{ $index === 0 ? 'pr-3' : '' }}">
{{ __('dashboard.load.value', ['booked' => $this->hours(intdiv($load->bookedMinutes, 15)), 'capacity' => $this->hours(intdiv($load->capacityMinutes, 15)), 'ratio' => $this->load($load)]) }}
@if ($load->isOverloaded())
<span class="flex items-center justify-end gap-1 font-medium text-red-700 dark:text-red-400">
<x-icon name="exclamation-triangle" class="size-4" aria-hidden="true" />{{ __('dashboard.load.overloaded') }}
</span>
@endif
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
<p class="text-sm">{{ __('dashboard.load.note') }}</p>
<p class="text-sm"><x-link :href="route('jobs.calendar')" navigate>{{ __('dashboard.load.to_calendar') }}</x-link></p>
@endif
</x-panel>
</div>
</section>