From 50c6a433e39bc93171ce2f1440b8f5192a80a118 Mon Sep 17 00:00:00 2001 From: Cristina Boca Date: Wed, 9 Mar 2016 16:30:03 +0100 Subject: [PATCH] Bugfix for negative total stock followed by positive entry ( --- src/PartKeepr/PartBundle/Entity/Part.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php index 4bae020db..668f9ac62 100644 --- a/src/PartKeepr/PartBundle/Entity/Part.php +++ b/src/PartKeepr/PartBundle/Entity/Part.php @@ -827,6 +827,7 @@ public function recomputeStockLevels() $totalPartStockPrice = 0; $lastPosEntryQuant = 0; $lastPosEntryPrice = 0; + $negativeStock = 0; foreach ($this->getStockLevels() as $stockLevel) { @@ -836,14 +837,17 @@ public function recomputeStockLevels() $lastPosEntryQuant = $stockLevel->getStockLevel(); $lastPosEntryPrice = $stockLevel->getPrice(); - $totalPartStockPrice += $lastPosEntryPrice * $lastPosEntryQuant; + $totalPartStockPrice += $lastPosEntryPrice * ($lastPosEntryQuant + $negativeStock); $price = $totalPartStockPrice / $sum; } else { - if ($sum < 0) { + if ($sum <= 0) { $price = 0; + $totalPartStockPrice = 0; + $negativeStock = $sum; } else { + $negativeStock = 0; if ($sum < $lastPosEntryQuant){ $totalPartStockPrice = $sum * $lastPosEntryPrice; $price = $totalPartStockPrice / $sum;