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]>
103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\TimeTracking\Domain\Entities;
|
|
|
|
use App\Modules\TimeTracking\Domain\ValueObjects\WorkedHours;
|
|
use DateTimeImmutable;
|
|
|
|
/**
|
|
* A user's hours on one task on one day (one entry per day). The job and
|
|
* work type are copied from the task when the entry is made, for billing.
|
|
*/
|
|
final class TimeEntry
|
|
{
|
|
private function __construct(
|
|
private ?int $id,
|
|
private int $userId,
|
|
private int $taskId,
|
|
private int $jobId,
|
|
private int $workTypeId,
|
|
private DateTimeImmutable $workedOn,
|
|
private WorkedHours $hours,
|
|
private ?string $note,
|
|
) {}
|
|
|
|
public static function create(int $userId, int $taskId, int $jobId, int $workTypeId, DateTimeImmutable $workedOn, WorkedHours $hours, ?string $note = null): self
|
|
{
|
|
return new self(null, $userId, $taskId, $jobId, $workTypeId, $workedOn, $hours, self::text($note));
|
|
}
|
|
|
|
public static function reconstitute(int $id, int $userId, int $taskId, int $jobId, int $workTypeId, DateTimeImmutable $workedOn, WorkedHours $hours, ?string $note): self
|
|
{
|
|
return new self($id, $userId, $taskId, $jobId, $workTypeId, $workedOn, $hours, $note);
|
|
}
|
|
|
|
public function changeHours(WorkedHours $hours, ?string $note): void
|
|
{
|
|
$this->hours = $hours;
|
|
$this->note = self::text($note);
|
|
}
|
|
|
|
/**
|
|
* Adds more hours to the day's entry; a new note continues the old one.
|
|
*/
|
|
public function addHours(WorkedHours $hours, ?string $note): void
|
|
{
|
|
$this->hours = $this->hours->plus($hours);
|
|
$note = self::text($note);
|
|
|
|
if ($note !== null) {
|
|
$this->note = $this->note === null ? $note : $this->note."\n".$note;
|
|
}
|
|
}
|
|
|
|
public function id(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function userId(): int
|
|
{
|
|
return $this->userId;
|
|
}
|
|
|
|
public function taskId(): int
|
|
{
|
|
return $this->taskId;
|
|
}
|
|
|
|
public function jobId(): int
|
|
{
|
|
return $this->jobId;
|
|
}
|
|
|
|
public function workTypeId(): int
|
|
{
|
|
return $this->workTypeId;
|
|
}
|
|
|
|
public function workedOn(): DateTimeImmutable
|
|
{
|
|
return $this->workedOn;
|
|
}
|
|
|
|
public function hours(): WorkedHours
|
|
{
|
|
return $this->hours;
|
|
}
|
|
|
|
public function note(): ?string
|
|
{
|
|
return $this->note;
|
|
}
|
|
|
|
private static function text(?string $value): ?string
|
|
{
|
|
$value = $value === null ? '' : trim($value);
|
|
|
|
return $value === '' ? null : $value;
|
|
}
|
|
}
|