From 57d70851c8d5031691f9a3046292e9de08b91b69 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 24 Jul 2022 21:36:29 +0200 Subject: [PATCH] Fixed stock overview page status button counters related to the product option "Never show on stock overview" (fixes #1956) --- changelog/69_UNRELEASED_xxxx-xx-xx.md | 4 +++- public/viewjs/stockoverview.js | 13 +++++++++---- services/StockService.php | 11 ++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/changelog/69_UNRELEASED_xxxx-xx-xx.md b/changelog/69_UNRELEASED_xxxx-xx-xx.md index 88ad6ad6..4e8bafd0 100644 --- a/changelog/69_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/69_UNRELEASED_xxxx-xx-xx.md @@ -11,6 +11,7 @@ - Fixed that the average shelf life of a product (on the productcard) was wrong when the corresponding stock entry was edited - Fixed that when the stock setting "Decimal places allowed for amounts" was set to `0`, unit conversion (if any) failed when adding the corresponding product to stock - Fixed that consuming a parent product which is not in stock itself (so essentially using any of the child products) may failed when unit conversions were involved (the current stock amount check was wrong in that case) +- Fixed that the status button counters on the stock overview page ("X products are overdue" and so on) included products which have the option `Never show on stock overview` enabled ### Shopping list @@ -55,4 +56,5 @@ ### API -- xxx +- Endpoint `/stock/volatile` + - The field/property `missing_products` now also contains the `product` object diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index 3cb5bcb4..36ecd5c7 100755 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -267,10 +267,15 @@ function RefreshStatistics() Grocy.Api.Get('stock/volatile?due_soon_days=' + nextXDays, function(result) { - $("#info-duesoon-products").html('' + result.due_products.length + ' ' + __n(result.due_products.length, '%s product is due', '%s products are due') + ' ' + __n(nextXDays, 'within the next day', 'within the next %s days') + ''); - $("#info-overdue-products").html('' + result.overdue_products.length + ' ' + __n(result.overdue_products.length, '%s product is overdue', '%s products are overdue') + ''); - $("#info-expired-products").html('' + result.expired_products.length + ' ' + __n(result.expired_products.length, '%s product is expired', '%s products are expired') + ''); - $("#info-missing-products").html('' + result.missing_products.length + ' ' + __n(result.missing_products.length, '%s product is below defined min. stock amount', '%s products are below defined min. stock amount') + ''); + var dueProducts = result.due_products.filter(x => !BoolVal(x.product.hide_on_stock_overview)); + var overdueProducts = result.overdue_products.filter(x => !BoolVal(x.product.hide_on_stock_overview)); + var expiredProducts = result.expired_products.filter(x => !BoolVal(x.product.hide_on_stock_overview)); + var missingProducts = result.missing_products.filter(x => !BoolVal(x.product.hide_on_stock_overview)); + + $("#info-duesoon-products").html('' + dueProducts.length + ' ' + __n(dueProducts.length, '%s product is due', '%s products are due') + ' ' + __n(nextXDays, 'within the next day', 'within the next %s days') + ''); + $("#info-overdue-products").html('' + overdueProducts.length + ' ' + __n(overdueProducts.length, '%s product is overdue', '%s products are overdue') + ''); + $("#info-expired-products").html('' + expiredProducts.length + ' ' + __n(expiredProducts.length, '%s product is expired', '%s products are expired') + ''); + $("#info-missing-products").html('' + missingProducts.length + ' ' + __n(missingProducts.length, '%s product is below defined min. stock amount', '%s products are below defined min. stock amount') + ''); }, function(xhr) { diff --git a/services/StockService.php b/services/StockService.php index 0565c5d0..b563125a 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -677,7 +677,16 @@ class StockService extends BaseService public function GetMissingProducts() { - return $this->getDatabaseService()->ExecuteDbQuery('SELECT * FROM stock_missing_products')->fetchAll(\PDO::FETCH_OBJ); + $missingProductsResponse = $this->getDatabaseService()->ExecuteDbQuery('SELECT * FROM stock_missing_products')->fetchAll(\PDO::FETCH_OBJ); + + $relevantProducts = $this->getDatabase()->products()->where('id IN (SELECT id FROM stock_missing_products)'); + foreach ($relevantProducts as $product) + { + FindObjectInArrayByPropertyValue($missingProductsResponse, 'id', $product->id)->product = $product; + + } + + return $missingProductsResponse; } public function GetProductDetails(int $productId)