partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit f494a539a2ab2404136bee16cbc909b9594a6474
parent 4a3dc3e29c6b1fbbb144e71eb4231fa6c52f806e
Author: Timo A. Hummel <felicitus@felicitus.org>
Date:   Wed,  9 Mar 2016 16:11:46 +0100

Merge pull request #601 from tinutac/Patch-#500

[Bugfix]: Item prices does not work #500
Diffstat:
Msrc/PartKeepr/PartBundle/Entity/Part.php | 43++++++++++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php @@ -823,24 +823,41 @@ class Part extends BaseEntity { $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); - } + + if ($stockLevel->getStockLevel() > 0) { + + $lastPosEntryQuant = $stockLevel->getStockLevel(); + $lastPosEntryPrice = $stockLevel->getPrice(); + $totalPartStockPrice += $lastPosEntryPrice * $lastPosEntryQuant; + $price = $totalPartStockPrice / $sum; + } + else { + if ($sum < 0) { + $price = 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);