mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
recipes can create products (#501)
This commit is contained in:
parent
c22496ca7c
commit
3a36bdaf45
@ -20,6 +20,25 @@ ADD correlation_id TEXT;
|
|||||||
ALTER TABLE stock_log
|
ALTER TABLE stock_log
|
||||||
ADD transaction_id TEXT;
|
ADD transaction_id TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE recipes
|
||||||
|
ADD product_id INTEGER;
|
||||||
|
|
||||||
|
DROP VIEW recipes_resolved;
|
||||||
|
CREATE VIEW recipes_resolved
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
1 AS id, -- Dummy, LessQL needs an id column
|
||||||
|
r.id AS recipe_id,
|
||||||
|
IFNULL(MIN(rpr.need_fulfilled), 1) AS need_fulfilled,
|
||||||
|
IFNULL(MIN(rpr.need_fulfilled_with_shopping_list), 1) AS need_fulfilled_with_shopping_list, (
|
||||||
|
SELECT COUNT(*) FROM recipes_pos_resolved WHERE recipe_id = r.id AND need_fulfilled = 0) AS missing_products_count,
|
||||||
|
IFNULL(SUM(rpr.costs), 0) AS costs,
|
||||||
|
IFNULL(SUM(rpr.calories), 0) AS calories
|
||||||
|
FROM recipes r
|
||||||
|
LEFT JOIN recipes_pos_resolved rpr
|
||||||
|
ON r.id = rpr.recipe_id
|
||||||
|
GROUP BY r.id;
|
||||||
|
|
||||||
ALTER TABLE stock_log
|
ALTER TABLE stock_log
|
||||||
ADD stock_row_id INTEGER;
|
ADD stock_row_id INTEGER;
|
||||||
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
$('#save-recipe-button').on('click', function(e)
|
$(document).ready(function() {
|
||||||
|
Grocy.Components.ProductPicker.GetPicker().trigger('change');
|
||||||
|
} );
|
||||||
|
|
||||||
|
$('#save-recipe-button').on('click', function(e)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -349,3 +353,13 @@ $(window).on("message", function(e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||||
|
{
|
||||||
|
var productId = $(e.target).val();
|
||||||
|
|
||||||
|
if (productId)
|
||||||
|
{
|
||||||
|
Grocy.Components.ProductCard.Refresh(productId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@ -67,6 +67,15 @@ class RecipesService extends BaseService
|
|||||||
throw new \Exception('Recipe does not exist');
|
throw new \Exception('Recipe does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$recipeRow = $this->Database->recipes()->where('id = :1', $recipeId)->fetch();
|
||||||
|
if ($recipeRow->product_id != null)
|
||||||
|
{
|
||||||
|
$recipeResolvedRow = $this->Database->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch();
|
||||||
|
$price = number_format($recipeResolvedRow->costs, 2);
|
||||||
|
$bookingAmount = floatval($recipeRow->desired_servings);
|
||||||
|
$this->StockService->AddProduct($recipeRow->product_id, $bookingAmount, null, StockService::TRANSACTION_TYPE_PURCHASE, date('Y-m-d'), $price);
|
||||||
|
}
|
||||||
|
|
||||||
$recipePositions = $this->Database->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll();
|
$recipePositions = $this->Database->recipes_pos_resolved()->where('recipe_id', $recipeId)->fetchAll();
|
||||||
foreach ($recipePositions as $recipePosition)
|
foreach ($recipePositions as $recipePosition)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +63,12 @@
|
|||||||
'hint' => $__t('The ingredients listed here result in this amount of servings')
|
'hint' => $__t('The ingredients listed here result in this amount of servings')
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@include('components.productpicker', array(
|
||||||
|
'products' => $products,
|
||||||
|
'isRequired' => false,
|
||||||
|
'label' => 'Creates Product'
|
||||||
|
))
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input type="hidden" name="not_check_shoppinglist" value="0">
|
<input type="hidden" name="not_check_shoppinglist" value="0">
|
||||||
@ -216,8 +222,14 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row mt-5">
|
||||||
|
<div class="col">
|
||||||
|
@include('components.productcard')
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" id="recipe-include-editform-modal" tabindex="-1">
|
<div class="modal fade" id="recipe-include-editform-modal" tabindex="-1">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
@ -137,7 +137,7 @@
|
|||||||
<a class="btn btn-sm btn-outline-primary py-0 recipe-order-missing-button hide-when-embedded hide-on-fullscreen-card @if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $selectedRecipe->id)->need_fulfilled_with_shopping_list == 1) disabled @endif" href="#" data-toggle="tooltip" title="{{ $__t('Put missing products on shopping list') }}" data-recipe-id="{{ $selectedRecipe->id }}" data-recipe-name="{{ $selectedRecipe->name }}">
|
<a class="btn btn-sm btn-outline-primary py-0 recipe-order-missing-button hide-when-embedded hide-on-fullscreen-card @if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $selectedRecipe->id)->need_fulfilled_with_shopping_list == 1) disabled @endif" href="#" data-toggle="tooltip" title="{{ $__t('Put missing products on shopping list') }}" data-recipe-id="{{ $selectedRecipe->id }}" data-recipe-name="{{ $selectedRecipe->name }}">
|
||||||
<i class="fas fa-cart-plus"></i>
|
<i class="fas fa-cart-plus"></i>
|
||||||
</a>
|
</a>
|
||||||
<a id="selectedRecipeEditButton" class="btn btn-sm btn-outline-info hide-when-embedded hide-on-fullscreen-card py-0" href="{{ $U('/recipe/') }}{{ $selectedRecipe->id }}">
|
<a id="selectedRecipeEditButton" class="btn btn-sm btn-outline-info hide-when-embedded hide-on-fullscreen-card py-0" href="{{ $U('/recipe/') }}{{ $selectedRecipe->id }}?product={{ $selectedRecipe->product_id }}">
|
||||||
<i class="fas fa-edit"></i>
|
<i class="fas fa-edit"></i>
|
||||||
</a>
|
</a>
|
||||||
<a id="selectedRecipeDeleteButton" class="btn btn-sm btn-outline-danger hide-when-embedded hide-on-fullscreen-card py-0" href="#" data-recipe-id="{{ $selectedRecipe->id }}" data-recipe-name="{{ $selectedRecipe->name }}">
|
<a id="selectedRecipeDeleteButton" class="btn btn-sm btn-outline-danger hide-when-embedded hide-on-fullscreen-card py-0" href="#" data-recipe-id="{{ $selectedRecipe->id }}" data-recipe-name="{{ $selectedRecipe->name }}">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user