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:
@@ -6,6 +6,7 @@ use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidCatalogName;
|
||||
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\Exceptions\WorkflowTemplateNameTaken;
|
||||
@@ -24,16 +25,34 @@ class WorkflowTemplateForm extends Form
|
||||
public string $work_type_id = '';
|
||||
|
||||
/**
|
||||
* @var list<array{key: int, title: string, work_type_id: string, description: string}>
|
||||
* @var list<array{key: int, title: string, work_type_id: string, description: string, materials: list<array{key: int, stock_item_id: string, quantity: string}>}>
|
||||
*/
|
||||
public array $steps = [];
|
||||
|
||||
public int $nextKey = 1;
|
||||
|
||||
public function addStep(string $title = '', string $workTypeId = '', string $description = ''): int
|
||||
/**
|
||||
* @param list<array{stock_item_id: string, quantity: string}> $materials
|
||||
*/
|
||||
public function addStep(string $title = '', string $workTypeId = '', string $description = '', array $materials = []): int
|
||||
{
|
||||
$key = $this->nextKey++;
|
||||
$this->steps[] = ['key' => $key, 'title' => $title, 'work_type_id' => $workTypeId, 'description' => $description];
|
||||
$this->steps[] = ['key' => $key, 'title' => $title, 'work_type_id' => $workTypeId, 'description' => $description, 'materials' => []];
|
||||
|
||||
foreach ($materials as $material) {
|
||||
$this->addMaterial(count($this->steps) - 1, $material['stock_item_id'], $material['quantity']);
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a default material row to a step and returns its key.
|
||||
*/
|
||||
public function addMaterial(int $stepIndex, string $stockItemId = '', string $quantity = '1'): int
|
||||
{
|
||||
$key = $this->nextKey++;
|
||||
$this->steps[$stepIndex]['materials'][] = ['key' => $key, 'stock_item_id' => $stockItemId, 'quantity' => $quantity];
|
||||
|
||||
return $key;
|
||||
}
|
||||
@@ -60,6 +79,7 @@ class WorkflowTemplateForm extends Form
|
||||
$exception instanceof CatalogItemNotFound => ['work_type_id', 'catalog.errors.work_type_unavailable'],
|
||||
$exception instanceof WorkflowTemplateNeedsSteps => ['steps', 'catalog.workflows.errors.steps_required'],
|
||||
$exception instanceof InvalidWorkflowStepTitle => ['steps.'.($exception->stepIndex ?? 0).'.title', 'catalog.workflows.errors.invalid_step_title'],
|
||||
$exception instanceof InvalidWorkflowStepMaterial => ['steps.'.($exception->stepIndex ?? 0).'.materials.'.($exception->materialIndex ?? 0).'.quantity', 'catalog.workflows.errors.invalid_material'],
|
||||
$exception instanceof WorkflowStepWorkTypeNotAllowed => ['steps.'.$exception->stepIndex.'.work_type_id', 'catalog.workflows.errors.step_work_type_not_allowed'],
|
||||
default => throw $exception,
|
||||
};
|
||||
@@ -79,6 +99,9 @@ class WorkflowTemplateForm extends Form
|
||||
'steps.*.title' => ['required', 'string', 'max:255'],
|
||||
'steps.*.work_type_id' => ['nullable', 'integer'],
|
||||
'steps.*.description' => ['nullable', 'string', 'max:5000'],
|
||||
'steps.*.materials' => ['array'],
|
||||
'steps.*.materials.*.stock_item_id' => ['nullable', 'integer'],
|
||||
'steps.*.materials.*.quantity' => ['nullable', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -98,6 +121,8 @@ class WorkflowTemplateForm extends Form
|
||||
'steps.*.title.max' => __('catalog.workflows.errors.invalid_step_title'),
|
||||
'steps.*.work_type_id.integer' => __('catalog.workflows.errors.step_work_type_not_allowed'),
|
||||
'steps.*.description.max' => __('catalog.workflows.errors.description_too_long'),
|
||||
'steps.*.materials.*.stock_item_id.integer' => __('catalog.workflows.errors.invalid_material'),
|
||||
'steps.*.materials.*.quantity.max' => __('catalog.workflows.errors.invalid_material'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user