mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 21:26:16 +02:00
parent
efc7b999bb
commit
c8ed8b6a16
|
|
@ -74,12 +74,6 @@ class RecipesService extends BaseService
|
||||||
throw new \Exception('Recipe does not exist');
|
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();
|
$transactionId = uniqid();
|
||||||
$recipePositions = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll();
|
$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)
|
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();
|
$this->getDatabaseService()->GetDbConnectionRaw()->rollback();
|
||||||
throw $ex;
|
throw $ex;
|
||||||
|
|
|
||||||
|
|
@ -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))
|
if (!$this->ProductExists($productId))
|
||||||
{
|
{
|
||||||
|
|
@ -409,7 +409,11 @@ class StockService extends BaseService
|
||||||
$productStockAmount = floatval($productDetails->stock_amount_aggregated);
|
$productStockAmount = floatval($productDetails->stock_amount_aggregated);
|
||||||
if (round($amount, 2) > round($productStockAmount, 2))
|
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)
|
if ($transactionId === null)
|
||||||
|
|
|
||||||
|
|
@ -313,7 +313,7 @@
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<h3 class="card-title mb-0">{{ $recipe->name }}</h3>
|
<h3 class="card-title mb-0">{{ $recipe->name }}</h3>
|
||||||
<div class="card-icons d-flex flex-wrap justify-content-end flex-shrink-1">
|
<div class="card-icons d-flex flex-wrap justify-content-end flex-shrink-1">
|
||||||
<a class="btn @if(!GROCY_FEATURE_FLAG_STOCK) d-none @endif recipe-consume @if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled == 0) disabled @endif"
|
<a class="btn @if(!GROCY_FEATURE_FLAG_STOCK) d-none @endif recipe-consume"
|
||||||
href="#"
|
href="#"
|
||||||
data-toggle="tooltip"
|
data-toggle="tooltip"
|
||||||
title="{{ $__t('Consume all ingredients needed by this recipe') }}"
|
title="{{ $__t('Consume all ingredients needed by this recipe') }}"
|
||||||
|
|
@ -349,7 +349,7 @@
|
||||||
<div class="mb-4 @if(!empty($recipe->picture_file_name)) d-none @else d-flex @endif d-print-block justify-content-between align-items-center">
|
<div class="mb-4 @if(!empty($recipe->picture_file_name)) d-none @else d-flex @endif d-print-block justify-content-between align-items-center">
|
||||||
<h1 class="card-title mb-0">{{ $recipe->name }}</h1>
|
<h1 class="card-title mb-0">{{ $recipe->name }}</h1>
|
||||||
<div class="card-icons d-flex flex-wrap justify-content-end flex-shrink-1 d-print-none">
|
<div class="card-icons d-flex flex-wrap justify-content-end flex-shrink-1 d-print-none">
|
||||||
<a class="btn recipe-consume @if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled == 0) disabled @endif"
|
<a class="btn recipe-consume"
|
||||||
href="#"
|
href="#"
|
||||||
data-toggle="tooltip"
|
data-toggle="tooltip"
|
||||||
title="{{ $__t('Consume all ingredients needed by this recipe') }}"
|
title="{{ $__t('Consume all ingredients needed by this recipe') }}"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user