Fixed productcard spoil rate (fixes #1319)

This commit is contained in:
Bernd Bestel 2021-06-28 19:43:08 +02:00
parent 7587ead732
commit 76cfe7fece
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 4 additions and 3 deletions

View File

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

View File

@ -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,