diff --git a/changelog/60_3.0.0_2020-12-22.md b/changelog/60_3.0.0_2020-12-22.md index 287c0798..779a6638 100644 --- a/changelog/60_3.0.0_2020-12-22.md +++ b/changelog/60_3.0.0_2020-12-22.md @@ -4,7 +4,7 @@ > > [Here](https://github.com/grocy/grocy/issues/1209#issuecomment-749760765) is a workaround if you still run a SQLite version >= 3.8.3 < 3.9.0 > -> _PHP 7.2 with SQLite 3.8.3 was the currently in [README mentioned](https://github.com/grocy/grocy#how-to-install) minimum runtime requirement, any future release will only be tested against a reasonable recent runtime (currently PHP 7.4 with SQLite 3.27.2) - supporting those (very) old runtime stuff is too time consuming..._ +> _PHP 7.2 with SQLite 3.8.3 was the formerly in [README mentioned](https://github.com/grocy/grocy#how-to-install) minimum runtime requirement, any future release will only be tested against a reasonable recent runtime (currently PHP 7.4 with SQLite 3.27.2) - supporting those (very) old runtime stuff is too time consuming..._ > ❗ If some pages/tables doesn't load at all, please check that your `/data/config.php` setting `CURRENCY` is a valid ISO 4217 currency code - that's most probably the issue then. diff --git a/changelog/61_UNRELEASED_xxxx-xx-xx.md b/changelog/61_UNRELEASED_xxxx-xx-xx.md index f5d4b8a1..7f312099 100644 --- a/changelog/61_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/61_UNRELEASED_xxxx-xx-xx.md @@ -2,10 +2,11 @@ > > [Here](https://github.com/grocy/grocy/issues/1209#issuecomment-749760765) is a workaround if you still run a SQLite version >= 3.8.3 < 3.9.0 > -> _PHP 7.2 with SQLite 3.8.3 was the currently in [README mentioned](https://github.com/grocy/grocy#how-to-install) minimum runtime requirement, any future release will only be tested against a reasonable recent runtime (currently PHP 7.4 with SQLite 3.27.2) - supporting those (very) old runtime stuff is too time consuming..._ +> _PHP 7.2 with SQLite 3.8.3 was the formerly in [README mentioned](https://github.com/grocy/grocy#how-to-install) minimum runtime requirement, any future release will only be tested against a reasonable recent runtime (currently PHP 7.4 with SQLite 3.27.2) - supporting those (very) old runtime stuff is too time consuming..._ - Improved the prerequisites checker (added missing required PHP extension `ctype`) (thanks @Forceu) - Added validation checks for most `data/config.php` settings to prevent using invalid ones (thanks @Forceu) -- Fixed that browser camera barcode scanning did not work on the product edit page +- Fixed that some number inputs were broken when the new decimal places setting were set to `0` +- Fixed that browser camera barcode scanning did not work on the product edit page for adding product barcodes - Fixed that the new product option "Never show on stock overview" was unintentionally set by default for new products -- Fixed that the success message on purchase displayed not amount when `FEATURE_FLAG_STOCK_PRICE_TRACKING` was disabled +- Fixed that the success message on purchase displayed no amount when `FEATURE_FLAG_STOCK_PRICE_TRACKING` was disabled diff --git a/controllers/BaseController.php b/controllers/BaseController.php index 6d7eef6f..58fb0313 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -159,6 +159,17 @@ class BaseController $this->View->set('permissions', User::PermissionList()); } + $decimalPlacesAmounts = intval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'stock_decimal_places_amounts')); + if ($decimalPlacesAmounts <= 0) + { + $defaultMinAmount = 1; + } + else + { + $defaultMinAmount = '0.' . str_repeat('0', $decimalPlacesAmounts - 1) . '1'; + } + $this->View->set('DEFAULT_MIN_AMOUNT', $defaultMinAmount); + return $this->View->render($response, $page, $data); } @@ -168,7 +179,6 @@ class BaseController try { $usersService = $this->getUsersService(); - if (defined('GROCY_USER_ID')) { $this->View->set('userSettings', $usersService->GetUserSettings(GROCY_USER_ID)); diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index 5b91e2bf..8a362268 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -92,7 +92,7 @@ Grocy.Components.ProductPicker.FinishFlow(); Grocy.Components.ProductAmountPicker.Reset(); - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); $("#display_amount").removeAttr("max"); if (BoolVal(Grocy.UserSettings.stock_default_consume_amount_use_quick_consume_amount)) { @@ -366,7 +366,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) } else { - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); $("#tare-weight-handling-info").addClass("d-none"); } @@ -598,7 +598,7 @@ function RefreshForm() { $("#tare-weight-handling-info").addClass("d-none"); - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); $('#display_amount').attr('max', sumValue * $("#qu_id option:selected").attr("data-qu-factor")); if (sumValue == 0) diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index f9c22c06..f8acbe0e 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -144,7 +144,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) } else { - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", "0"); $("#tare-weight-handling-info").addClass("d-none"); } @@ -346,3 +346,5 @@ function UndoStockTransaction(transactionId) } ); }; + +$("#display_amount").attr("min", "0"); diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 250bb042..c8bf5fba 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -130,7 +130,7 @@ $('#save-purchase-button').on('click', function(e) Grocy.Components.ProductAmountPicker.Reset(); $("#purchase-form").removeAttr("data-used-barcode"); - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); $('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount)); $(".input-group-productamountpicker").trigger("change"); $('#price').val(''); @@ -247,7 +247,7 @@ if (Grocy.Components.ProductPicker !== undefined) } else { - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); $("#tare-weight-handling-info").addClass("d-none"); } diff --git a/public/viewjs/recipeposform.js b/public/viewjs/recipeposform.js index 72a81768..d8cdbbf7 100644 --- a/public/viewjs/recipeposform.js +++ b/public/viewjs/recipeposform.js @@ -140,7 +140,7 @@ $("#only_check_single_unit_in_stock").on("change", function() { if (this.checked) { - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); Grocy.Components.ProductAmountPicker.AllowAnyQu(true); Grocy.FrontendHelpers.ValidateForm("recipe-pos-form"); } diff --git a/public/viewjs/transfer.js b/public/viewjs/transfer.js index 9ca74b0b..66d3166d 100644 --- a/public/viewjs/transfer.js +++ b/public/viewjs/transfer.js @@ -89,7 +89,7 @@ Grocy.Components.ProductAmountPicker.Reset(); $("#location_id_from").find("option").remove().end().append(""); - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); $("#display_amount").removeAttr("max"); $('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_transfer_amount)); RefreshLocaleNumberInput(); @@ -194,7 +194,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) } else { - $("#display_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1"); + $("#display_amount").attr("min", Grocy.DefaultMinAmount); $("#tare-weight-handling-info").addClass("d-none"); } diff --git a/services/StockService.php b/services/StockService.php index 4741b4bc..87610e6d 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -921,9 +921,9 @@ class StockService extends BaseService //If no entry was found with for this product, we return gracefully if ($productRow != null && !empty($productRow)) { + $decimals = intval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'stock_decimal_places_amounts')); $newAmount = $productRow->amount - $amount; - - if ($newAmount < floatval('0.' . str_repeat('0', intval($this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'stock_decimal_places_amounts')) - 1) . '1')) + if ($newAmount < floatval('0.' . str_repeat('0', $decimals - ($decimals <= 0 ? 0 : 1)) . '1')) { $productRow->delete(); } diff --git a/views/choreform.blade.php b/views/choreform.blade.php index 5714683b..c0276a6b 100644 --- a/views/choreform.blade.php +++ b/views/choreform.blade.php @@ -267,7 +267,7 @@ 'id' => 'product_amount', 'label' => 'Amount', 'contextInfoId' => 'amount_qu_unit', - 'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1', + 'min' => $DEFAULT_MIN_AMOUNT, 'decimals' => $userSettings['stock_decimal_places_amounts'], 'isRequired' => false, 'value' => $value, diff --git a/views/components/numberpicker.blade.php b/views/components/numberpicker.blade.php index 878129d0..4e3df4a8 100644 --- a/views/components/numberpicker.blade.php +++ b/views/components/numberpicker.blade.php @@ -50,7 +50,7 @@ @if(!empty($max)) max="{{ number_format($max, $decimals, '.', '') }}" @endif - step="@if($decimals == 0){{1}}@else{{'.' . str_repeat('0', $decimals - 1) . '1'}}@endif" + step="@if($decimals <= 0){{1}}@else{{'.' . str_repeat('0', $decimals - 1) . '1'}}@endif" data-decimals="{{ $decimals }}" @if($isRequired) required diff --git a/views/components/productamountpicker.blade.php b/views/components/productamountpicker.blade.php index 9dbb792b..0736454c 100644 --- a/views/components/productamountpicker.blade.php +++ b/views/components/productamountpicker.blade.php @@ -18,7 +18,7 @@ @include('components.numberpicker', array( 'id' => 'display_amount', 'label' => $label, - 'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1', + 'min' => $DEFAULT_MIN_AMOUNT, 'decimals' => $userSettings['stock_decimal_places_amounts'], 'value' => $value, 'additionalGroupCssClasses' => 'col-sm-5 col-xs-12 my-0', diff --git a/views/consume.blade.php b/views/consume.blade.php index 6a530a2e..7c586bad 100644 --- a/views/consume.blade.php +++ b/views/consume.blade.php @@ -12,6 +12,7 @@
'amount', 'label' => 'Amount', - 'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1', + 'min' => 0, 'decimals' => $userSettings['stock_decimal_places_amounts'], 'isRequired' => false, 'value' => 1, diff --git a/views/recipeform.blade.php b/views/recipeform.blade.php index b28c5e04..a1862f7e 100644 --- a/views/recipeform.blade.php +++ b/views/recipeform.blade.php @@ -55,7 +55,7 @@ @include('components.numberpicker', array( 'id' => 'base_servings', 'label' => 'Servings', - 'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1', + 'min' => $DEFAULT_MIN_AMOUNT, 'decimals' => $userSettings['stock_decimal_places_amounts'], 'value' => $value, 'hint' => $__t('The ingredients listed here result in this amount of servings'), @@ -351,7 +351,7 @@ @include('components.numberpicker', array( 'id' => 'includes_servings', 'label' => 'Servings', - 'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts'] - 1) . '1', + 'min' => $DEFAULT_MIN_AMOUNT, 'decimals' => $userSettings['stock_decimal_places_amounts'], 'value' => '1', 'additionalCssClasses' => 'locale-number-input locale-number-quantity-amount' diff --git a/views/recipeposform.blade.php b/views/recipeposform.blade.php index 9077e467..187ddae9 100644 --- a/views/recipeposform.blade.php +++ b/views/recipeposform.blade.php @@ -9,6 +9,10 @@ @section('viewJsName', 'recipeposform') @section('content') + +