Refresh stock statistics on consume on stock overview page (references #26)

This commit is contained in:
Bernd Bestel
2018-08-04 14:25:32 +02:00
parent 6081b8ee67
commit ca3f28b615
7 changed files with 125 additions and 13 deletions

View File

@@ -63,6 +63,7 @@ $(document).on('click', '.product-consume-button', function(e)
}
toastr.success(L('Removed #1 #2 of #3 from stock', consumeAmount, productQuName, productName));
RefreshStatistics();
},
function(xhr)
{
@@ -70,3 +71,37 @@ $(document).on('click', '.product-consume-button', function(e)
}
);
});
function RefreshStatistics()
{
Grocy.Api.Get('stock/get-current-stock',
function(result)
{
var amountSum = 0;
result.forEach(element => {
amountSum += parseInt(element.amount);
});
$("#info-current-stock").text(result.length + " " + Pluralize(result.length, L('Product'), L('Products')) + ", " + amountSum.toString() + " " + Pluralize(amountSum, L('Unit'), L('Units')));
},
function(xhr)
{
console.error(xhr);
}
);
var nextXDays = $("#info-expiring-products").data("next-x-days");
Grocy.Api.Get('stock/get-current-volatil-stock?expiring_days=' + nextXDays,
function(result)
{
$("#info-expiring-products").text(Pluralize(result.expiring_products.length, L('#1 product expires within the next #2 days', result.expiring_products.length, nextXDays), L('#1 products expiring within the next #2 days', result.expiring_products.length, nextXDays)));
$("#info-expired-products").text(Pluralize(result.expired_products.length, L('#1 product is already expired', result.expired_products.length), L('#1 products are already expired', result.expired_products.length)));
$("#info-missing-products").text(Pluralize(result.missing_products.length, L('#1 product is below defined min. stock amount', result.missing_products.length), L('#1 products are below defined min. stock amount', result.missing_products.length)));
},
function(xhr)
{
console.error(xhr);
}
);
}
RefreshStatistics();