Let a service unit use stock and machines
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class SharedUnitCannotUseStock extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The shared service unit follows the job\'s units and cannot use stock by itself.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user