Add time tracking on tasks with a weekly sheet

Phase 1, item 8 (last of phase 1). New TimeTracking module:
- One entry per user, task and day (0.25-24 h in quarters, with a note);
  the job and work type are copied from the task. A user's day cannot
  exceed 24 h, and hours on a done, invoiced, billed or archived job
  cannot be added or changed.
- Weekly sheet /time: tasks as rows (own open tasks, tasks with hours
  that week, tasks added by search), days as columns, row, day and week
  totals, week navigation. A cell saves on change and an empty cell
  removes the entry; on phones one day at a time. Saves and errors are
  announced, errors are tied to their cell.
- Task booking page /time/tasks/{task}: date, hours and note, added to
  the day's entry; own entries with edit and remove.
- Anyone but subcontractors may book on any unlocked task;
  subcontractors only on jobs they are attached to.

Jobs module:
- JobStatus::locksTime(), BookableTask and task queries for booking.
- A task with time entries cannot be removed (TaskUsage contract,
  provided by TimeTracking); the job page links tasks to booking.
- The "involved in a job" rule is shared in JobInvolvement.

Spec and CLAUDE.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 05:52:45 +02:00
co-authored by Claude Opus 5.5
parent 02a62eb16e
commit 3922c744a7
53 changed files with 2496 additions and 19 deletions
@@ -0,0 +1,78 @@
<?php
use App\Models\User;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use App\Modules\TimeTracking\Infrastructure\Persistence\Eloquent\TimeEntryModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->create();
$this->actingAs($this->user);
$this->task = TaskModel::factory()->assignedTo([$this->user->id])->create(['title' => 'Mainoskuvat']);
$this->monday = now()->startOfWeek()->toDateString();
TimeEntryModel::factory()->create(['task_id' => $this->task->id, 'user_id' => $this->user->id, 'worked_on' => $this->monday, 'hours' => 1.5, 'note' => 'Luonnokset']);
});
it('has no accessibility issues on the time pages and no sideways scrolling', function (string $page, string $device, string $colorScheme) {
$url = $page === 'week' ? route('time.week') : route('time.task', $this->task->id);
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee('Mainoskuvat')
->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true)
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['week', 'task page'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('records hours in the weekly view with the keyboard', function () {
$tuesday = now()->startOfWeek()->addDay()->toDateString();
$cell = '#cell-'.$this->task->id.'-'.$tuesday;
visit(route('time.week'))
->on()->desktop()
->type($cell, '2,5')
->keys($cell, 'Tab')
->assertSee('Tallennettu: Mainoskuvat')
->assertSee('Viikko yhteensä: 4 h')
->assertNoAccessibilityIssues(level: 2);
expect((float) TimeEntryModel::query()->whereDate('worked_on', $tuesday)->sole()->hours)->toBe(2.5);
});
it('shows an invalid value as an error at the field', function (string $device) {
$selector = $device === 'mobile'
? '#mcell-'.$this->task->id.'-'.$this->monday
: '#cell-'.$this->task->id.'-'.$this->monday;
$visit = visit(route('time.week'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
if ($device === 'mobile') {
$visit->click('[aria-pressed][wire\\:click="selectDay(\''.$this->monday.'\')"]');
}
$visit->clear($selector)
->type($selector, '1,1')
->keys($selector, 'Tab')
->assertSee('Anna tunnit vartin tarkkuudella')
->assertAttribute($selector, 'aria-invalid', 'true')
->assertNoAccessibilityIssues(level: 2);
})->with(['desktop', 'mobile']);
it('records hours from the task page', function () {
visit(route('time.task', $this->task->id))
->fill('[wire\\:model="workedOn"]', $this->monday)
->fill('[wire\\:model="hours"]', '2')
->press('Kirjaa tunnit')
->assertSee('kirjaus on nyt 3,5 h.')
->assertNoAccessibilityIssues(level: 2);
});