src/IlaveU/ShopBundle/Entity/Order/Order.php line 46

  1. <?php
  2. namespace App\IlaveU\ShopBundle\Entity\Order;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use App\Entity\LogHistory;
  8. use App\Entity\User;
  9. use App\IlaveU\ShopBundle\Entity\Accounting\Invoice;
  10. use App\IlaveU\ShopBundle\Entity\Customer\Customer;
  11. use App\IlaveU\ShopBundle\Entity\Product\ProductSubscription;
  12. use App\IlaveU\ShopBundle\Entity\Shipping\Shipment;
  13. use App\IlaveU\ShopBundle\Entity\Customer\CustomerWalletPoint;
  14. use App\IlaveU\ShopBundle\Entity\Payment\PaymentMethod;
  15. use App\IlaveU\ShopBundle\Entity\Promotion\Coupon;
  16. use App\IlaveU\ShopBundle\Entity\Shipping\CityRegion;
  17. use App\IlaveU\ShopBundle\Entity\Resource\Agent;
  18. use App\IlaveU\ShopBundle\Entity\Shipping\ShippingMethod;
  19. use App\IlaveU\ShopBundle\Entity\Store\Store;
  20. use App\IlaveU\ShopBundle\Entity\Vendor\Vendor;
  21. use App\IlaveU\ShopBundle\Repository\Order\OrderRepository;
  22. use Doctrine\Common\Collections\ArrayCollection;
  23. use Doctrine\Common\Collections\Collection;
  24. use Doctrine\DBAL\Types\Types;
  25. use Doctrine\ORM\Mapping as ORM;
  26. use Doctrine\ORM\Mapping\Entity;
  27. use Doctrine\ORM\Mapping\InheritanceType;
  28. use Gedmo\Mapping\Annotation as Gedmo;
  29. use Symfony\Component\Serializer\Annotation\Groups;
  30. use Symfony\Component\Validator\Constraints as Assert;
  31. #[ApiResource(
  32.     normalizationContext: ['groups' => ['read']],
  33.     denormalizationContext: ['groups' => ['write']],
  34. )]
  35. #[ApiFilter(SearchFilter::class, properties: ['status' => 'exact','customer'=>'exact','statusShipping' => 'exact'])]
  36. #[ApiFilter(RangeFilter::class, properties: ['createdAt'])]
  37. #[ORM\Table(name'`order`')]
  38. #[ORM\Entity(repositoryClassOrderRepository::class)]
  39. #[InheritanceType('JOINED')]
  40. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  41. #[Gedmo\Loggable(logEntryClass:LogHistory::class)]
  42. class Order implements \Stringable
  43. {
  44.     #[ORM\Id]
  45.     #[ORM\GeneratedValue]
  46.     #[ORM\Column(type'integer')]
  47.     #[Groups(['read'])]
  48.     private $id;
  49.     #[Groups(['read'])]
  50.     #[ORM\Column(type'datetime'nullabletrue)]
  51.     private ?\DateTime $createdAt null;
  52.     #[Groups(['read','write'])]
  53.     #[ORM\Column(type'text'nullabletrue)]
  54.     #[Gedmo\Versioned]
  55.     private ?string $description null;
  56.     #[Groups(['read','write'])]
  57.     #[ORM\ManyToOne(targetEntityCustomer::class, inversedBy'orders'cascade: ['persist'])]
  58.     #[Assert\Valid]
  59.     #[Gedmo\Versioned]
  60.     private ?\App\IlaveU\ShopBundle\Entity\Customer\Customer $customer null;
  61.     /**
  62.      *
  63.      * @example OrderItems that contain products,quantities,partial reductions, and details of the order
  64.      */
  65.     #[Groups(['read','write'])]
  66.     #[ORM\OneToMany(targetEntityOrderItem::class, mappedBy'parentOrder'cascade: ['persist''remove'])]
  67.     #[Assert\Valid]
  68.     
  69.     private \Doctrine\Common\Collections\Collection|array $orderItems;
  70.     
  71.     #[ORM\OneToMany(targetEntityAdjustment::class, mappedBy'parentOrder')]
  72.     private \Doctrine\Common\Collections\Collection|array $adjustments;
  73.     #[ORM\Column(type'string'length255nullabletrue)]
  74.     #[Groups(['read','write'])]
  75.     private ?string $firstName null;
  76.     #[ORM\Column(type'string'length255nullabletrue)]
  77.     #[Groups(['read','write'])]
  78.     private ?string $lastName null;
  79.     #[ORM\Column(type'string'length255nullabletrue)]
  80.     #[Groups(['read','write'])]
  81.     private ?string $companyName null;
  82.     #[ORM\Column(type'string'length255nullabletrue)]
  83.     #[Groups(['read','write'])]
  84.     private ?string $address null;
  85.     #[ORM\Column(type'string'length255nullabletrue)]
  86.     #[Groups(['read','write'])]
  87.     private ?string $city null;
  88.     #[ORM\Column(type'string'length255nullabletrue)]
  89.     #[Groups(['read','write'])]
  90.     private ?string $country null;
  91.     #[ORM\Column(type'string'length255nullabletrue)]
  92.     private ?string $department null;
  93.     #[ORM\Column(type'string'length255nullabletrue)]
  94.     private ?string $postcode null;
  95.     #[ORM\Column(type'string'length255nullabletrue)]
  96.     #[Groups(['read','write'])]
  97.     private ?string $email null;
  98.     #[ORM\Column(type'string'length255nullabletrue)]
  99.     #[Groups(['read','write'])]
  100.     private ?string $tel null;
  101.     #[ORM\Column(type'text'nullabletrue)]
  102.     private ?string $comment null;
  103.     #[ORM\ManyToOne(targetEntityDemandeFund::class, inversedBy'orders')]
  104.     private ?\App\IlaveU\ShopBundle\Entity\Order\DemandeFund $demandeFund null;
  105.     #[Groups(['read','write'])]
  106.     #[ORM\Column(type'string'length255nullabletrue)]
  107.     #[Gedmo\Versioned]
  108.     private ?string $status "draft";
  109.     #[Groups(['read','write'])]
  110.     #[ORM\Column(type'string'length255nullabletrue)]
  111.     #[Gedmo\Versioned]
  112.     private ?string $statusShipping "draft";
  113.     
  114.     #[Groups(['read','write'])]
  115.     #[ORM\Column(type'string'length255nullabletrue)]
  116.     private ?string $source null;
  117.     #[ORM\Column(type'text'nullabletrue)]
  118.     private $deliveryAt;
  119.     #[ORM\Column(type'text'nullabletrue)]
  120.     private $recoveryAt;
  121.     #[ORM\Column(type'string'length255nullabletrue)]
  122.     private ?string $oldOrderNumber null;
  123.     #[Groups(['read','write'])]
  124.     #[ORM\Column(type'float'nullabletrue)]
  125.     private ?float $reduction null;
  126.     #[ORM\Column(type'float'nullabletrue)]
  127.     private $distance 0;
  128.     #[ORM\ManyToOne(targetEntityShippingMethod::class, inversedBy'orders'cascade: ['persist'])]
  129.     #[Groups(['read','write'])]
  130.     #[Gedmo\Versioned]
  131.     private ?\App\IlaveU\ShopBundle\Entity\Shipping\ShippingMethod $shippingMethod null;
  132.     #[ORM\ManyToOne(targetEntityAgent::class, inversedBy'orders')]
  133.     #[Groups(['read','write'])]
  134.     #[Gedmo\Versioned]
  135.     private ?\App\IlaveU\ShopBundle\Entity\Resource\Agent $agent null;
  136.     #[Groups(['read','write'])]
  137.     #[ORM\ManyToOne(targetEntitypaymentMethod::class, inversedBy'orders'cascade: ['persist'])]
  138.     #[ORM\JoinColumn(nullabletrueonDelete'CASCADE')]
  139.     
  140.     private ?\App\IlaveU\ShopBundle\Entity\Payment\PaymentMethod $paymentMethod null;
  141.     #[ORM\Column(type'float'nullabletrue)]
  142.     #[Groups(['read','write'])]
  143.     #[Gedmo\Versioned]
  144.     private ?float $payedAmount null;
  145.     #[ORM\Column(type'datetime'nullabletrue)]
  146.     #[Groups(['read','write'])]
  147.     #[Gedmo\Versioned]
  148.     private ?\DateTimeInterface $startProcessingAt null;
  149.     #[Groups(['read','write'])]
  150.     #[ORM\Column(type'string'length255nullabletrue)]
  151.     private ?string $deliveryType null;
  152.     #[ORM\Column(type'datetime'nullabletrue)]
  153.     #[Groups(['read','write'])]
  154.     #[Gedmo\Versioned]
  155.     private ?\DateTimeInterface $startDeliveryAt null;
  156.     #[ORM\OneToMany(targetEntityCustomerWalletPoint::class, mappedBy'originOrder')]
  157.     private \Doctrine\Common\Collections\Collection|array $customerWalletPoints;
  158.     #[ORM\ManyToOne(targetEntityCoupon::class, inversedBy'orders')]
  159.     #[Groups(['read','write'])]
  160.     private ?\App\IlaveU\ShopBundle\Entity\Promotion\Coupon $coupon null;
  161.     #[ORM\ManyToOne(targetEntityAgent::class, inversedBy'ordersToDolist')]
  162.     private ?\App\IlaveU\ShopBundle\Entity\Resource\Agent $agentToDo null;
  163.     #[ORM\Column(type'boolean'nullabletrue)]
  164.     private ?bool $isToDo false;
  165.     #[ORM\ManyToOne(targetEntityCityRegion::class, inversedBy'orders')]
  166.     private ?\App\IlaveU\ShopBundle\Entity\Shipping\CityRegion $cityRegionShipping null;
  167.     #[ORM\ManyToOne(targetEntityCityRegion::class, inversedBy'collectedOrders')]
  168.     private $cityRegionCollect;
  169.     #[ORM\ManyToOne(targetEntityVendor::class, inversedBy'orders')]
  170.     private ?\App\IlaveU\ShopBundle\Entity\Vendor\Vendor $vendor null;
  171.     #[ORM\Column(type'text'nullabletrue)]
  172.     #[Groups(['read','write'])]
  173.     private ?string $collectAddress null;
  174.     #[ORM\Column(type'text'nullabletrue)]
  175.     #[Groups(['read','write'])]
  176.     private ?string $shippingAddress null;
  177.     #[ORM\Column(type'string'length255nullabletrue)]
  178.     #[Groups(['read','write'])]
  179.     private ?string $collectTel null;
  180.     
  181.     
  182.      #[ORM\Column(type'string'length255nullabletrue)]
  183.     #[Groups(['read','write'])]
  184.     private ?string $collectLng null;
  185.     
  186.          #[ORM\Column(type'string'length255nullabletrue)]
  187.     #[Groups(['read','write'])]
  188.     private ?string $collectLat null;
  189.     
  190.          #[ORM\Column(type'string'length255nullabletrue)]
  191.     #[Groups(['read','write'])]
  192.     private ?string $shippingLng null;
  193.     
  194.          #[ORM\Column(type'string'length255nullabletrue)]
  195.     #[Groups(['read','write'])]
  196.     private ?string $shippingLat null;
  197.     #[ORM\Column(type'boolean'nullabletrue)]
  198.     #[Groups(['read','write'])]
  199.     private ?bool $isHeavy null;
  200.     #[Groups(['read','write'])]
  201.     #[ORM\Column(type'float'nullabletrue)]
  202.     private $shippingTips 0;
  203.     #[Groups(['read','write'])]
  204.      #[ORM\Column(type'float'nullabletrue)]
  205.     private $walletPaymentAmount 0;
  206.     
  207.     #[ORM\Column(type'boolean'nullabletrue)]
  208.     private $isChecked;
  209.     #[ORM\Column(type'string'length255nullabletrue)]
  210.     private $tokenStripe;
  211.     #[ORM\Column(length255nullabletrue)]
  212.     #[Groups(['read','write'])]
  213.     private ?string $orderType "order";
  214.     #[ORM\Column(nullabletrue)]
  215.     private ?\DateTimeImmutable $deletedAt null;
  216.     #[ORM\ManyToOne(inversedBy'orders')]
  217.     private ?Store $store null;
  218.     #[ORM\OneToOne(inversedBy'relatedOrder'cascade: ['persist''remove'])]
  219.     #[Groups(['read','write'])]
  220.     private ?Shipment $shipment null;
  221.     // Undefined array key \"invoice\"" To be fixed for #[Groups(['read','write'])]
  222.     #[ORM\ManyToOne(inversedBy'orders')]
  223.     private ?Invoice $invoice null;
  224.     #[ORM\Column(typeTypes::STRING,nullabletrue)]
  225.     #[Gedmo\Blameable(on'create')]
  226.     private $createdBy;
  227.     #[ORM\OneToOne(mappedBy'relatedOrder'cascade: ['persist''remove'])]
  228.     private ?ProductSubscription $productSubscription null;
  229.     #[Groups(['read','write'])]
  230.     #[ORM\Column(nullabletrue)]
  231.     private ?array $metaData null;
  232.     #[ORM\Column(length255nullabletrue)]
  233.     private ?string $defaultCurrency null;
  234.     #[ORM\Column(nullabletrue)]
  235.     private ?float $extraShippingFees 0;
  236.     #[ORM\Column(length255nullabletrue)]
  237.     private ?string $extraShippingMethodName "";
  238.     #[ORM\Column(length255nullabletrue)]
  239.     private ?string $extraShippingInfos "";
  240.     public function __construct()
  241.     {
  242.         $this->orderItems = new ArrayCollection();
  243.         $this->adjustments = new ArrayCollection();
  244.         $this->createdAt = new \DateTime();
  245.         $this->customerWalletPoints = new ArrayCollection();
  246.         
  247.     }
  248.    
  249.     public function __toString(): string
  250.     {
  251.         return (string)$this->getOrderNumber();
  252.     }
  253.     public function getId(): ?int
  254.     {
  255.         return $this->id;
  256.     }
  257.     #[Groups(['read'])]
  258.     public function getOrderNumber($secondaryPrefix=null)
  259.     {
  260.         $prefix "CMD-";
  261.         if($this->getOrderType()=="invoice"){
  262.             $prefix "FA-";
  263.         }
  264.         $orderNumber $prefix.$this->createdAt->format("ym").str_pad((string) $this->id5"0"STR_PAD_LEFT);
  265.         if($secondaryPrefix){
  266.             $orderNumber $prefix.$this->createdAt->format("ym").str_pad((string) $this->id5"0"STR_PAD_LEFT)."-".$secondaryPrefix;
  267.         }
  268.         return $orderNumber;
  269.     }
  270.     #[Groups(['read'])]
  271.     public function getIdPrefixed()
  272.     {
  273.         return $this->getOrderNumber();
  274.     }
  275.     public function getFirstName(): ?string
  276.     {
  277.         return $this->firstName;
  278.     }
  279.     public function setFirstName(string $firstName): self
  280.     {
  281.         $this->firstName $firstName;
  282.         return $this;
  283.     }
  284.     public function getLastName(): ?string
  285.     {
  286.         return $this->lastName;
  287.     }
  288.     public function setLastName(string $lastName): self
  289.     {
  290.         $this->lastName $lastName;
  291.         return $this;
  292.     }
  293.     public function getCreatedAt(): ?\DateTime
  294.     {
  295.         return $this->createdAt;
  296.     }
  297.     public function setCreatedAt(?\DateTime $createdAt): self
  298.     {
  299.         $this->createdAt $createdAt;
  300.         return $this;
  301.     }
  302.     public function getCustomer(): ?Customer
  303.     {
  304.         return $this->customer;
  305.     }
  306.     public function setCustomer(?Customer $customer): self
  307.     {
  308.         $this->customer $customer;
  309.         return $this;
  310.     }
  311.     public function getCategoriesProduct(){
  312.         $categories = [];
  313.         foreach($this->getOrderItems() as $singleOrderItem){
  314.             if($singleOrderItem->getProduct()){
  315.                 if($singleOrderItem->getProduct()->getParentCategory()){
  316.                     $categories[] = $singleOrderItem->getProduct()->getParentCategory()->getName();
  317.                 }
  318.                 
  319.             }
  320.         }
  321.         return $categories;
  322.     }
  323.     public function getSubCategoriesProduct(){
  324.         $categories = [];
  325.         foreach($this->getOrderItems() as $singleOrderItem){
  326.             if($singleOrderItem->getProduct()){
  327.                 foreach($singleOrderItem->getProduct()->getCategoriesProduct() as $singleCategory){
  328.                     if(!in_array($singleCategory->getName(),$categories)){
  329.                         $categories[] = $singleCategory->getName();
  330.                     }
  331.                     
  332.                 }
  333.                 
  334.             }
  335.         }
  336.         return $categories;
  337.     }
  338.     /**
  339.      * @return Collection|OrderItem[]
  340.      */
  341.     public function getOrderItems(): Collection
  342.     {
  343.         return $this->orderItems;
  344.     }
  345.     public function addOrderItem(OrderItem $orderItem): self
  346.     {
  347.         if (!$this->orderItems->contains($orderItem)) {
  348.             $this->orderItems[] = $orderItem;
  349.             $orderItem->setParentOrder($this);
  350.         }
  351.         return $this;
  352.     }
  353.     public function removeOrderItem(OrderItem $orderItem): self
  354.     {
  355.         if ($this->orderItems->removeElement($orderItem)) {
  356.             // set the owning side to null (unless already changed)
  357.             if ($orderItem->getParentOrder() === $this) {
  358.                 $orderItem->setParentOrder(null);
  359.             }
  360.         }
  361.         return $this;
  362.     }
  363.     /**
  364.      * @return Collection|Adjustment[]
  365.      */
  366.     public function getAdjustments(): Collection
  367.     {
  368.         return $this->adjustments;
  369.     }
  370.     public function addAdjustment(Adjustment $adjustment): self
  371.     {
  372.         if (!$this->adjustments->contains($adjustment)) {
  373.             $this->adjustments[] = $adjustment;
  374.             $adjustment->setParentOrder($this);
  375.         }
  376.         return $this;
  377.     }
  378.     public function removeAdjustment(Adjustment $adjustment): self
  379.     {
  380.         if ($this->adjustments->removeElement($adjustment)) {
  381.             // set the owning side to null (unless already changed)
  382.             if ($adjustment->getParentOrder() === $this) {
  383.                 $adjustment->setParentOrder(null);
  384.             }
  385.         }
  386.         return $this;
  387.     }
  388.     #[Groups(['read'])]
  389.     public function getReductionOnCoupon(){
  390.         $reductionCoupon=0;
  391.         if($this->getCoupon()){
  392.             if($this->getCoupon()->getTypeReduction()=="percent"){
  393.                 $reductionCoupon = ($this->getTotalAmount()/100)*$this->getCoupon()->getValueReduction();
  394.             }else{
  395.                 $reductionCoupon $this->getCoupon()->getValueReduction();
  396.             }
  397.         }
  398.         return  $reductionCoupon;
  399.     }
  400.     public function getCompanyName(): ?string
  401.     {
  402.         return $this->companyName;
  403.     }
  404.     public function setCompanyName(?string $companyName): self
  405.     {
  406.         $this->companyName $companyName;
  407.         return $this;
  408.     }
  409.     public function getAddress(): ?string
  410.     {
  411.         return $this->address;
  412.     }
  413.     public function setAddress(string $address): self
  414.     {
  415.         $this->address $address;
  416.         return $this;
  417.     }
  418.     public function getCity(): ?string
  419.     {
  420.         return $this->city;
  421.     }
  422.     public function setCity(string $city): self
  423.     {
  424.         $this->city $city;
  425.         return $this;
  426.     }
  427.     public function getCountry(): ?string
  428.     {
  429.         return $this->country;
  430.     }
  431.     public function setCountry(string $country): self
  432.     {
  433.         $this->country $country;
  434.         return $this;
  435.     }
  436.     public function getDepartment(): ?string
  437.     {
  438.         return $this->department;
  439.     }
  440.     public function setDepartment(?string $department): self
  441.     {
  442.         $this->department $department;
  443.         return $this;
  444.     }
  445.     public function getPostcode(): ?string
  446.     {
  447.         return $this->postcode;
  448.     }
  449.     public function setPostcode(?string $postcode): self
  450.     {
  451.         $this->postcode $postcode;
  452.         return $this;
  453.     }
  454.     public function getEmail(): ?string
  455.     {
  456.         return $this->email;
  457.     }
  458.     public function setEmail(string $email): self
  459.     {
  460.         $this->email $email;
  461.         return $this;
  462.     }
  463.     public function getTel(): ?string
  464.     {
  465.         return $this->tel;
  466.     }
  467.     public function setTel(string $tel): self
  468.     {
  469.         $this->tel $tel;
  470.         return $this;
  471.     }
  472.     public function getComment(): ?string
  473.     {
  474.         return $this->comment;
  475.     }
  476.     public function setComment(?string $comment): self
  477.     {
  478.         $this->comment $comment;
  479.         return $this;
  480.     }
  481.   
  482.     #[Groups(['read'])]
  483.     public function getTotalAmount(){
  484.         $total=0;
  485.         foreach($this->orderItems as $singleOrderItem){
  486.             $total $total + ($singleOrderItem->getTotalAmount());
  487.         }
  488.         return $total;
  489.         
  490.     }
  491.     #[Groups(['read'])]
  492.     public function getFullTotalAmount(){
  493.         
  494.        
  495.         $total 
  496.         ((float)$this->getTotalAmount() + 
  497.         (float)$this->getShippingFees()  
  498.         
  499.         + (float)$this->getShippingTips()) - 
  500.         ((float)$this->getTotalReduction()) ;
  501.         return $total;
  502.         
  503.     }
  504.     #[Groups(['read'])]
  505.     public function getFullRestAmount(){
  506.         $payedAmount $this->getPayedAmount();
  507.         $walletPayedAmount $this->getWalletPaymentAmount();
  508.         $paymentMethodCode null;
  509.         if($this->getPaymentMethod()){
  510.             $paymentMethodCode $this->getPaymentMethod()->getCode();
  511.         }
  512.         
  513.         if( ( $this->statusShipping == "cancelled")){
  514.             // ToReview
  515.             //return 0;
  516.             $payedAmount 0;
  517.             
  518.         }
  519.        
  520.         $total = ($this->getTotalAmount() + $this->getShippingTips() + $this->getShippingFees()) - ($payedAmount $walletPayedAmount $this->getTotalReduction());
  521.          ;
  522.         return $total;
  523.         
  524.     }
  525.     //needs optimisation
  526.     #[Groups(['read'])]
  527.     public function getShippingFees(){
  528.         $fees 0;
  529.         foreach($this->getOrderItems() as $singleOrderItem){
  530.             $fees += $singleOrderItem->getShippingFees();
  531.         }
  532.         $fees += $this->getExtraShippingFees();
  533.         if($fees>0) {return $fees;} 
  534.         if($this->getShippingMethod()){
  535.             
  536.             // Condition IlaveU / Classic 19 DH
  537.             
  538.             if($this->getShippingMethod()->getCode() == "CLASSIQUE GRATUIT" and $this->getDeliveryType() == "on-store"){
  539.                     return 0;
  540.            }
  541.             
  542.             
  543.             if($this->getShippingMethod()->isIsSeparatelyCalculated()){
  544.                 $fees $this->getShippingMethod()->getPrice();
  545.             
  546.                 foreach($this->getShippingMethod()->getShippingRules() as $shippingRule){
  547.     
  548.     
  549.                     if($shippingRule->getTypeCalculation() == "distance"){
  550.                         if( $shippingRule->getMin() < $this->getDistance()  and   $shippingRule->getMax() >= $this->getDistance() ){
  551.                             $fees =  $this->getDistance() * $shippingRule->getValueCalculation();
  552.     
  553.                             /*Condition for TLCS may be it works for all people*/
  554.                             if ($fees $this->getShippingMethod()->getPrice()){
  555.                                 $fees $this->getShippingMethod()->getPrice();
  556.                             }
  557.                             /*Condition for TLCS may be it works for all people*/
  558.                         }
  559.                         
  560.                     }
  561.                         else{
  562.                             if(
  563.                             $shippingRule->getMin() < $this->getTotalAmount() and $shippingRule->getMax() >=  $this->getTotalAmount()
  564.                             
  565.                             ){
  566.                                 if($shippingRule->getTypeCalculation() == "percent"){
  567.                                     $fees = ($this->getTotalAmount() / 100 ) * $shippingRule->getValueCalculation();
  568.                                 }
  569.                                 else{
  570.                                     $fees =  $shippingRule->getValueCalculation();
  571.                                 }
  572.                             }
  573.                         
  574.                     }
  575.     
  576.                     
  577.                 }
  578.             }
  579.             
  580.         }
  581.     
  582.         
  583.         
  584.        
  585.         return $fees;
  586.     }
  587.     #[Groups(['read'])]
  588.     public function getTotalReduction(){
  589.         $total=0;
  590.         $total $total $this->getReduction() + $this->getReductionOnCoupon();
  591.         return $total;
  592.     }
  593.     public function getReductionOnTotal(){
  594.         $reductionAmount 0;
  595.         
  596.         if($this->getReduction() and $this->getReduction()>0){
  597.             $reductionAmount = ($this->getTotalAmount() / 100) * $this->getReduction();
  598.         }
  599.         return $reductionAmount;
  600.     }
  601.     #[Groups(['read'])]
  602.     public function getAmountPayedByCredit(){
  603.         $total=0;
  604.         foreach($this->getCustomerWalletPoints() as $singleWalletPoints){
  605.             if($singleWalletPoints->getPoints()<0){
  606.                 $total $total + ($singleWalletPoints->getPoints());
  607.             }
  608.             
  609.         }
  610.         return $total;
  611.     }
  612.     #[Groups(['read'])]
  613.     public function getAmountEarnedAsCredit(){
  614.         $total=0;
  615.         foreach($this->getCustomerWalletPoints() as $singleWalletPoints){
  616.             if($singleWalletPoints->getPoints()>0){
  617.                 $total $total + ($singleWalletPoints->getPoints());
  618.             }
  619.             
  620.         }
  621.         return $total;
  622.     }
  623.     public function getDemandeFund(): ?DemandeFund
  624.     {
  625.         return $this->demandeFund;
  626.     }
  627.     public function setDemandeFund(?DemandeFund $demandeFund): self
  628.     {
  629.         $this->demandeFund $demandeFund;
  630.         return $this;
  631.     }
  632.     public function getStatus(): ?string
  633.     {
  634.         $status "draft";
  635.         
  636.         
  637.         $shippingMethodCode $this->getPaymentMethod() ? $this->getPaymentMethod()->getCode() : "";
  638.         
  639.         
  640.         
  641.         $cashTranslations = [
  642.             "CASH",
  643.             "ESPECES"
  644.             ]; 
  645.         
  646.         
  647.         
  648.         if( 
  649.             ($this->statusShipping == "cancelled") or
  650.             ($this->getPayedAmount() == and $this->status == "paid") or
  651.             ($this->status == "waiting" and $this->source == "mobile" and $this->payedAmount == $this->getFullTotalAmount() and in_array($shippingMethodCode,$cashTranslations)  )
  652.         
  653.         ){
  654.             
  655.             return "waiting";
  656.             
  657.         }
  658.         
  659.         
  660.         
  661.         
  662.         if( ($this->getFullRestAmount() >= and $this->getFullRestAmount() < $this->getFullTotalAmount())){
  663.             return "partially-paid";
  664.             
  665.         }
  666.         
  667.         // BySamir : ToReview : $this->status != "waiting" and $this->source != "mobile" and $this->source
  668.         
  669.         
  670.         if( $this->getFullRestAmount() == and $this->getFullTotalAmount() > 0){
  671.             return "paid";
  672.         }
  673.         if($this->status)
  674.         {
  675.             $status $this->status;
  676.         }
  677.         
  678.         return $status;
  679.     }
  680.     public function setStatus(?string $status): self
  681.     {
  682.         $this->status $status;
  683.         return $this;
  684.     }
  685.     // BySamir : TO CLEAN
  686.  
  687.     public function getSource(): ?string
  688.     {
  689.         return $this->source;
  690.     }
  691.     public function setSource(?string $source): self
  692.     {
  693.         $this->source $source;
  694.         return $this;
  695.     }
  696.     public function getDeliveryAt()
  697.     {
  698.         return $this->deliveryAt;
  699.     }
  700.     public function setDeliveryAt($deliveryAt)
  701.     {
  702.         $this->deliveryAt $deliveryAt;
  703.         return $this;
  704.     }
  705.     public function getRecoveryAt()
  706.     {
  707.         return $this->recoveryAt;
  708.     }
  709.     public function setRecoveryAt($recoveryAt)
  710.     {
  711.         $this->recoveryAt $recoveryAt;
  712.         return $this;
  713.     }
  714.     public function getReduction(): ?float
  715.     {
  716.         return $this->reduction;
  717.     }
  718.     public function setReduction(?float $reduction): self
  719.     {
  720.         $this->reduction $reduction;
  721.         return $this;
  722.     }
  723.    #[Groups(['read'])]
  724.     public function getReductionInPercent(): ?float
  725.     {
  726.         $reduction 0;
  727.         if(($this->reduction $this->getFullTotalAmount()) > 0){
  728.             $reduction $this->reduction / (($this->reduction $this->getFullTotalAmount()) / 100);
  729.         }
  730.         
  731.         return $reduction;
  732.     }
  733.     public function getShippingMethod(): ?ShippingMethod
  734.     {
  735.         return $this->shippingMethod;
  736.     }
  737.     public function setShippingMethod(?ShippingMethod $shippingMethod): self
  738.     {
  739.         $this->shippingMethod $shippingMethod;
  740.         return $this;
  741.     }
  742.     public function getAgent(): ?Agent
  743.     {
  744.         return $this->agent;
  745.     }
  746.     public function setAgent(?Agent $agent): self
  747.     {
  748.         $this->agent $agent;
  749.         return $this;
  750.     }
  751.     public function getPaymentMethod(): ?paymentMethod
  752.     {
  753.         return $this->paymentMethod;
  754.     }
  755.     public function setPaymentMethod(?paymentMethod $paymentMethod): self
  756.     {
  757.         $this->paymentMethod $paymentMethod;
  758.         return $this;
  759.     }
  760.     public function getPayedAmount(): ?float
  761.     {
  762.         return $this->payedAmount;
  763.     }
  764.     public function setPayedAmount(?float $payedAmount): self
  765.     {
  766.         $this->payedAmount $payedAmount;
  767.         return $this;
  768.     }
  769.     public function getStartProcessingAt(): ?\DateTimeInterface
  770.     {
  771.         return $this->startProcessingAt;
  772.     }
  773.     public function setStartProcessingAt(?\DateTimeInterface $startProcessingAt): self
  774.     {
  775.         $this->startProcessingAt $startProcessingAt;
  776.         return $this;
  777.     }
  778.     public function getDeliveryType(): ?string
  779.     {
  780.         return $this->deliveryType;
  781.     }
  782.     public function setDeliveryType(?string $deliveryType): self
  783.     {
  784.         $this->deliveryType $deliveryType;
  785.         return $this;
  786.     }
  787.     public function getStartDeliveryAt(): ?\DateTimeInterface
  788.     {
  789.         return $this->startDeliveryAt;
  790.     }
  791.     public function setStartDeliveryAt(?\DateTimeInterface $startDeliveryAt): self
  792.     {
  793.         $this->startDeliveryAt $startDeliveryAt;
  794.         return $this;
  795.     }
  796.     /**
  797.      * @return Collection<int, CustomerWalletPoint>
  798.      */
  799.     public function getCustomerWalletPoints(): Collection
  800.     {
  801.         return $this->customerWalletPoints;
  802.     }
  803.     public function addCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  804.     {
  805.         if (!$this->customerWalletPoints->contains($customerWalletPoint)) {
  806.             $this->customerWalletPoints[] = $customerWalletPoint;
  807.             $customerWalletPoint->setOriginOrder($this);
  808.         }
  809.         return $this;
  810.     }
  811.     public function removeCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  812.     {
  813.         if ($this->customerWalletPoints->removeElement($customerWalletPoint)) {
  814.             // set the owning side to null (unless already changed)
  815.             if ($customerWalletPoint->getOriginOrder() === $this) {
  816.                 $customerWalletPoint->setOriginOrder(null);
  817.             }
  818.         }
  819.         return $this;
  820.     }
  821.     public function getCoupon(): ?Coupon
  822.     {
  823.         return $this->coupon;
  824.     }
  825.     public function setCoupon(?Coupon $coupon): self
  826.     {
  827.         $this->coupon $coupon;
  828.         return $this;
  829.     }
  830.     public function getAgentToDo(): ?Agent
  831.     {
  832.         return $this->agentToDo;
  833.     }
  834.     public function setAgentToDo(?Agent $agentToDo): self
  835.     {
  836.         $this->agentToDo $agentToDo;
  837.         return $this;
  838.     }
  839.     public function getIsToDo(): ?bool
  840.     {
  841.         return $this->isToDo;
  842.     }
  843.     public function setIsToDo(?bool $isToDo): self
  844.     {
  845.         $this->isToDo $isToDo;
  846.         return $this;
  847.     }
  848.     public function getCityRegionShipping(): ?CityRegion
  849.     {
  850.         return $this->cityRegionShipping;
  851.     }
  852.     public function setCityRegionShipping(?CityRegion $cityRegionShipping): self
  853.     {
  854.         $this->cityRegionShipping $cityRegionShipping;
  855.         return $this;
  856.     }
  857.     public function getVendor(): ?Vendor
  858.     {
  859.         return $this->vendor;
  860.     }
  861.     public function setVendor(?Vendor $vendor): self
  862.     {
  863.         $this->vendor $vendor;
  864.         return $this;
  865.     }
  866.     public function getCollectAddress(): ?string
  867.     {
  868.         return $this->collectAddress;
  869.     }
  870.     public function setCollectAddress(?string $collectAddress): self
  871.     {
  872.         $this->collectAddress $collectAddress;
  873.         return $this;
  874.     }
  875.     public function getCollectTel(): ?string
  876.     {
  877.         return $this->collectTel;
  878.     }
  879.     public function setCollectTel(?string $collectTel): self
  880.     {
  881.         $this->collectTel $collectTel;
  882.         return $this;
  883.     }
  884.     public function getIsHeavy(): ?bool
  885.     {
  886.         return $this->isHeavy;
  887.     }
  888.     public function setIsHeavy(?bool $isHeavy): self
  889.     {
  890.         $this->isHeavy $isHeavy;
  891.         return $this;
  892.     }
  893.     #[Groups(['read'])]
  894.     public function getShippingTips(): ?float
  895.     {
  896.         return $this->shippingTips;
  897.     }
  898.     public function setShippingTips(?float $shippingTips): self
  899.     {
  900.         $this->shippingTips $shippingTips;
  901.         return $this;
  902.     }
  903.  
  904.     
  905.     /**
  906.      * Get the value of isChecked
  907.      */ 
  908.     public function getIsChecked()
  909.     {
  910.         return $this->isChecked;
  911.     }
  912.     /**
  913.      * Set the value of isChecked
  914.      *
  915.      * @return  self
  916.      */ 
  917.     public function setIsChecked($isChecked)
  918.     {
  919.         $this->isChecked $isChecked;
  920.         return $this;
  921.     }
  922.     /**
  923.      * Get the value of walletPaymentAmount
  924.      */ 
  925.     public function getWalletPaymentAmount()
  926.     {
  927.         return $this->walletPaymentAmount;
  928.     }
  929.     /**
  930.      * Set the value of walletPaymentAmount
  931.      *
  932.      * @return  self
  933.      */ 
  934.     public function setWalletPaymentAmount($walletPaymentAmount)
  935.     {
  936.         $this->walletPaymentAmount $walletPaymentAmount;
  937.         return $this;
  938.     }
  939.     /**
  940.      * Get the value of cityRegionCollect
  941.      */ 
  942.     public function getCityRegionCollect()
  943.     {
  944.         return $this->cityRegionCollect;
  945.     }
  946.     /**
  947.      * Set the value of cityRegionCollect
  948.      *
  949.      * @return  self
  950.      */ 
  951.     public function setCityRegionCollect($cityRegionCollect)
  952.     {
  953.         $this->cityRegionCollect $cityRegionCollect;
  954.         return $this;
  955.     }
  956.     /**
  957.      * Get the value of distance
  958.      */ 
  959.     public function getDistance()
  960.     {
  961.         return $this->distance;
  962.     }
  963.     /**
  964.      * Set the value of distance
  965.      *
  966.      * @return  self
  967.      */ 
  968.     public function setDistance($distance)
  969.     {
  970.         $this->distance $distance;
  971.         return $this;
  972.     }
  973.     /**
  974.      * Get the value of tokenStripe
  975.      */ 
  976.     public function getTokenStripe()
  977.     {
  978.         return $this->tokenStripe;
  979.     }
  980.     /**
  981.      * Set the value of tokenStripe
  982.      *
  983.      * @return  self
  984.      */ 
  985.     public function setTokenStripe($tokenStripe)
  986.     {
  987.         $this->tokenStripe $tokenStripe;
  988.         return $this;
  989.     }
  990.     public function getOrderType(): ?string
  991.     {
  992.         return $this->orderType;
  993.     }
  994.     public function setOrderType(?string $orderType): self
  995.     {
  996.         $this->orderType $orderType;
  997.         return $this;
  998.     }
  999.     /**
  1000.      * Get the value of deletedAt
  1001.      */ 
  1002.     public function getDeletedAt()
  1003.     {
  1004.         return $this->deletedAt;
  1005.     }
  1006.     /**
  1007.      * Set the value of deletedAt
  1008.      *
  1009.      * @return  self
  1010.      */ 
  1011.     public function setDeletedAt($deletedAt)
  1012.     {
  1013.         $this->deletedAt $deletedAt;
  1014.         return $this;
  1015.     }
  1016.     public function getStore(): ?Store
  1017.     {
  1018.         return $this->store;
  1019.     }
  1020.     public function setStore(?Store $store): self
  1021.     {
  1022.         $this->store $store;
  1023.         return $this;
  1024.     }
  1025.     public function getShipment(): ?Shipment
  1026.     {
  1027.         return $this->shipment;
  1028.     }
  1029.     public function setShipment(?Shipment $shipment): self
  1030.     {
  1031.         $this->shipment $shipment;
  1032.         return $this;
  1033.     }
  1034.     public function getInvoice(): ?Invoice
  1035.     {
  1036.         return $this->invoice;
  1037.     }
  1038.     public function setInvoice(?Invoice $invoice): self
  1039.     {
  1040.         $this->invoice $invoice;
  1041.         return $this;
  1042.     }
  1043.     /**
  1044.      * Get the value of shippingAddress
  1045.      */ 
  1046.     public function getShippingAddress()
  1047.     {
  1048.         return $this->shippingAddress;
  1049.     }
  1050.     /**
  1051.      * Set the value of shippingAddress
  1052.      *
  1053.      * @return  self
  1054.      */ 
  1055.     public function setShippingAddress($shippingAddress)
  1056.     {
  1057.         $this->shippingAddress $shippingAddress;
  1058.         return $this;
  1059.     }
  1060.     public function getCreatedBy()
  1061.     {
  1062.         return $this->createdBy;
  1063.     }
  1064.     public function getDescription(): ?string
  1065.     {
  1066.         return $this->description;
  1067.     }
  1068.     public function setDescription(?string $description): self
  1069.     {
  1070.         $this->description $description;
  1071.         return $this;
  1072.     }
  1073.     #[Groups(['read'])]
  1074.     public function getStartProcessingAtText()
  1075.     {
  1076.         $value null;
  1077.         if($this->startDeliveryAt and $this->getShippingMethod()){
  1078.             $intervalDate = clone $this->startProcessingAt;
  1079.         $intervalInMinutes $this->shippingMethod->getShippingDuration() * 60;
  1080.         $intervalDate->modify(" + ".$intervalInMinutes." minutes");
  1081.         
  1082.         $value $this->startProcessingAt->format("d/m/Y H:i") ." - ".$intervalDate->format("H:i");
  1083.         }
  1084.         
  1085.         
  1086.         return $value;
  1087.         
  1088.     }
  1089.     
  1090.     #[Groups(['read'])]
  1091.     public function getCreatedAtText()
  1092.     {
  1093.         $value null;
  1094.         if($this->createdAt){
  1095.            
  1096.         
  1097.             $value $this->createdAt->format("d/m/Y H:i");
  1098.         }
  1099.         
  1100.         
  1101.         return $value;
  1102.     }
  1103.     
  1104.     #[Groups(['read'])]
  1105.     public function getStartDeliveryAtText()
  1106.     {
  1107.         
  1108.         $value null;
  1109.         if($this->startDeliveryAt and $this->getShippingMethod()){
  1110.             $intervalDate = clone $this->startDeliveryAt;
  1111.             $intervalInMinutes $this->shippingMethod->getShippingDuration() * 60;
  1112.             $intervalDate->modify(" + ".$intervalInMinutes." minutes");
  1113.             $value $this->startDeliveryAt->format("d/m/Y H:i") ." - ".$intervalDate->format("H:i");
  1114.         }
  1115.         
  1116.         
  1117.         return $value;
  1118.     }
  1119.     #[Groups(['read'])]
  1120.     public function getShippingMethodText()
  1121.     {
  1122.         $value null
  1123.         if($this->shippingMethod){
  1124.             $value $this->shippingMethod->getName();
  1125.         }
  1126.         return $value;
  1127.         
  1128.     }
  1129.     #[Groups(['read'])]
  1130.     public function getPaymentMethodText()
  1131.     {   
  1132.         $value null
  1133.         if($this->paymentMethod){
  1134.             $value $this->paymentMethod->getName();
  1135.         }
  1136.         return $value;
  1137.     }
  1138.     
  1139.     
  1140.         #[Groups(['read'])]
  1141.     public function getStatusText()
  1142.     {
  1143.         //$translated = $this->translator->trans($this->getSatus());
  1144.         
  1145.         
  1146.         $translatedStatusArray = [
  1147.                 "paid"=>"Réglé",
  1148.                 "canceled"=>"annulé",
  1149.                 "waiting"=>"Non réglé",
  1150.                 "partially-paid"=>"Réglé partiellement",
  1151.             ];
  1152.             
  1153.         if(array_key_exists($this->getStatus(),$translatedStatusArray)){
  1154.             return $translatedStatusArray[$this->getStatus()];
  1155.         }
  1156.         
  1157.         return  "Non réglé";
  1158.         
  1159.     }
  1160.     
  1161.     
  1162.     
  1163.     #[Groups(['read'])]
  1164.     public function getTotalProducts()
  1165.     {   
  1166.         $value 0
  1167.         foreach($this->getOrderItems() as $singleOrderItem){
  1168.             $defaultQuantityProduct 1;
  1169.             
  1170.             if($singleOrderItem->getProduct()){
  1171.                 if($singleOrderItem->getProduct()->getDefaultQuantity() > 0){
  1172.                     $defaultQuantityProduct $singleOrderItem->getProduct()->getDefaultQuantity();
  1173.                 }
  1174.             }
  1175.             
  1176.             
  1177.                 $value $value + ($singleOrderItem->getQuantity() * $defaultQuantityProduct );
  1178.             
  1179.             
  1180.         }
  1181.         
  1182.         return $value;
  1183.     }
  1184.     public function getProductSubscription(): ?ProductSubscription
  1185.     {
  1186.         return $this->productSubscription;
  1187.     }
  1188.     public function setProductSubscription(?ProductSubscription $productSubscription): self
  1189.     {
  1190.         // unset the owning side of the relation if necessary
  1191.         if ($productSubscription === null && $this->productSubscription !== null) {
  1192.             $this->productSubscription->setRelatedOrder(null);
  1193.         }
  1194.         // set the owning side of the relation if necessary
  1195.         if ($productSubscription !== null && $productSubscription->getRelatedOrder() !== $this) {
  1196.             $productSubscription->setRelatedOrder($this);
  1197.         }
  1198.         $this->productSubscription $productSubscription;
  1199.         return $this;
  1200.     }
  1201.     /**
  1202.      * Get the value of statusShipping
  1203.      */ 
  1204.     public function getStatusShipping()
  1205.     {
  1206.         return $this->statusShipping;
  1207.     }
  1208.     /**
  1209.      * Set the value of statusShipping
  1210.      *
  1211.      * @return  self
  1212.      */ 
  1213.     public function setStatusShipping($statusShipping)
  1214.     {
  1215.         $this->statusShipping $statusShipping;
  1216.         return $this;
  1217.     }
  1218.     
  1219.     public function getCollectLng()
  1220.     {
  1221.         return $this->collectLng;
  1222.     }
  1223.     public function getCollectLat()
  1224.     {
  1225.         return $this->collectLat;
  1226.     }
  1227.     
  1228.     public function setCollectLng($collectLng)
  1229.     {
  1230.         $this->collectLng $collectLng;
  1231.         return $this;
  1232.     }
  1233.     
  1234.         public function setCollectLat($collectLat)
  1235.     {
  1236.         $this->collectLat $collectLat;
  1237.         return $this;
  1238.     }
  1239.     
  1240.     
  1241.     
  1242.         public function getShippingLng()
  1243.     {
  1244.         return $this->shippingLng;
  1245.     }
  1246.     public function getShippingLat()
  1247.     {
  1248.         return $this->shippingLat;
  1249.     }
  1250.     
  1251.     public function setShippingLng($shippingLng)
  1252.     {
  1253.         $this->shippingLng $shippingLng;
  1254.         return $this;
  1255.     }
  1256.     
  1257.         public function setShippingLat($shippingLat)
  1258.     {
  1259.         $this->shippingLat $shippingLat;
  1260.         return $this;
  1261.     }
  1262.         public function getMetaData(): ?array
  1263.         {
  1264.             return $this->metaData;
  1265.         }
  1266.         public function setMetaData(?array $metaData): static
  1267.         {
  1268.             $this->metaData $metaData;
  1269.             return $this;
  1270.         }
  1271.         public function getDefaultCurrency(): ?string
  1272.         {
  1273.             return $this->defaultCurrency;
  1274.         }
  1275.         public function setDefaultCurrency(?string $defaultCurrency): static
  1276.         {
  1277.             $this->defaultCurrency $defaultCurrency;
  1278.             return $this;
  1279.         }
  1280.         public function getExtraShippingFees(): ?float
  1281.         {
  1282.             return $this->extraShippingFees;
  1283.         }
  1284.         public function setExtraShippingFees(?float $extraShippingFees): static
  1285.         {
  1286.             $this->extraShippingFees $extraShippingFees;
  1287.             return $this;
  1288.         }
  1289.         public function getExtraShippingMethodName(): ?string
  1290.         {
  1291.             return $this->extraShippingMethodName;
  1292.         }
  1293.         public function setExtraShippingMethodName(?string $extraShippingMethodName): static
  1294.         {
  1295.             $this->extraShippingMethodName $extraShippingMethodName;
  1296.             return $this;
  1297.         }
  1298.         public function getExtraShippingInfos(): ?string
  1299.         {
  1300.             return $this->extraShippingInfos;
  1301.         }
  1302.         public function setExtraShippingInfos(?string $extraShippingInfos): static
  1303.         {
  1304.             $this->extraShippingInfos $extraShippingInfos;
  1305.             return $this;
  1306.         }
  1307.     
  1308.     public function getShippingMonth(){
  1309.         $result "";
  1310.         if($this->getStartDeliveryAt()){
  1311.             $result $this->getStartDeliveryAt()->format('M');
  1312.         }
  1313.         return $result;
  1314.     }
  1315.     
  1316. }