Files
petriandClaude Sonnet 5.5 8079c272d2 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]>
2026-11-25 08:46:22 +02:00

47 lines
1.5 KiB
PHP

<?php
namespace App\Modules\Reports\Presentation\Csv;
use App\Modules\Reports\Application\UseCases\ReimbursementsReport;
use App\Modules\Reports\Presentation\ReportFormat;
use Illuminate\Http\Request;
/**
* Expense reimbursements as CSV: a row per expense, kilometres with a
* decimal comma and the cost in cents (VAT 0).
*/
class ReimbursementsCsv implements ReportCsv
{
public function __construct(private ReimbursementsReport $report) {}
public function fileName(Request $request): string
{
$period = CsvFilters::period($request);
return __('reports.reimbursements.file').'-'.$period->from.'-'.$period->to;
}
public function headers(): array
{
return array_values(__('reports.reimbursements.csv'));
}
public function rows(Request $request): iterable
{
foreach ($this->report->execute(CsvFilters::period($request))->people as $person) {
foreach ($person->lines as $line) {
yield [
$person->name,
$line->expense->spentOn,
__('expenses.categories.'.$line->expense->category),
ReportFormat::expenseText($line->expense),
$line->jobNumber,
$line->jobName,
$line->expense->kilometerTenths === null ? '' : ReportFormat::csvKilometers($line->expense->kilometerTenths),
$line->expense->costCents,
];
}
}
}
}