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.     #[Groups(['read','write'])]
  241.     #[ORM\Column(nullabletrue)]
  242.     private ?bool $notifyCustomer null;
  243.     #[ORM\Column(length255nullabletrue)]
  244.     private ?string $updateNotificationMessage null;
  245.     public function __construct()
  246.     {
  247.         $this->orderItems = new ArrayCollection();
  248.         $this->adjustments = new ArrayCollection();
  249.         $this->createdAt = new \DateTime();
  250.         $this->customerWalletPoints = new ArrayCollection();
  251.         
  252.     }
  253.    
  254.     public function __toString(): string
  255.     {
  256.         return (string)$this->getOrderNumber();
  257.     }
  258.     public function getId(): ?int
  259.     {
  260.         return $this->id;
  261.     }
  262.     #[Groups(['read'])]
  263.     public function getOrderNumber($secondaryPrefix=null)
  264.     {
  265.         $prefix "CMD-";
  266.         if($this->getOrderType()=="invoice"){
  267.             $prefix "FA-";
  268.         }
  269.         $orderNumber $prefix.$this->createdAt->format("ym").str_pad((string) $this->id5"0"STR_PAD_LEFT);
  270.         if($secondaryPrefix){
  271.             $orderNumber $prefix.$this->createdAt->format("ym").str_pad((string) $this->id5"0"STR_PAD_LEFT)."-".$secondaryPrefix;
  272.         }
  273.         return $orderNumber;
  274.     }
  275.     #[Groups(['read'])]
  276.     public function getIdPrefixed()
  277.     {
  278.         return $this->getOrderNumber();
  279.     }
  280.     public function getFirstName(): ?string
  281.     {
  282.         return $this->firstName;
  283.     }
  284.     public function setFirstName(string $firstName): self
  285.     {
  286.         $this->firstName $firstName;
  287.         return $this;
  288.     }
  289.     public function getLastName(): ?string
  290.     {
  291.         return $this->lastName;
  292.     }
  293.     public function setLastName(string $lastName): self
  294.     {
  295.         $this->lastName $lastName;
  296.         return $this;
  297.     }
  298.     public function getCreatedAt(): ?\DateTime
  299.     {
  300.         return $this->createdAt;
  301.     }
  302.     public function setCreatedAt(?\DateTime $createdAt): self
  303.     {
  304.         $this->createdAt $createdAt;
  305.         return $this;
  306.     }
  307.     public function getCustomer(): ?Customer
  308.     {
  309.         return $this->customer;
  310.     }
  311.     public function setCustomer(?Customer $customer): self
  312.     {
  313.         $this->customer $customer;
  314.         return $this;
  315.     }
  316.     public function getCategoriesProduct(){
  317.         $categories = [];
  318.         foreach($this->getOrderItems() as $singleOrderItem){
  319.             if($singleOrderItem->getProduct()){
  320.                 if($singleOrderItem->getProduct()->getParentCategory()){
  321.                     $categories[] = $singleOrderItem->getProduct()->getParentCategory()->getName();
  322.                 }
  323.                 
  324.             }
  325.         }
  326.         return $categories;
  327.     }
  328.     public function getSubCategoriesProduct(){
  329.         $categories = [];
  330.         foreach($this->getOrderItems() as $singleOrderItem){
  331.             if($singleOrderItem->getProduct()){
  332.                 foreach($singleOrderItem->getProduct()->getCategoriesProduct() as $singleCategory){
  333.                     if(!in_array($singleCategory->getName(),$categories)){
  334.                         $categories[] = $singleCategory->getName();
  335.                     }
  336.                     
  337.                 }
  338.                 
  339.             }
  340.         }
  341.         return $categories;
  342.     }
  343.     /**
  344.      * @return Collection|OrderItem[]
  345.      */
  346.     public function getOrderItems(): Collection
  347.     {
  348.         return $this->orderItems;
  349.     }
  350.     public function addOrderItem(OrderItem $orderItem): self
  351.     {
  352.         if (!$this->orderItems->contains($orderItem)) {
  353.             $this->orderItems[] = $orderItem;
  354.             $orderItem->setParentOrder($this);
  355.         }
  356.         return $this;
  357.     }
  358.     public function removeOrderItem(OrderItem $orderItem): self
  359.     {
  360.         if ($this->orderItems->removeElement($orderItem)) {
  361.             // set the owning side to null (unless already changed)
  362.             if ($orderItem->getParentOrder() === $this) {
  363.                 $orderItem->setParentOrder(null);
  364.             }
  365.         }
  366.         return $this;
  367.     }
  368.     /**
  369.      * @return Collection|Adjustment[]
  370.      */
  371.     public function getAdjustments(): Collection
  372.     {
  373.         return $this->adjustments;
  374.     }
  375.     public function addAdjustment(Adjustment $adjustment): self
  376.     {
  377.         if (!$this->adjustments->contains($adjustment)) {
  378.             $this->adjustments[] = $adjustment;
  379.             $adjustment->setParentOrder($this);
  380.         }
  381.         return $this;
  382.     }
  383.     public function removeAdjustment(Adjustment $adjustment): self
  384.     {
  385.         if ($this->adjustments->removeElement($adjustment)) {
  386.             // set the owning side to null (unless already changed)
  387.             if ($adjustment->getParentOrder() === $this) {
  388.                 $adjustment->setParentOrder(null);
  389.             }
  390.         }
  391.         return $this;
  392.     }
  393.     #[Groups(['read'])]
  394.     public function getReductionOnCoupon(){
  395.         $reductionCoupon=0;
  396.         if($this->getCoupon()){
  397.             if($this->getCoupon()->getTypeReduction()=="percent"){
  398.                 $reductionCoupon = ($this->getTotalAmount()/100)*$this->getCoupon()->getValueReduction();
  399.             }else{
  400.                 $reductionCoupon $this->getCoupon()->getValueReduction();
  401.             }
  402.         }
  403.         return  $reductionCoupon;
  404.     }
  405.     public function getCompanyName(): ?string
  406.     {
  407.         return $this->companyName;
  408.     }
  409.     public function setCompanyName(?string $companyName): self
  410.     {
  411.         $this->companyName $companyName;
  412.         return $this;
  413.     }
  414.     public function getAddress(): ?string
  415.     {
  416.         return $this->address;
  417.     }
  418.     public function setAddress(string $address): self
  419.     {
  420.         $this->address $address;
  421.         return $this;
  422.     }
  423.     public function getCity(): ?string
  424.     {
  425.         return $this->city;
  426.     }
  427.     public function setCity(string $city): self
  428.     {
  429.         $this->city $city;
  430.         return $this;
  431.     }
  432.     public function getCountry(): ?string
  433.     {
  434.         return $this->country;
  435.     }
  436.     public function setCountry(string $country): self
  437.     {
  438.         $this->country $country;
  439.         return $this;
  440.     }
  441.     public function getDepartment(): ?string
  442.     {
  443.         return $this->department;
  444.     }
  445.     public function setDepartment(?string $department): self
  446.     {
  447.         $this->department $department;
  448.         return $this;
  449.     }
  450.     public function getPostcode(): ?string
  451.     {
  452.         return $this->postcode;
  453.     }
  454.     public function setPostcode(?string $postcode): self
  455.     {
  456.         $this->postcode $postcode;
  457.         return $this;
  458.     }
  459.     public function getEmail(): ?string
  460.     {
  461.         return $this->email;
  462.     }
  463.     public function setEmail(string $email): self
  464.     {
  465.         $this->email $email;
  466.         return $this;
  467.     }
  468.     public function getTel(): ?string
  469.     {
  470.         return $this->tel;
  471.     }
  472.     public function setTel(string $tel): self
  473.     {
  474.         $this->tel $tel;
  475.         return $this;
  476.     }
  477.     public function getComment(): ?string
  478.     {
  479.         return $this->comment;
  480.     }
  481.     public function setComment(?string $comment): self
  482.     {
  483.         $this->comment $comment;
  484.         return $this;
  485.     }
  486.   
  487.     #[Groups(['read'])]
  488.     public function getTotalAmount(){
  489.         $total=0;
  490.         foreach($this->orderItems as $singleOrderItem){
  491.             $total $total + ($singleOrderItem->getTotalAmount());
  492.         }
  493.         return $total;
  494.         
  495.     }
  496.     #[Groups(['read'])]
  497.     public function getFullPayedAmount(){
  498.         return $this->getPayedAmount() + $this->getWalletPaymentAmount() + $this->getTotalReduction();
  499.     }
  500.     #[Groups(['read'])]
  501.     public function getFullTotalAmount(){
  502.         
  503.        
  504.         $total 
  505.         ((float)$this->getTotalAmount() + 
  506.         (float)$this->getShippingFees()  
  507.         
  508.         + (float)$this->getShippingTips()) - 
  509.         ((float)$this->getTotalReduction()) ;
  510.         return $total;
  511.         
  512.     }
  513.     #[Groups(['read'])]
  514.     public function getFullRestAmount(){
  515.         $payedAmount $this->getPayedAmount();
  516.         $walletPayedAmount $this->getWalletPaymentAmount();
  517.         $paymentMethodCode null;
  518.         if($this->getPaymentMethod()){
  519.             $paymentMethodCode $this->getPaymentMethod()->getCode();
  520.         }
  521.         
  522.         if( ( $this->statusShipping == "cancelled")){
  523.             // ToReview
  524.             //return 0;
  525.             $payedAmount 0;
  526.             
  527.         }
  528.        
  529.         $total $this->getFullTotalAmount() - ($payedAmount $walletPayedAmount $this->getTotalReduction());
  530.          ;
  531.         return $total;
  532.         
  533.     }
  534.     //needs optimisation
  535.     #[Groups(['read'])]
  536.     public function getShippingFees(){
  537.         $fees 0;
  538.         foreach($this->getOrderItems() as $singleOrderItem){
  539.             $fees += $singleOrderItem->getShippingFees();
  540.         }
  541.         $fees += $this->getExtraShippingFees();
  542.         if($fees>0) {return $fees;} 
  543.         if($this->getShippingMethod()){
  544.             
  545.             // Condition IlaveU / Classic 19 DH
  546.             
  547.             if($this->getShippingMethod()->getCode() == "CLASSIQUE GRATUIT" and $this->getDeliveryType() == "on-store"){
  548.                     return 0;
  549.            }
  550.             
  551.             
  552.             if($this->getShippingMethod()->isIsSeparatelyCalculated()){
  553.                 $fees $this->getShippingMethod()->getPrice();
  554.             
  555.                 foreach($this->getShippingMethod()->getShippingRules() as $shippingRule){
  556.     
  557.     
  558.                     if($shippingRule->getTypeCalculation() == "distance"){
  559.                         if( $shippingRule->getMin() < $this->getDistance()  and   $shippingRule->getMax() >= $this->getDistance() ){
  560.                             $fees =  $this->getDistance() * $shippingRule->getValueCalculation();
  561.     
  562.                             /*Condition for TLCS may be it works for all people*/
  563.                             if ($fees $this->getShippingMethod()->getPrice()){
  564.                                 $fees $this->getShippingMethod()->getPrice();
  565.                             }
  566.                             /*Condition for TLCS may be it works for all people*/
  567.                         }
  568.                         
  569.                     }
  570.                         else{
  571.                             if(
  572.                             $shippingRule->getMin() < $this->getTotalAmount() and $shippingRule->getMax() >=  $this->getTotalAmount()
  573.                             
  574.                             ){
  575.                                 if($shippingRule->getTypeCalculation() == "percent"){
  576.                                     $fees = ($this->getTotalAmount() / 100 ) * $shippingRule->getValueCalculation();
  577.                                 }
  578.                                 else{
  579.                                     $fees =  $shippingRule->getValueCalculation();
  580.                                 }
  581.                             }
  582.                         
  583.                     }
  584.     
  585.                     
  586.                 }
  587.             }
  588.             
  589.         }
  590.     
  591.         
  592.         
  593.        
  594.         return $fees;
  595.     }
  596.     #[Groups(['read'])]
  597.     public function getTotalReduction(){
  598.         $total=0;
  599.         $total $total $this->getReduction() + $this->getReductionOnCoupon();
  600.         return $total;
  601.     }
  602.     public function getReductionOnTotal(){
  603.         $reductionAmount 0;
  604.         
  605.         if($this->getReduction() and $this->getReduction()>0){
  606.             $reductionAmount = ($this->getTotalAmount() / 100) * $this->getReduction();
  607.         }
  608.         return $reductionAmount;
  609.     }
  610.     #[Groups(['read'])]
  611.     public function getAmountPayedByCredit(){
  612.         $total=0;
  613.         foreach($this->getCustomerWalletPoints() as $singleWalletPoints){
  614.             if($singleWalletPoints->getPoints()<0){
  615.                 $total $total + ($singleWalletPoints->getPoints());
  616.             }
  617.             
  618.         }
  619.         return $total;
  620.     }
  621.     #[Groups(['read'])]
  622.     public function getAmountEarnedAsCredit(){
  623.         $total=0;
  624.         foreach($this->getCustomerWalletPoints() as $singleWalletPoints){
  625.             if($singleWalletPoints->getPoints()>0){
  626.                 $total $total + ($singleWalletPoints->getPoints());
  627.             }
  628.             
  629.         }
  630.         return $total;
  631.     }
  632.     public function getDemandeFund(): ?DemandeFund
  633.     {
  634.         return $this->demandeFund;
  635.     }
  636.     public function setDemandeFund(?DemandeFund $demandeFund): self
  637.     {
  638.         $this->demandeFund $demandeFund;
  639.         return $this;
  640.     }
  641.     public function getStatus(): ?string
  642.     {
  643.         $status "waiting";
  644.         
  645.         
  646.         $shippingMethodCode $this->getPaymentMethod() ? $this->getPaymentMethod()->getCode() : "";
  647.         
  648.         
  649.         
  650.         $cashTranslations = [
  651.             "CASH",
  652.             "ESPECES"
  653.             ]; 
  654.         if( $this->getFullRestAmount() == and $this->getFullTotalAmount() > 0){
  655.             return "paid";
  656.         }
  657.         // if( ($this->getPayedAmount() > 0 &&  $this->getPayedAmount() < $this->getFullTotalAmount())){
  658.         //     return "partially-paid";
  659.             
  660.         // }
  661.         if($this->getFullRestAmount() > and $this->getFullPayedAmount() > 0){
  662.             return "partially-paid";
  663.         }
  664.         return "waiting";
  665.         
  666.         
  667.       
  668.         
  669.         
  670.         
  671.         
  672.         
  673.         
  674.         // BySamir : ToReview : $this->status != "waiting" and $this->source != "mobile" and $this->source
  675.         
  676.         
  677.         
  678.         if($this->status)
  679.         {
  680.             $status $this->status;
  681.         }
  682.         
  683.         return $status;
  684.     }
  685.     public function setStatus(?string $status): self
  686.     {
  687.         $this->status $status;
  688.         return $this;
  689.     }
  690.     // BySamir : TO CLEAN
  691.  
  692.     public function getSource(): ?string
  693.     {
  694.         return $this->source;
  695.     }
  696.     public function setSource(?string $source): self
  697.     {
  698.         $this->source $source;
  699.         return $this;
  700.     }
  701.     public function getDeliveryAt()
  702.     {
  703.         return $this->deliveryAt;
  704.     }
  705.     public function setDeliveryAt($deliveryAt)
  706.     {
  707.         $this->deliveryAt $deliveryAt;
  708.         return $this;
  709.     }
  710.     public function getRecoveryAt()
  711.     {
  712.         return $this->recoveryAt;
  713.     }
  714.     public function setRecoveryAt($recoveryAt)
  715.     {
  716.         $this->recoveryAt $recoveryAt;
  717.         return $this;
  718.     }
  719.     public function getReduction(): ?float
  720.     {
  721.         return $this->reduction;
  722.     }
  723.     public function setReduction(?float $reduction): self
  724.     {
  725.         $this->reduction $reduction;
  726.         return $this;
  727.     }
  728.    #[Groups(['read'])]
  729.     public function getReductionInPercent(): ?float
  730.     {
  731.         $reduction 0;
  732.         if(($this->reduction $this->getFullTotalAmount()) > 0){
  733.             $reduction $this->reduction / (($this->reduction $this->getFullTotalAmount()) / 100);
  734.         }
  735.         
  736.         return $reduction;
  737.     }
  738.     public function getShippingMethod(): ?ShippingMethod
  739.     {
  740.         return $this->shippingMethod;
  741.     }
  742.     public function setShippingMethod(?ShippingMethod $shippingMethod): self
  743.     {
  744.         $this->shippingMethod $shippingMethod;
  745.         return $this;
  746.     }
  747.     public function getAgent(): ?Agent
  748.     {
  749.         return $this->agent;
  750.     }
  751.     public function setAgent(?Agent $agent): self
  752.     {
  753.         $this->agent $agent;
  754.         return $this;
  755.     }
  756.     public function getPaymentMethod(): ?paymentMethod
  757.     {
  758.         return $this->paymentMethod;
  759.     }
  760.     public function setPaymentMethod(?paymentMethod $paymentMethod): self
  761.     {
  762.         $this->paymentMethod $paymentMethod;
  763.         return $this;
  764.     }
  765.     public function getPayedAmount(): ?float
  766.     {
  767.         return $this->payedAmount;
  768.     }
  769.     public function setPayedAmount(?float $payedAmount): self
  770.     {
  771.         $this->payedAmount $payedAmount;
  772.         return $this;
  773.     }
  774.     public function getStartProcessingAt(): ?\DateTimeInterface
  775.     {
  776.         return $this->startProcessingAt;
  777.     }
  778.     public function setStartProcessingAt(?\DateTimeInterface $startProcessingAt): self
  779.     {
  780.         $this->startProcessingAt $startProcessingAt;
  781.         return $this;
  782.     }
  783.     public function getDeliveryType(): ?string
  784.     {
  785.         return $this->deliveryType;
  786.     }
  787.     public function setDeliveryType(?string $deliveryType): self
  788.     {
  789.         $this->deliveryType $deliveryType;
  790.         return $this;
  791.     }
  792.     public function getStartDeliveryAt(): ?\DateTimeInterface
  793.     {
  794.         return $this->startDeliveryAt;
  795.     }
  796.     public function setStartDeliveryAt(?\DateTimeInterface $startDeliveryAt): self
  797.     {
  798.         $this->startDeliveryAt $startDeliveryAt;
  799.         return $this;
  800.     }
  801.     /**
  802.      * @return Collection<int, CustomerWalletPoint>
  803.      */
  804.     public function getCustomerWalletPoints(): Collection
  805.     {
  806.         return $this->customerWalletPoints;
  807.     }
  808.     public function addCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  809.     {
  810.         if (!$this->customerWalletPoints->contains($customerWalletPoint)) {
  811.             $this->customerWalletPoints[] = $customerWalletPoint;
  812.             $customerWalletPoint->setOriginOrder($this);
  813.         }
  814.         return $this;
  815.     }
  816.     public function removeCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  817.     {
  818.         if ($this->customerWalletPoints->removeElement($customerWalletPoint)) {
  819.             // set the owning side to null (unless already changed)
  820.             if ($customerWalletPoint->getOriginOrder() === $this) {
  821.                 $customerWalletPoint->setOriginOrder(null);
  822.             }
  823.         }
  824.         return $this;
  825.     }
  826.     public function getCoupon(): ?Coupon
  827.     {
  828.         return $this->coupon;
  829.     }
  830.     public function setCoupon(?Coupon $coupon): self
  831.     {
  832.         $this->coupon $coupon;
  833.         return $this;
  834.     }
  835.     public function getAgentToDo(): ?Agent
  836.     {
  837.         return $this->agentToDo;
  838.     }
  839.     public function setAgentToDo(?Agent $agentToDo): self
  840.     {
  841.         $this->agentToDo $agentToDo;
  842.         return $this;
  843.     }
  844.     public function getIsToDo(): ?bool
  845.     {
  846.         return $this->isToDo;
  847.     }
  848.     public function setIsToDo(?bool $isToDo): self
  849.     {
  850.         $this->isToDo $isToDo;
  851.         return $this;
  852.     }
  853.     public function getCityRegionShipping(): ?CityRegion
  854.     {
  855.         return $this->cityRegionShipping;
  856.     }
  857.     public function setCityRegionShipping(?CityRegion $cityRegionShipping): self
  858.     {
  859.         $this->cityRegionShipping $cityRegionShipping;
  860.         return $this;
  861.     }
  862.     public function getVendor(): ?Vendor
  863.     {
  864.         return $this->vendor;
  865.     }
  866.     public function setVendor(?Vendor $vendor): self
  867.     {
  868.         $this->vendor $vendor;
  869.         return $this;
  870.     }
  871.     public function getCollectAddress(): ?string
  872.     {
  873.         return $this->collectAddress;
  874.     }
  875.     public function setCollectAddress(?string $collectAddress): self
  876.     {
  877.         $this->collectAddress $collectAddress;
  878.         return $this;
  879.     }
  880.     public function getCollectTel(): ?string
  881.     {
  882.         return $this->collectTel;
  883.     }
  884.     public function setCollectTel(?string $collectTel): self
  885.     {
  886.         $this->collectTel $collectTel;
  887.         return $this;
  888.     }
  889.     public function getIsHeavy(): ?bool
  890.     {
  891.         return $this->isHeavy;
  892.     }
  893.     public function setIsHeavy(?bool $isHeavy): self
  894.     {
  895.         $this->isHeavy $isHeavy;
  896.         return $this;
  897.     }
  898.     #[Groups(['read'])]
  899.     public function getShippingTips(): ?float
  900.     {
  901.         return $this->shippingTips;
  902.     }
  903.     public function setShippingTips(?float $shippingTips): self
  904.     {
  905.         $this->shippingTips $shippingTips;
  906.         return $this;
  907.     }
  908.  
  909.     
  910.     /**
  911.      * Get the value of isChecked
  912.      */ 
  913.     public function getIsChecked()
  914.     {
  915.         return $this->isChecked;
  916.     }
  917.     /**
  918.      * Set the value of isChecked
  919.      *
  920.      * @return  self
  921.      */ 
  922.     public function setIsChecked($isChecked)
  923.     {
  924.         $this->isChecked $isChecked;
  925.         return $this;
  926.     }
  927.     /**
  928.      * Get the value of walletPaymentAmount
  929.      */ 
  930.     public function getWalletPaymentAmount()
  931.     {
  932.         return $this->walletPaymentAmount;
  933.     }
  934.     /**
  935.      * Set the value of walletPaymentAmount
  936.      *
  937.      * @return  self
  938.      */ 
  939.     public function setWalletPaymentAmount($walletPaymentAmount)
  940.     {
  941.         $this->walletPaymentAmount $walletPaymentAmount;
  942.         return $this;
  943.     }
  944.     /**
  945.      * Get the value of cityRegionCollect
  946.      */ 
  947.     public function getCityRegionCollect()
  948.     {
  949.         return $this->cityRegionCollect;
  950.     }
  951.     /**
  952.      * Set the value of cityRegionCollect
  953.      *
  954.      * @return  self
  955.      */ 
  956.     public function setCityRegionCollect($cityRegionCollect)
  957.     {
  958.         $this->cityRegionCollect $cityRegionCollect;
  959.         return $this;
  960.     }
  961.     /**
  962.      * Get the value of distance
  963.      */ 
  964.     public function getDistance()
  965.     {
  966.         return $this->distance;
  967.     }
  968.     /**
  969.      * Set the value of distance
  970.      *
  971.      * @return  self
  972.      */ 
  973.     public function setDistance($distance)
  974.     {
  975.         $this->distance $distance;
  976.         return $this;
  977.     }
  978.     /**
  979.      * Get the value of tokenStripe
  980.      */ 
  981.     public function getTokenStripe()
  982.     {
  983.         return $this->tokenStripe;
  984.     }
  985.     /**
  986.      * Set the value of tokenStripe
  987.      *
  988.      * @return  self
  989.      */ 
  990.     public function setTokenStripe($tokenStripe)
  991.     {
  992.         $this->tokenStripe $tokenStripe;
  993.         return $this;
  994.     }
  995.     public function getOrderType(): ?string
  996.     {
  997.         return $this->orderType;
  998.     }
  999.     public function setOrderType(?string $orderType): self
  1000.     {
  1001.         $this->orderType $orderType;
  1002.         return $this;
  1003.     }
  1004.     /**
  1005.      * Get the value of deletedAt
  1006.      */ 
  1007.     public function getDeletedAt()
  1008.     {
  1009.         return $this->deletedAt;
  1010.     }
  1011.     /**
  1012.      * Set the value of deletedAt
  1013.      *
  1014.      * @return  self
  1015.      */ 
  1016.     public function setDeletedAt($deletedAt)
  1017.     {
  1018.         $this->deletedAt $deletedAt;
  1019.         return $this;
  1020.     }
  1021.     public function getStore(): ?Store
  1022.     {
  1023.         return $this->store;
  1024.     }
  1025.     public function setStore(?Store $store): self
  1026.     {
  1027.         $this->store $store;
  1028.         return $this;
  1029.     }
  1030.     public function getShipment(): ?Shipment
  1031.     {
  1032.         return $this->shipment;
  1033.     }
  1034.     public function setShipment(?Shipment $shipment): self
  1035.     {
  1036.         $this->shipment $shipment;
  1037.         return $this;
  1038.     }
  1039.     public function getInvoice(): ?Invoice
  1040.     {
  1041.         return $this->invoice;
  1042.     }
  1043.     public function setInvoice(?Invoice $invoice): self
  1044.     {
  1045.         $this->invoice $invoice;
  1046.         return $this;
  1047.     }
  1048.     /**
  1049.      * Get the value of shippingAddress
  1050.      */ 
  1051.     public function getShippingAddress()
  1052.     {
  1053.         return $this->shippingAddress;
  1054.     }
  1055.     /**
  1056.      * Set the value of shippingAddress
  1057.      *
  1058.      * @return  self
  1059.      */ 
  1060.     public function setShippingAddress($shippingAddress)
  1061.     {
  1062.         $this->shippingAddress $shippingAddress;
  1063.         return $this;
  1064.     }
  1065.     public function getCreatedBy()
  1066.     {
  1067.         return $this->createdBy;
  1068.     }
  1069.     public function getDescription(): ?string
  1070.     {
  1071.         return $this->description;
  1072.     }
  1073.     public function setDescription(?string $description): self
  1074.     {
  1075.         $this->description $description;
  1076.         return $this;
  1077.     }
  1078.     #[Groups(['read'])]
  1079.     public function getStartProcessingAtText()
  1080.     {
  1081.         $value null;
  1082.         if($this->startDeliveryAt and $this->getShippingMethod()){
  1083.             $intervalDate = clone $this->startProcessingAt;
  1084.         $intervalInMinutes $this->shippingMethod->getShippingDuration() * 60;
  1085.         $intervalDate->modify(" + ".$intervalInMinutes." minutes");
  1086.         
  1087.         $value $this->startProcessingAt->format("d/m/Y H:i") ." - ".$intervalDate->format("H:i");
  1088.         }
  1089.         
  1090.         
  1091.         return $value;
  1092.         
  1093.     }
  1094.     
  1095.     #[Groups(['read'])]
  1096.     public function getCreatedAtText()
  1097.     {
  1098.         $value null;
  1099.         if($this->createdAt){
  1100.            
  1101.         
  1102.             $value $this->createdAt->format("d/m/Y H:i");
  1103.         }
  1104.         
  1105.         
  1106.         return $value;
  1107.     }
  1108.     
  1109.     #[Groups(['read'])]
  1110.     public function getStartDeliveryAtText()
  1111.     {
  1112.         
  1113.         $value null;
  1114.         if($this->startDeliveryAt and $this->getShippingMethod()){
  1115.             $intervalDate = clone $this->startDeliveryAt;
  1116.             $intervalInMinutes $this->shippingMethod->getShippingDuration() * 60;
  1117.             $intervalDate->modify(" + ".$intervalInMinutes." minutes");
  1118.             $value $this->startDeliveryAt->format("d/m/Y H:i") ." - ".$intervalDate->format("H:i");
  1119.         }
  1120.         
  1121.         
  1122.         return $value;
  1123.     }
  1124.     #[Groups(['read'])]
  1125.     public function getShippingMethodText()
  1126.     {
  1127.         $value null
  1128.         if($this->shippingMethod){
  1129.             $value $this->shippingMethod->getName();
  1130.         }
  1131.         return $value;
  1132.         
  1133.     }
  1134.     #[Groups(['read'])]
  1135.     public function getPaymentMethodText()
  1136.     {   
  1137.         $value null
  1138.         if($this->paymentMethod){
  1139.             $value $this->paymentMethod->getName();
  1140.         }
  1141.         return $value;
  1142.     }
  1143.     
  1144.     
  1145.         #[Groups(['read'])]
  1146.     public function getStatusText()
  1147.     {
  1148.         //$translated = $this->translator->trans($this->getSatus());
  1149.         
  1150.         
  1151.         $translatedStatusArray = [
  1152.                 "paid"=>"Réglé",
  1153.                 "canceled"=>"annulé",
  1154.                 "waiting"=>"Non réglé",
  1155.                 "partially-paid"=>"Réglé partiellement",
  1156.             ];
  1157.             
  1158.         if(array_key_exists($this->getStatus(),$translatedStatusArray)){
  1159.             return $translatedStatusArray[$this->getStatus()];
  1160.         }
  1161.         
  1162.         return  "Non réglé";
  1163.         
  1164.     }
  1165.     
  1166.     
  1167.     
  1168.     #[Groups(['read'])]
  1169.     public function getTotalProducts()
  1170.     {   
  1171.         $value 0
  1172.         foreach($this->getOrderItems() as $singleOrderItem){
  1173.             $defaultQuantityProduct 1;
  1174.             
  1175.             if($singleOrderItem->getProduct()){
  1176.                 if($singleOrderItem->getProduct()->getDefaultQuantity() > 0){
  1177.                     $defaultQuantityProduct $singleOrderItem->getProduct()->getDefaultQuantity();
  1178.                 }
  1179.             }
  1180.             
  1181.             
  1182.                 $value $value + ($singleOrderItem->getQuantity() * $defaultQuantityProduct );
  1183.             
  1184.             
  1185.         }
  1186.         
  1187.         return $value;
  1188.     }
  1189.     public function getProductSubscription(): ?ProductSubscription
  1190.     {
  1191.         return $this->productSubscription;
  1192.     }
  1193.     public function setProductSubscription(?ProductSubscription $productSubscription): self
  1194.     {
  1195.         // unset the owning side of the relation if necessary
  1196.         if ($productSubscription === null && $this->productSubscription !== null) {
  1197.             $this->productSubscription->setRelatedOrder(null);
  1198.         }
  1199.         // set the owning side of the relation if necessary
  1200.         if ($productSubscription !== null && $productSubscription->getRelatedOrder() !== $this) {
  1201.             $productSubscription->setRelatedOrder($this);
  1202.         }
  1203.         $this->productSubscription $productSubscription;
  1204.         return $this;
  1205.     }
  1206.     /**
  1207.      * Get the value of statusShipping
  1208.      */ 
  1209.     public function getStatusShipping()
  1210.     {
  1211.         return $this->statusShipping;
  1212.     }
  1213.     /**
  1214.      * Set the value of statusShipping
  1215.      *
  1216.      * @return  self
  1217.      */ 
  1218.     public function setStatusShipping($statusShipping)
  1219.     {
  1220.         $this->statusShipping $statusShipping;
  1221.         return $this;
  1222.     }
  1223.     
  1224.     public function getCollectLng()
  1225.     {
  1226.         return $this->collectLng;
  1227.     }
  1228.     public function getCollectLat()
  1229.     {
  1230.         return $this->collectLat;
  1231.     }
  1232.     
  1233.     public function setCollectLng($collectLng)
  1234.     {
  1235.         $this->collectLng $collectLng;
  1236.         return $this;
  1237.     }
  1238.     
  1239.         public function setCollectLat($collectLat)
  1240.     {
  1241.         $this->collectLat $collectLat;
  1242.         return $this;
  1243.     }
  1244.     
  1245.     
  1246.     
  1247.         public function getShippingLng()
  1248.     {
  1249.         return $this->shippingLng;
  1250.     }
  1251.     public function getShippingLat()
  1252.     {
  1253.         return $this->shippingLat;
  1254.     }
  1255.     
  1256.     public function setShippingLng($shippingLng)
  1257.     {
  1258.         $this->shippingLng $shippingLng;
  1259.         return $this;
  1260.     }
  1261.     
  1262.         public function setShippingLat($shippingLat)
  1263.     {
  1264.         $this->shippingLat $shippingLat;
  1265.         return $this;
  1266.     }
  1267.         public function getMetaData(): ?array
  1268.         {
  1269.             return $this->metaData;
  1270.         }
  1271.         public function setMetaData(?array $metaData): static
  1272.         {
  1273.             $this->metaData $metaData;
  1274.             return $this;
  1275.         }
  1276.         public function getDefaultCurrency(): ?string
  1277.         {
  1278.             return $this->defaultCurrency;
  1279.         }
  1280.         public function setDefaultCurrency(?string $defaultCurrency): static
  1281.         {
  1282.             $this->defaultCurrency $defaultCurrency;
  1283.             return $this;
  1284.         }
  1285.         public function getExtraShippingFees(): ?float
  1286.         {
  1287.             return $this->extraShippingFees;
  1288.         }
  1289.         public function setExtraShippingFees(?float $extraShippingFees): static
  1290.         {
  1291.             $this->extraShippingFees $extraShippingFees;
  1292.             return $this;
  1293.         }
  1294.         public function getExtraShippingMethodName(): ?string
  1295.         {
  1296.             return $this->extraShippingMethodName;
  1297.         }
  1298.         public function setExtraShippingMethodName(?string $extraShippingMethodName): static
  1299.         {
  1300.             $this->extraShippingMethodName $extraShippingMethodName;
  1301.             return $this;
  1302.         }
  1303.         public function getExtraShippingInfos(): ?string
  1304.         {
  1305.             return $this->extraShippingInfos;
  1306.         }
  1307.         public function setExtraShippingInfos(?string $extraShippingInfos): static
  1308.         {
  1309.             $this->extraShippingInfos $extraShippingInfos;
  1310.             return $this;
  1311.         }
  1312.     
  1313.     public function getShippingMonth(){
  1314.         $result "";
  1315.         if($this->getStartDeliveryAt()){
  1316.             $result $this->getStartDeliveryAt()->format('M');
  1317.         }
  1318.         return $result;
  1319.     }
  1320.     public function getNotifyCustomer(): ?bool
  1321.     {
  1322.         return $this->notifyCustomer;
  1323.     }
  1324.     public function setNotifyCustomer(?bool $notifyCustomer): static
  1325.     {
  1326.         $this->notifyCustomer $notifyCustomer;
  1327.         return $this;
  1328.     }
  1329.     public function getUpdateNotificationMessage(): ?string
  1330.     {
  1331.         return $this->updateNotificationMessage;
  1332.     }
  1333.     public function setUpdateNotificationMessage(?string $updateNotificationMessage): static
  1334.     {
  1335.         $this->updateNotificationMessage $updateNotificationMessage;
  1336.         return $this;
  1337.     }
  1338.     
  1339. }