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
@@ -0,0 +1,70 @@
<?php
namespace App\Modules\Inventory\Infrastructure\Adapters;
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Inventory\Application\Contracts\StockTasks;
use App\Modules\Inventory\Application\DTOs\StockTaskContext;
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
use App\Modules\Jobs\Application\Contracts\TaskQueries;
use App\Modules\Jobs\Application\DTOs\BookableTask;
/**
* Reads tasks from Jobs and the stock setting of their service units from
* Catalog. A task's work type decides: its unit must use stock, and a
* shared work type's task follows the job's units (spec 19).
*/
class TasksForStock implements StockTasks
{
public function __construct(
private TaskQueries $tasks,
private CustomerJobQueries $jobs,
private CatalogQueries $catalog,
) {}
public function context(int $taskId): ?StockTaskContext
{
$task = $this->tasks->bookableTask($taskId);
if ($task === null) {
return null;
}
return new StockTaskContext($task->taskId, $task->jobId, $task->label(), $this->usesStock($task), $task->isLocked());
}
public function labels(array $taskIds): array
{
$labels = [];
foreach ($this->tasks->bookableTasks($taskIds) as $task) {
$labels[$task->taskId] = $task->label();
}
return $labels;
}
private function usesStock(BookableTask $task): bool
{
$stockUnitIds = $this->catalog->stockServiceUnitIds();
if ($stockUnitIds === []) {
return false;
}
$workType = $this->catalog->findWorkType($task->workTypeId);
$unit = $workType === null ? null : $this->catalog->findServiceUnit($workType->serviceUnitId);
if ($unit === null) {
return false;
}
if (! $unit->isShared) {
return in_array($unit->id, $stockUnitIds, true);
}
$jobUnitIds = array_map(fn ($unit): int => $unit->id, $this->jobs->findDetails($task->jobId)->serviceUnits ?? []);
return array_intersect($jobUnitIds, $stockUnitIds) !== [];
}
}