0 ? ['2026-11-30' => new TimesheetCell($quarters, null, null, null, false)] : []; return new TimesheetTaskRow($task, $cells, $quarters, $pinned); } it('reads hours and minutes, decimal hours and minutes from a cell', function (string $value, ?int $quarters) { expect(WorkedHours::parseFlexible($value)?->quarters)->toBe($quarters); })->with([ 'h:mm' => ['1:30', 6], 'decimal comma' => ['1,5', 6], 'decimal point' => ['2.25', 9], 'whole hours' => ['2', 8], 'minutes over 24' => ['90', 6], 'zero' => ['0:00', null], 'empty' => ['', null], ]); it('refuses times that are not whole quarter hours', function (string $value) { WorkedHours::parseFlexible($value); })->throws(InvalidWorkedHours::class)->with(['1:10', '50', '1,1', 'abc', '25:00']); it('formats quarters as hours and minutes', function () { expect(WorkedHours::formatClock(0))->toBe('0:00') ->and(WorkedHours::formatClock(6))->toBe('1:30') ->and(WorkedHours::formatClock(41))->toBe('10:15'); }); it('takes the default billing basis from the job\'s payment basis', function (?string $basis, EntryBillingModel $model) { expect(EntryBillingModel::forPaymentBasis($basis))->toBe($model); })->with([ ['fixed_quote', EntryBillingModel::Fixed], ['price_list', EntryBillingModel::Fixed], ['monthly_fee', EntryBillingModel::Fixed], ['hourly', EntryBillingModel::Hourly], [null, EntryBillingModel::Hourly], ['not_billable', EntryBillingModel::NonBillable], ]); it('groups rows customer A–Ö, then job, then task, in Finnish order', function () { $rows = [ sheetRow(1, 'Ässä KP Oy', '798', 'Markkinointi'), sheetRow(2, 'Agrikumppanit Oy', '5', 'Myyntityö'), sheetRow(3, 'Loimaan kaupunki', '778', 'Videokuvaus'), sheetRow(4, 'Loimaan kaupunki', '778', 'Käsikirjoitus'), sheetRow(5, 'Ravintola ATA ky', '470', 'Lounaslista'), ]; $sections = (new TimesheetLayout)->arrange($rows, [1, 2, 3, 4, 5], []); expect(array_map(fn ($customer) => $customer->name, $sections['scheduled']))->toBe(['Agrikumppanit Oy', 'Loimaan kaupunki', 'Ravintola ATA ky', 'Ässä KP Oy']) ->and(array_map(fn ($row) => $row->task->taskTitle, $sections['scheduled'][1]->jobs[0]->rows))->toBe(['Käsikirjoitus', 'Videokuvaus']); }); it('moves pinned rows out of the scheduled part and keeps lapsed pins only with hours', function () { $rows = [ sheetRow(1, 'A Oy', '1', 'Pinned open', pinned: true), sheetRow(2, 'A Oy', '1', 'Pinned done with hours', pinned: true, quarters: 4, jobStatus: JobStatus::Done), sheetRow(3, 'A Oy', '1', 'Pinned done without hours', pinned: true, jobStatus: JobStatus::Done), sheetRow(4, 'B Oy', '2', 'Scheduled'), sheetRow(5, 'B Oy', '2', 'Not scheduled, no hours'), sheetRow(6, 'B Oy', '2', 'Hours only', quarters: 2), ]; $sections = (new TimesheetLayout)->arrange($rows, [1, 4], []); $titles = fn (array $groups): array => array_merge(...array_map(fn ($customer) => array_merge(...array_map(fn ($job) => array_map(fn ($row) => $row->task->taskTitle, $job->rows), $customer->jobs)), $groups)); expect($titles($sections['pinned']))->toBe(['Pinned done with hours', 'Pinned open']) ->and($titles($sections['scheduled']))->toBe(['Hours only', 'Scheduled']); });