<?php
namespace App\Entity\Gos;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\Gos\ProductPackItemRepository")
* @ORM\HasLifecycleCallbacks
*/
class ProductPackItem
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=true)
*/
private $isGross;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $discount;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductPack", inversedBy="productPackItem")
* @ORM\JoinColumn()
*/
private $productPack;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductVariant", inversedBy="productPackItem")
* @ORM\JoinColumn()
*/
private $productVariant;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\OrderProductVariant", mappedBy="productPackItem")
*/
private $orderProductVariant;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $price;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $bulletPoints = [];
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="integer", options={"default": 1})
*/
private $quantity = 1;
public function __construct()
{
$this->orderProductVariant = new ArrayCollection();
}
/** @ORM\PrePersist() */
public function prePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __toString()
{
return (string) $this->id;
}
public function getDiscountNet()
{
if ($this->getIsGross())
{
return $this->getProductVariant()->getFullPrice('net') - $this->getPriceNet();
}
return $this->getDiscount();
}
public function getDiscountGross()
{
if ($this->getIsGross())
{
return $this->getDiscount();
}
return $this->getProductVariant()->getFullPrice('gross') - $this->getPriceGross();
}
public function getPriceNet(): ?float
{
$productVariant = $this->getProductVariant();
$fullPriceGross = $productVariant->getFullPrice('gross');
if ($this->getIsGross())
{
$priceNet = $productVariant->getPriceNetDiscountAmount($fullPriceGross, $this->getDiscount());
/** @var ProductVariant $virtualVariant */
foreach ($productVariant->getVirtualVariant() as $virtualVariant)
{
$priceNet += $virtualVariant->getPriceNetDiscountAmount($fullPriceGross, $this->getDiscount());
}
}
else
{
$priceNet = $productVariant->getFullPrice('net') - $this->getDiscount();
}
if ($priceNet < 0) $priceNet = 0;
return round($priceNet, 2);
}
public function getPriceGross(): ?float
{
$productVariant = $this->getProductVariant();
$fullPriceNet = $productVariant->getFullPrice('net');
if ($this->getIsGross())
{
$priceGross = $productVariant->getFullPrice('gross') - $this->getDiscount();
}
else
{
$priceGross = $productVariant->getPriceGrossDiscountAmount($fullPriceNet, $this->getDiscount());
/** @var ProductVariant $virtualVariant */
foreach ($productVariant->getVirtualVariant() as $virtualVariant)
{
$priceGross += $virtualVariant->getPriceGrossDiscountAmount($fullPriceNet, $this->getDiscount());
}
}
if ($priceGross < 0) $priceGross = 0;
return round($priceGross, 2);
}
//------------------------------ setters & getters
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getProductPack(): ?ProductPack
{
return $this->productPack;
}
public function setProductPack(?ProductPack $productPack): self
{
$this->productPack = $productPack;
return $this;
}
public function getProductVariant(): ?ProductVariant
{
return $this->productVariant;
}
public function setProductVariant(?ProductVariant $productVariant): self
{
$this->productVariant = $productVariant;
return $this;
}
/**
* @return Collection|OrderProductVariant[]
*/
public function getOrderProductVariant(): Collection
{
return $this->orderProductVariant;
}
public function addOrderProductVariant(OrderProductVariant $orderProductVariant): self
{
if (!$this->orderProductVariant->contains($orderProductVariant)) {
$this->orderProductVariant[] = $orderProductVariant;
$orderProductVariant->setProductPackItem($this);
}
return $this;
}
public function removeOrderProductVariant(OrderProductVariant $orderProductVariant): self
{
if ($this->orderProductVariant->contains($orderProductVariant)) {
$this->orderProductVariant->removeElement($orderProductVariant);
// set the owning side to null (unless already changed)
if ($orderProductVariant->getProductPackItem() === $this) {
$orderProductVariant->setProductPackItem(null);
}
}
return $this;
}
public function getIsGross(): ?bool
{
return $this->isGross;
}
public function setIsGross(?bool $isGross): self
{
$this->isGross = $isGross;
return $this;
}
public function getDiscount(): ?float
{
return $this->discount;
}
public function setDiscount(?float $discount): self
{
$this->discount = $discount;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
public function getBulletPoints(): ?array
{
return $this->bulletPoints;
}
public function setBulletPoints(?array $bulletPoints): self
{
$this->bulletPoints = array_values($bulletPoints);
return $this;
}
public function getDescription()
{
return $this->description;
}
public function setDescription(string $description): void
{
$this->description = $description;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
}