diff --git a/services/RecipesService.php b/services/RecipesService.php index 5fc86e72..f843d5d7 100644 --- a/services/RecipesService.php +++ b/services/RecipesService.php @@ -74,12 +74,6 @@ class RecipesService extends BaseService throw new \Exception('Recipe does not exist'); } - $recipeResolved = $this->getDatabase()->recipes_resolved()->where('recipe_id', $recipeId)->fetch(); - if ($recipeResolved->need_fulfilled == 0) - { - throw new \Exception('Recipe need is not fulfilled, consuming not possible'); - } - $transactionId = uniqid(); $recipePositions = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll(); @@ -90,11 +84,11 @@ class RecipesService extends BaseService { if ($recipePosition->only_check_single_unit_in_stock == 0) { - $this->getStockService()->ConsumeProduct($recipePosition->product_id, $recipePosition->recipe_amount, false, StockService::TRANSACTION_TYPE_CONSUME, 'default', $recipeId, null, $transactionId, true, true); + $this->getStockService()->ConsumeProduct($recipePosition->product_id, $recipePosition->recipe_amount, false, StockService::TRANSACTION_TYPE_CONSUME, 'default', $recipeId, null, $transactionId, true, true, true); } } } - catch (Exception $ex) + catch (\Exception $ex) { $this->getDatabaseService()->GetDbConnectionRaw()->rollback(); throw $ex; diff --git a/services/StockService.php b/services/StockService.php index c67bc115..9cd8a6d2 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -357,7 +357,7 @@ class StockService extends BaseService } } - public function ConsumeProduct(int $productId, float $amount, bool $spoiled, $transactionType, $specificStockEntryId = 'default', $recipeId = null, $locationId = null, &$transactionId = null, $allowSubproductSubstitution = false, $consumeExactAmount = false) + public function ConsumeProduct(int $productId, float $amount, bool $spoiled, $transactionType, $specificStockEntryId = 'default', $recipeId = null, $locationId = null, &$transactionId = null, $allowSubproductSubstitution = false, $consumeExactAmount = false, $consume_all_available = false) { if (!$this->ProductExists($productId)) { @@ -409,7 +409,11 @@ class StockService extends BaseService $productStockAmount = floatval($productDetails->stock_amount_aggregated); if (round($amount, 2) > round($productStockAmount, 2)) { - throw new \Exception('Amount to be consumed cannot be > current stock amount (if supplied, at the desired location)'); + if ($consume_all_available) { + $amount = $productStockAmount; + } else { + throw new \Exception('Amount to be consumed cannot be > current stock amount (if supplied, at the desired location)'); + } } if ($transactionId === null) diff --git a/views/recipes.blade.php b/views/recipes.blade.php index 23c6f45e..8324ce5f 100644 --- a/views/recipes.blade.php +++ b/views/recipes.blade.php @@ -313,7 +313,7 @@

{{ $recipe->name }}

-

{{ $recipe->name }}

-