Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
[#SDV-202] Enable saving of closing balances
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulVM committed Jan 27, 2015
1 parent c3f26f3 commit b88cae2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
27 changes: 15 additions & 12 deletions src/Opg/Core/Model/Entity/Document/Decorators/ClosingBalances.php
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Type;
use Opg\Core\Model\Entity\LineItem\LineItem;

/**
Expand All @@ -12,16 +13,17 @@
*/
trait ClosingBalances
{

/**
* @ORM\OneToMany(targetEntity="Opg\Core\Model\Entity\LineItem\LineItem", mappedBy="document", cascade={"all"},)
* @var ArrayCollection
* @Type("ArrayCollection<Opg\Core\Model\Entity\LineItem\LineItem>")
*/
protected $balances;
protected $closingBalances;

protected function initClosingBalances()
{
if (null === $this->balances) {
$this->balances = new ArrayCollection();
if (null === $this->closingBalances) {
$this->closingBalances = new ArrayCollection();
}
}
/**
Expand All @@ -31,17 +33,18 @@ public function getClosingBalances()
{
$this->initClosingBalances();

return $this->balances;
return $this->closingBalances;
}

/**
* @param LineItem $closingBalance
* @param \Opg\Core\Model\Entity\LineItem\LineItem $closingBalance
* @return HasClosingBalances
*/
public function addClosingBalance(LineItem $closingBalance)
{
$this->initClosingBalances();
$this->balances->add($closingBalance);
$closingBalance->setDocument($this);
$this->closingBalances->add($closingBalance);

return $this;
}
Expand All @@ -52,7 +55,7 @@ public function addClosingBalance(LineItem $closingBalance)
*/
public function setClosingBalances(ArrayCollection $closingBalances)
{
$this->balances = new ArrayCollection();
$this->closingBalances = new ArrayCollection();

foreach ($closingBalances as $closingBalance) {
$this->addClosingBalance($closingBalance);
Expand All @@ -62,24 +65,24 @@ public function setClosingBalances(ArrayCollection $closingBalances)
}

/**
* @param LineItem $closingBalance
* @param \Opg\Core\Model\Entity\LineItem\LineItem $closingBalance
* @return boolean
*/
public function closingBalanceExists(LineItem $closingBalance)
{
$this->initClosingBalances();

return $this->balances->contains($closingBalance);
return $this->closingBalances->contains($closingBalance);
}

/**
* @param LineItem $closingBalance
* @param \Opg\Core\Model\Entity\LineItem\LineItem $closingBalance
* @return HasClosingBalances
*/
public function removeClosingBalance(LineItem $closingBalance)
{
if ($this->closingBalanceExists($closingBalance)) {
$this->balances->removeElement($closingBalance);
$this->closingBalances->removeElement($closingBalance);
}

return $this;
Expand Down
2 changes: 2 additions & 0 deletions src/Opg/Core/Model/Entity/Document/LodgingChecklist.php
Expand Up @@ -2,6 +2,7 @@

namespace Opg\Core\Model\Entity\Document;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Type;
Expand All @@ -10,6 +11,7 @@
use JMS\Serializer\Annotation\ReadOnly;
use Opg\Core\Model\Entity\Document\Decorators\ClosingBalances;
use Opg\Core\Model\Entity\Document\Decorators\HasClosingBalances;
use Opg\Core\Model\Entity\LineItem\LineItem;

/**
* @ORM\Entity
Expand Down
30 changes: 28 additions & 2 deletions src/Opg/Core/Model/Entity/LineItem/LineItem.php
Expand Up @@ -3,8 +3,10 @@
namespace Opg\Core\Model\Entity\LineItem;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Type;
use Opg\Common\Model\Entity\HasIdInterface;
use Opg\Common\Model\Entity\Traits\HasId;
use Opg\Core\Model\Entity\Document\Document;

/**
* Class LineItem
Expand All @@ -16,6 +18,13 @@ class LineItem implements HasIdInterface
{
use HasId;

/**
* @ORM\ManyToOne(targetEntity="Opg\Core\Model\Entity\Document\Document", cascade={"all"}, fetch="EAGER")
* @Type("Opg\Core\Model\Entity\Document\Document")
* @var \Opg\Core\Model\Entity\Document\Document
*/
protected $document;

/**
* @ORM\Column(type="string", nullable=true)
* @var string
Expand All @@ -28,6 +37,25 @@ class LineItem implements HasIdInterface
*/
protected $itemValue;

/**
* @param \Opg\Core\Model\Entity\Document\Document $document
* @return LineItem
*/
public function setDocument(Document $document)
{
$this->document = $document;

return $this;
}

/**
* @return \Opg\Core\Model\Entity\Document\Document
*/
public function getDocument()
{
return $this->document;
}

/**
* @param string $itemName
* @return LineItem
Expand Down Expand Up @@ -65,6 +93,4 @@ public function getValue()
{
return $this->itemValue;
}


}

0 comments on commit b88cae2

Please sign in to comment.