- 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]>
154 lines
8.5 KiB
PHP
154 lines
8.5 KiB
PHP
<?php
|
|
|
|
use App\Modules\Inventory\Domain\ValueObjects\StockQuantity;
|
|
use App\Modules\Reports\Application\DTOs\StockUsageReportData;
|
|
use App\Modules\Reports\Application\DTOs\StockUsageRow;
|
|
use App\Modules\Reports\Application\UseCases\StockUsageReport;
|
|
use App\Modules\Reports\Presentation\Livewire\Concerns\ReportPage;
|
|
use App\Modules\Users\Application\Contracts\Clock;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* Stock usage (Varaston käyttö, spec 19.8): stock used, written off and
|
|
* corrected in stock counts in a period, quantities and values at cost,
|
|
* by item, group, machine and job. Management only.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
use ReportPage;
|
|
|
|
public function mount(Clock $clock): void
|
|
{
|
|
$this->startPeriod($clock, 'this_month');
|
|
}
|
|
|
|
#[Computed]
|
|
public function report(): ?StockUsageReportData
|
|
{
|
|
$period = $this->period();
|
|
|
|
return $period === null ? null : app(StockUsageReport::class)->execute($period, __('reports.stock_usage.none_target'));
|
|
}
|
|
|
|
public function updated(): void
|
|
{
|
|
$this->authorize('reports.view');
|
|
unset($this->report);
|
|
}
|
|
|
|
public function quantity(int $milli, ?string $unit): string
|
|
{
|
|
return StockQuantity::format($milli).($unit === null ? '' : "\u{00A0}".__('inventory.units.'.$unit));
|
|
}
|
|
|
|
public function signedMoney(int $cents): string
|
|
{
|
|
return ($cents < 0 ? '-' : '').$this->money(abs($cents));
|
|
}
|
|
|
|
/**
|
|
* @return list<array{key: string, rows: list<StockUsageRow>}>
|
|
*/
|
|
public function summaries(StockUsageReportData $report): array
|
|
{
|
|
return [
|
|
['key' => 'groups', 'rows' => $report->groups],
|
|
['key' => 'machines', 'rows' => $report->machines],
|
|
['key' => 'jobs', 'rows' => $report->jobs],
|
|
];
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('reports.stock_usage.title'));
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-6xl space-y-6 p-4 sm:p-6">
|
|
<div class="space-y-2">
|
|
<x-page-title icon="archive-box-arrow-down">{{ __('reports.stock_usage.title') }}</x-page-title>
|
|
<p class="max-w-3xl text-sm">{{ __('reports.stock_usage.intro') }}</p>
|
|
</div>
|
|
|
|
<x-reports.period-filter :presets="$this->periodPresets()" :valid="$this->period !== null" />
|
|
|
|
@php($report = $this->report)
|
|
|
|
@if ($report !== null)
|
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
|
<h2 class="text-xl font-semibold"><span role="status" aria-live="polite">{{ $this->periodLabel() }}</span></h2>
|
|
<x-button :href="$this->csvUrl('stock-usage')" subtle color="black" icon="arrow-down-tray" :text="__('reports.download_csv')" />
|
|
</div>
|
|
|
|
@if ($report->items === [])
|
|
<x-empty-state icon="chart-bar">{{ __('reports.stock_usage.empty') }}</x-empty-state>
|
|
@else
|
|
<p class="font-semibold">{{ __('reports.stock_usage.total', ['amount' => $this->signedMoney($report->total->totalCents())]) }}</p>
|
|
|
|
<section aria-labelledby="usage-items" class="space-y-2">
|
|
<h3 id="usage-items" class="text-lg font-semibold">{{ __('reports.stock_usage.by_item') }}</h3>
|
|
<div class="card overflow-x-auto focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600" tabindex="0" role="region" aria-label="{{ __('reports.stock_usage.by_item') }}, {{ $this->periodLabel() }}">
|
|
<table class="w-full text-sm">
|
|
<caption class="sr-only">{{ __('reports.stock_usage.by_item') }}, {{ $this->periodLabel() }}</caption>
|
|
<thead>
|
|
<tr class="border-b-2 border-primary-200 text-left align-bottom text-primary-900 dark:border-primary-800 dark:text-primary-100">
|
|
<th scope="col" class="py-2 pr-3">{{ __('reports.stock_usage.item') }}</th>
|
|
<th scope="col" class="py-2 pr-3">{{ __('reports.stock_usage.group') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.stock_usage.used') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.stock_usage.written_off') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.stock_usage.adjusted') }}</th>
|
|
<th scope="col" class="py-2 text-right">{{ __('reports.stock_usage.value') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
@foreach ($report->items as $index => $row)
|
|
<tr wire:key="item-{{ $index }}">
|
|
<th scope="row" class="py-2 pr-3 text-left font-normal">{{ $row->label }}</th>
|
|
<td class="py-2 pr-3">{{ $row->group }}</td>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->quantity($row->usedMilli, $row->unit) }}</td>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->quantity($row->writtenOffMilli, $row->unit) }}</td>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->quantity($row->adjustedMilli, $row->unit) }}</td>
|
|
<td class="py-2 text-right whitespace-nowrap">{{ $this->signedMoney($row->totalCents()) }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
|
|
@foreach ($this->summaries($report) as $summary)
|
|
<section wire:key="summary-{{ $summary['key'] }}" aria-labelledby="usage-{{ $summary['key'] }}" class="space-y-2">
|
|
<h3 id="usage-{{ $summary['key'] }}" class="text-lg font-semibold">{{ __('reports.stock_usage.by_'.$summary['key']) }}</h3>
|
|
<div class="card overflow-x-auto focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600" tabindex="0" role="region" aria-label="{{ __('reports.stock_usage.by_'.$summary['key']) }}, {{ $this->periodLabel() }}">
|
|
<table class="w-full text-sm">
|
|
<caption class="sr-only">{{ __('reports.stock_usage.by_'.$summary['key']) }}, {{ $this->periodLabel() }}</caption>
|
|
<thead>
|
|
<tr class="border-b-2 border-primary-200 text-left text-primary-900 dark:border-primary-800 dark:text-primary-100">
|
|
<th scope="col" class="py-2 pr-3">{{ __('reports.stock_usage.'.$summary['key'].'_column') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.stock_usage.used_value') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.stock_usage.written_off_value') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.stock_usage.adjusted_value') }}</th>
|
|
<th scope="col" class="py-2 text-right">{{ __('reports.stock_usage.value') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
@foreach ($summary['rows'] as $index => $row)
|
|
<tr wire:key="{{ $summary['key'] }}-{{ $index }}">
|
|
<th scope="row" class="py-2 pr-3 text-left font-normal">{{ $row->label }}</th>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->signedMoney($row->usedCents) }}</td>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->signedMoney($row->writtenOffCents) }}</td>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->signedMoney($row->adjustedCents) }}</td>
|
|
<td class="py-2 text-right whitespace-nowrap">{{ $this->signedMoney($row->totalCents()) }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
@endforeach
|
|
@endif
|
|
@endif
|
|
</div>
|