partkeepr

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

commit 80dd9eb70ef8c1deff33a67007bd1899bc580742
parent 3f518eadb17bcf85e984f02464a27d6e0340d939
Author: Timo A. Hummel <felicitus@felicitus.org>
Date:   Fri, 11 Mar 2016 12:30:17 +0100

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

[Bugfix]: Item prices (negative total stock followed by positive entry) (Bugfix for #601)
Diffstat:
Msrc/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 @@ -827,6 +827,7 @@ class Part extends BaseEntity $totalPartStockPrice = 0; $lastPosEntryQuant = 0; $lastPosEntryPrice = 0; + $negativeStock = 0; foreach ($this->getStockLevels() as $stockLevel) { @@ -836,14 +837,17 @@ class Part extends BaseEntity $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;