Record used material on tasks and suggest workflow steps' default materials
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
/**
|
||||
* A step's default material has no item or no valid quantity. $stepIndex
|
||||
* and $materialIndex count from 0 when known.
|
||||
*/
|
||||
final class InvalidWorkflowStepMaterial extends DomainException
|
||||
{
|
||||
public function __construct(public readonly ?int $stepIndex = null, public readonly ?int $materialIndex = null)
|
||||
{
|
||||
parent::__construct('A default material needs an item and a quantity greater than zero.');
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,20 @@ namespace App\Modules\Catalog\Domain\ValueObjects;
|
||||
/**
|
||||
* One step of a workflow template. A task is made of it: the title, the
|
||||
* description and the work type, which is the template's own when
|
||||
* $workTypeId is null.
|
||||
* $workTypeId is null, and the default materials suggested on the task.
|
||||
*/
|
||||
final readonly class WorkflowStep
|
||||
{
|
||||
public ?string $description;
|
||||
|
||||
/**
|
||||
* @param list<WorkflowStepMaterial> $materials
|
||||
*/
|
||||
public function __construct(
|
||||
public WorkflowStepTitle $title,
|
||||
?string $description = null,
|
||||
public ?int $workTypeId = null,
|
||||
public array $materials = [],
|
||||
) {
|
||||
$description = $description === null ? '' : trim($description);
|
||||
$this->description = $description === '' ? null : $description;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidWorkflowStepMaterial;
|
||||
|
||||
/**
|
||||
* A default material of a workflow step (spec 19.4): a stock item and its
|
||||
* quantity in thousandths of the item's unit, suggested on the step's task.
|
||||
*/
|
||||
final readonly class WorkflowStepMaterial
|
||||
{
|
||||
public const int MAX_MILLI = 9_999_999_999;
|
||||
|
||||
public function __construct(
|
||||
public int $stockItemId,
|
||||
public int $quantityMilli,
|
||||
) {
|
||||
if ($stockItemId < 1 || $quantityMilli < 1 || $quantityMilli > self::MAX_MILLI) {
|
||||
throw new InvalidWorkflowStepMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A quantity typed as "2,5" or "2.5", with at most three decimals.
|
||||
*
|
||||
* @throws InvalidWorkflowStepMaterial
|
||||
*/
|
||||
public static function parse(int $stockItemId, string $quantity): self
|
||||
{
|
||||
$quantity = str_replace(',', '.', preg_replace('/[\s\x{00A0}]+/u', '', $quantity) ?? '');
|
||||
|
||||
if (preg_match('/^(\d{1,7})(?:\.(\d{1,3}))?$/', $quantity, $matches) !== 1) {
|
||||
throw new InvalidWorkflowStepMaterial;
|
||||
}
|
||||
|
||||
return new self($stockItemId, (int) $matches[1] * 1000 + (int) str_pad($matches[2] ?? '', 3, '0'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user