Created
August 28, 2012 22:20
-
-
Save clubdesarrolladores/3504860 to your computer and use it in GitHub Desktop.
Entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace WebFactory\PurchaseBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use APY\DataGridBundle\Grid\Mapping as Grid; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* WebFactory\PurchaseBundle\Entity\Expense | |
* | |
* @ORM\Table(name="webfactory_purchase_expenses") | |
* @ORM\Entity(repositoryClass="WebFactory\PurchaseBundle\Entity\ExpenseRepository") | |
* @Grid\Source(columns="id, provider.name, name, type, plannedDischarges.ammount:sum") | |
*/ | |
class Expense | |
{ | |
/** | |
* @var integer $id | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* | |
* @var type | |
* @ORM\Column(type="string", length=32) | |
* @Grid\Column(title="Name") | |
* @Assert\NotBlank | |
*/ | |
private $name; | |
/** | |
* | |
* @var type | |
* @ORM\Column(type="string", length=32) | |
* @Grid\Column(title="Type", filter="select", selectFrom="values", values={"expense.type.tax"="expense.type.tax","expense.type.fixed"="expense.type.fixed", "expense.type.variable"="expense.type.variable"}, operatorsVisible=false ) | |
* @Assert\NotBlank | |
*/ | |
private $type; | |
/** | |
* | |
* @var type | |
* @ORM\ManyToOne(targetEntity="WebFactory\CompanyBundle\Entity\Provider") | |
* @Grid\Column(field="provider.name", title="Provider") | |
* @Assert\NotBlank | |
*/ | |
private $provider; | |
/** | |
* | |
* @var type | |
* @ORM\OneToMany(targetEntity="PlannedDischarge", mappedBy="expense", cascade={"persist"}, orphanRemoval=true) | |
* @Grid\Column(title="Ammount (calculated)", field="plannedDischarges.ammount:sum", type="number", style="currency", currencyCode="ARS") | |
*/ | |
private $plannedDischarges; | |
/** | |
* @ORM\OneToMany(targetEntity="ExpenseGenerationConfiguration", mappedBy="expense", cascade={"all"}, orphanRemoval=true) | |
* @var ExpenseGenerationConfiguration $expenseGenerationConfigurations | |
* @Assert\Valid | |
*/ | |
private $expenseGenerationConfigurations; | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
$this->plannedDischarges = new \Doctrine\Common\Collections\ArrayCollection(); | |
} | |
/** | |
* Get id | |
* | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set name | |
* | |
* @param string $name | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
} | |
/** | |
* Get name | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* Set type | |
* | |
* @param string $type | |
*/ | |
public function setType($type) | |
{ | |
$this->type = $type; | |
} | |
/** | |
* Get type | |
* | |
* @return string | |
*/ | |
public function getType() | |
{ | |
return $this->type; | |
} | |
/** | |
* Set provider | |
* | |
* @param WebFactory\CompanyBundle\Entity\Provider $provider | |
*/ | |
public function setProvider(\WebFactory\CompanyBundle\Entity\Provider $provider) | |
{ | |
$this->provider = $provider; | |
} | |
/** | |
* Get provider | |
* | |
* @return WebFactory\CompanyBundle\Entity\Provider | |
*/ | |
public function getProvider() | |
{ | |
return $this->provider; | |
} | |
/** | |
* Add plannedDischarges | |
* | |
* @param WebFactory\PurchaseBundle\Entity\PlannedDischarge $plannedDischarges | |
*/ | |
public function addPlannedDischarge(\WebFactory\PurchaseBundle\Entity\PlannedDischarge $plannedDischarges) | |
{ | |
$this->plannedDischarges[] = $plannedDischarges; | |
} | |
/** | |
* Get plannedDischarges | |
* | |
* @return Doctrine\Common\Collections\Collection | |
*/ | |
public function getPlannedDischarges() | |
{ | |
return $this->plannedDischarges; | |
} | |
/** | |
* Reprensentación del gasto como texto | |
* | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
$pattern = '%s (%s)'; | |
return sprintf($pattern, $this->getName(), $this->getProvider()); | |
} | |
/** | |
* Add expenseGenerationConfigurations | |
* | |
* @param WebFactory\PurchaseBundle\Entity\ExpenseGenerationConfiguration $expenseGenerationConfigurations | |
* @return Expense | |
*/ | |
public function addExpenseGenerationConfiguration(\WebFactory\PurchaseBundle\Entity\ExpenseGenerationConfiguration $expenseGenerationConfigurations) | |
{ | |
$this->expenseGenerationConfigurations[] = $expenseGenerationConfigurations; | |
return $this; | |
} | |
/** | |
* Set expenseGenerationConfigurations | |
* | |
* @param \Doctrine\Common\Collections\ArrayCollection $expenseGenerationConfigurations | |
* @return Expense | |
*/ | |
public function setExpenseGenerationConfigurations($expenseGenerationConfigurations) | |
{ | |
foreach($expenseGenerationConfigurations as $expenseGenerationConfiguration) { | |
$expenseGenerationConfiguration->setExpense($this); | |
} | |
$this->expenseGenerationConfigurations = $expenseGenerationConfigurations; | |
return $this; | |
} | |
/** | |
* Get expenseGenerationConfigurations | |
* | |
* @return Doctrine\Common\Collections\Collection | |
*/ | |
public function getExpenseGenerationConfigurations() | |
{ | |
return $this->expenseGenerationConfigurations; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment