src/Entity/OnlineShop/ProductOrder.php line 19

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