src/Entity/OnlineShop/ProductOrder.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\OnlineShop;
  3. use App\Entity\AbstractBase;
  4. use App\Entity\MiniAbstractBase;
  5. use App\Entity\Whatsapp\WhatsappOrder;
  6. use App\Entity\Whatsapp\WhatsappOrderProduct;
  7. use App\Repository\OnlineShop\ProductOrderRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Money\Currency;
  11. use Money\Money;
  12. /**
  13.  * @ORM\Table(name="vulco_order_product")
  14.  *
  15.  * @ORM\Entity(repositoryClass=ProductOrderRepository::class)
  16.  *
  17.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  18.  */
  19. class ProductOrder extends AbstractBase
  20. {
  21.     /**
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private int $quantity;
  25.     /**
  26.      * @ORM\Column(type="money", nullable=true)
  27.      */
  28.     private ?Money $sigaus;
  29.     /**
  30.      * @ORM\Column(type="money", nullable=true)
  31.      */
  32.     private ?Money $greenPoint;
  33.     /**
  34.      * @ORM\Column(type="money", nullable=true)
  35.      */
  36.     private ?Money $ecoTax;
  37.     /**
  38.      * @ORM\Column(type="money", nullable=false)
  39.      */
  40.     private Money $ratePrice;
  41.     /**
  42.      * @ORM\Column(type="money", nullable=false)
  43.      */
  44.     private Money $costPrice;
  45.     /**
  46.      * @ORM\Column(type="money", nullable=true)
  47.      * At the moment we only use this field for orders export of garages with GRIPS software
  48.      */
  49.     private ?Money $pvpPrice null;
  50.     /**
  51.      * @ORM\Column(type="money", nullable=false)
  52.      */
  53.     private Money $totalPrice;
  54.     /**
  55.      * @ORM\Column(type="money", nullable=true)
  56.      */
  57.     private ?Money $totalPriceWithoutTax null;
  58.     /**
  59.      * @ORM\Column(type="text", length=10000, nullable=true)
  60.      */
  61.     private ?string $promotion null;
  62.     /**
  63.      * @ORM\Column(type="text", length=10000, nullable=true)
  64.      */
  65.     private ?string $comment null;
  66.     /**
  67.      * @ORM\Column(type="float", nullable=true)
  68.      */
  69.     private ?float $rateDiscount 0.0;
  70.     /**
  71.      * @ORM\Column(type="float", nullable=true)
  72.      */
  73.     private ?float $costDiscount 0.0;
  74.     /**
  75.      * @ORM\Column(type="money", nullable=true, options={"default": "EUR 0"})
  76.      */
  77.     private ?Money $noLinealDiscountRate;
  78.     /**
  79.      * @ORM\Column(type="money", nullable=true, options={"default": "EUR 0"})
  80.      */
  81.     private ?Money $noLinealDiscountCost;
  82.     /**
  83.      * @ORM\Column(type="integer", nullable=true, options={"default": 0})
  84.      */
  85.     private ?int $linealDiscountRate 0;
  86.     /**
  87.      * @ORM\Column(type="integer", nullable=true, options={"default": 0})
  88.      */
  89.     private ?int $linealDiscountCost 0;
  90.     /**
  91.      * @ORM\ManyToOne(targetEntity="App\Entity\OnlineShop\Order", inversedBy="products")
  92.      *
  93.      * @ORM\JoinColumn(name="order_id", referencedColumnName="id")
  94.      */
  95.     private Order $order;
  96.     /**
  97.      * @ORM\ManyToOne(targetEntity="App\Entity\OnlineShop\Product", fetch="EAGER")
  98.      *
  99.      * @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  100.      */
  101.     private ?Product $product null;
  102.     /**
  103.      * @ORM\Column(type="string", nullable=true)
  104.      */
  105.     private ?string $productFamilyName null;
  106.     /**
  107.      * @ORM\Column(type="string", nullable=true)
  108.      */
  109.     private ?string $productName null;
  110.     public function __construct()
  111.     {
  112.         $this->sigaus = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  113.         $this->greenPoint = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  114.         $this->ecoTax = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  115.         $this->ratePrice = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  116.         $this->costPrice = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  117.         $this->totalPrice = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  118.         $this->noLinealDiscountCost = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  119.         $this->noLinealDiscountRate = new Money(0, new Currency(self::DEFAULT_EURO_CURRENCY));
  120.     }
  121.     public function getQuantity(): int
  122.     {
  123.         return $this->quantity;
  124.     }
  125.     public function setQuantity(int $quantity): self
  126.     {
  127.         $this->quantity $quantity;
  128.         return $this;
  129.     }
  130.     public function getSigaus(): ?Money
  131.     {
  132.         return $this->sigaus;
  133.     }
  134.     public function setSigaus(?Money $sigaus): self
  135.     {
  136.         $this->sigaus $sigaus;
  137.         return $this;
  138.     }
  139.     public function getGreenPoint(): ?Money
  140.     {
  141.         return $this->greenPoint;
  142.     }
  143.     public function setGreenPoint(?Money $greenPoint): self
  144.     {
  145.         $this->greenPoint $greenPoint;
  146.         return $this;
  147.     }
  148.     public function getEcoTax(): ?Money
  149.     {
  150.         return $this->ecoTax;
  151.     }
  152.     public function setEcoTax(?Money $ecoTax): self
  153.     {
  154.         $this->ecoTax $ecoTax;
  155.         return $this;
  156.     }
  157.     public function getRatePrice(): Money
  158.     {
  159.         return $this->ratePrice;
  160.     }
  161.     public function getRatePriceWithAdditionalDiscount(): Money
  162.     {
  163.         if (!empty($this->getRateDiscount())) {
  164.             return $this->ratePrice->multiply($this->getRateDiscount() / 100);
  165.         }
  166.         return $this->ratePrice;
  167.     }
  168.     private function getRatePriceWithDiscountAndTax(): Money
  169.     {
  170.         return $this->getRatePriceWithAdditionalDiscount()
  171.             ->add($this->sigaus)
  172.             ->add($this->greenPoint)
  173.             ->add($this->ecoTax);
  174.     }
  175.     public function getRatePriceWithAllDiscountsForCSVExport(): Money
  176.     {
  177.         $price $this->getRatePriceWithAdditionalDiscount();
  178.         if (!empty($this->linealDiscountRate)) {
  179.             return $price->multiply($this->linealDiscountRate 100);
  180.         }
  181.         if (!is_null($this->noLinealDiscountRate)) {
  182.             if ($this->noLinealDiscountRate->isPositive()) {
  183.                 return $price->subtract($this->noLinealDiscountRate);
  184.             }
  185.         }
  186.         return $price;
  187.     }
  188.     public function setRatePrice(Money $ratePrice): self
  189.     {
  190.         $this->ratePrice $ratePrice;
  191.         return $this;
  192.     }
  193.     public function getCostPrice(): Money
  194.     {
  195.         return $this->costPrice;
  196.     }
  197.     public function getCostPriceWithAdditionalDiscount(): Money
  198.     {
  199.         if (!empty($this->getCostDiscount())) {
  200.             return $this->costPrice->multiply($this->getCostDiscount() / 100);
  201.         }
  202.         return $this->costPrice;
  203.     }
  204.     public function getCostPriceWithAllDiscountsForCSVExport(): Money
  205.     {
  206.         $price $this->getCostPriceWithAdditionalDiscount();
  207.         if (!is_null($this->linealDiscountCost) && $this->linealDiscountCost 0) {
  208.             return $price->multiply($this->linealDiscountCost 100);
  209.         }
  210.         if (!is_null($this->noLinealDiscountCost) && $this->noLinealDiscountCost->isPositive()) {
  211.             return $price->subtract($this->noLinealDiscountCost);
  212.         }
  213.         return $price;
  214.     }
  215.     public function setCostPrice(Money $costPrice): self
  216.     {
  217.         $this->costPrice $costPrice;
  218.         return $this;
  219.     }
  220.     public function getPvpPrice(): ?Money
  221.     {
  222.         return $this->pvpPrice;
  223.     }
  224.     public function setPvpPrice(?Money $pvpPrice): self
  225.     {
  226.         $this->pvpPrice $pvpPrice;
  227.         return $this;
  228.     }
  229.     public function getTotalPrice(): Money
  230.     {
  231.         return $this->totalPrice;
  232.     }
  233.     public function setTotalPrice(Money $totalPrice): self
  234.     {
  235.         $this->totalPrice $totalPrice;
  236.         return $this;
  237.     }
  238.     public function getTotalPriceWithoutTax(): ?Money
  239.     {
  240.         return $this->totalPriceWithoutTax;
  241.     }
  242.     public function setTotalPriceWithoutTax(?Money $totalPriceWithoutTax): self
  243.     {
  244.         $this->totalPriceWithoutTax $totalPriceWithoutTax;
  245.         return $this;
  246.     }
  247.     public function getPromotion(): ?string
  248.     {
  249.         return $this->promotion;
  250.     }
  251.     public function setPromotion(?string $promotion): self
  252.     {
  253.         $this->promotion $promotion;
  254.         return $this;
  255.     }
  256.     public function getComment(): ?string
  257.     {
  258.         return $this->comment;
  259.     }
  260.     public function setComment(?string $comment): self
  261.     {
  262.         $this->comment $comment;
  263.         return $this;
  264.     }
  265.     public function getRateDiscount(): ?float
  266.     {
  267.         return $this->rateDiscount;
  268.     }
  269.     public function setRateDiscount(?float $rateDiscount): self
  270.     {
  271.         $this->rateDiscount $rateDiscount;
  272.         return $this;
  273.     }
  274.     public function getCostDiscount(): ?float
  275.     {
  276.         return $this->costDiscount;
  277.     }
  278.     public function setCostDiscount(?float $costDiscount): self
  279.     {
  280.         $this->costDiscount $costDiscount;
  281.         return $this;
  282.     }
  283.     public function getNoLinealDiscountRate(): ?Money
  284.     {
  285.         return $this->noLinealDiscountRate;
  286.     }
  287.     public function setNoLinealDiscountRate(?Money $noLinealDiscountRate): self
  288.     {
  289.         $this->noLinealDiscountRate $noLinealDiscountRate;
  290.         return $this;
  291.     }
  292.     public function getNoLinealDiscountCost(): ?Money
  293.     {
  294.         return $this->noLinealDiscountCost;
  295.     }
  296.     public function setNoLinealDiscountCost(?Money $noLinealDiscountCost): self
  297.     {
  298.         $this->noLinealDiscountCost $noLinealDiscountCost;
  299.         return $this;
  300.     }
  301.     public function getLinealDiscountRate(): ?int
  302.     {
  303.         return $this->linealDiscountRate;
  304.     }
  305.     public function setLinealDiscountRate(?int $linealDiscountRate): self
  306.     {
  307.         $this->linealDiscountRate $linealDiscountRate;
  308.         return $this;
  309.     }
  310.     public function getLinealDiscountCost(): ?int
  311.     {
  312.         return $this->linealDiscountCost;
  313.     }
  314.     public function setLinealDiscountCost(?int $linealDiscountCost): self
  315.     {
  316.         $this->linealDiscountCost $linealDiscountCost;
  317.         return $this;
  318.     }
  319.     public function getOrder(): Order
  320.     {
  321.         return $this->order;
  322.     }
  323.     public function setOrder(Order $order): self
  324.     {
  325.         $this->order $order;
  326.         return $this;
  327.     }
  328.     public function getProduct(): ?Product
  329.     {
  330.         return $this->product;
  331.     }
  332.     public function setProduct(?Product $product): self
  333.     {
  334.         $this->product $product;
  335.         return $this;
  336.     }
  337.     public function getProductFamilyName(): ?string
  338.     {
  339.         return $this->productFamilyName;
  340.     }
  341.     public function setProductFamilyName(?string $productFamilyName): self
  342.     {
  343.         $this->productFamilyName $productFamilyName;
  344.         return $this;
  345.     }
  346.     public function getProductName(): ?string
  347.     {
  348.         return $this->productName;
  349.     }
  350.     public function setProductName(?string $productName): self
  351.     {
  352.         $this->productName $productName;
  353.         return $this;
  354.     }
  355.     public function update(Product $productint $quantity, ?WhatsappOrderProduct $whatsappOrderProduct): self
  356.     {
  357.         $this->product $product;
  358.         $this->sigaus $product->getSigaus();
  359.         $this->ecoTax $product->getEcoTax();
  360.         $this->greenPoint $product->getGreenPoint();
  361.         if ($product->hasSpecialPriceActive()) {
  362.             $this->ratePrice $product->getSpecialPriceActive()->getPrice();
  363.             $this->costPrice $product->getSpecialPriceActive()->getCostPrice();
  364.         } else {
  365.             $this->ratePrice $product->getRatePriceWithDiscount($quantity);
  366.             $this->costPrice $product->getCostPriceWithDiscount($quantity);
  367.         }
  368.         if ($whatsappOrderProduct) {
  369.             $this->ratePrice = new Money((int) ($whatsappOrderProduct->getItemPrice() * 100), new Currency(MiniAbstractBase::DEFAULT_EURO_CURRENCY));  // price of the product if was purchased via WhatsappOrder
  370.         }
  371.         $this->pvpPrice $product->getPvpPrice();
  372.         $this->quantity $quantity;
  373.         $this->totalPrice $this->getRatePriceWithDiscountAndTax()->multiply($quantity);
  374.         $this->totalPriceWithoutTax $this->getRatePriceWithAdditionalDiscount()->multiply($quantity);
  375.         $this->promotion $product->getPromotion();
  376.         return $this;
  377.     }
  378.     public function updateFromSpecialOfferProduct(SpecialOfferProduct $specialOfferProduct$quantity): self
  379.     {
  380.         $realQuantity $quantity $specialOfferProduct->units()->quantity();
  381.         $product $specialOfferProduct->getProduct();
  382.         $this->product $product;
  383.         $this->sigaus $product->getSigaus();
  384.         $this->ecoTax $product->getEcoTax();
  385.         $this->greenPoint $product->getGreenPoint();
  386.         $this->ratePrice = new Money((int) ($specialOfferProduct->finalPrice() * 100), new Currency(self::DEFAULT_EURO_CURRENCY));
  387.         $this->costPrice $product->getCostPriceWithDiscount($realQuantity);
  388.         $this->pvpPrice $product->getPvpPrice();
  389.         $this->quantity $realQuantity;
  390.         $this->totalPrice $this->getRatePriceWithDiscountAndTax()->multiply($realQuantity);
  391.         $this->totalPriceWithoutTax $this->getRatePriceWithAdditionalDiscount()->multiply($realQuantity);
  392.         $this->promotion $specialOfferProduct->specialOffer()->code();
  393.         return $this;
  394.     }
  395. }