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:
@@ -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 = [],
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Domain\Contracts\ServiceUnitRepository;
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkTypeRepository;
|
||||
use App\Modules\Catalog\Domain\Entities\WorkType;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidWorkflowStepMaterial;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidWorkflowStepTitle;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowStepWorkTypeNotAllowed;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStep;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStepMaterial;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStepTitle;
|
||||
|
||||
/**
|
||||
@@ -28,6 +30,7 @@ final class WorkflowStepBuilder
|
||||
* @return list<WorkflowStep>
|
||||
*
|
||||
* @throws InvalidWorkflowStepTitle with the index of the step
|
||||
* @throws InvalidWorkflowStepMaterial with the indexes of the step and the material
|
||||
*/
|
||||
public function build(array $input): array
|
||||
{
|
||||
@@ -40,7 +43,17 @@ final class WorkflowStepBuilder
|
||||
throw new InvalidWorkflowStepTitle($index);
|
||||
}
|
||||
|
||||
$steps[] = new WorkflowStep($title, $step->description, $step->workTypeId);
|
||||
$materials = [];
|
||||
|
||||
foreach ($step->materials as $materialIndex => $material) {
|
||||
try {
|
||||
$materials[] = WorkflowStepMaterial::parse($material['stockItemId'], $material['quantity']);
|
||||
} catch (InvalidWorkflowStepMaterial) {
|
||||
throw new InvalidWorkflowStepMaterial($index, $materialIndex);
|
||||
}
|
||||
}
|
||||
|
||||
$steps[] = new WorkflowStep($title, $step->description, $step->workTypeId, $materials);
|
||||
}
|
||||
|
||||
return $steps;
|
||||
|
||||
Reference in New Issue
Block a user