Skip to content

Commit

Permalink
Merge pull request #601 from tinutac/Patch-#500
Browse files Browse the repository at this point in the history
[Bugfix]: Item prices does not work #500
  • Loading branch information
Timo A. Hummel committed Mar 9, 2016
2 parents 4a3dc3e + bc8023f commit f494a53
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/PartKeepr/PartBundle/Entity/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,24 +823,41 @@ 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);
}

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);
Expand Down

0 comments on commit f494a53

Please sign in to comment.