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

57 lines
2.9 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Expenses\Infrastructure\Persistence\Eloquent\ExpenseModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->actingAs(User::factory()->management()->create());
$this->aino = User::factory()->employee()->create(['name' => 'Aino']);
$this->bertta = User::factory()->employee()->create(['name' => 'Bertta']);
$this->job = CustomerJobModel::factory()->create(['name' => 'Messut']);
});
it('lists the expenses employees paid by person with totals', function () {
ExpenseModel::factory()->paidByEmployee()->mileage(12.5, 59)->create(['user_id' => $this->bertta->id, 'customer_job_id' => $this->job->id, 'spent_on' => '2026-10-31']);
ExpenseModel::factory()->paidByEmployee()->create(['user_id' => $this->aino->id, 'customer_job_id' => $this->job->id, 'spent_on' => '2026-10-02', 'description' => 'Teippi', 'cost_cents' => 1250]);
ExpenseModel::factory()->paidByEmployee()->create(['user_id' => $this->aino->id, 'customer_job_id' => $this->job->id, 'spent_on' => '2026-10-05', 'cost_cents' => 750]);
ExpenseModel::factory()->create(['user_id' => $this->aino->id, 'customer_job_id' => $this->job->id, 'spent_on' => '2026-10-05', 'cost_cents' => 99900]);
ExpenseModel::factory()->paidByEmployee()->create(['user_id' => $this->aino->id, 'customer_job_id' => $this->job->id, 'spent_on' => '2026-11-01', 'cost_cents' => 99900]);
$report = Livewire::withQueryParams(['alku' => '2026-10-01', 'loppu' => '2026-10-31'])
->test('reports::reimbursements')
->assertOk()
->assertSee('Teippi')
->assertSee('Tampere, Asiakastapaaminen')
->assertSee('12,5')
->instance()
->report();
expect(array_map(fn ($person) => $person->name, $report->people))->toBe(['Aino', 'Bertta'])
->and($report->people[0]->costCents)->toBe(2000)
->and($report->people[0]->lines[0]->jobName)->toBe('Messut')
->and($report->people[1]->kilometerTenths)->toBe(125)
->and($report->people[1]->costCents)->toBe(738)
->and($report->costCents)->toBe(2738);
$response = $this->get(route('reports.csv', ['report' => 'reimbursements', 'alku' => '2026-10-01', 'loppu' => '2026-10-31']))
->assertOk()
->assertDownload('kulukorvaukset-2026-10-01-2026-10-31.csv');
expect($response->streamedContent())
->toContain('Aino;2026-10-02;"Tuotteet, tarvikkeet ja materiaalit";Teippi;'.$this->job->number.';Messut;;1250')
->toContain('Bertta;2026-10-31;Matkakilometrit;"Tampere, Asiakastapaaminen";'.$this->job->number.';Messut;12,5;738');
});
it('starts with the previous month', function () {
$this->travelTo('2026-11-25 12:00');
Livewire::test('reports::reimbursements')
->assertSet('from', '2026-10-01')
->assertSet('to', '2026-10-31');
});