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
@@ -15,6 +15,7 @@ use App\Modules\Jobs\Domain\Contracts\TaskRepository;
use App\Modules\Jobs\Domain\Entities\Task;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Domain\Events\PeopleAddedToTask;
use App\Modules\Jobs\Domain\Events\TaskMaterialsSuggested;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
@@ -31,7 +32,8 @@ use App\Modules\Users\Application\Contracts\Clock;
* assignee entered for it (without an entry, the adder is the assignee).
* When asked, a task with a due date is scheduled to end on it, booked
* backwards from the due date (TaskPlanner::planBackwards). The tasks are
* copies, so later changes to the template do not touch them.
* copies, so later changes to the template do not touch them. A step's
* default materials are published as suggestions for its task.
*/
final class AddTasksFromWorkflowTemplate
{
@@ -98,6 +100,14 @@ final class AddTasksFromWorkflowTemplate
if ($added !== null) {
$this->events->dispatch($added);
}
if ($step->materials !== []) {
$this->events->dispatch(new TaskMaterialsSuggested(
(int) $task->id(),
$jobId,
array_map(fn ($material): array => ['stockItemId' => $material->stockItemId, 'quantityMilli' => $material->quantityMilli], $step->materials),
));
}
}
return new TemplateTasksResult(count($template->steps), $scheduled, $late);