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
@@ -3,10 +3,12 @@
namespace App\Modules\Catalog\Infrastructure\Persistence\Repositories;
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
use App\Modules\Catalog\Application\DTOs\WorkflowStepMaterialSummary;
use App\Modules\Catalog\Application\DTOs\WorkflowStepSummary;
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateDetails;
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateSummary;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateStepMaterialModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateStepModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use Illuminate\Database\Eloquent\Builder;
@@ -93,6 +95,7 @@ class EloquentWorkflowTemplateQueries implements WorkflowTemplateQueries
}
$steps = WorkflowTemplateStepModel::query()
->with('materials')
->whereIn('workflow_template_id', $models->pluck('id'))
->orderBy('sort_order')
->get()
@@ -119,6 +122,10 @@ class EloquentWorkflowTemplateQueries implements WorkflowTemplateQueries
$step->work_type_id,
$step->work_type_id ?? $model->work_type_id,
$step->work_type_id === null ? $workTypeName : (string) $workTypeNames->get($step->work_type_id),
$step->materials
->map(fn (WorkflowTemplateStepMaterialModel $material): WorkflowStepMaterialSummary => new WorkflowStepMaterialSummary($material->stock_item_id, $material->quantity_milli))
->values()
->all(),
))
->values()
->all(),
@@ -6,15 +6,17 @@ use App\Modules\Catalog\Domain\Contracts\WorkflowTemplateRepository;
use App\Modules\Catalog\Domain\Entities\WorkflowTemplate;
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStep;
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStepMaterial;
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStepTitle;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateStepMaterialModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateStepModel;
class EloquentWorkflowTemplateRepository implements WorkflowTemplateRepository
{
public function findById(int $id): ?WorkflowTemplate
{
$model = WorkflowTemplateModel::query()->with('steps')->find($id);
$model = WorkflowTemplateModel::query()->with('steps.materials')->find($id);
return $model === null ? null : $this->toEntity($model);
}
@@ -33,16 +35,25 @@ class EloquentWorkflowTemplateRepository implements WorkflowTemplateRepository
WorkflowTemplateStepModel::query()->where('workflow_template_id', $model->id)->delete();
foreach ($template->steps() as $index => $step) {
WorkflowTemplateStepModel::query()->create([
$stepModel = WorkflowTemplateStepModel::query()->create([
'workflow_template_id' => $model->id,
'work_type_id' => $step->workTypeId,
'title' => $step->title->value,
'description' => $step->description,
'sort_order' => $index + 1,
]);
foreach ($step->materials as $materialIndex => $material) {
WorkflowTemplateStepMaterialModel::query()->create([
'workflow_template_step_id' => $stepModel->id,
'stock_item_id' => $material->stockItemId,
'quantity_milli' => $material->quantityMilli,
'sort_order' => $materialIndex + 1,
]);
}
}
return $this->toEntity($model->load('steps'));
return $this->toEntity($model->load('steps.materials'));
}
public function isNameTaken(int $workTypeId, string $name, ?int $exceptId = null): bool
@@ -66,6 +77,10 @@ class EloquentWorkflowTemplateRepository implements WorkflowTemplateRepository
new WorkflowStepTitle($step->title),
$step->description,
$step->work_type_id,
$step->materials
->map(fn (WorkflowTemplateStepMaterialModel $material): WorkflowStepMaterial => new WorkflowStepMaterial($material->stock_item_id, $material->quantity_milli))
->values()
->all(),
))
->values()
->all(),