diff --git a/changelog/62_UNRELEASED_xxxx-xx-xx.md b/changelog/62_UNRELEASED_xxxx-xx-xx.md index 0396bcf4..445862c9 100644 --- a/changelog/62_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/62_UNRELEASED_xxxx-xx-xx.md @@ -32,6 +32,7 @@ - Fixed that undoing a consume/open action from the success notification on the stock entries page was not possible - Fixed that adding a barcode to a product didn't save the selected quantity unit when the product only has a single one - Fixed that the store information on a stock entry was lost when transferring a partial amount to a different location +- Fixed that the "Spoil rate" on the product card was wrong in some cases ### Shopping list improvements/fixes - The amount now defaults to `1` for adding items quicker diff --git a/services/StockService.php b/services/StockService.php index 30919fdc..0cd1a49a 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -632,14 +632,14 @@ class StockService extends BaseService $averageShelfLifeDays = intval($this->getDatabase()->stock_average_product_shelf_life()->where('id', $productId)->fetch()->average_shelf_life_days); $defaultShoppingLocation = null; - $consumeCount = $this->getDatabase()->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->where('undone = 0 AND spoiled = 0')->sum('amount') * -1; + $consumeCount = $this->getDatabase()->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->where('undone = 0')->sum('amount') * -1; $consumeCountSpoiled = $this->getDatabase()->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->where('undone = 0 AND spoiled = 1')->sum('amount') * -1; - if ($consumeCount == 0) + if ($consumeCount == 0 || $consumeCount == null) { $consumeCount = 1; } - $spoilRate = ($consumeCountSpoiled * 100) / $consumeCount; + $spoilRate = ($consumeCountSpoiled * 100.0) / $consumeCount; return [ 'product' => $product,