<?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 Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="cart_product_equipment")
*/
class CartProductEquipment implements BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use SoftDeletableTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\CartProduct", inversedBy="equipments")
*/
private $cartProduct;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ProductEquipment")
*/
private $equipment;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product")
*/
private $product;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Currency")
*/
private $currency;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ProductVat")
*/
private $vat;
/**
* @var integer
*
* @ORM\Column(name="quantity", type="integer", length=6, nullable=true)
*/
private $quantity;
/**
* @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
protected $price;
/**
* @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, name="price_net", scale=2, nullable=true)
*/
protected $priceNet;
/**
* @var string
*
* @ORM\Column(name="session", type="string", length=40, nullable=true)
*/
private $session;
public function getId(): ?int
{
return $this->id;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(?int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getPrice()
{
return $this->price;
}
public function setPrice($price): self
{
$this->price = $price;
$this->priceNet = $this->calculatePriceNet();
return $this;
}
public function getSession(): ?string
{
return $this->session;
}
public function setSession(?string $session): self
{
$this->session = $session;
return $this;
}
public function getCartProduct(): ?CartProduct
{
return $this->cartProduct;
}
public function setCartProduct(?CartProduct $cartProduct): self
{
$this->cartProduct = $cartProduct;
return $this;
}
public function getEquipment(): ?ProductEquipment
{
return $this->equipment;
}
public function setEquipment(?ProductEquipment $equipment): self
{
$this->equipment = $equipment;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getCurrency(): ?Currency
{
return $this->currency;
}
public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}
public function getVat(): ?ProductVat
{
return $this->vat;
}
public function setVat(?ProductVat $vat): self
{
$this->vat = $vat;
return $this;
}
/**
* @return mixed
*/
public function getPriceNet()
{
return $this->priceNet;
}
/**
* @param mixed $priceNet
*/
public function setPriceNet($priceNet): void
{
$this->priceNet = $priceNet;
}
/**
* Wyliczamy cenÄ™ netto na podstawie ceny brutto - w panelu podajemy cenÄ™ brutto dodatku
*
* @param ProductVat|null $productVat
* @param int $precision
* @return float
*/
public function calculatePriceNet() {
$gross = $this->price;
if (!$gross) {
return 0;
}
$vatRate = ($this->getCartProduct()->getVat()->getValue()+100)/100;
$returnPrice = round($gross / $vatRate, $this->getCartProduct()->getCart()->getLanguage()->getPrecision());
return $returnPrice;
}
}