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
@@ -5,27 +5,45 @@ declare(strict_types=1);
namespace App\Modules\Catalog\Application\DTOs;
/**
* A step of a workflow template as entered. A null work type means the template's own.
* A step of a workflow template as entered. A null work type means the
* template's own. Materials are the step's default materials: a stock item
* id and the quantity as typed ("2,5").
*/
final readonly class WorkflowStepData
{
/**
* @param list<array{stockItemId: int, quantity: string}> $materials
*/
public function __construct(
public string $title,
public ?string $description = null,
public ?int $workTypeId = null,
public array $materials = [],
) {}
/**
* @param array{title?: string, description?: string|null, work_type_id?: int|string|null} $input
* Rows without an item are left out.
*
* @param array{title?: string, description?: string|null, work_type_id?: int|string|null, materials?: list<array{stock_item_id?: int|string|null, quantity?: string|null}>} $input
*/
public static function fromArray(array $input): self
{
$workTypeId = $input['work_type_id'] ?? null;
$materials = [];
foreach ($input['materials'] ?? [] as $material) {
$itemId = $material['stock_item_id'] ?? null;
if ($itemId !== null && $itemId !== '') {
$materials[] = ['stockItemId' => (int) $itemId, 'quantity' => (string) ($material['quantity'] ?? '')];
}
}
return new self(
(string) ($input['title'] ?? ''),
$input['description'] ?? null,
$workTypeId === null || $workTypeId === '' ? null : (int) $workTypeId,
$materials,
);
}
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace App\Modules\Catalog\Application\DTOs;
/**
* A default material of a workflow step: a stock item and its quantity in
* thousandths of the item's unit.
*/
final readonly class WorkflowStepMaterialSummary
{
public function __construct(
public int $stockItemId,
public int $quantityMilli,
) {}
}
@@ -6,15 +6,20 @@ namespace App\Modules\Catalog\Application\DTOs;
/**
* A step of a workflow template. $workTypeId is the step's own work type
* (null: the template's), $effectiveWorkTypeId the one its task gets.
* (null: the template's), $effectiveWorkTypeId the one its task gets, and
* $materials the default materials suggested on the task.
*/
final readonly class WorkflowStepSummary
{
/**
* @param list<WorkflowStepMaterialSummary> $materials
*/
public function __construct(
public string $title,
public ?string $description,
public ?int $workTypeId,
public int $effectiveWorkTypeId,
public string $workTypeName,
public array $materials = [],
) {}
}