src/AtechNet/CoreBundle/Entity/ProductContainerMeta.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping\Column;
  4. use Doctrine\ORM\Mapping\Entity;
  5. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  6. use Doctrine\ORM\Mapping\JoinColumn;
  7. use Doctrine\ORM\Mapping\ManyToOne;
  8. use Doctrine\ORM\Mapping\Table;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * ProductContainerMeta
  12.  *
  13.  * @Table(name="product_container_metas")
  14.  * @Entity
  15.  * @HasLifecycleCallbacks
  16.  */
  17. class ProductContainerMeta extends AbstractSignedEntity
  18. {
  19.     /**
  20.      * @var Domain
  21.      *
  22.      * @Assert\NotNull
  23.      *
  24.      * @ManyToOne(targetEntity="Domain")
  25.      * @JoinColumn(name="domain_id", referencedColumnName="id")
  26.      */
  27.     private $domain;
  28.     
  29.     /**
  30.      * @var ProductContainer
  31.      *
  32.      * @Assert\NotNull
  33.      *
  34.      * @ManyToOne(targetEntity="ProductContainer", inversedBy="metas")
  35.      * @JoinColumn(name="product_container_id", referencedColumnName="id")
  36.      */
  37.     private $productContainer;
  38.     
  39.     /**
  40.      * @var int
  41.      *
  42.      * @Column(name="price", type="decimal", precision=10, scale=3)
  43.      */
  44.     private $price = 0;
  45.     
  46.     /**
  47.      * @var int
  48.      *
  49.      * @Column(name="discount", type="decimal", precision=10, scale=3)
  50.      */
  51.     private $discount = 0;
  52.     /**
  53.      * @return Domain
  54.      */
  55.     public function getDomain(): Domain
  56.     {
  57.         return $this->domain;
  58.     }
  59.     
  60.     /**
  61.      * @param Domain $domain
  62.      */
  63.     public function setDomain(Domain $domain)
  64.     {
  65.         $this->domain = $domain;
  66.     }
  67.     /**
  68.      * @return \AtechNet\CoreBundle\Entity\ProductContainer
  69.      */
  70.     public function getProductContainer(): ProductContainer
  71.     {
  72.         return $this->productContainer;
  73.     }
  74.     /**
  75.      * @param \AtechNet\CoreBundle\Entity\ProductContainer $productContainer
  76.      */
  77.     public function setProductContainer(ProductContainer $productContainer)
  78.     {
  79.         $this->productContainer = $productContainer;
  80.     }
  81.     /**
  82.      * @return float
  83.      */
  84.     public function getPrice()
  85.     {
  86.         return $this->price;
  87.     }
  88.     
  89.     /**
  90.      * @param float $price
  91.      */
  92.     public function setPrice($price)
  93.     {
  94.         $this->price = $price;
  95.     }
  96.     
  97.     /**
  98.      * @return float
  99.      */
  100.     public function getDiscount()
  101.     {
  102.         return $this->discount;
  103.     }
  104.     
  105.     /**
  106.      * @param float $discount
  107.      */
  108.     public function setDiscount($discount)
  109.     {
  110.         $this->discount = $discount;
  111.     }
  112.     
  113.     /**
  114.      * @return float
  115.      */
  116.     public function getVatDiscount()
  117.     {
  118.         return $this->discount * (1 + $this->domain->getVat() / 100.);
  119.     }
  120.     
  121.     private $priceCache = null;
  122.     
  123.     /**
  124.      * @return float|null
  125.      */
  126.     public function getDomainPrice()
  127.     {
  128.         if ($this->priceCache == null) {
  129.             $this->priceCache = round($this->getDomainVatPrice() / (1 + $this->domain->getVat() / 100.), $this->domain->getPricePrecision(), PHP_ROUND_HALF_UP);
  130.         }
  131.         return $this->priceCache;
  132.     }
  133.     
  134.     private $vatPriceCache = null;
  135.     
  136.     /**
  137.      * @return float|null
  138.      */
  139.     public function getDomainVatPrice()
  140.     {
  141.         if ($this->vatPriceCache == null) {
  142.             $this->vatPriceCache = $this->domain->createVatPrice($this->getPrice());
  143.         }
  144.         return $this->vatPriceCache;
  145.     }
  146.     
  147.     private $discountPriceCache = null;
  148.     
  149.     /**
  150.      * @return float|null
  151.      */
  152.     public function getDomainDiscount()
  153.     {
  154.         if ($this->discountPriceCache == null) {
  155.             $this->discountPriceCache = round($this->getDomainVatDiscount() / (1 + $this->domain->getVat() / 100.), $this->domain->getPricePrecision(), PHP_ROUND_HALF_UP);
  156.         }
  157.         return $this->discountPriceCache;
  158.     }
  159.     private $discountVatPriceCache = null;
  160.     /**
  161.      * @return float|null
  162.      */
  163.     public function getDomainVatDiscount()
  164.     {
  165.         if ($this->discountVatPriceCache == null) {
  166.             $this->discountVatPriceCache = $this->domain->createVatPrice($this->getDiscount());
  167.         }
  168.         return $this->discountVatPriceCache;
  169.     }
  170. }