commit b9dd7484f2808804bdf130a3765847e11dac7128
parent 03f4b35c8a50a15125280998e6cb83d6c012d155
Author: Felicitus <felicitus@felicitus.org>
Date: Fri, 2 Oct 2015 18:44:27 +0200
Added the average price and removals listeners
Diffstat:
2 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20151001180120.php b/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20151001180120.php
@@ -5,7 +5,7 @@ use Doctrine\DBAL\Schema\Schema;
use PartKeepr\AuthBundle\Entity\UserProvider;
/**
- * Auto-generated Migration: Please modify to your needs!
+ * Attaches the builtin user provider to all existing users
*/
class Version20151001180120 extends BaseMigration
{
diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php
@@ -148,11 +148,10 @@ class Part extends BaseEntity
/**
* The average price for the part. Note that this is a cached value.
*
- * @todo It would be nice if we could get rid of that
- * @ORM\Column(type="decimal",precision=13,scale=4,nullable=true)
+ * @ORM\Column(type="decimal",precision=13,scale=4,nullable=false)
* @var float
*/
- private $averagePrice = null;
+ private $averagePrice = 0;
/**
* The stock level history
@@ -222,6 +221,28 @@ class Part extends BaseEntity
*/
private $internalPartNumber;
+ /**
+ * @ORM\Column(type="boolean",nullable=false)
+ * @var boolean
+ */
+ private $removals = false;
+
+ /**
+ * @return mixed
+ */
+ public function hetRemovals()
+ {
+ return $this->removals;
+ }
+
+ /**
+ * @param mixed $removals
+ */
+ public function setRemovals($removals = false)
+ {
+ $this->removals = $removals;
+ }
+
public function __construct()
{
$this->distributors = new ArrayCollection();
@@ -618,8 +639,7 @@ class Part extends BaseEntity
*/
public function onPrePersist()
{
- $this->checkCategoryConsistency();
- $this->checkStorageLocationConsistency();
+ $this->executeSaveListener();
}
/**
@@ -634,8 +654,25 @@ class Part extends BaseEntity
*/
public function onPreUpdate()
{
+ $this->executeSaveListener();
+ }
+
+ public function executeSaveListener () {
$this->checkCategoryConsistency();
$this->checkStorageLocationConsistency();
+
+ $price = 0;
+
+ $this->setRemovals(false);
+
+ foreach ($this->getStockLevels() as $stockEntry) {
+ $price += $stockEntry->getPrice();
+ if ($stockEntry->getStockLevel() < 0) {
+ $this->setRemovals(true);
+ }
+ }
+
+ $this->setAveragePrice($price);
}
/**
@@ -661,7 +698,7 @@ class Part extends BaseEntity
/**
* Returns all stock entries
*
- * @return ArrayCollection
+ * @return StockEntry[]
*/
public function getStockLevels()
{
@@ -756,16 +793,4 @@ class Part extends BaseEntity
{
return $this->projectParts;
}
-
- /**
- * Returns a string representation of the part
- *
- * @param none
- *
- * @return string The name and the ID of the part
- */
- public function __toString()
- {
- return $this->getName()." (".$this->getId().")";
- }
}