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 6a3f8e48..e00ca4ef 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -21,6 +21,15 @@ jsonData.stock_entry_id = jsonForm.specific_stock_entry; } + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) + { + jsonData.location_id = Grocy.Components.LocationPicker.GetValue(); + } + 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 +111,10 @@ { Grocy.Components.RecipePicker.Clear(); } + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) + { + Grocy.Components.LocationPicker.Clear(); + } Grocy.Components.ProductPicker.GetInputElement().focus(); Grocy.FrontendHelpers.ValidateForm('consume-form'); } @@ -197,6 +210,10 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) { $('#amount').attr('max', productDetails.stock_amount); $('#amount_qu_unit').text(productDetails.quantity_unit_stock.name); + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) + { + Grocy.Components.LocationPicker.SetId(productDetails.location.id); + } if (productDetails.product.allow_partial_units_in_stock == 1) { diff --git a/views/consume.blade.php b/views/consume.blade.php index e31a4d8f..f21013d4 100644 --- a/views/consume.blade.php +++ b/views/consume.blade.php @@ -27,6 +27,15 @@ '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) + @include('components.locationpicker', array( + 'locations' => $locations, + 'isRequired' => false + )) + @else + + @endif +