src/Entity/CartProductEquipment.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  4. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  5. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  6. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  7. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Symfony\Component\HttpFoundation\File\File;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. /**
  17.  * @ORM\Entity
  18.  * @ORM\Table(name="cart_product_equipment")
  19.  */
  20. class CartProductEquipment implements BlameableInterfaceTimestampableInterfaceSoftDeletableInterface  {
  21.     use BlameableTrait;
  22.     use TimestampableTrait;
  23.     
  24.     use SoftDeletableTrait;
  25.     
  26. /**
  27.      * @ORM\Id
  28.      * @ORM\Column(type="integer")
  29.      * @ORM\GeneratedValue(strategy="AUTO")
  30.      */
  31.     protected $id;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity="App\Entity\CartProduct", inversedBy="equipments")
  34.      */
  35.     private $cartProduct;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\ProductEquipment")
  38.      */
  39.     private $equipment;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\Product")
  42.      */
  43.     private $product;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity="App\Entity\Currency")
  46.      */
  47.     private $currency;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\ProductVat")
  50.      */
  51.     private $vat;
  52.     /**
  53.      * @var integer
  54.      *
  55.      * @ORM\Column(name="quantity", type="integer", length=6, nullable=true)
  56.      */
  57.     private $quantity;
  58.     /**
  59.      * @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, scale=2, nullable=true)
  60.      */
  61.     protected $price;
  62.     /**
  63.      * @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, name="price_net", scale=2, nullable=true)
  64.      */
  65.     protected $priceNet;
  66.     /**
  67.      * @var string
  68.      *
  69.      * @ORM\Column(name="session", type="string", length=40, nullable=true)
  70.      */
  71.     private $session;
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getQuantity(): ?int
  77.     {
  78.         return $this->quantity;
  79.     }
  80.     public function setQuantity(?int $quantity): self
  81.     {
  82.         $this->quantity $quantity;
  83.         return $this;
  84.     }
  85.     public function getPrice()
  86.     {
  87.         return $this->price;
  88.     }
  89.     public function setPrice($price): self
  90.     {
  91.         $this->price $price;
  92.         $this->priceNet $this->calculatePriceNet();
  93.         return $this;
  94.     }
  95.     public function getSession(): ?string
  96.     {
  97.         return $this->session;
  98.     }
  99.     public function setSession(?string $session): self
  100.     {
  101.         $this->session $session;
  102.         return $this;
  103.     }
  104.     public function getCartProduct(): ?CartProduct
  105.     {
  106.         return $this->cartProduct;
  107.     }
  108.     public function setCartProduct(?CartProduct $cartProduct): self
  109.     {
  110.         $this->cartProduct $cartProduct;
  111.         return $this;
  112.     }
  113.     public function getEquipment(): ?ProductEquipment
  114.     {
  115.         return $this->equipment;
  116.     }
  117.     public function setEquipment(?ProductEquipment $equipment): self
  118.     {
  119.         $this->equipment $equipment;
  120.         return $this;
  121.     }
  122.     public function getProduct(): ?Product
  123.     {
  124.         return $this->product;
  125.     }
  126.     public function setProduct(?Product $product): self
  127.     {
  128.         $this->product $product;
  129.         return $this;
  130.     }
  131.     public function getCurrency(): ?Currency
  132.     {
  133.         return $this->currency;
  134.     }
  135.     public function setCurrency(?Currency $currency): self
  136.     {
  137.         $this->currency $currency;
  138.         return $this;
  139.     }
  140.     public function getVat(): ?ProductVat
  141.     {
  142.         return $this->vat;
  143.     }
  144.     public function setVat(?ProductVat $vat): self
  145.     {
  146.         $this->vat $vat;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return mixed
  151.      */
  152.     public function getPriceNet()
  153.     {
  154.         return $this->priceNet;
  155.     }
  156.     /**
  157.      * @param mixed $priceNet
  158.      */
  159.     public function setPriceNet($priceNet): void
  160.     {
  161.         $this->priceNet $priceNet;
  162.     }
  163.     /**
  164.      * Wyliczamy cenÄ™ netto na podstawie ceny brutto - w panelu podajemy cenÄ™ brutto dodatku
  165.      *
  166.      * @param ProductVat|null $productVat
  167.      * @param int $precision
  168.      * @return float
  169.      */
  170.     public function calculatePriceNet() {
  171.         $gross $this->price;
  172.         if (!$gross) {
  173.             return 0;
  174.         }
  175.         $vatRate = ($this->getCartProduct()->getVat()->getValue()+100)/100;
  176.         $returnPrice round($gross $vatRate$this->getCartProduct()->getCart()->getLanguage()->getPrecision());
  177.         return $returnPrice;
  178.     }
  179. }