Add approval of hours and lock opening for management

- Time entries store who approved them and when. Approved hours are
  locked: cells, task page edits and removals are refused.
- "Hyväksy viikko" in the weekly view approves the user's own week;
  subcontractors' hours are approved by management.
- Management gets an approval page (unapproved weeks by person, recently
  approved weeks) and can open anyone's week read-only to approve it or
  cancel its approval, which only management may do.
- Only management may move a done job back to an earlier status, which
  opens the lock on its hours and expenses; the history marks it.
- The Clock contract gets now() for approval times.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 08:24:34 +02:00
co-authored by Claude Opus 5.5
parent 54d98d9d2f
commit d5cbf9d6eb
43 changed files with 1183 additions and 34 deletions
@@ -4,12 +4,14 @@ declare(strict_types=1);
namespace App\Modules\TimeTracking\Domain\Entities;
use App\Modules\TimeTracking\Domain\Exceptions\TimeApproved;
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.
* Approved hours are locked until management cancels the approval.
*/
final class TimeEntry
{
@@ -22,6 +24,8 @@ final class TimeEntry
private DateTimeImmutable $workedOn,
private WorkedHours $hours,
private ?string $note,
private ?int $approvedBy = null,
private ?DateTimeImmutable $approvedAt = null,
) {}
public static function create(int $userId, int $taskId, int $jobId, int $workTypeId, DateTimeImmutable $workedOn, WorkedHours $hours, ?string $note = null): self
@@ -29,13 +33,17 @@ final class TimeEntry
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
public static function reconstitute(int $id, int $userId, int $taskId, int $jobId, int $workTypeId, DateTimeImmutable $workedOn, WorkedHours $hours, ?string $note, ?int $approvedBy = null, ?DateTimeImmutable $approvedAt = null): self
{
return new self($id, $userId, $taskId, $jobId, $workTypeId, $workedOn, $hours, $note);
return new self($id, $userId, $taskId, $jobId, $workTypeId, $workedOn, $hours, $note, $approvedBy, $approvedAt);
}
/**
* @throws TimeApproved
*/
public function changeHours(WorkedHours $hours, ?string $note): void
{
$this->ensureNotApproved();
$this->hours = $hours;
$this->note = self::text($note);
}
@@ -45,6 +53,7 @@ final class TimeEntry
*/
public function addHours(WorkedHours $hours, ?string $note): void
{
$this->ensureNotApproved();
$this->hours = $this->hours->plus($hours);
$note = self::text($note);
@@ -53,6 +62,50 @@ final class TimeEntry
}
}
/**
* Approves the entry; an approved entry keeps its first approval.
*/
public function approve(int $approvedBy, DateTimeImmutable $approvedAt): void
{
if ($this->isApproved()) {
return;
}
$this->approvedBy = $approvedBy;
$this->approvedAt = $approvedAt;
}
public function cancelApproval(): void
{
$this->approvedBy = null;
$this->approvedAt = null;
}
public function isApproved(): bool
{
return $this->approvedAt !== null;
}
/**
* @throws TimeApproved
*/
public function ensureNotApproved(): void
{
if ($this->isApproved()) {
throw new TimeApproved;
}
}
public function approvedBy(): ?int
{
return $this->approvedBy;
}
public function approvedAt(): ?DateTimeImmutable
{
return $this->approvedAt;
}
public function id(): ?int
{
return $this->id;