Allow price to be 4 decimals

This commit is contained in:
Kurt Riddlesperger 2020-10-20 07:09:20 -05:00
parent 9e982979c3
commit 24d8b21901
9 changed files with 33 additions and 25 deletions

View File

@ -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);

View File

@ -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()

View File

@ -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 = {};

View File

@ -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();

View File

@ -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 = {};

View File

@ -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))
{

View File

@ -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'
))
<div class="form-check form-check-inline mb-3">
<input class="form-check-input"
type="radio"

View File

@ -89,8 +89,8 @@
'id' => '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

View File

@ -87,6 +87,17 @@
'additionalCssClasses' => 'user-setting-control'
))
<h4 class="mt-2">{{ $__t('Price decimal places allowed') }}</h4>
@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'
))
<div class="form-group">
<div class="checkbox">
<label for="show_icon_on_stock_overview_page_when_product_is_on_shopping_list">