Let a service unit use stock and machines

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:01:59 +02:00
co-authored by Claude Sonnet 5.5
parent d160854b79
commit 361a2974cf
16 changed files with 204 additions and 13 deletions
@@ -4,32 +4,51 @@ declare(strict_types=1);
namespace App\Modules\Catalog\Domain\Entities;
use App\Modules\Catalog\Domain\Exceptions\SharedUnitCannotUseStock;
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
/**
* A service unit (palveluyksikkö), e.g. Mediatuotanto. The shared unit
* ("Kaikille yhteiset") holds work types offered in every unit and has no
* services.
* services. A unit may use stock and machines (varaston ja koneiden
* käyttö); the shared unit follows the job's units instead.
*/
final class ServiceUnit extends CatalogItem
{
private function __construct(?int $id, CatalogName $name, private bool $shared, bool $active, int $sortOrder)
private function __construct(?int $id, CatalogName $name, private bool $shared, bool $active, int $sortOrder, private bool $usesStock)
{
parent::__construct($id, $name, $active, $sortOrder);
}
public static function create(CatalogName $name, int $sortOrder, bool $shared = false): self
{
return new self(null, $name, $shared, true, $sortOrder);
return new self(null, $name, $shared, true, $sortOrder, false);
}
public static function reconstitute(int $id, CatalogName $name, bool $shared, bool $active, int $sortOrder): self
public static function reconstitute(int $id, CatalogName $name, bool $shared, bool $active, int $sortOrder, bool $usesStock = false): self
{
return new self($id, $name, $shared, $active, $sortOrder);
return new self($id, $name, $shared, $active, $sortOrder, $usesStock);
}
public function isShared(): bool
{
return $this->shared;
}
public function usesStock(): bool
{
return $this->usesStock;
}
/**
* @throws SharedUnitCannotUseStock
*/
public function useStock(bool $usesStock): void
{
if ($usesStock && $this->shared) {
throw new SharedUnitCannotUseStock;
}
$this->usesStock = $usesStock;
}
}