Add machines with day-by-day work lists for job tasks

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:43:55 +02:00
co-authored by Claude Sonnet 5.5
parent 0de0e332b2
commit aac579257a
59 changed files with 3803 additions and 1 deletions
@@ -0,0 +1,162 @@
<?php
declare(strict_types=1);
namespace App\Modules\Machines\Domain\Entities;
use App\Modules\Machines\Domain\Enums\MachineType;
use App\Modules\Machines\Domain\Exceptions\MachineInactive;
use App\Modules\Machines\Domain\Exceptions\MachineNeedsServiceUnit;
use App\Modules\Machines\Domain\ValueObjects\MachineCounter;
use App\Modules\Machines\Domain\ValueObjects\MachineName;
/**
* A machine (kone, spec 19.4): a printing press, a sticker cutter or other,
* in one or more service units, with a responsible person who gets the
* maintenance notifications, and counters. Machines are never deleted: one
* out of use is not offered, but its history stays.
*/
final class Machine
{
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*/
private function __construct(
private ?int $id,
private MachineName $name,
private MachineType $type,
private ?string $description,
private array $serviceUnitIds,
private ?int $responsibleUserId,
private array $counters,
private bool $active,
) {
if ($serviceUnitIds === []) {
throw new MachineNeedsServiceUnit;
}
}
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*
* @throws MachineNeedsServiceUnit
*/
public static function create(MachineName $name, MachineType $type, ?string $description, array $serviceUnitIds, ?int $responsibleUserId, array $counters): self
{
return new self(null, $name, $type, self::text($description), array_values(array_unique($serviceUnitIds)), $responsibleUserId, $counters, true);
}
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*/
public static function reconstitute(int $id, MachineName $name, MachineType $type, ?string $description, array $serviceUnitIds, ?int $responsibleUserId, array $counters, bool $active): self
{
return new self($id, $name, $type, $description, $serviceUnitIds, $responsibleUserId, $counters, $active);
}
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*
* @throws MachineNeedsServiceUnit
*/
public function change(MachineName $name, MachineType $type, ?string $description, array $serviceUnitIds, ?int $responsibleUserId, array $counters): void
{
if ($serviceUnitIds === []) {
throw new MachineNeedsServiceUnit;
}
$this->name = $name;
$this->type = $type;
$this->description = self::text($description);
$this->serviceUnitIds = array_values(array_unique($serviceUnitIds));
$this->responsibleUserId = $responsibleUserId;
$this->counters = $counters;
}
/**
* Whether the machine serves any of the service units.
*
* @param list<int> $serviceUnitIds
*/
public function servesAnyOf(array $serviceUnitIds): bool
{
return array_intersect($this->serviceUnitIds, $serviceUnitIds) !== [];
}
/**
* @throws MachineInactive
*/
public function ensureActive(): void
{
if (! $this->active) {
throw new MachineInactive;
}
}
public function activate(): void
{
$this->active = true;
}
public function deactivate(): void
{
$this->active = false;
}
public function id(): ?int
{
return $this->id;
}
public function name(): MachineName
{
return $this->name;
}
public function type(): MachineType
{
return $this->type;
}
public function description(): ?string
{
return $this->description;
}
/**
* @return list<int>
*/
public function serviceUnitIds(): array
{
return $this->serviceUnitIds;
}
public function responsibleUserId(): ?int
{
return $this->responsibleUserId;
}
/**
* @return list<MachineCounter>
*/
public function counters(): array
{
return $this->counters;
}
public function isActive(): bool
{
return $this->active;
}
private static function text(?string $value): ?string
{
$value = $value === null ? '' : trim($value);
return $value === '' ? null : mb_substr($value, 0, 5000);
}
}
@@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
namespace App\Modules\Machines\Domain\Entities;
use App\Modules\Machines\Domain\Exceptions\QueueEntryCompleted;
use DateTimeImmutable;
/**
* A row of a machine's work list (spec 19.4): a job's task, or a step of a
* quick sale order line, to be made on the machine on its planned day, in
* its position among that day's rows. A row not made on its day stays open
* and shows as late on the following days. Completed rows leave the list.
*/
final class QueueEntry
{
private function __construct(
private ?int $id,
private int $machineId,
private DateTimeImmutable $plannedOn,
private int $position,
private ?int $taskId,
private ?int $orderLineId,
private ?int $stepPosition,
private ?DateTimeImmutable $completedAt,
private ?int $completedBy,
) {}
public static function forTask(int $machineId, int $taskId, DateTimeImmutable $plannedOn, int $position): self
{
return new self(null, $machineId, $plannedOn, $position, $taskId, null, null, null, null);
}
public static function forOrderLine(int $machineId, int $orderLineId, int $stepPosition, DateTimeImmutable $plannedOn, int $position): self
{
return new self(null, $machineId, $plannedOn, $position, null, $orderLineId, $stepPosition, null, null);
}
public static function reconstitute(int $id, int $machineId, DateTimeImmutable $plannedOn, int $position, ?int $taskId, ?int $orderLineId, ?int $stepPosition, ?DateTimeImmutable $completedAt, ?int $completedBy): self
{
return new self($id, $machineId, $plannedOn, $position, $taskId, $orderLineId, $stepPosition, $completedAt, $completedBy);
}
/**
* @throws QueueEntryCompleted
*/
public function plan(int $machineId, DateTimeImmutable $plannedOn, int $position): void
{
$this->ensureOpen();
$this->machineId = $machineId;
$this->plannedOn = $plannedOn;
$this->position = $position;
}
public function moveTo(int $position): void
{
$this->position = $position;
}
/**
* @param int|null $userId Null when the task was marked done elsewhere.
*
* @throws QueueEntryCompleted
*/
public function complete(?int $userId, DateTimeImmutable $at): void
{
$this->ensureOpen();
$this->completedBy = $userId;
$this->completedAt = $at;
}
/**
* @throws QueueEntryCompleted
*/
public function ensureOpen(): void
{
if ($this->completedAt !== null) {
throw new QueueEntryCompleted;
}
}
public function isOrderLine(): bool
{
return $this->orderLineId !== null;
}
public function id(): ?int
{
return $this->id;
}
public function machineId(): int
{
return $this->machineId;
}
public function plannedOn(): DateTimeImmutable
{
return $this->plannedOn;
}
public function position(): int
{
return $this->position;
}
public function taskId(): ?int
{
return $this->taskId;
}
public function orderLineId(): ?int
{
return $this->orderLineId;
}
public function stepPosition(): ?int
{
return $this->stepPosition;
}
public function completedAt(): ?DateTimeImmutable
{
return $this->completedAt;
}
public function completedBy(): ?int
{
return $this->completedBy;
}
}