From cf3217ada4856f49f9e5f4881a301cc5bab1b5e6 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 26 Sep 2019 16:42:59 +0200 Subject: [PATCH] Fixed expired products count on stock overview page (fixes #392) --- changelog/53_UNRELEASED_2019-xx-xx.md | 20 +++++++++++++++----- controllers/StockController.php | 2 +- services/StockService.php | 16 ++++++++-------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/changelog/53_UNRELEASED_2019-xx-xx.md b/changelog/53_UNRELEASED_2019-xx-xx.md index 887af78a..868e93fa 100644 --- a/changelog/53_UNRELEASED_2019-xx-xx.md +++ b/changelog/53_UNRELEASED_2019-xx-xx.md @@ -1,13 +1,23 @@ -- Fixed that barcode lookups now compare the whole barcode, not parts of it (e. g. when you have two products with the barcodes "$1" and "$10" and scan "$1" maybe the product of "$10" was found till now) +### Stock improvements/fixes +- Fixed that barcode lookups now compare the whole barcode, not parts of it (e. g. when you have two products with the barcodes `$1` and `$10` and scan `$1` maybe the product of `$10` was found till now) +- Fixed that the "X products are already expired" count on the stock overview page was wrong - It's now possible to accumulate min. stock amounts on parent product level (new option per product, means the sub product will never be "missing" then, only the parent product) +- When adding a product to the shopping list from the new context/more menu from the stock overview page and if the product is already on the shopping list, the amount of that entry will be updated acccordingly instead of adding a new (double) shopping list item + +### Recipe improvements/fixes +- Fixed a problem regarding quantity unit conversion handling for recipe ingredients of products with no unit relations, but only a different purchase/stock quantity unit - It's now possible to display a recipe directly from the meal plan (new "eye button") (thanks @kriddles) - Improved the responsiveness of the meal plan and calendar page by automatically switching to a day calendar view on smaller screens (thanks for the idea @kriddles) + +### Calendar improvements - The calendar now also contains all planned recipes from the meal plan on the corresponding day -- When adding a product to the shopping list from the new context/more menu from the stock overview page and if the product is already on the shopping list, the amount of that entry will be updated acccordingly instead of adding a new (double) shopping list item +- Improved that dates in the iCal calendar export now include the server timezone + +### General & other improvements/fixes - Fixed that the browser barcode scanner button was not clickable on iOS Safari (thanks @DeeeeLAN) -- Fixed a problem regarding quantity unit conversion handling for recipe ingredients of products with no unit relations, but only a different purchase/stock quantity unit -- Improved that dates in the iCal calendar export now includes the server timezone - It's now also possible to set the meal plan page as the default/entry page (`config.php` setting `ENTRY_PAGE`) (thanks @lwis) +- Some UI detail-refinements + +### API improvements/fixes - The API Endpoint `GET /files/{group}/{fileName}` now also returns a `Cache-Control` header (defaults fixed to 30 days) to further increase page load times - Fixed that the API endpoint `/stock/shoppinglist/add-product` failed when a product should be added which was not already on the shopping list (thanks @Forceu) -- Some style/CSS detail-refinements diff --git a/controllers/StockController.php b/controllers/StockController.php index 64dd3fc6..ec946ae0 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -28,7 +28,7 @@ class StockController extends BaseController 'products' => $this->Database->products()->orderBy('name'), 'quantityunits' => $this->Database->quantity_units()->orderBy('name'), 'locations' => $this->Database->locations()->orderBy('name'), - 'currentStock' => $this->StockService->GetCurrentStock(), + 'currentStock' => $this->StockService->GetCurrentStock(true), 'currentStockLocations' => $this->StockService->GetCurrentStockLocations(), 'missingProducts' => $this->StockService->GetMissingProducts(), 'nextXDays' => $nextXDays, diff --git a/services/StockService.php b/services/StockService.php index 67a01e14..48276380 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -11,15 +11,15 @@ class StockService extends BaseService public function GetCurrentStock($includeNotInStockButMissingProducts = false) { - $missingProductsView = 'stock_missing_products_including_opened'; - if (!GROCY_FEATURE_SETTING_STOCK_COUNT_OPENED_PRODUCTS_AGAINST_MINIMUM_STOCK_AMOUNT) - { - $missingProductsView = 'stock_missing_products'; - } - - $sql = 'SELECT * FROM stock_current UNION SELECT id, 0, 0, null, 0, 0, 0 FROM ' . $missingProductsView . ' WHERE id NOT IN (SELECT product_id FROM stock_current)'; + $sql = 'SELECT * FROM stock_current'; if ($includeNotInStockButMissingProducts) { + $missingProductsView = 'stock_missing_products_including_opened'; + if (!GROCY_FEATURE_SETTING_STOCK_COUNT_OPENED_PRODUCTS_AGAINST_MINIMUM_STOCK_AMOUNT) + { + $missingProductsView = 'stock_missing_products'; + } + $sql = 'SELECT * FROM stock_current WHERE best_before_date IS NOT NULL UNION SELECT id, 0, 0, null, 0, 0, 0 FROM ' . $missingProductsView . ' WHERE id NOT IN (SELECT product_id FROM stock_current)'; } @@ -69,7 +69,7 @@ class StockService extends BaseService public function GetExpiringProducts(int $days = 5, bool $excludeExpired = false) { - $currentStock = $this->GetCurrentStock(true); + $currentStock = $this->GetCurrentStock(false); $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime("+$days days")), '<'); if ($excludeExpired)