From d699bd4c978e600b8c0eae0012de4a0d3bcf45e3 Mon Sep 17 00:00:00 2001 From: Cristina Boca Date: Fri, 12 Feb 2016 18:58:34 +0100 Subject: [PATCH 1/3] [Bugfix]: Item prices does not work #500 --- src/PartKeepr/PartBundle/Entity/Part.php | 44 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php index d53644782..30d8bffdf 100644 --- a/src/PartKeepr/PartBundle/Entity/Part.php +++ b/src/PartKeepr/PartBundle/Entity/Part.php @@ -823,24 +823,40 @@ public function recomputeStockLevels() { $sum = 0; $price = 0; + + $totalPartStockPrice = 0; + $lastPosEntryQuant = 0; + $lastPosEntryPrice = 0; foreach ($this->getStockLevels() as $stockLevel) { - - if ($stockLevel->getStockLevel() < 0) { - $this->setRemovals(true); - } else { - $price += $stockLevel->getPrice() * $stockLevel->getStockLevel(); - } - $sum += $stockLevel->getStockLevel(); - } - - if ($sum > 0) { - $this->setAveragePrice($price / $sum); - } else { - $this->setAveragePrice(0); - } + + $sum += $stockLevel->getStockLevel(); + + if ($stockLevel->getStockLevel() > 0) { + $lastPosEntryQuant = $stockLevel->getStockLevel(); + $lastPosEntryPrice = $stockLevel->getPrice(); + $totalPartStockPrice += $lastPosEntryPrice * $lastPosEntryQuant; + $price = $totalPartStockPrice / $sum; + } + else { + if ($sum < 0) { + $price = 0; + $sum = 0; + } + else + if ($sum < $lastPosEntryQuant){ + $totalPartStockPrice = $sum * $lastPosEntryPrice; + $price = $totalPartStockPrice / $sum; + } + else { + $totalPartStockPrice += $stockLevel->getStockLevel() * $price; + $price = $totalPartStockPrice / $sum; + } + } + } $this->setStockLevel($sum); + $this->setAveragePrice($price); if ($sum < $this->getMinStockLevel()) { $this->setLowStock(true); From fe8c838602197ffdca85c30d5afe5c923281264e Mon Sep 17 00:00:00 2001 From: Cristina Boca Date: Tue, 16 Feb 2016 13:53:12 +0100 Subject: [PATCH 2/3] removed correction for negative stock level --- src/PartKeepr/PartBundle/Entity/Part.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php index 30d8bffdf..09275aee1 100644 --- a/src/PartKeepr/PartBundle/Entity/Part.php +++ b/src/PartKeepr/PartBundle/Entity/Part.php @@ -841,7 +841,7 @@ public function recomputeStockLevels() else { if ($sum < 0) { $price = 0; - $sum = 0; + //$sum = 0; } else if ($sum < $lastPosEntryQuant){ From bc8023f25fd65e1117a5a60c449b3e31c5bc9f70 Mon Sep 17 00:00:00 2001 From: Cristina Boca Date: Fri, 26 Feb 2016 13:55:44 +0100 Subject: [PATCH 3/3] removed correction for negative stock level (not commented) fixed formatting --- src/PartKeepr/PartBundle/Entity/Part.php | 39 ++++++++++++------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php index 09275aee1..4bae020db 100644 --- a/src/PartKeepr/PartBundle/Entity/Part.php +++ b/src/PartKeepr/PartBundle/Entity/Part.php @@ -824,39 +824,40 @@ public function recomputeStockLevels() $sum = 0; $price = 0; - $totalPartStockPrice = 0; + $totalPartStockPrice = 0; $lastPosEntryQuant = 0; $lastPosEntryPrice = 0; foreach ($this->getStockLevels() as $stockLevel) { - - $sum += $stockLevel->getStockLevel(); - - if ($stockLevel->getStockLevel() > 0) { - $lastPosEntryQuant = $stockLevel->getStockLevel(); - $lastPosEntryPrice = $stockLevel->getPrice(); - $totalPartStockPrice += $lastPosEntryPrice * $lastPosEntryQuant; - $price = $totalPartStockPrice / $sum; + + $sum += $stockLevel->getStockLevel(); + + if ($stockLevel->getStockLevel() > 0) { + + $lastPosEntryQuant = $stockLevel->getStockLevel(); + $lastPosEntryPrice = $stockLevel->getPrice(); + $totalPartStockPrice += $lastPosEntryPrice * $lastPosEntryQuant; + $price = $totalPartStockPrice / $sum; } else { - if ($sum < 0) { - $price = 0; - //$sum = 0; + if ($sum < 0) { + $price = 0; } - else - if ($sum < $lastPosEntryQuant){ - $totalPartStockPrice = $sum * $lastPosEntryPrice; - $price = $totalPartStockPrice / $sum; + else { + if ($sum < $lastPosEntryQuant){ + $totalPartStockPrice = $sum * $lastPosEntryPrice; + $price = $totalPartStockPrice / $sum; } else { - $totalPartStockPrice += $stockLevel->getStockLevel() * $price; - $price = $totalPartStockPrice / $sum; + $totalPartStockPrice += $stockLevel->getStockLevel() * $price; + $price = $totalPartStockPrice / $sum; } + } } } $this->setStockLevel($sum); - $this->setAveragePrice($price); + $this->setAveragePrice($price); if ($sum < $this->getMinStockLevel()) { $this->setLowStock(true);