diff --git a/config-dist.php b/config-dist.php index 9186c8e1..7e03ce8e 100644 --- a/config-dist.php +++ b/config-dist.php @@ -48,3 +48,8 @@ DefaultUserSetting('auto_reload_on_db_change', true); # Show a clock in the header next to the logo or not DefaultUserSetting('show_clock_in_header', false); + +# Shopping list to stock workflow: +# Automatically do the booking using the last price and the amount +# of the shopping list item, if the product has "Default best before days" set +DefaultUserSetting('shopping_list_to_stock_workflow_auto_submit_when_prefilled', false); diff --git a/controllers/StockController.php b/controllers/StockController.php index fb133f49..84d303aa 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -70,9 +70,9 @@ class StockController extends BaseController ]); } - public function ProductDefaults(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + public function StockSettings(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { - return $this->AppContainer->view->render($response, 'productpresets', [ + return $this->AppContainer->view->render($response, 'stocksettings', [ 'locations' => $this->Database->locations()->orderBy('name'), 'quantityunits' => $this->Database->quantity_units()->orderBy('name'), 'productGroups' => $this->Database->product_groups()->orderBy('name') diff --git a/localization/en/strings.php b/localization/en/strings.php index 45f05fca..55ce25b9 100644 --- a/localization/en/strings.php +++ b/localization/en/strings.php @@ -322,5 +322,8 @@ return array( 'Task due' => 'Task due', 'Chore due' => 'Chore due', 'Battery charge cycle due' => 'Battery charge cycle due', - 'Show clock in header' => 'Show clock in header' + 'Show clock in header' => 'Show clock in header', + 'Stock settings' => 'Stock settings', + 'Shopping list to stock workflow' => 'Shopping list to stock workflow', + 'Automatically do the booking using the last price and the amount of the shopping list item, if the product has "Default best before days" set' => 'Automatically do the booking using the last price and the amount of the shopping list item, if the product has "Default best before days" set' ); diff --git a/public/js/grocy.js b/public/js/grocy.js index af778959..f15ffc25 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -357,3 +357,9 @@ function WindowMessageBag(message, payload = null) obj.Payload = payload; return obj; } + +// Add border around anchor link section +if (window.location.hash) +{ + $(window.location.hash).addClass("p-2 border border-info rounded"); +} diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 331dfe05..e447cb69 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -104,6 +104,13 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) Grocy.Components.DateTimePicker.SetValue(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD')); } $('#amount').focus(); + + Grocy.FrontendHelpers.ValidateForm('purchase-form'); + if (GetUriParam("flow") === "shoppinglistitemtostock" && BoolVal(Grocy.UserSettings.shopping_list_to_stock_workflow_auto_submit_when_prefilled) && document.getElementById("purchase-form").checkValidity() === true) + { + console.log("hey"); + $("#save-purchase-button").click(); + } } else { @@ -174,7 +181,7 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e) Grocy.FrontendHelpers.ValidateForm('purchase-form'); }); -$('#amount').on('change', function (e) +$('#amount').on('change', function(e) { Grocy.FrontendHelpers.ValidateForm('purchase-form'); }); diff --git a/public/viewjs/productpresets.js b/public/viewjs/stocksettings.js similarity index 58% rename from public/viewjs/productpresets.js rename to public/viewjs/stocksettings.js index 5280271a..10bf28d8 100644 --- a/public/viewjs/productpresets.js +++ b/public/viewjs/stocksettings.js @@ -1,3 +1,8 @@ $("#product_presets_location_id").val(Grocy.UserSettings.product_presets_location_id); $("#product_presets_product_group_id").val(Grocy.UserSettings.product_presets_product_group_id); $("#product_presets_qu_id").val(Grocy.UserSettings.product_presets_qu_id); + +if (BoolVal(Grocy.UserSettings.shopping_list_to_stock_workflow_auto_submit_when_prefilled)) +{ + $("#shopping-list-to-stock-workflow-auto-submit-when-prefilled").prop("checked", true); +} diff --git a/routes.php b/routes.php index 2b924cd4..b7b13ad7 100644 --- a/routes.php +++ b/routes.php @@ -26,7 +26,7 @@ $app->group('', function() $this->get('/inventory', '\Grocy\Controllers\StockController:Inventory'); $this->get('/products', '\Grocy\Controllers\StockController:ProductsList'); $this->get('/product/{productId}', '\Grocy\Controllers\StockController:ProductEditForm'); - $this->get('/productpresets', '\Grocy\Controllers\StockController:ProductDefaults'); + $this->get('/stocksettings', '\Grocy\Controllers\StockController:StockSettings'); $this->get('/locations', '\Grocy\Controllers\StockController:LocationsList'); $this->get('/location/{locationId}', '\Grocy\Controllers\StockController:LocationEditForm'); $this->get('/quantityunits', '\Grocy\Controllers\StockController:QuantityUnitsList'); diff --git a/services/DemoDataGeneratorService.php b/services/DemoDataGeneratorService.php index 44b3f73c..2d4c12c7 100644 --- a/services/DemoDataGeneratorService.php +++ b/services/DemoDataGeneratorService.php @@ -54,10 +54,10 @@ class DemoDataGeneratorService extends BaseService INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Yogurt')}', 2, 6, 6, 1, 6); --9 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Cheese')}', 2, 3, 3, 1, 6); --10 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Cold cuts')}', 2, 3, 3, 1, 6); --11 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Paprika')}', 2, 2, 2, 1, 5, 'paprika.jpg'); --12 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Cucumber')}', 2, 2, 2, 1, 5, 'cucumber.jpg'); --13 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Radish')}', 2, 7, 7, 1, 5); --14 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Tomato')}', 2, 2, 2, 1, 5, 'tomato.jpg'); --15 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$localizationService->Localize('Paprika')}', 2, 2, 2, 1, 5, 'paprika.jpg', 7); --12 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$localizationService->Localize('Cucumber')}', 2, 2, 2, 1, 5, 'cucumber.jpg', 7); --13 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, default_best_before_days) VALUES ('{$localizationService->Localize('Radish')}', 2, 7, 7, 1, 5, 7); --14 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name, default_best_before_days) VALUES ('{$localizationService->Localize('Tomato')}', 2, 2, 2, 1, 5, 'tomato.jpg', 7); --15 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Pizza dough')}', 3, 3, 3, 1, 6); --16 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Sieved tomatoes')}', 4, 5, 5, 1, 3); --17 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Salami')}', 2, 3, 3, 1, 6); --18 diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 9db0d76c..c6d78781 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -274,6 +274,7 @@