- Dark theme page background is #5a5e60; text on it is lifted to zinc-200 / primary-100 and TallStackUI's dark labels, hints and checkbox labels are lightened so everything stays at 4.5:1. - Shared HexColor picks white or black text by the higher WCAG contrast; a native-dialog colour picker and a large work dialog component. - Customers get a header colour (customers.header_color), set on the customer page. - New job status Jatkuvat / Kausi (ongoing): open, never late, billed monthly like running jobs. - Kanban model: board columns and views, urgent threshold, per-user board preferences (density, column colours and sort), card positions, tasks of continuing jobs pinned to the board, MoveBoardCard and board queries with logged hours from TimeTracking. Co-Authored-By: Claude Opus 5.5 <[email protected]>
119 lines
3.0 KiB
PHP
119 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Jobs\Domain\Entities;
|
|
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Domain\Enums\Priority;
|
|
use App\Modules\Jobs\Domain\ValueObjects\FieldChange;
|
|
use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
|
|
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
|
use DateTimeImmutable;
|
|
|
|
/**
|
|
* A customer job (asiakastyö): the work done for a customer, which tasks,
|
|
* time entries and invoices are attached to. It knows when it was done:
|
|
* reaching a status that locks hours sets the time, and opening the lock
|
|
* clears it.
|
|
*/
|
|
final class CustomerJob
|
|
{
|
|
private function __construct(
|
|
private ?int $id,
|
|
private JobNumber $number,
|
|
private JobDetails $details,
|
|
private int $createdBy,
|
|
private ?DateTimeImmutable $completedAt = null,
|
|
) {}
|
|
|
|
public static function open(JobNumber $number, JobDetails $details, int $createdBy): self
|
|
{
|
|
return new self(null, $number, $details, $createdBy);
|
|
}
|
|
|
|
public static function reconstitute(int $id, JobNumber $number, JobDetails $details, int $createdBy, ?DateTimeImmutable $completedAt = null): self
|
|
{
|
|
return new self($id, $number, $details, $createdBy, $completedAt);
|
|
}
|
|
|
|
/**
|
|
* Keeps the completion time in step with the status: set when the job
|
|
* first reaches a locking status, kept while it stays locked, cleared
|
|
* when the lock is opened.
|
|
*/
|
|
public function recordCompletion(DateTimeImmutable $now): void
|
|
{
|
|
if (! $this->details->status->locksTime()) {
|
|
$this->completedAt = null;
|
|
|
|
return;
|
|
}
|
|
|
|
$this->completedAt ??= $now;
|
|
}
|
|
|
|
public function completedAt(): ?DateTimeImmutable
|
|
{
|
|
return $this->completedAt;
|
|
}
|
|
|
|
/**
|
|
* Replaces the details and returns what changed, for the history.
|
|
*
|
|
* @return list<FieldChange>
|
|
*/
|
|
public function changeDetails(JobDetails $details): array
|
|
{
|
|
$before = $this->details->comparable();
|
|
$after = $details->comparable();
|
|
$this->details = $details;
|
|
|
|
$changes = [];
|
|
|
|
foreach ($after as $field => $value) {
|
|
if (($before[$field] ?? null) !== $value) {
|
|
$changes[] = new FieldChange($field, $before[$field] ?? null, $value);
|
|
}
|
|
}
|
|
|
|
return $changes;
|
|
}
|
|
|
|
/**
|
|
* @return list<FieldChange>
|
|
*/
|
|
public function changeStatus(JobStatus $status): array
|
|
{
|
|
return $this->changeDetails($this->details->withStatus($status));
|
|
}
|
|
|
|
/**
|
|
* @return list<FieldChange>
|
|
*/
|
|
public function changePriority(Priority $priority): array
|
|
{
|
|
return $this->changeDetails($this->details->withPriority($priority));
|
|
}
|
|
|
|
public function id(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function number(): JobNumber
|
|
{
|
|
return $this->number;
|
|
}
|
|
|
|
public function details(): JobDetails
|
|
{
|
|
return $this->details;
|
|
}
|
|
|
|
public function createdBy(): int
|
|
{
|
|
return $this->createdBy;
|
|
}
|
|
}
|