diff --git a/controllers/StockController.php b/controllers/StockController.php
index ec946ae0..1b763c56 100644
--- a/controllers/StockController.php
+++ b/controllers/StockController.php
@@ -50,7 +50,8 @@ class StockController extends BaseController
{
return $this->AppContainer->view->render($response, 'consume', [
'products' => $this->Database->products()->orderBy('name'),
- 'recipes' => $this->Database->recipes()->orderBy('name')
+ 'recipes' => $this->Database->recipes()->orderBy('name'),
+ 'locations' => $this->Database->locations()->orderBy('name')
]);
}
diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js
index 1a7bffb4..75e32076 100644
--- a/public/viewjs/consume.js
+++ b/public/viewjs/consume.js
@@ -5,11 +5,6 @@
var jsonForm = $('#consume-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("consume-form");
- if ($("#use_specific_stock_entry").is(":checked"))
- {
- jsonForm.amount = 1;
- }
-
var apiUrl = 'stock/products/' + jsonForm.product_id + '/consume';
var jsonData = {};
@@ -21,6 +16,15 @@
jsonData.stock_entry_id = jsonForm.specific_stock_entry;
}
+ if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
+ {
+ jsonData.location_id = $("#location_id").val();
+ }
+ else
+ {
+ jsonData.location_id = 1;
+ }
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_RECIPES && Grocy.Components.RecipePicker.GetValue().toString().length > 0)
{
jsonData.recipe_id = Grocy.Components.RecipePicker.GetValue();
@@ -102,6 +106,10 @@
{
Grocy.Components.RecipePicker.Clear();
}
+ if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
+ {
+ $("#location_id").find("option").remove().end().append("");
+ }
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('consume-form');
}
@@ -128,11 +136,6 @@ $('#save-mark-as-open-button').on('click', function(e)
var jsonForm = $('#consume-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("consume-form");
- if ($("#use_specific_stock_entry").is(":checked"))
- {
- jsonForm.amount = 1;
- }
-
var apiUrl = 'stock/products/' + jsonForm.product_id + '/open';
jsonData = { };
@@ -178,6 +181,59 @@ $('#save-mark-as-open-button').on('click', function(e)
);
});
+$("#location_id").on('change', function(e)
+{
+ var locationId = $(e.target).val();
+ var sumValue = 0;
+ $("#specific_stock_entry").find("option").remove().end().append("");
+ if ($("#use_specific_stock_entry").is(":checked"))
+ {
+ $("#use_specific_stock_entry").click();
+ }
+
+ if (locationId)
+ {
+ Grocy.Api.Get("stock/products/" + Grocy.Components.ProductPicker.GetValue() + '/entries',
+ function(stockEntries)
+ {
+ stockEntries.forEach(stockEntry =>
+ {
+ if (stockEntry.location_id == locationId)
+ {
+ $("#specific_stock_entry").append($("");
@@ -185,6 +241,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
$("#use_specific_stock_entry").click();
}
+ $("#location_id").val("");
var productId = $(e.target).val();
@@ -195,9 +252,41 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
Grocy.Api.Get('stock/products/' + productId,
function(productDetails)
{
- $('#amount').attr('max', productDetails.stock_amount);
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
+ $("#location_id").find("option").remove().end().append("");
+ Grocy.Api.Get("stock/products/" + productId + '/locations',
+ function(stockLocations)
+ {
+ var setDefault = 0;
+ stockLocations.forEach(stockLocation =>
+ {
+ if (productDetails.location.id == stockLocation.location_id) {
+ $("#location_id").append($("");
$("#specific_stock_entry").attr("disabled", "");
- $("#amount").removeAttr("disabled");
- $("#amount").attr("required", "");
$("#specific_stock_entry").removeAttr("required");
}
diff --git a/views/consume.blade.php b/views/consume.blade.php
index e31a4d8f..61a7d51b 100644
--- a/views/consume.blade.php
+++ b/views/consume.blade.php
@@ -22,11 +22,33 @@
'label' => 'Amount',
'hintId' => 'amount_qu_unit',
'min' => 1,
- 'value' => 1,
+ 'value' => 0,
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
'additionalHtmlContextHelp' => '
' . $__t('Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated') . '
'
))
+ @if(GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
+ @php /*@include('components.locationpicker', array(
+ 'id' => 'location_id',
+ 'locations' => $locations,
+ 'isRequired' => true,
+ 'label' => 'Location'
+ ))*/ @endphp
+
+
+ @else
+
+ @endif
+