2018-04-16 19:11:32 +02:00
|
|
|
|
$('#stock-overview-table').DataTable({
|
|
|
|
|
'pageLength': 50,
|
2018-05-12 16:15:28 +02:00
|
|
|
|
'order': [[3, 'asc']],
|
|
|
|
|
'columnDefs': [
|
|
|
|
|
{ 'orderable': false, 'targets': 0 }
|
|
|
|
|
],
|
2018-04-16 19:11:32 +02:00
|
|
|
|
'language': JSON.parse(L('datatables_localization'))
|
2017-04-16 23:11:03 +02:00
|
|
|
|
});
|
2018-05-12 16:15:28 +02:00
|
|
|
|
|
|
|
|
|
$(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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-12 16:30:10 +02:00
|
|
|
|
toastr.success(L('Removed #1 #2 of #3 from stock', 1, productQuName, productName));
|
2018-05-12 16:15:28 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
console.error(xhr);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|