Skip to content

Commit

Permalink
Merge pull request #611 from tinutac/Patch-#500
Browse files Browse the repository at this point in the history
[Bugfix]: Item prices (negative total stock followed by positive entry) (Bugfix for #601)
  • Loading branch information
Timo A. Hummel committed Mar 11, 2016
2 parents 3f518ea + 50c6a43 commit 80dd9eb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/PartKeepr/PartBundle/Entity/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ public function recomputeStockLevels()
$totalPartStockPrice = 0;
$lastPosEntryQuant = 0;
$lastPosEntryPrice = 0;
$negativeStock = 0;

foreach ($this->getStockLevels() as $stockLevel) {

Expand All @@ -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;
Expand Down

0 comments on commit 80dd9eb

Please sign in to comment.