From 2e7af1b0506c29aff7fa379c256ec78f3906dd6b Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 12 May 2018 16:15:28 +0200 Subject: [PATCH] Added possibility to consume products directly from stock overview --- localization/de.php | 3 ++- public/viewjs/stockoverview.js | 34 +++++++++++++++++++++++++++++++++- views/stockoverview.blade.php | 13 +++++++++++-- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/localization/de.php b/localization/de.php index 4237002d..b41bd4bf 100644 --- a/localization/de.php +++ b/localization/de.php @@ -162,5 +162,6 @@ return array( '#1 batteries are overdue to be charged' => '#1 Batterien sind überfällig', '#1 habits are due to be done within the next #2 days' => '#1 Gewohnheiten stehen in den nächsten #2 Tagen an', '#1 habits are overdue to be done' => '#1 Gewohnheiten sind überfällig', - 'Released on' => 'Veröffentlicht am' + 'Released on' => 'Veröffentlicht am', + 'Consume 1 #1 of #2' => 'Verbrauche 1 #1 von #2' ); diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index e7922127..f24a0eec 100644 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -1,5 +1,37 @@ $('#stock-overview-table').DataTable({ 'pageLength': 50, - 'order': [[2, 'asc']], + 'order': [[3, 'asc']], + 'columnDefs': [ + { 'orderable': false, 'targets': 0 } + ], 'language': JSON.parse(L('datatables_localization')) }); + +$(document).on('click', '.product-consume-button', function(e) +{ + var productId = $(e.currentTarget).attr('data-product-id'); + var productName = $(e.currentTarget).attr('data-product-name'); + var productQuName = $(e.currentTarget).attr('data-product-qu-name'); + + Grocy.Api.Get('stock/consume-product/' + productId + '/1', + function(result) + { + var oldAmount = parseInt($('#product-' + productId + '-amount').text()); + var newAmount = oldAmount - 1; + if (newAmount === 0) + { + $('#product-' + productId + '-row').remove(); + } + else + { + $('#product-' + productId + '-amount').text(newAmount); + } + + toastr.success('Removed 1 ' + productQuName + ' of ' + productName + ' from stock'); + }, + function(xhr) + { + console.error(xhr); + } + ); +}); diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index 5386ed2d..45882297 100644 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -21,6 +21,7 @@ + @@ -28,12 +29,20 @@ @foreach($currentStock as $currentStockEntry) - + +
# {{ $L('Product') }} {{ $L('Amount') }} {{ $L('Next best before date') }}
+ + + + {{ FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name }} - {{ $currentStockEntry->amount . ' ' . FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name }} + {{ $currentStockEntry->amount }} {{ FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name }} {{ $currentStockEntry->best_before_date }}