mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Added possibility to consume products directly from stock overview
This commit is contained in:
parent
89bae8d25e
commit
2e7af1b050
@ -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'
|
||||
);
|
||||
|
@ -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);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -21,6 +21,7 @@
|
||||
<table id="stock-overview-table" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>{{ $L('Product') }}</th>
|
||||
<th>{{ $L('Amount') }}</th>
|
||||
<th>{{ $L('Next best before date') }}</th>
|
||||
@ -28,12 +29,20 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($currentStock as $currentStockEntry)
|
||||
<tr class="@if($currentStockEntry->best_before_date < date('Y-m-d', strtotime('-1 days'))) error-bg @elseif($currentStockEntry->best_before_date < date('Y-m-d', strtotime('+5 days'))) warning-bg @elseif (FindObjectInArrayByPropertyValue($missingProducts, 'id', $currentStockEntry->product_id) !== null) info-bg @endif">
|
||||
<tr id="product-{{ $currentStockEntry->product_id }}-row" class="@if($currentStockEntry->best_before_date < date('Y-m-d', strtotime('-1 days'))) error-bg @elseif($currentStockEntry->best_before_date < date('Y-m-d', strtotime('+5 days'))) warning-bg @elseif (FindObjectInArrayByPropertyValue($missingProducts, 'id', $currentStockEntry->product_id) !== null) info-bg @endif">
|
||||
<td class="fit-content">
|
||||
<a class="btn btn-danger btn-xs product-consume-button" href="#" title="{{ $L('Consume 1 #1 of #2', FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name, FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name) }}"
|
||||
data-product-id="{{ $currentStockEntry->product_id }}"
|
||||
data-product-name="{{ FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name }}"
|
||||
data-product-qu-name="{{ FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name }}">
|
||||
<i class="fa fa-cutlery"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $currentStockEntry->amount . ' ' . FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name }}
|
||||
<span id="product-{{ $currentStockEntry->product_id }}-amount">{{ $currentStockEntry->amount }}</span> {{ FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $currentStockEntry->best_before_date }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user