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:
2026-11-26 16:28:16 +02:00
co-authored by Claude Sonnet 5.5
parent 30132deb0e
commit bca1eed166
41 changed files with 1521 additions and 19 deletions
@@ -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'));
}
}