$materials */ public function suggest(int $taskId, array $materials): void { $this->transactions->run(function () use ($taskId, $materials): void { foreach ($materials as $material) { $this->suggestions->add($taskId, $material['stockItemId'], $material['quantityMilli']); } }); } /** * @throws StockTaskNotAvailable * @throws StockItemNotFound * @throws StockItemInactive * @throws InvalidStockQuantity */ public function record(int $taskId, int $stockItemId, string $quantity, int $actorUserId): StockUseResult { $context = $this->tasks->context($taskId); if ($context === null || ! $context->usesStock || $context->isLocked) { throw new StockTaskNotAvailable; } return $this->recordUse->execute(new StockUseData($stockItemId, $quantity, taskId: $taskId, jobId: $context->jobId), $actorUserId); } /** * Records a suggested material with the quantity confirmed (possibly * changed) and removes the suggestion. * * @throws StockTaskSuggestionNotFound * @throws StockTaskNotAvailable * @throws StockItemNotFound * @throws StockItemInactive * @throws InvalidStockQuantity */ public function confirm(int $taskId, int $suggestionId, string $quantity, int $actorUserId): StockUseResult { return $this->transactions->run(function () use ($taskId, $suggestionId, $quantity, $actorUserId): StockUseResult { $suggestion = $this->suggestions->find($suggestionId); if ($suggestion === null || $suggestion['taskId'] !== $taskId) { throw new StockTaskSuggestionNotFound; } $result = $this->record($taskId, $suggestion['stockItemId'], $quantity, $actorUserId); $this->suggestions->remove($suggestionId); return $result; }); } /** * @throws StockTaskSuggestionNotFound */ public function dismiss(int $taskId, int $suggestionId): void { $suggestion = $this->suggestions->find($suggestionId); if ($suggestion === null || $suggestion['taskId'] !== $taskId) { throw new StockTaskSuggestionNotFound; } $this->suggestions->remove($suggestionId); } }