Add the expense reimbursements report

The expenses employees paid themselves in a period, by person with
kilometres and amounts, printable and as CSV for payroll.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 08:46:22 +02:00
co-authored by Claude Sonnet 5.5
parent 568871c9dc
commit 8079c272d2
21 changed files with 639 additions and 1 deletions
@@ -0,0 +1,125 @@
<?php
use App\Modules\Reports\Application\DTOs\ReimbursementEntry;
use App\Modules\Reports\Application\DTOs\ReimbursementReport;
use App\Modules\Reports\Application\UseCases\ReimbursementsReport;
use App\Modules\Reports\Presentation\Livewire\Concerns\ReportPage;
use App\Modules\Reports\Presentation\ReportFormat;
use App\Modules\Users\Application\Contracts\Clock;
use Livewire\Attributes\Computed;
use Livewire\Component;
/**
* Expense reimbursements (spec 10, 13): the expenses employees paid
* themselves in a period, by person, to print or download for payroll.
* Paying them is outside this system.
*/
new class extends Component
{
use ReportPage;
public function mount(Clock $clock): void
{
$this->startPeriod($clock, 'previous_month');
}
#[Computed]
public function report(): ?ReimbursementReport
{
$period = $this->period();
return $period === null ? null : app(ReimbursementsReport::class)->execute($period);
}
public function updated(): void
{
$this->authorize('reports.view');
unset($this->report);
}
public function kilometers(?int $tenths): string
{
return $tenths === null ? '' : ReportFormat::kilometers($tenths);
}
public function what(ReimbursementEntry $expense): string
{
return ReportFormat::expenseText($expense);
}
public function render(): mixed
{
return $this->view()->title(__('reports.reimbursements.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.reimbursements.title') }}</h1>
<p class="max-w-3xl text-sm">{{ __('reports.reimbursements.intro') }}</p>
</div>
<x-reports.period-filter class="print:hidden" :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" role="status" aria-live="polite">{{ $this->periodLabel() }}</h2>
<div class="flex flex-wrap gap-2 print:hidden">
<x-button x-on:click="window.print()" subtle color="black" icon="printer" :text="__('reports.reimbursements.print')" />
<x-button :href="$this->csvUrl('reimbursements')" subtle color="black" icon="arrow-down-tray" :text="__('reports.download_csv')" />
</div>
</div>
@if ($report->people === [])
<p>{{ __('reports.reimbursements.none') }}</p>
@else
<p class="font-semibold">
{{ __('reports.reimbursements.grand_total', ['amount' => $this->money($report->costCents), 'km' => $this->kilometers($report->kilometerTenths)]) }}
</p>
@foreach ($report->people as $person)
<section wire:key="person-{{ $person->userId }}" aria-labelledby="person-{{ $person->userId }}" class="space-y-2 break-inside-avoid">
<h3 id="person-{{ $person->userId }}" class="text-lg font-semibold">{{ $person->name }}</h3>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<caption class="sr-only">{{ __('reports.reimbursements.table', ['name' => $person->name, 'period' => $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.reimbursements.day') }}</th>
<th scope="col" class="py-2 pr-3">{{ __('reports.reimbursements.category') }}</th>
<th scope="col" class="py-2 pr-3">{{ __('reports.reimbursements.what') }}</th>
<th scope="col" class="py-2 pr-3">{{ __('reports.reimbursements.job') }}</th>
<th scope="col" class="py-2 pr-3 text-right">{{ __('reports.reimbursements.km') }}</th>
<th scope="col" class="py-2 text-right">{{ __('reports.reimbursements.amount') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
@foreach ($person->lines as $line)
<tr class="align-top">
<td class="py-2 pr-3 whitespace-nowrap">{{ $this->dateLabel($line->expense->spentOn) }}</td>
<td class="py-2 pr-3">{{ __('expenses.categories.'.$line->expense->category) }}</td>
<td class="py-2 pr-3">{{ $this->what($line->expense) }}</td>
<td class="py-2 pr-3">{{ $line->jobNumber }} {{ $line->jobName }}</td>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->kilometers($line->expense->kilometerTenths) }}</td>
<td class="py-2 text-right whitespace-nowrap">{{ $this->money($line->expense->costCents) }}</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr class="border-t-2 border-zinc-400 font-semibold dark:border-zinc-500">
<th scope="row" colspan="4" class="py-2 pr-3 text-left">{{ __('reports.reimbursements.person_total', ['name' => $person->name]) }}</th>
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->kilometers($person->kilometerTenths) }}</td>
<td class="py-2 text-right whitespace-nowrap">{{ $this->money($person->costCents) }}</td>
</tr>
</tfoot>
</table>
</div>
</section>
@endforeach
@endif
@endif
</div>