154 lines
8.4 KiB
PHP
154 lines
8.4 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">
|
|
<h1 class="text-2xl font-semibold">{{ __('reports.stock_usage.title') }}</h1>
|
|
<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 === [])
|
|
<p>{{ __('reports.stock_usage.empty') }}</p>
|
|
@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="overflow-x-auto rounded 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 border-zinc-300 text-left align-bottom dark:border-zinc-600">
|
|
<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="overflow-x-auto rounded 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 border-zinc-300 text-left dark:border-zinc-600">
|
|
<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>
|