Files
Toiminnanohjaus/app/Modules/Reports/Presentation/Livewire/⚡profitability.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

221 lines
14 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\Reports\Application\DTOs\ProfitabilityReport;
use App\Modules\Reports\Application\UseCases\ProfitabilityByJob;
use App\Modules\Reports\Domain\ValueObjects\Profit;
use App\Modules\Reports\Presentation\Livewire\Concerns\ReportPage;
use App\Modules\Users\Application\Contracts\Clock;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Url;
use Livewire\Component;
/**
* Profitability by service unit and by job (spec 13) in a period: what
* was billed less the expenses' purchase costs and the hours at the
* internal hourly cost (set on the price list maintenance page).
*/
new class extends Component
{
use ReportPage;
#[Url(as: 'sisaiset', except: false)]
public bool $includeInternal = false;
public function mount(Clock $clock): void
{
$this->startPeriod($clock, 'this_year');
}
#[Computed]
public function report(): ?ProfitabilityReport
{
$period = $this->period();
return $period === null ? null : app(ProfitabilityByJob::class)->execute($period, $this->includeInternal);
}
public function updated(): void
{
$this->authorize('reports.view');
unset($this->report);
}
public function margin(Profit $profit): string
{
$margin = $profit->marginCents();
return $margin === null ? '–' : $this->money($margin);
}
public function marginPercent(Profit $profit): string
{
$ratio = $profit->marginRatio();
return $ratio === null ? '–' : $this->percent($ratio);
}
public function hourCost(Profit $profit): string
{
return $profit->hourCostCents === null ? '–' : $this->money($profit->hourCostCents);
}
public function effectiveRate(Profit $profit): string
{
$cents = $profit->effectiveHourlyCents();
return $cents === null ? '–' : $this->money($cents);
}
public function render(): mixed
{
return $this->view()->title(__('reports.profitability.title'));
}
};
?>
<div class="mx-auto max-w-7xl space-y-6 p-4 sm:p-6">
<div class="space-y-2">
<x-page-title icon="chart-bar">{{ __('reports.profitability.title') }}</x-page-title>
<p class="max-w-3xl text-sm">{{ __('reports.profitability.intro') }}</p>
</div>
<x-reports.period-filter :presets="$this->periodPresets()" :valid="$this->period !== null" />
<x-checkbox id="include-internal" wire:model.live="includeInternal" :label="__('reports.profitability.include_internal')" />
@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('profitability', ['sisaiset' => $includeInternal ? '1' : ''])" subtle color="black" icon="arrow-down-tray" :text="__('reports.download_csv')" />
</div>
@if ($report->hourlyCostCents === null)
<div class="flex items-start gap-2 rounded-lg border border-amber-700 bg-amber-50 p-4 text-sm text-amber-950 dark:border-amber-400 dark:bg-amber-400/10 dark:text-amber-100">
<x-icon name="exclamation-triangle" class="size-5 shrink-0" aria-hidden="true" />
<p>
{{ __('reports.profitability.no_cost') }}
@can('catalog.manage')
<x-link :href="route('catalog.prices').'#internal-cost-heading'">{{ __('reports.profitability.set_cost') }}</x-link>
@endcan
</p>
</div>
@else
<p class="text-sm">{{ __('reports.profitability.cost_used', ['cost' => $this->money($report->hourlyCostCents)]) }}</p>
@endif
@if ($report->jobs === [])
<x-empty-state icon="chart-bar">{{ __('reports.profitability.none') }}</x-empty-state>
@else
<section aria-labelledby="units-heading" class="space-y-4">
<h2 id="units-heading" class="text-xl font-semibold">{{ __('reports.profitability.by_service_unit') }}</h2>
<p class="text-sm">{{ __('reports.profitability.split_note') }}</p>
<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.profitability.units_table', ['period' => $this->periodLabel()]) }}">
<table class="w-full text-sm">
<caption class="sr-only">{{ __('reports.profitability.units_table', ['period' => $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.profitability.service_unit') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.jobs') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.hours') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.revenue') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.costs') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.margin') }}</th>
<th scope="col" class="py-2 text-right">{{ __('reports.profitability.margin_percent') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
@foreach ($report->serviceUnits as $unit)
<tr wire:key="unit-{{ $unit->serviceUnitId }}">
<th scope="row" class="py-2 pr-3 text-left font-normal">{{ $unit->name !== '' ? $unit->name : __('reports.profitability.no_service_unit') }}</th>
<td class="py-2 pr-3 text-right">{{ $unit->jobCount }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->hours($unit->profit->quarters) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($unit->profit->revenueCents()) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($unit->profit->expenseCostCents + $unit->profit->materialCostCents + ($unit->profit->hourCostCents ?? 0)) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->margin($unit->profit) }}</td>
<td class="py-2 text-right whitespace-nowrap">{{ $this->marginPercent($unit->profit) }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@if ($report->hourlyCostCents !== null)
<x-reports.chart
:title="__('reports.profitability.chart')"
:summary="implode(', ', array_map(fn ($unit) => $unit->name.' '.$this->margin($unit->profit), $report->serviceUnits))"
:labels="array_map(fn ($unit) => $unit->name, $report->serviceUnits)"
:values="array_map(fn ($unit) => ($unit->profit->marginCents() ?? 0) / 100, $report->serviceUnits)"
:formatter="fn (float $value) => number_format($value, 0, ',', ' ').' €'"
/>
@endif
</section>
<section aria-labelledby="jobs-heading" class="space-y-4">
<h2 id="jobs-heading" class="text-xl font-semibold">{{ __('reports.profitability.by_job') }}</h2>
<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.profitability.jobs_table', ['period' => $this->periodLabel()]) }}">
<table class="w-full text-sm">
<caption class="sr-only">{{ __('reports.profitability.jobs_table', ['period' => $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.profitability.job') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.hours') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.billed_hours') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.work_revenue') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.expense_revenue') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.expense_cost') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.material_cost') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.hour_cost') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.margin') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.profitability.margin_percent') }}</th>
<th scope="col" class="py-2 text-right">{{ __('reports.profitability.effective_rate') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
@foreach ($report->jobs as $row)
<tr wire:key="job-{{ $row->job->id }}" class="align-top">
<th scope="row" class="py-2 pr-3 text-left font-normal">
<x-link :href="route('jobs.show', $row->job->id)" navigate>{{ $row->job->number }} {{ $row->job->name }}</x-link>
<span class="block text-xs text-zinc-600 dark:text-zinc-300">
{{ $row->job->customerName }}@if ($row->job->paymentBasis !== null), {{ __('jobs.payment_bases.'.$row->job->paymentBasis) }}@endif
@if ($row->job->quotedAmountCents !== null), {{ __('reports.profitability.quoted', ['amount' => $this->money($row->job->quotedAmountCents)]) }}@endif
</span>
</th>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->hours($row->profit->quarters) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->hours($row->profit->billedQuarters) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($row->profit->workCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($row->profit->expenseRevenueCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($row->profit->expenseCostCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($row->profit->materialCostCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->hourCost($row->profit) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->margin($row->profit) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->marginPercent($row->profit) }}</td>
<td class="py-2 text-right whitespace-nowrap">{{ $this->effectiveRate($row->profit) }}</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr class="border-t-2 border-zinc-400 font-semibold dark:border-zinc-500">
<th scope="row" class="py-2 pr-3 text-left">{{ __('reports.total') }}</th>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->hours($report->total->quarters) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->hours($report->total->billedQuarters) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($report->total->workCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($report->total->expenseRevenueCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($report->total->expenseCostCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($report->total->materialCostCents) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->hourCost($report->total) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->margin($report->total) }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->marginPercent($report->total) }}</td>
<td class="py-2 text-right whitespace-nowrap">{{ $this->effectiveRate($report->total) }}</td>
</tr>
</tfoot>
</table>
</div>
</section>
@endif
@endif
</div>