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,49 @@
<?php
namespace App\Modules\TimeTracking\Infrastructure\Persistence\Eloquent;
use Carbon\CarbonImmutable;
use Database\Factories\TimeEntryFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Database\Eloquent\Attributes\UseFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $user_id
* @property int $task_id
* @property int $customer_job_id
* @property int $work_type_id
* @property CarbonImmutable $worked_on
* @property string $hours
* @property string|null $note
*/
#[Table('time_entries')]
#[Fillable(['user_id', 'task_id', 'customer_job_id', 'work_type_id', 'worked_on', 'hours', 'note'])]
#[UseFactory(TimeEntryFactory::class)]
class TimeEntryModel extends Model
{
/** @use HasFactory<TimeEntryFactory> */
use HasFactory;
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'user_id' => 'integer',
'task_id' => 'integer',
'customer_job_id' => 'integer',
'work_type_id' => 'integer',
'worked_on' => 'immutable_date',
];
}
public function quarters(): int
{
return (int) round((float) $this->hours * 4);
}
}