src/Entity/CartProductEquipment.php line 26

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