diff --git a/config-dist.php b/config-dist.php index d52b155e..60661110 100644 --- a/config-dist.php +++ b/config-dist.php @@ -106,6 +106,7 @@ DefaultUserSetting('keep_screen_on_when_fullscreen_card', false); // Keep the sc DefaultUserSetting('product_presets_location_id', -1); // Default location id for new products (-1 means no location is preset) DefaultUserSetting('product_presets_product_group_id', -1); // Default product group id for new products (-1 means no product group is preset) DefaultUserSetting('product_presets_qu_id', -1); // Default quantity unit id for new products (-1 means no quantity unit is preset) +DefaultUserSetting('stock_decimal_places_prices', 4); // Default decimal places allowed for prices DefaultUserSetting('stock_expiring_soon_days', 5); DefaultUserSetting('stock_default_purchase_amount', 0); DefaultUserSetting('stock_default_consume_amount', 1); diff --git a/public/js/grocy.js b/public/js/grocy.js index 5d675dbe..8d991d3b 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -553,7 +553,7 @@ function RefreshLocaleNumberDisplay(rootSelector = "#page-content") return; } - $(this).text(parseFloat($(this).text()).toLocaleString(undefined, { style: "currency", currency: Grocy.Currency })); + $(this).text(parseFloat($(this).text()).toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices})); }); $(rootSelector + " .locale-number.locale-number-quantity-amount").each(function() diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index b2819260..a5d72db1 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -11,7 +11,7 @@ var price = ""; if (!jsonForm.price.toString().isEmpty()) { - price = parseFloat(jsonForm.price).toFixed(2); + price = parseFloat(jsonForm.price).toFixed(Grocy.UserSettings.stock_decimal_places_prices); } var jsonData = {}; diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 883a0320..962bac2c 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -8,27 +8,22 @@ Grocy.Api.Get('stock/products/' + jsonForm.product_id, function(productDetails) { - var amount = jsonForm.amount * jsonForm.qu_factor_purchase_to_stock; - - var price = ""; - if (!jsonForm.price.toString().isEmpty()) - { - // price is saved as 1 QU to stock - price = parseFloat(jsonForm.price / amount).toFixed(2); - - if ($("input[name='price-type']:checked").val() == "total-price") - { - price = price / jsonForm.amount; - } - } + var jsonData = {}; + jsonData.amount = jsonForm.amount * jsonForm.qu_factor_purchase_to_stock; if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { - price = 0; - } + jsonData.price = 0; + } else { + // price is saved as 1 QU to stock + var price = parseFloat(jsonForm.price / jsonForm.qu_factor_purchase_to_stock).toFixed(Grocy.UserSettings.stock_decimal_places_prices); - var jsonData = {}; - jsonData.amount = amount; + if ($("input[name='price-type']:checked").val() == "total-price") + { + price = parseFloat(price / jsonForm.amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices); + } + jsonData.price = price; + } if (Grocy.UserSettings.show_purchased_date_on_purchase) { @@ -48,7 +43,6 @@ { jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); } - jsonData.price = price; if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) { jsonData.location_id = Grocy.Components.LocationPicker.GetValue(); diff --git a/public/viewjs/stockentryform.js b/public/viewjs/stockentryform.js index 3da1e12e..d970b94f 100644 --- a/public/viewjs/stockentryform.js +++ b/public/viewjs/stockentryform.js @@ -7,7 +7,7 @@ if (!jsonForm.price.toString().isEmpty()) { - price = parseFloat(jsonForm.price).toFixed(2); + price = parseFloat(jsonForm.price).toFixed(Grocy.UserSettings.stock_decimal_places_prices); } var jsonData = {}; diff --git a/public/viewjs/stocksettings.js b/public/viewjs/stocksettings.js index 003ed189..0784883a 100644 --- a/public/viewjs/stocksettings.js +++ b/public/viewjs/stocksettings.js @@ -4,6 +4,7 @@ $("#product_presets_qu_id").val(Grocy.UserSettings.product_presets_qu_id); $("#stock_expiring_soon_days").val(Grocy.UserSettings.stock_expiring_soon_days); $("#stock_default_purchase_amount").val(Grocy.UserSettings.stock_default_purchase_amount); $("#stock_default_consume_amount").val(Grocy.UserSettings.stock_default_consume_amount); +$("#stock_decimal_places_prices").val(Grocy.UserSettings.stock_decimal_places_prices); if (BoolVal(Grocy.UserSettings.show_icon_on_stock_overview_page_when_product_is_on_shopping_list)) { diff --git a/views/purchase.blade.php b/views/purchase.blade.php index 85926864..996dead9 100644 --- a/views/purchase.blade.php +++ b/views/purchase.blade.php @@ -94,14 +94,15 @@ @include('components.numberpicker', array( 'id' => 'price', 'label' => 'Price', - 'min' => 0.01, - 'decimals' => 2, + 'min' => 0.0001, + 'decimals' => $userSettings['stock_decimal_places_prices'], 'value' => '', 'hintId' => 'price-hint', 'invalidFeedback' => $__t('The price cannot be lower than %s', '0'), 'isRequired' => false, 'additionalGroupCssClasses' => 'mb-1' )) +
'price', 'value' => $price, 'label' => 'Price', - 'min' => 0.01, - 'decimals' => 2, + 'min' => 0.0001, + 'decimals' => $userSettings['stock_decimal_places_prices'], 'hint' => $__t('in %s per purchase quantity unit', GROCY_CURRENCY), 'invalidFeedback' => $__t('The price cannot be lower than %s', '0'), 'isRequired' => false diff --git a/views/stocksettings.blade.php b/views/stocksettings.blade.php index b330781a..1970bef3 100644 --- a/views/stocksettings.blade.php +++ b/views/stocksettings.blade.php @@ -87,6 +87,17 @@ 'additionalCssClasses' => 'user-setting-control' )) +

{{ $__t('Price decimal places allowed') }}

+ @include('components.numberpicker', array( + 'id' => 'stock_price_decimal_places', + 'additionalAttributes' => 'data-setting-key="stock_price_decimal_places"', + 'label' => 'Decimal places allowed for prices', + 'min' => 0, + 'decimals' => 0, + 'invalidFeedback' => $__t('This cannot be lower than %s', '0'), + 'additionalCssClasses' => 'user-setting-control' + )) +