Add "one click shopping list to stock workflow" (closes #110)

This commit is contained in:
Bernd Bestel 2018-11-21 19:08:36 +01:00
parent c61c37e67a
commit 306d0f7da6
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
12 changed files with 96 additions and 55 deletions

View File

@ -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);

View File

@ -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')

View File

@ -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'
);

View File

@ -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");
}

View File

@ -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
{

View File

@ -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);
}

View File

@ -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');

View File

@ -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

View File

@ -274,6 +274,7 @@
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item discrete-link" href="{{ $U('/users') }}"><i class="fas fa-users"></i>&nbsp;{{ $L('Manage users') }}</a>
<a class="dropdown-item discrete-link" href="{{ $U('/stocksettings') }}"><i class="fas fa-box"></i>&nbsp;{{ $L('Stock settings') }}</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item discrete-link" href="{{ $U('/manageapikeys') }}"><i class="fas fa-handshake"></i>&nbsp;{{ $L('Manage API keys') }}</a>
<a class="dropdown-item discrete-link" target="_blank" href="{{ $U('/api') }}"><i class="fas fa-book"></i>&nbsp;{{ $L('REST API & data model documentation') }}</a>

View File

@ -1,45 +0,0 @@
@extends('layout.default')
@section('title', $L('Presets for new products'))
@section('viewJsName', 'productpresets')
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
<div class="form-group">
<label for="product_presets_location_id">{{ $L('Location') }}</label>
<select class="form-control user-setting-control" id="product_presets_location_id" data-setting-key="product_presets_location_id">
<option value="-1"></option>
@foreach($locations as $location)
<option value="{{ $location->id }}">{{ $location->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="product_presets_product_group_id">{{ $L('Product group') }}</label>
<select class="form-control user-setting-control" id="product_presets_product_group_id" data-setting-key="product_presets_product_group_id">
<option value="-1"></option>
@foreach($productGroups as $productGroup)
<option value="{{ $productGroup->id }}">{{ $productGroup->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="product_presets_qu_id">{{ $L('Quantity unit') }}</label>
<select class="form-control user-setting-control" id="product_presets_qu_id" data-setting-key="product_presets_qu_id">
<option value="-1"></option>
@foreach($quantityunits as $quantityunit)
<option value="{{ $quantityunit->id }}">{{ $quantityunit->name }}</option>
@endforeach
</select>
</div>
<a href="{{ $U('/products') }}" class="btn btn-success">{{ $L('OK') }}</a>
</div>
</div>
@stop

View File

@ -12,7 +12,7 @@
<a class="btn btn-outline-dark" href="{{ $U('/product/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/productpresets') }}">
<a class="btn btn-outline-secondary" href="{{ $U('/stocksettings#productpresets') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Presets for new products') }}
</a>
</h1>

View File

@ -0,0 +1,59 @@
@extends('layout.default')
@section('title', $L('Stock settings'))
@section('viewJsName', 'stocksettings')
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
<div id="productpresets">
<h4>{{ $L('Presets for new products') }}</h4>
<div class="form-group">
<label for="product_presets_location_id">{{ $L('Location') }}</label>
<select class="form-control user-setting-control" id="product_presets_location_id" data-setting-key="product_presets_location_id">
<option value="-1"></option>
@foreach($locations as $location)
<option value="{{ $location->id }}">{{ $location->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="product_presets_product_group_id">{{ $L('Product group') }}</label>
<select class="form-control user-setting-control" id="product_presets_product_group_id" data-setting-key="product_presets_product_group_id">
<option value="-1"></option>
@foreach($productGroups as $productGroup)
<option value="{{ $productGroup->id }}">{{ $productGroup->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="product_presets_qu_id">{{ $L('Quantity unit') }}</label>
<select class="form-control user-setting-control" id="product_presets_qu_id" data-setting-key="product_presets_qu_id">
<option value="-1"></option>
@foreach($quantityunits as $quantityunit)
<option value="{{ $quantityunit->id }}">{{ $quantityunit->name }}</option>
@endforeach
</select>
</div>
</div>
<h4 class="mt-2">{{ $L('Shopping list to stock workflow') }}</h4>
<div class="form-group">
<div class="checkbox">
<label for="shopping-list-to-stock-workflow-auto-submit-when-prefilled">
<input type="checkbox" class="user-setting-control" id="shopping-list-to-stock-workflow-auto-submit-when-prefilled" name="shopping-list-to-stock-workflow-auto-submit-when-prefilled" data-setting-key="shopping_list_to_stock_workflow_auto_submit_when_prefilled"> {{ $L('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') }}
</label>
</div>
</div>
<a href="{{ $U('/products') }}" class="btn btn-success">{{ $L('OK') }}</a>
</div>
</div>
@stop