<?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;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ProductContainerMeta
*
* @Table(name="product_container_metas")
* @Entity
* @HasLifecycleCallbacks
*/
class ProductContainerMeta extends AbstractSignedEntity
{
/**
* @var Domain
*
* @Assert\NotNull
*
* @ManyToOne(targetEntity="Domain")
* @JoinColumn(name="domain_id", referencedColumnName="id")
*/
private $domain;
/**
* @var ProductContainer
*
* @Assert\NotNull
*
* @ManyToOne(targetEntity="ProductContainer", inversedBy="metas")
* @JoinColumn(name="product_container_id", referencedColumnName="id")
*/
private $productContainer;
/**
* @var int
*
* @Column(name="price", type="decimal", precision=10, scale=3)
*/
private $price = 0;
/**
* @var int
*
* @Column(name="discount", type="decimal", precision=10, scale=3)
*/
private $discount = 0;
/**
* @return Domain
*/
public function getDomain(): Domain
{
return $this->domain;
}
/**
* @param Domain $domain
*/
public function setDomain(Domain $domain)
{
$this->domain = $domain;
}
/**
* @return \AtechNet\CoreBundle\Entity\ProductContainer
*/
public function getProductContainer(): ProductContainer
{
return $this->productContainer;
}
/**
* @param \AtechNet\CoreBundle\Entity\ProductContainer $productContainer
*/
public function setProductContainer(ProductContainer $productContainer)
{
$this->productContainer = $productContainer;
}
/**
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* @param float $price
*/
public function setPrice($price)
{
$this->price = $price;
}
/**
* @return float
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param float $discount
*/
public function setDiscount($discount)
{
$this->discount = $discount;
}
/**
* @return float
*/
public function getVatDiscount()
{
return $this->discount * (1 + $this->domain->getVat() / 100.);
}
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);
}
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);
}
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;
}
}