- 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]>
182 lines
7.4 KiB
PHP
182 lines
7.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Jobs\Domain\ValueObjects;
|
|
|
|
use App\Modules\Jobs\Domain\Enums\JobKind;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
|
use App\Modules\Jobs\Domain\Enums\Priority;
|
|
use App\Modules\Jobs\Domain\Exceptions\DueBeforeStart;
|
|
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
|
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
|
|
use App\Modules\Shared\Domain\ValueObjects\Money;
|
|
use DateTimeImmutable;
|
|
|
|
/**
|
|
* Everything about a customer job that users edit. Kept in one value so a
|
|
* change can be compared field by field for the job's history.
|
|
*/
|
|
final readonly class JobDetails
|
|
{
|
|
/** @var list<int> */
|
|
public array $serviceUnitIds;
|
|
|
|
/** @var list<int> */
|
|
public array $memberUserIds;
|
|
|
|
/** @var list<Tag> */
|
|
public array $tags;
|
|
|
|
/**
|
|
* @param list<int> $serviceUnitIds
|
|
* @param list<int> $memberUserIds
|
|
* @param list<Tag> $tags
|
|
* @param list<JobLink> $links
|
|
*/
|
|
public function __construct(
|
|
public JobName $name,
|
|
public ?string $description,
|
|
public int $customerId,
|
|
array $serviceUnitIds,
|
|
public ?DateTimeImmutable $startsOn,
|
|
public ?DateTimeImmutable $dueOn,
|
|
public ?DateTimeImmutable $plannedFrom,
|
|
public ?DateTimeImmutable $plannedTo,
|
|
public JobKind $kind,
|
|
public JobStatus $status,
|
|
public Priority $priority,
|
|
public ?PaymentBasis $paymentBasis,
|
|
public ?EstimatedHours $estimatedHours,
|
|
public ?string $customerReference,
|
|
public ?string $instructions,
|
|
public int $responsibleUserId,
|
|
public ?int $contactUserId,
|
|
public ?int $customerContactId,
|
|
public ?int $billerUserId,
|
|
public ?int $billingUnitId,
|
|
array $memberUserIds,
|
|
array $tags,
|
|
public array $links,
|
|
public ?Money $quotedAmount = null,
|
|
public ?Money $monthlyFee = null,
|
|
) {
|
|
$serviceUnitIds = array_values(array_unique($serviceUnitIds));
|
|
|
|
if ($serviceUnitIds === []) {
|
|
throw new ServiceUnitRequired;
|
|
}
|
|
|
|
if ($startsOn !== null && $dueOn !== null && $dueOn < $startsOn) {
|
|
throw new DueBeforeStart;
|
|
}
|
|
|
|
if ($plannedFrom !== null && $plannedTo !== null && $plannedTo < $plannedFrom) {
|
|
throw new PlanEndsBeforeStart;
|
|
}
|
|
|
|
sort($serviceUnitIds);
|
|
$memberUserIds = array_values(array_unique($memberUserIds));
|
|
sort($memberUserIds);
|
|
|
|
$uniqueTags = [];
|
|
foreach ($tags as $tag) {
|
|
$uniqueTags[mb_strtolower($tag->value)] ??= $tag;
|
|
}
|
|
|
|
$this->serviceUnitIds = $serviceUnitIds;
|
|
$this->memberUserIds = $memberUserIds;
|
|
$this->tags = array_values($uniqueTags);
|
|
}
|
|
|
|
public function withStatus(JobStatus $status): self
|
|
{
|
|
return new self(
|
|
$this->name, $this->description, $this->customerId, $this->serviceUnitIds,
|
|
$this->startsOn, $this->dueOn, $this->plannedFrom, $this->plannedTo,
|
|
$this->kind, $status, $this->priority, $this->paymentBasis, $this->estimatedHours,
|
|
$this->customerReference, $this->instructions, $this->responsibleUserId, $this->contactUserId,
|
|
$this->customerContactId, $this->billerUserId, $this->billingUnitId, $this->memberUserIds,
|
|
$this->tags, $this->links, $this->quotedAmount, $this->monthlyFee,
|
|
);
|
|
}
|
|
|
|
public function withPriority(Priority $priority): self
|
|
{
|
|
return new self(
|
|
$this->name, $this->description, $this->customerId, $this->serviceUnitIds,
|
|
$this->startsOn, $this->dueOn, $this->plannedFrom, $this->plannedTo,
|
|
$this->kind, $this->status, $priority, $this->paymentBasis, $this->estimatedHours,
|
|
$this->customerReference, $this->instructions, $this->responsibleUserId, $this->contactUserId,
|
|
$this->customerContactId, $this->billerUserId, $this->billingUnitId, $this->memberUserIds,
|
|
$this->tags, $this->links, $this->quotedAmount, $this->monthlyFee,
|
|
);
|
|
}
|
|
|
|
public function withServiceUnit(int $serviceUnitId): self
|
|
{
|
|
return new self(
|
|
$this->name, $this->description, $this->customerId, [...$this->serviceUnitIds, $serviceUnitId],
|
|
$this->startsOn, $this->dueOn, $this->plannedFrom, $this->plannedTo,
|
|
$this->kind, $this->status, $this->priority, $this->paymentBasis, $this->estimatedHours,
|
|
$this->customerReference, $this->instructions, $this->responsibleUserId, $this->contactUserId,
|
|
$this->customerContactId, $this->billerUserId, $this->billingUnitId, $this->memberUserIds,
|
|
$this->tags, $this->links, $this->quotedAmount, $this->monthlyFee,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Whether the user is a named member of the job in any role.
|
|
*/
|
|
public function involves(int $userId): bool
|
|
{
|
|
return in_array($userId, [$this->responsibleUserId, $this->contactUserId, $this->billerUserId], true)
|
|
|| in_array($userId, $this->memberUserIds, true);
|
|
}
|
|
|
|
/**
|
|
* Every field as a comparable string (or null), keyed by the field name
|
|
* used in the job's history.
|
|
*
|
|
* @return array<string, string|null>
|
|
*/
|
|
public function comparable(): array
|
|
{
|
|
$date = fn (?DateTimeImmutable $date): ?string => $date?->format('Y-m-d');
|
|
$ids = fn (array $ids): ?string => $ids === [] ? null : implode(',', $ids);
|
|
|
|
// Tags are shared and matched ignoring case, so a change of case is no change.
|
|
$tagNames = array_map(fn (Tag $tag): string => mb_strtolower($tag->value), $this->tags);
|
|
sort($tagNames);
|
|
|
|
return [
|
|
'name' => $this->name->value,
|
|
'description' => $this->description,
|
|
'customer' => (string) $this->customerId,
|
|
'service_units' => $ids($this->serviceUnitIds),
|
|
'starts_on' => $date($this->startsOn),
|
|
'due_on' => $date($this->dueOn),
|
|
'planned_from' => $date($this->plannedFrom),
|
|
'planned_to' => $date($this->plannedTo),
|
|
'kind' => $this->kind->value,
|
|
'status' => $this->status->value,
|
|
'priority' => $this->priority->value,
|
|
'payment_basis' => $this->paymentBasis?->value,
|
|
'estimated_hours' => $this->estimatedHours?->format(),
|
|
'quoted_amount' => $this->quotedAmount === null ? null : (string) $this->quotedAmount->cents,
|
|
'monthly_fee' => $this->monthlyFee === null ? null : (string) $this->monthlyFee->cents,
|
|
'customer_reference' => $this->customerReference,
|
|
'instructions' => $this->instructions,
|
|
'responsible_user' => (string) $this->responsibleUserId,
|
|
'contact_user' => $this->contactUserId === null ? null : (string) $this->contactUserId,
|
|
'customer_contact' => $this->customerContactId === null ? null : (string) $this->customerContactId,
|
|
'biller_user' => $this->billerUserId === null ? null : (string) $this->billerUserId,
|
|
'billing_unit' => $this->billingUnitId === null ? null : (string) $this->billingUnitId,
|
|
'members' => $ids($this->memberUserIds),
|
|
'tags' => $tagNames === [] ? null : implode(', ', $tagNames),
|
|
'links' => $this->links === [] ? null : implode("\n", array_map(fn (JobLink $link): string => $link->title.' <'.$link->url.'>', $this->links)),
|
|
];
|
|
}
|
|
}
|