diff --git a/public/viewjs/components/productcard.js b/public/viewjs/components/productcard.js index c20994e7..3a946423 100644 --- a/public/viewjs/components/productcard.js +++ b/public/viewjs/components/productcard.js @@ -95,7 +95,7 @@ Grocy.Components.ProductCard.Refresh = function(productId) { if (productDetails.last_qu_factor_purchase_to_stock > 1) { - $('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price).toLocaleString() + ' ' + Grocy.Currency + ' per 1 ' + productDetails.quantity_unit_purchase.name + ' of ' + productDetails.last_qu_factor_purchase_to_stock + ' ' + productDetails.quantity_unit_stock.name_plural); + $('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price * productDetails.last_qu_factor_purchase_to_stock).toLocaleString() + ' ' + Grocy.Currency + ' per 1 ' + productDetails.quantity_unit_purchase.name + ' of ' + productDetails.last_qu_factor_purchase_to_stock + ' ' + productDetails.quantity_unit_stock.name_plural); } else { @@ -109,7 +109,7 @@ Grocy.Components.ProductCard.Refresh = function(productId) if (productDetails.avg_price !== null) { - $('#productcard-product-average-price').text(Number.parseFloat(productDetails.avg_price).toLocaleString() + ' ' + Grocy.Currency); + $('#productcard-product-average-price').text(Number.parseFloat(productDetails.avg_price).toLocaleString() + ' ' + Grocy.Currency + ' per ' + productDetails.quantity_unit_stock.name); } else { diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index d6e6632d..97ef1be9 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -183,7 +183,6 @@ if (Grocy.Components.ProductPicker !== undefined) function(productDetails) { - $('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 })); var qu_factor_purchase_to_stock = null; var barcode_shopping_location_id = null; @@ -232,6 +231,8 @@ if (Grocy.Components.ProductPicker !== undefined) $('#amount_qu_unit').attr("quantity-unit-stock-name-plural", productDetails.quantity_unit_stock.name_plural); $('#qu_factor_purchase_to_stock').val(qu_factor_purchase_to_stock); + $('#price').val(parseFloat(productDetails.last_price * qu_factor_purchase_to_stock).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 })); + if (qu_factor_purchase_to_stock == 1) { @@ -439,9 +440,17 @@ function refreshPriceHint() if ($("input[name='price-type']:checked").val() == "total-price") { - var price = parseFloat($('#price').val()) / parseFloat($('#amount').val()); + var price = $('#price').val() / document.getElementById("amount_qu_unit").getAttribute("qu-factor-purchase-to-stock") / $('#amount').val(); + var quprice = $('#price').val() / $('#amount').val(); - $('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }), document.getElementById("amount_qu_unit").getAttribute("quantity-unit-stock-name"))); + if (document.getElementById("amount_qu_unit").getAttribute("qu-factor-purchase-to-stock") > 1) + { + $('#price-hint').text(__t('means %1$s per %2$s and %3$s per %4$s', price.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }), document.getElementById("amount_qu_unit").getAttribute("quantity-unit-stock-name"), quprice.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }),document.getElementById("amount_qu_unit").getAttribute("quantity-unit-purchase-name"))); + } + else + { + $('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }), document.getElementById("amount_qu_unit").getAttribute("quantity-unit-stock-name"))); + } } else {