src/Entity/OrderProduct.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="order_product")
  19.  */
  20. class OrderProduct 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\Order", inversedBy="products")
  34.      */
  35.     private $order;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\Product")
  38.      */
  39.     private $product;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\SubProduct", inversedBy="orders")
  42.      */
  43.     private $subProduct;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity="App\Entity\Currency")
  46.      */
  47.     private $currency;
  48.     /**
  49.      * @var integer
  50.      *
  51.      * @ORM\Column(name="quantity", type="integer", length=6, nullable=true)
  52.      */
  53.     private $quantity;
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(name="inscription", type="text", nullable=true)
  58.      */
  59.     private $inscription;
  60.     /**
  61.      * @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, scale=2, nullable=true)
  62.      */
  63.     protected $price;
  64.     /**
  65.      * @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, name="price_net", scale=2, nullable=true)
  66.      */
  67.     protected $priceNet;
  68.     /**
  69.      * @var string
  70.      *
  71.      * @ORM\Column(name="session", type="string", length=40, nullable=true)
  72.      */
  73.     private $session;
  74.     /**
  75.      * @Doctrine\ORM\Mapping\Column(name="price_initial", type="decimal", precision=10, scale=2, nullable=true)
  76.      */
  77.     protected $priceInitial;
  78.     /**
  79.      * @ORM\OneToMany(targetEntity="App\Entity\OrderProductParameterValue", mappedBy="orderProduct", cascade={"all"})
  80.      */
  81.     protected $parameterValues;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity="App\Entity\OrderProductEquipment", mappedBy="orderProduct", cascade={"all"})
  84.      * @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
  85.      */
  86.     protected $equipments;
  87.     /**
  88.      * @ORM\ManyToOne(targetEntity="App\Entity\ProductPriceVariants")
  89.      */
  90.     private $variant;
  91.     public function getSubtotal() {
  92.         if ($this->getOrder()->getLanguage()->getLocaleShort() == 'ro') {
  93.             $params $this->getProduct()->getLangParams();
  94.             foreach ($params as $param) {
  95.                 if ($param->getLanguage()->getLocaleShort() == 'ro') {
  96.                     $vat $param->getVat();
  97.                     $vatRate = ($vat->getValue()+100)/100;
  98.                     return $this->getPriceNet() * $this->getQuantity() * $vatRate;
  99.                 }
  100.             }
  101.         }
  102.         return $this->getPrice() * $this->getQuantity();
  103.     }
  104.     public function getEquipmentAsString($cut false$delimiter ', ')
  105.     {
  106.         $data = array();
  107.         $equipments $this->getEquipments();
  108.         if ($equipments->count() == 0) {
  109.             return '';
  110.         }
  111.         /** @var $kind OrderProductEquipment */
  112.         foreach ($equipments as $kind)
  113.         {
  114.             $data[] = $kind->getEquipment()->getName().' ('.$kind->getPrice().$kind->getCurrency()->getSign().')';
  115.         }
  116.         return implode($delimiter$data);
  117.     }
  118.     public function __construct()
  119.     {
  120.         $this->parameterValues = new ArrayCollection();
  121.         $this->equipments = new ArrayCollection();
  122.     }
  123.     /**
  124.      * Get id
  125.      *
  126.      * @return integer
  127.      */
  128.     public function getId()
  129.     {
  130.         return $this->id;
  131.     }
  132.     /**
  133.      * Set quantity
  134.      *
  135.      * @param integer $quantity
  136.      *
  137.      * @return OrderProduct
  138.      */
  139.     public function setQuantity($quantity)
  140.     {
  141.         $this->quantity $quantity;
  142.         return $this;
  143.     }
  144.     /**
  145.      * Get quantity
  146.      *
  147.      * @return integer
  148.      */
  149.     public function getQuantity()
  150.     {
  151.         return $this->quantity;
  152.     }
  153.     /**
  154.      * Set inscription
  155.      *
  156.      * @param string $inscription
  157.      *
  158.      * @return OrderProduct
  159.      */
  160.     public function setInscription($inscription)
  161.     {
  162.         $this->inscription $inscription;
  163.         return $this;
  164.     }
  165.     /**
  166.      * Get inscription
  167.      *
  168.      * @return string
  169.      */
  170.     public function getInscription()
  171.     {
  172.         return $this->inscription;
  173.     }
  174.     /**
  175.      * Set price
  176.      *
  177.      * @param string $price
  178.      *
  179.      * @return OrderProduct
  180.      */
  181.     public function setPrice($price)
  182.     {
  183.         $this->price $price;
  184.         return $this;
  185.     }
  186.     public function getPrice() {
  187.         return $this->getPriceNetto();
  188.     }
  189.     public function getPriceNetto() {
  190.         return $this->price;
  191.     }
  192.     public function getGrossPrice() {
  193.         return $this->price;
  194.     }
  195.     public function getPriceBrutto() {
  196.         return $this->getPrice();
  197.     }
  198.     public function getSumNetto() {
  199.         $sum 0;
  200.         /** @var $orderProduct OrderProduct */
  201.         foreach ($this->getOrder()->getProducts() as $orderProduct) {
  202.             $sum $sum + ($this->getQuantity() * $this->getPriceNetto());
  203.         }
  204.         return $sum;
  205.     }
  206.     public function getQuantityOfProducts() {
  207.         $c 0;
  208.         /** @var $orderProduct OrderProduct */
  209.         foreach ($this->getOrder()->getProducts() as $orderProduct) {
  210.             $c $c+$orderProduct->getQuantity();
  211.         }
  212.         return $c;
  213.     }
  214.     /**
  215.      * Set session
  216.      *
  217.      * @param string $session
  218.      *
  219.      * @return OrderProduct
  220.      */
  221.     public function setSession($session)
  222.     {
  223.         $this->session $session;
  224.         return $this;
  225.     }
  226.     /**
  227.      * Get session
  228.      *
  229.      * @return string
  230.      */
  231.     public function getSession()
  232.     {
  233.         return $this->session;
  234.     }
  235.     /**
  236.      * Set priceInitial
  237.      *
  238.      * @param string $priceInitial
  239.      *
  240.      * @return OrderProduct
  241.      */
  242.     public function setPriceInitial($priceInitial)
  243.     {
  244.         $this->priceInitial $priceInitial;
  245.         return $this;
  246.     }
  247.     /**
  248.      * Get priceInitial
  249.      *
  250.      * @return string
  251.      */
  252.     public function getPriceInitial()
  253.     {
  254.         return $this->priceInitial;
  255.     }
  256.     /**
  257.      * Set order
  258.      *
  259.      * @param \App\Entity\Order $order
  260.      *
  261.      * @return OrderProduct
  262.      */
  263.     public function setOrder(\App\Entity\Order $order null)
  264.     {
  265.         $this->order $order;
  266.         return $this;
  267.     }
  268.     /**
  269.      * Get order
  270.      *
  271.      * @return \App\Entity\Order
  272.      */
  273.     public function getOrder()
  274.     {
  275.         return $this->order;
  276.     }
  277.     /**
  278.      * Set product
  279.      *
  280.      * @param \App\Entity\Product $product
  281.      *
  282.      * @return OrderProduct
  283.      */
  284.     public function setProduct(\App\Entity\Product $product null)
  285.     {
  286.         $this->product $product;
  287.         return $this;
  288.     }
  289.     /**
  290.      * Get product
  291.      *
  292.      * @return \App\Entity\Product
  293.      */
  294.     public function getProduct()
  295.     {
  296.         return $this->product;
  297.     }
  298.     /**
  299.      * Set currency
  300.      *
  301.      * @param \App\Entity\Currency $currency
  302.      *
  303.      * @return OrderProduct
  304.      */
  305.     public function setCurrency(\App\Entity\Currency $currency null)
  306.     {
  307.         $this->currency $currency;
  308.         return $this;
  309.     }
  310.     /**
  311.      * Get currency
  312.      *
  313.      * @return \App\Entity\Currency
  314.      */
  315.     public function getCurrency()
  316.     {
  317.         return $this->currency;
  318.     }
  319.     /**
  320.      * @return Collection|OrderProductParameterValue[]
  321.      */
  322.     public function getParameterValues(): Collection
  323.     {
  324.         return $this->parameterValues;
  325.     }
  326.     public function addParameterValue(OrderProductParameterValue $parameterValue): self
  327.     {
  328.         if (!$this->parameterValues->contains($parameterValue)) {
  329.             $this->parameterValues[] = $parameterValue;
  330.             $parameterValue->setOrderProduct($this);
  331.         }
  332.         return $this;
  333.     }
  334.     public function removeParameterValue(OrderProductParameterValue $parameterValue): self
  335.     {
  336.         if ($this->parameterValues->contains($parameterValue)) {
  337.             $this->parameterValues->removeElement($parameterValue);
  338.             // set the owning side to null (unless already changed)
  339.             if ($parameterValue->getOrderProduct() === $this) {
  340.                 $parameterValue->setOrderProduct(null);
  341.             }
  342.         }
  343.         return $this;
  344.     }
  345.     /**
  346.      * @return Collection|OrderProductEquipment[]
  347.      */
  348.     public function getEquipments(): Collection
  349.     {
  350.         return $this->equipments;
  351.     }
  352.     public function addEquipment(OrderProductEquipment $equipment): self
  353.     {
  354.         if (!$this->equipments->contains($equipment)) {
  355.             $this->equipments[] = $equipment;
  356.             $equipment->setOrderProduct($this);
  357.         }
  358.         return $this;
  359.     }
  360.     public function removeEquipment(OrderProductEquipment $equipment): self
  361.     {
  362.         if ($this->equipments->contains($equipment)) {
  363.             $this->equipments->removeElement($equipment);
  364.             // set the owning side to null (unless already changed)
  365.             if ($equipment->getOrderProduct() === $this) {
  366.                 $equipment->setOrderProduct(null);
  367.             }
  368.         }
  369.         return $this;
  370.     }
  371.     public function getSubProduct(): ?SubProduct
  372.     {
  373.         return $this->subProduct;
  374.     }
  375.     public function setSubProduct(?SubProduct $subProduct): self
  376.     {
  377.         $this->subProduct $subProduct;
  378.         return $this;
  379.     }
  380.     public function getProductName() {
  381.         if ($this->getSubProduct()) {
  382.             return $this->getSubProduct()->getName();
  383.         }
  384.         return $this->getProduct()->getName();
  385.     }
  386.     /**
  387.      * @return mixed
  388.      */
  389.     public function getPriceNet()
  390.     {
  391.         return $this->priceNet;
  392.     }
  393.     /**
  394.      * @param mixed $priceNet
  395.      */
  396.     public function setPriceNet($priceNet): void
  397.     {
  398.         $this->priceNet $priceNet;
  399.     }
  400.     public function getVariant(): ?ProductPriceVariants
  401.     {
  402.         return $this->variant;
  403.     }
  404.     public function setVariant(?ProductPriceVariants $variant): self
  405.     {
  406.         $this->variant $variant;
  407.         return $this;
  408.     }
  409. }