<?php
namespace App\AtechNet\CoreBundle\Entity;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table as Table;
use Symfony\Component\Validator\Constraints as Assert;
/**
* AttributeOptionMeta
*
* @Table(name="attribute_options_metas")
* @Entity
* @HasLifecycleCallbacks
*/
class AttributeOptionMeta extends AbstractSignedEntity
{
/**
* @var Domain
*
* @Assert\NotNull
*
* @ManyToOne(targetEntity="Domain")
* @JoinColumn(name="domain_id", referencedColumnName="id")
*/
private $domain;
/**
* @var AttributeOption
*
* @Assert\NotNull
*
* @ManyToOne(targetEntity="AttributeOption", inversedBy="metas")
* @JoinColumn(name="attribute_option_id", referencedColumnName="id")
*/
private $attributeOption;
/**
* @var int
*
* @Column(name="price", type="decimal", precision=10, scale=2)
*/
private $price = 0;
/**
* @var int
*
* @Column(name="discount", type="decimal", precision=10, scale=2)
*/
private $discount = 0;
/**
* @var bool
*
* @Column(name="discounted", type="boolean")
*/
private $discounted = false;
/**
* @return Domain
*/
public function getDomain()
{
return $this->domain;
}
/**
* @param Domain $domain
*/
public function setDomain($domain)
{
$this->domain = $domain;
return $this;
}
/**
* @return AttributeOption
*/
public function getAttributeOption()
{
return $this->attributeOption;
}
/**
* @param AttributeOption $attributeOption
*/
public function setAttributeOption($attributeOption)
{
$this->attributeOption = $attributeOption;
return $this;
}
/**
* @return int
*/
public function getPrice()
{
return $this->price;
}
/**
* @param int $price
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* @return int
*/
public function getVatPrice()
{
return $this->price * (1 + $this->domain->getVat() / 100.);
}
/**
* @return int
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param int $discount
*/
public function setDiscount($discount)
{
$this->discount = $discount;
return $this;
}
/**
* @return int
*/
public function getVatDiscount()
{
return $this->discount * (1 + $this->domain->getVat() / 100.);
}
/**
* @return boolean
*/
public function isDiscounted()
{
return $this->discounted;
}
/**
* @param boolean $discounted
*/
public function setDiscounted($discounted)
{
$this->discounted = $discounted;
return $this;
}
private $priceCache = null;
/**
* @return float|null
*/
public function getDomainPrice()
{
if ($this->priceCache == null) {
$this->priceCache = round($this->getDomainVatPrice() / (1 + $this->domain->getVat() / 100.), $this->domain->getPricePrecision(), PHP_ROUND_HALF_UP);
}
if (in_array($this->domain->getId(), [Domain::DOMAIN_ID_RT_HU, Domain::DOMAIN_ID_WS_HU]) && $this->priceCache % 10 != 0) {
return ceil($this->priceCache / 10) * 10;
}
return $this->priceCache;
}
private $vatPriceCache = null;
/**
* @return float|null
*/
public function getDomainVatPrice()
{
if ($this->vatPriceCache == null) {
$this->vatPriceCache = $this->domain->createVatPrice($this->getPrice());
}
return $this->vatPriceCache;
}
private $discountPriceCache = null;
/**
* @return float|null
*/
public function getDomainDiscount()
{
if ($this->discountPriceCache == null) {
$this->discountPriceCache = round($this->getDomainVatDiscount() / (1 + $this->domain->getVat() / 100.), $this->domain->getPricePrecision(), PHP_ROUND_HALF_UP);
}
if (in_array($this->domain->getId(), [Domain::DOMAIN_ID_RT_HU, Domain::DOMAIN_ID_WS_HU]) && $this->discountPriceCache % 10 != 0) {
return ceil($this->discountPriceCache / 10) * 10;
}
return $this->discountPriceCache;
}
private $discountVatPriceCache = null;
/**
* @return float|null
*/
public function getDomainVatDiscount()
{
if ($this->discountVatPriceCache == null) {
$this->discountVatPriceCache = $this->domain->createVatPrice($this->getDiscount());
}
return $this->discountVatPriceCache;
}
}