src/Entity/OnlineShop/ProductOrder.php line 20

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