Files
petriandClaude Opus 5.5 f4b58f6b1d Darken the dark canvas, add customer colours, the ongoing status and the board model
- 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]>
2026-11-30 06:11:49 +02:00

161 lines
4.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Customers\Domain\Entities;
use App\Modules\Customers\Domain\Enums\CustomerType;
use App\Modules\Customers\Domain\Exceptions\CompanyCannotHavePersonalIdentityCode;
use App\Modules\Customers\Domain\Exceptions\ConsumerCannotHaveBusinessId;
use App\Modules\Customers\Domain\Exceptions\InternalCustomerMustBeCompany;
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
use App\Modules\Customers\Domain\ValueObjects\PersonalIdentityCode;
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
use App\Modules\Shared\Domain\ValueObjects\HexColor;
/**
* A customer of the company: a business or a private consumer.
*
* Only the name is needed at job intake; other details are added later.
* A consumer who is invoiced needs a personal identity code.
*/
final class Customer
{
private function __construct(
private ?int $id,
private CustomerName $name,
private CustomerType $type,
private ?BusinessId $businessId,
private ?PersonalIdentityCode $personalIdentityCode,
private bool $internal = false,
private ?HexColor $headerColor = null,
) {
self::ensureIdentifiersFitType($type, $businessId, $personalIdentityCode);
self::ensureInternalIsCompany($internal, $type);
}
/**
* A new customer that is not stored yet, so it has no id.
*/
public static function register(
CustomerName $name,
CustomerType $type,
?BusinessId $businessId = null,
?PersonalIdentityCode $personalIdentityCode = null,
): self {
return new self(null, $name, $type, $businessId, $personalIdentityCode);
}
/**
* Rebuilds a stored customer. Used only by repositories.
*/
public static function reconstitute(
int $id,
CustomerName $name,
CustomerType $type,
?BusinessId $businessId,
?PersonalIdentityCode $personalIdentityCode = null,
bool $internal = false,
?HexColor $headerColor = null,
): self {
return new self($id, $name, $type, $businessId, $personalIdentityCode, $internal, $headerColor);
}
/**
* Changes the details. A null personal identity code keeps the stored
* one, except that a company never keeps one.
*/
public function changeDetails(
CustomerName $name,
CustomerType $type,
?BusinessId $businessId,
?PersonalIdentityCode $personalIdentityCode = null,
): void {
if ($personalIdentityCode === null && $type === CustomerType::Consumer) {
$personalIdentityCode = $this->personalIdentityCode;
}
self::ensureIdentifiersFitType($type, $businessId, $personalIdentityCode);
self::ensureInternalIsCompany($this->internal, $type);
$this->name = $name;
$this->type = $type;
$this->businessId = $businessId;
$this->personalIdentityCode = $personalIdentityCode;
}
/**
* The colour of the customer's card headers on the Kanban board and of
* its rows on the time sheet. Null uses the default colour.
*/
public function changeHeaderColor(?HexColor $color): void
{
$this->headerColor = $color;
}
public function headerColor(): ?HexColor
{
return $this->headerColor;
}
public function removePersonalIdentityCode(): void
{
$this->personalIdentityCode = null;
}
public function id(): ?int
{
return $this->id;
}
public function name(): CustomerName
{
return $this->name;
}
public function type(): CustomerType
{
return $this->type;
}
public function businessId(): ?BusinessId
{
return $this->businessId;
}
public function personalIdentityCode(): ?PersonalIdentityCode
{
return $this->personalIdentityCode;
}
/**
* The company itself, whose jobs hold internal work (administration,
* sales, training). Created by a migration, never through the UI.
*/
public function isInternal(): bool
{
return $this->internal;
}
private static function ensureInternalIsCompany(bool $internal, CustomerType $type): void
{
if ($internal && $type !== CustomerType::Company) {
throw new InternalCustomerMustBeCompany;
}
}
private static function ensureIdentifiersFitType(
CustomerType $type,
?BusinessId $businessId,
?PersonalIdentityCode $personalIdentityCode,
): void {
if ($type === CustomerType::Consumer && $businessId !== null) {
throw new ConsumerCannotHaveBusinessId;
}
if ($type === CustomerType::Company && $personalIdentityCode !== null) {
throw new CompanyCannotHavePersonalIdentityCode;
}
}
}