src/AtechNet/CoreBundle/Entity/AttributeOptionMeta.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 as Table;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * AttributeOptionMeta
  12.  *
  13.  * @Table(name="attribute_options_metas")
  14.  * @Entity
  15.  * @HasLifecycleCallbacks
  16.  */
  17. class AttributeOptionMeta 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.      * @var AttributeOption
  30.      *
  31.      * @Assert\NotNull
  32.      *
  33.      * @ManyToOne(targetEntity="AttributeOption", inversedBy="metas")
  34.      * @JoinColumn(name="attribute_option_id", referencedColumnName="id")
  35.      */
  36.     private $attributeOption;
  37.     /**
  38.      * @var int
  39.      *
  40.      * @Column(name="price", type="decimal", precision=10, scale=2)
  41.      */
  42.     private $price = 0;
  43.     /**
  44.      * @var int
  45.      *
  46.      * @Column(name="discount", type="decimal", precision=10, scale=2)
  47.      */
  48.     private $discount = 0;
  49.     /**
  50.      * @var bool
  51.      *
  52.      * @Column(name="discounted", type="boolean")
  53.      */
  54.     private $discounted = false;
  55.     /**
  56.      * @return Domain
  57.      */
  58.     public function getDomain()
  59.     {
  60.         return $this->domain;
  61.     }
  62.     /**
  63.      * @param Domain $domain
  64.      */
  65.     public function setDomain($domain)
  66.     {
  67.         $this->domain = $domain;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return AttributeOption
  72.      */
  73.     public function getAttributeOption()
  74.     {
  75.         return $this->attributeOption;
  76.     }
  77.     /**
  78.      * @param AttributeOption $attributeOption
  79.      */
  80.     public function setAttributeOption($attributeOption)
  81.     {
  82.         $this->attributeOption = $attributeOption;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return int
  87.      */
  88.     public function getPrice()
  89.     {
  90.         return $this->price;
  91.     }
  92.     /**
  93.      * @param int $price
  94.      */
  95.     public function setPrice($price)
  96.     {
  97.         $this->price = $price;
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return int
  102.      */
  103.     public function getVatPrice()
  104.     {
  105.         return $this->price * (1 + $this->domain->getVat() / 100.);
  106.     }
  107.     /**
  108.      * @return int
  109.      */
  110.     public function getDiscount()
  111.     {
  112.         return $this->discount;
  113.     }
  114.     /**
  115.      * @param int $discount
  116.      */
  117.     public function setDiscount($discount)
  118.     {
  119.         $this->discount = $discount;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return int
  124.      */
  125.     public function getVatDiscount()
  126.     {
  127.         return $this->discount * (1 + $this->domain->getVat() / 100.);
  128.     }
  129.     /**
  130.      * @return boolean
  131.      */
  132.     public function isDiscounted()
  133.     {
  134.         return $this->discounted;
  135.     }
  136.     /**
  137.      * @param boolean $discounted
  138.      */
  139.     public function setDiscounted($discounted)
  140.     {
  141.         $this->discounted = $discounted;
  142.         return $this;
  143.     }
  144.     private $priceCache = null;
  145.     /**
  146.      * @return float|null
  147.      */
  148.     public function getDomainPrice()
  149.     {
  150.         if ($this->priceCache == null) {
  151.             $this->priceCache = round($this->getDomainVatPrice() / (1 + $this->domain->getVat() / 100.), $this->domain->getPricePrecision(), PHP_ROUND_HALF_UP);
  152.         }
  153.         if (in_array($this->domain->getId(), [Domain::DOMAIN_ID_RT_HU, Domain::DOMAIN_ID_WS_HU]) && $this->priceCache % 10 != 0) {
  154.             return ceil($this->priceCache / 10) * 10;
  155.         }
  156.         return $this->priceCache;
  157.     }
  158.     private $vatPriceCache = null;
  159.     /**
  160.      * @return float|null
  161.      */
  162.     public function getDomainVatPrice()
  163.     {
  164.         if ($this->vatPriceCache == null) {
  165.             $this->vatPriceCache = $this->domain->createVatPrice($this->getPrice());
  166.         }
  167.         return $this->vatPriceCache;
  168.     }
  169.     private $discountPriceCache = null;
  170.     /**
  171.      * @return float|null
  172.      */
  173.     public function getDomainDiscount()
  174.     {
  175.         if ($this->discountPriceCache == null) {
  176.             $this->discountPriceCache = round($this->getDomainVatDiscount() / (1 + $this->domain->getVat() / 100.), $this->domain->getPricePrecision(), PHP_ROUND_HALF_UP);
  177.         }
  178.         if (in_array($this->domain->getId(), [Domain::DOMAIN_ID_RT_HU, Domain::DOMAIN_ID_WS_HU]) && $this->discountPriceCache % 10 != 0) {
  179.             return ceil($this->discountPriceCache / 10) * 10;
  180.         }
  181.         return $this->discountPriceCache;
  182.     }
  183.     private $discountVatPriceCache = null;
  184.     /**
  185.      * @return float|null
  186.      */
  187.     public function getDomainVatDiscount()
  188.     {
  189.         if ($this->discountVatPriceCache == null) {
  190.             $this->discountVatPriceCache = $this->domain->createVatPrice($this->getDiscount());
  191.         }
  192.         return $this->discountVatPriceCache;
  193.     }
  194. }