<?php
// src/Acme/UserBundle/Entity/User.php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use App\Model\LangParamRelationInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @Doctrine\ORM\Mapping\Entity
* @Doctrine\ORM\Mapping\Table(name="product_price")
*/
class ProductPrice implements LangParamRelationInterface
, BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use SoftDeletableTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\Product", inversedBy="productPrices")
* @Doctrine\ORM\Mapping\JoinColumn(name="product_id", referencedColumnName="id")
*/
private $product;
/**
* @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\ProductPrice")
* @Doctrine\ORM\Mapping\JoinColumn(name="parent_product_price_id", referencedColumnName="id")
*/
private $parentProductPrice;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Currency")
*/
private $currency;
/**
* @Doctrine\ORM\Mapping\Column(type="float", nullable=true)
*/
protected $price;
/**
* @Doctrine\ORM\Mapping\Column(type="float", nullable=true)
*/
protected $discount;
/**
* @Doctrine\ORM\Mapping\Column(name="old_price", type="decimal", precision=10, scale=2, nullable=true)
*/
protected $oldPrice;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Language")
* @ORM\JoinColumn(name="language", referencedColumnName="id")
*/
protected $language;
/**
* Aktywny/nieakwtyny
* @Doctrine\ORM\Mapping\Column(type="boolean", options={"default"=1}, nullable=true)
*/
protected $active;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductPriceVariants", mappedBy="productPrice", cascade={"persist"})
*/
protected $variants;
private $tempVersion;
/**
* @var string
*
* @ORM\Column(name="automatic_price_comment", type="string", length=255, nullable=true)
*/
private $automaticPriceComment;
/**
* @var string
*
* @ORM\Column(name="ean", type="string", length=255, nullable=true)
*/
private $ean;
/**
* @Doctrine\ORM\Mapping\Column(name="automatic_price", type="boolean", options={"default"=1}, nullable=true)
*/
protected $automaticPrice = true;
/**
* @Doctrine\ORM\Mapping\Column(type="float", nullable=true)
*/
protected $automaticPriceDiscount;
private $customName = null;
/**
* @return null
*/
public function getCustomName()
{
return $this->customName;
}
/**
* @param null $customName
*/
public function setCustomName($customName): void
{
$this->customName = $customName;
}
/**
* @return mixed
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param mixed $discount
*/
public function setDiscount($discount)
{
$this->discount = $discount;
}
/**
* @return mixed
*/
public function getTempVersion()
{
return $this->tempVersion;
}
/**
* @param mixed $tempVersion
*/
public function setTempVersion($tempVersion): void
{
$this->tempVersion = $tempVersion;
}
public function __construct()
{
$this->variants = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set price
*
* @param string $price
*
* @return ProductPrice
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return string
*/
public function getPrice()
{
return $this->price;
}
public function getPriceGross(ProductVat $productVat = null, $precision = 2, $promoPriceIncluded = false) {
$net = $this->getPrice();
if ($promoPriceIncluded) {
foreach ($this->getProduct()->getLangParams() as $langParam) {
if ($this->getLanguage()->getId() === $langParam->getLanguage()->getId()) {
if ($langParam->getPromoPrice() && !$this->getProduct()->getIsVariants() && (float)$langParam->getPromoPrice() > 0) {
$net = $langParam->getPromoPrice();
}
}
}
}
if (is_object($productVat)) {
$vatRate = ($productVat->getValue()+100)/100;
} else {
$vatRate = 1;
}
$returnPrice = round($net * $vatRate, $precision);
return $returnPrice;
}
public function getPriceNet($priceGross, ProductVat $productVat = null, $precision = 2, $promoPriceIncluded = false) {
$gros = $priceGross;
if (is_object($productVat)) {
$vatRate = ($productVat->getValue()+100)/100;
} else {
$vatRate = 1;
}
if ($promoPriceIncluded) {
foreach ($this->getProduct()->getLangParams() as $langParam) {
if ($this->getLanguage()->getId() === $langParam->getLanguage()->getId()) {
if ($langParam->getPromoPrice() && !$this->getProduct()->getIsVariants() && (float)$langParam->getPromoPrice() > 0) {
$net = $langParam->getPromoPrice();
$gros = round($net * $vatRate, $langParam->getLanguage()->getRoundingPrecision());
}
}
}
}
$returnPrice = round($gros / $vatRate, $precision);
return $returnPrice;
}
/**
* Set product
*
* @param \App\Entity\Product $product
*
* @return ProductPrice
*/
public function setProduct(\App\Entity\Product $product = null)
{
$this->product = $product;
return $this;
}
/**
* Get product
*
* @return \App\Entity\Product
*/
public function getProduct()
{
return $this->product;
}
/**
* Set currency
*
* @param \App\Entity\Currency $currency
*
* @return ProductPrice
*/
public function setCurrency(\App\Entity\Currency $currency = null)
{
$this->currency = $currency;
return $this;
}
/**
* Get currency
*
* @return \App\Entity\Currency
*/
public function getCurrency()
{
return $this->currency;
}
public function getLanguage(): ?Language
{
return $this->language;
}
public function setLanguage(?Language $language): self
{
$this->language = $language;
return $this;
}
public function getOldPrice()
{
return $this->oldPrice;
}
public function setOldPrice($oldPrice): self
{
$this->oldPrice = $oldPrice;
return $this;
}
/**
* @return Collection|ProductPriceVariants[]
*/
public function getVariants(): Collection
{
return $this->variants;
}
public function addVariant(ProductPriceVariants $variant): self
{
if (!$this->variants->contains($variant)) {
$this->variants[] = $variant;
$variant->setProductPrice($this);
}
return $this;
}
public function removeVariant(ProductPriceVariants $variant): self
{
if ($this->variants->contains($variant)) {
$this->variants->removeElement($variant);
// set the owning side to null (unless already changed)
if ($variant->getProductPrice() === $this) {
$variant->setProductPrice(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getActive()
{
return $this->active;
}
/**
* @param mixed $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* Set parentProductPrice
*
* @param \App\Entity\ProductPrice $parentProductPrice
*
* @return ProductPrice
*/
public function setParentProductPrice(\App\Entity\ProductPrice $parentProductPrice = null)
{
$this->parentProductPrice = $parentProductPrice;
return $this;
}
/**
* Get parentProductPrice
*
* @return \App\Entity\ProductPrice
*/
public function getParentProductPrice()
{
return $this->parentProductPrice;
}
/**
* @return string
*/
public function getAutomaticPriceComment(): ?string
{
return $this->automaticPriceComment;
}
/**
* @param string $automaticPriceComment
*/
public function setAutomaticPriceComment(string $automaticPriceComment): void
{
$this->automaticPriceComment = $automaticPriceComment;
}
/**
* @return bool
*/
public function isAutomaticPrice(): bool
{
return $this->automaticPrice;
}
/**
* @return bool
*/
public function getAutomaticPrice(): bool
{
return $this->automaticPrice;
}
/**
* @param bool $automaticPrice
*/
public function setAutomaticPrice(bool $automaticPrice): void
{
$this->automaticPrice = $automaticPrice;
}
/**
* @return mixed
*/
public function getAutomaticPriceDiscount()
{
return $this->automaticPriceDiscount;
}
/**
* @param mixed $automaticPriceDiscount
*/
public function setAutomaticPriceDiscount($automaticPriceDiscount): void
{
$this->automaticPriceDiscount = $automaticPriceDiscount;
}
/**
* @return string
*/
public function getEan(): ?string
{
return $this->ean;
}
/**
* @param string $ean
*/
public function setEan($ean)
{
$this->ean = $ean;
}
}