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();
  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);
  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->getFullPayedAmount() > 0){
  662.             
  663.         
  664.             if($this->getFullRestAmount() > and $this->getFullPayedAmount() < $this->getFullTotalAmount() ){
  665.                 return "partially-paid";
  666.             }
  667.         }
  668.         return "waiting";
  669.         
  670.         
  671.       
  672.         
  673.         
  674.         
  675.         
  676.         
  677.         
  678.         // BySamir : ToReview : $this->status != "waiting" and $this->source != "mobile" and $this->source
  679.         
  680.         
  681.         
  682.         if($this->status)
  683.         {
  684.             $status $this->status;
  685.         }
  686.         
  687.         return $status;
  688.     }
  689.     public function setStatus(?string $status): self
  690.     {
  691.         $this->status $status;
  692.         return $this;
  693.     }
  694.     // BySamir : TO CLEAN
  695.  
  696.     public function getSource(): ?string
  697.     {
  698.         return $this->source;
  699.     }
  700.     public function setSource(?string $source): self
  701.     {
  702.         $this->source $source;
  703.         return $this;
  704.     }
  705.     public function getDeliveryAt()
  706.     {
  707.         return $this->deliveryAt;
  708.     }
  709.     public function setDeliveryAt($deliveryAt)
  710.     {
  711.         $this->deliveryAt $deliveryAt;
  712.         return $this;
  713.     }
  714.     public function getRecoveryAt()
  715.     {
  716.         return $this->recoveryAt;
  717.     }
  718.     public function setRecoveryAt($recoveryAt)
  719.     {
  720.         $this->recoveryAt $recoveryAt;
  721.         return $this;
  722.     }
  723.     public function getReduction(): ?float
  724.     {
  725.         return $this->reduction;
  726.     }
  727.     public function setReduction(?float $reduction): self
  728.     {
  729.         $this->reduction $reduction;
  730.         return $this;
  731.     }
  732.    #[Groups(['read'])]
  733.     public function getReductionInPercent(): ?float
  734.     {
  735.         $reduction 0;
  736.         if(($this->reduction $this->getFullTotalAmount()) > 0){
  737.             $reduction $this->reduction / (($this->reduction $this->getFullTotalAmount()) / 100);
  738.         }
  739.         
  740.         return $reduction;
  741.     }
  742.     public function getShippingMethod(): ?ShippingMethod
  743.     {
  744.         return $this->shippingMethod;
  745.     }
  746.     public function setShippingMethod(?ShippingMethod $shippingMethod): self
  747.     {
  748.         $this->shippingMethod $shippingMethod;
  749.         return $this;
  750.     }
  751.     public function getAgent(): ?Agent
  752.     {
  753.         return $this->agent;
  754.     }
  755.     public function setAgent(?Agent $agent): self
  756.     {
  757.         $this->agent $agent;
  758.         return $this;
  759.     }
  760.     public function getPaymentMethod(): ?paymentMethod
  761.     {
  762.         return $this->paymentMethod;
  763.     }
  764.     public function setPaymentMethod(?paymentMethod $paymentMethod): self
  765.     {
  766.         $this->paymentMethod $paymentMethod;
  767.         return $this;
  768.     }
  769.     public function getPayedAmount(): ?float
  770.     {
  771.         return $this->payedAmount;
  772.     }
  773.     public function setPayedAmount(?float $payedAmount): self
  774.     {
  775.         $this->payedAmount $payedAmount;
  776.         return $this;
  777.     }
  778.     public function getStartProcessingAt(): ?\DateTimeInterface
  779.     {
  780.         return $this->startProcessingAt;
  781.     }
  782.     public function setStartProcessingAt(?\DateTimeInterface $startProcessingAt): self
  783.     {
  784.         $this->startProcessingAt $startProcessingAt;
  785.         return $this;
  786.     }
  787.     public function getDeliveryType(): ?string
  788.     {
  789.         return $this->deliveryType;
  790.     }
  791.     public function setDeliveryType(?string $deliveryType): self
  792.     {
  793.         $this->deliveryType $deliveryType;
  794.         return $this;
  795.     }
  796.     public function getStartDeliveryAt(): ?\DateTimeInterface
  797.     {
  798.         return $this->startDeliveryAt;
  799.     }
  800.     public function setStartDeliveryAt(?\DateTimeInterface $startDeliveryAt): self
  801.     {
  802.         $this->startDeliveryAt $startDeliveryAt;
  803.         return $this;
  804.     }
  805.     /**
  806.      * @return Collection<int, CustomerWalletPoint>
  807.      */
  808.     public function getCustomerWalletPoints(): Collection
  809.     {
  810.         return $this->customerWalletPoints;
  811.     }
  812.     public function addCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  813.     {
  814.         if (!$this->customerWalletPoints->contains($customerWalletPoint)) {
  815.             $this->customerWalletPoints[] = $customerWalletPoint;
  816.             $customerWalletPoint->setOriginOrder($this);
  817.         }
  818.         return $this;
  819.     }
  820.     public function removeCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self
  821.     {
  822.         if ($this->customerWalletPoints->removeElement($customerWalletPoint)) {
  823.             // set the owning side to null (unless already changed)
  824.             if ($customerWalletPoint->getOriginOrder() === $this) {
  825.                 $customerWalletPoint->setOriginOrder(null);
  826.             }
  827.         }
  828.         return $this;
  829.     }
  830.     public function getCoupon(): ?Coupon
  831.     {
  832.         return $this->coupon;
  833.     }
  834.     public function setCoupon(?Coupon $coupon): self
  835.     {
  836.         $this->coupon $coupon;
  837.         return $this;
  838.     }
  839.     public function getAgentToDo(): ?Agent
  840.     {
  841.         return $this->agentToDo;
  842.     }
  843.     public function setAgentToDo(?Agent $agentToDo): self
  844.     {
  845.         $this->agentToDo $agentToDo;
  846.         return $this;
  847.     }
  848.     public function getIsToDo(): ?bool
  849.     {
  850.         return $this->isToDo;
  851.     }
  852.     public function setIsToDo(?bool $isToDo): self
  853.     {
  854.         $this->isToDo $isToDo;
  855.         return $this;
  856.     }
  857.     public function getCityRegionShipping(): ?CityRegion
  858.     {
  859.         return $this->cityRegionShipping;
  860.     }
  861.     public function setCityRegionShipping(?CityRegion $cityRegionShipping): self
  862.     {
  863.         $this->cityRegionShipping $cityRegionShipping;
  864.         return $this;
  865.     }
  866.     public function getVendor(): ?Vendor
  867.     {
  868.         return $this->vendor;
  869.     }
  870.     public function setVendor(?Vendor $vendor): self
  871.     {
  872.         $this->vendor $vendor;
  873.         return $this;
  874.     }
  875.     public function getCollectAddress(): ?string
  876.     {
  877.         return $this->collectAddress;
  878.     }
  879.     public function setCollectAddress(?string $collectAddress): self
  880.     {
  881.         $this->collectAddress $collectAddress;
  882.         return $this;
  883.     }
  884.     public function getCollectTel(): ?string
  885.     {
  886.         return $this->collectTel;
  887.     }
  888.     public function setCollectTel(?string $collectTel): self
  889.     {
  890.         $this->collectTel $collectTel;
  891.         return $this;
  892.     }
  893.     public function getIsHeavy(): ?bool
  894.     {
  895.         return $this->isHeavy;
  896.     }
  897.     public function setIsHeavy(?bool $isHeavy): self
  898.     {
  899.         $this->isHeavy $isHeavy;
  900.         return $this;
  901.     }
  902.     #[Groups(['read'])]
  903.     public function getShippingTips(): ?float
  904.     {
  905.         return $this->shippingTips;
  906.     }
  907.     public function setShippingTips(?float $shippingTips): self
  908.     {
  909.         $this->shippingTips $shippingTips;
  910.         return $this;
  911.     }
  912.  
  913.     
  914.     /**
  915.      * Get the value of isChecked
  916.      */ 
  917.     public function getIsChecked()
  918.     {
  919.         return $this->isChecked;
  920.     }
  921.     /**
  922.      * Set the value of isChecked
  923.      *
  924.      * @return  self
  925.      */ 
  926.     public function setIsChecked($isChecked)
  927.     {
  928.         $this->isChecked $isChecked;
  929.         return $this;
  930.     }
  931.     /**
  932.      * Get the value of walletPaymentAmount
  933.      */ 
  934.     public function getWalletPaymentAmount()
  935.     {
  936.         return $this->walletPaymentAmount;
  937.     }
  938.     /**
  939.      * Set the value of walletPaymentAmount
  940.      *
  941.      * @return  self
  942.      */ 
  943.     public function setWalletPaymentAmount($walletPaymentAmount)
  944.     {
  945.         $this->walletPaymentAmount $walletPaymentAmount;
  946.         return $this;
  947.     }
  948.     /**
  949.      * Get the value of cityRegionCollect
  950.      */ 
  951.     public function getCityRegionCollect()
  952.     {
  953.         return $this->cityRegionCollect;
  954.     }
  955.     /**
  956.      * Set the value of cityRegionCollect
  957.      *
  958.      * @return  self
  959.      */ 
  960.     public function setCityRegionCollect($cityRegionCollect)
  961.     {
  962.         $this->cityRegionCollect $cityRegionCollect;
  963.         return $this;
  964.     }
  965.     /**
  966.      * Get the value of distance
  967.      */ 
  968.     public function getDistance()
  969.     {
  970.         return $this->distance;
  971.     }
  972.     /**
  973.      * Set the value of distance
  974.      *
  975.      * @return  self
  976.      */ 
  977.     public function setDistance($distance)
  978.     {
  979.         $this->distance $distance;
  980.         return $this;
  981.     }
  982.     /**
  983.      * Get the value of tokenStripe
  984.      */ 
  985.     public function getTokenStripe()
  986.     {
  987.         return $this->tokenStripe;
  988.     }
  989.     /**
  990.      * Set the value of tokenStripe
  991.      *
  992.      * @return  self
  993.      */ 
  994.     public function setTokenStripe($tokenStripe)
  995.     {
  996.         $this->tokenStripe $tokenStripe;
  997.         return $this;
  998.     }
  999.     public function getOrderType(): ?string
  1000.     {
  1001.         return $this->orderType;
  1002.     }
  1003.     public function setOrderType(?string $orderType): self
  1004.     {
  1005.         $this->orderType $orderType;
  1006.         return $this;
  1007.     }
  1008.     /**
  1009.      * Get the value of deletedAt
  1010.      */ 
  1011.     public function getDeletedAt()
  1012.     {
  1013.         return $this->deletedAt;
  1014.     }
  1015.     /**
  1016.      * Set the value of deletedAt
  1017.      *
  1018.      * @return  self
  1019.      */ 
  1020.     public function setDeletedAt($deletedAt)
  1021.     {
  1022.         $this->deletedAt $deletedAt;
  1023.         return $this;
  1024.     }
  1025.     public function getStore(): ?Store
  1026.     {
  1027.         return $this->store;
  1028.     }
  1029.     public function setStore(?Store $store): self
  1030.     {
  1031.         $this->store $store;
  1032.         return $this;
  1033.     }
  1034.     public function getShipment(): ?Shipment
  1035.     {
  1036.         return $this->shipment;
  1037.     }
  1038.     public function setShipment(?Shipment $shipment): self
  1039.     {
  1040.         $this->shipment $shipment;
  1041.         return $this;
  1042.     }
  1043.     public function getInvoice(): ?Invoice
  1044.     {
  1045.         return $this->invoice;
  1046.     }
  1047.     public function setInvoice(?Invoice $invoice): self
  1048.     {
  1049.         $this->invoice $invoice;
  1050.         return $this;
  1051.     }
  1052.     /**
  1053.      * Get the value of shippingAddress
  1054.      */ 
  1055.     public function getShippingAddress()
  1056.     {
  1057.         return $this->shippingAddress;
  1058.     }
  1059.     /**
  1060.      * Set the value of shippingAddress
  1061.      *
  1062.      * @return  self
  1063.      */ 
  1064.     public function setShippingAddress($shippingAddress)
  1065.     {
  1066.         $this->shippingAddress $shippingAddress;
  1067.         return $this;
  1068.     }
  1069.     public function getCreatedBy()
  1070.     {
  1071.         return $this->createdBy;
  1072.     }
  1073.     public function getDescription(): ?string
  1074.     {
  1075.         return $this->description;
  1076.     }
  1077.     public function setDescription(?string $description): self
  1078.     {
  1079.         $this->description $description;
  1080.         return $this;
  1081.     }
  1082.     #[Groups(['read'])]
  1083.     public function getStartProcessingAtText()
  1084.     {
  1085.         $value null;
  1086.         if($this->startDeliveryAt and $this->getShippingMethod()){
  1087.             $intervalDate = clone $this->startProcessingAt;
  1088.         $intervalInMinutes $this->shippingMethod->getShippingDuration() * 60;
  1089.         $intervalDate->modify(" + ".$intervalInMinutes." minutes");
  1090.         
  1091.         $value $this->startProcessingAt->format("d/m/Y H:i") ." - ".$intervalDate->format("H:i");
  1092.         }
  1093.         
  1094.         
  1095.         return $value;
  1096.         
  1097.     }
  1098.     
  1099.     #[Groups(['read'])]
  1100.     public function getCreatedAtText()
  1101.     {
  1102.         $value null;
  1103.         if($this->createdAt){
  1104.            
  1105.         
  1106.             $value $this->createdAt->format("d/m/Y H:i");
  1107.         }
  1108.         
  1109.         
  1110.         return $value;
  1111.     }
  1112.     
  1113.     #[Groups(['read'])]
  1114.     public function getStartDeliveryAtText()
  1115.     {
  1116.         
  1117.         $value null;
  1118.         if($this->startDeliveryAt and $this->getShippingMethod()){
  1119.             $intervalDate = clone $this->startDeliveryAt;
  1120.             $intervalInMinutes $this->shippingMethod->getShippingDuration() * 60;
  1121.             $intervalDate->modify(" + ".$intervalInMinutes." minutes");
  1122.             $value $this->startDeliveryAt->format("d/m/Y H:i") ." - ".$intervalDate->format("H:i");
  1123.         }
  1124.         
  1125.         
  1126.         return $value;
  1127.     }
  1128.     #[Groups(['read'])]
  1129.     public function getShippingMethodText()
  1130.     {
  1131.         $value null
  1132.         if($this->shippingMethod){
  1133.             $value $this->shippingMethod->getName();
  1134.         }
  1135.         return $value;
  1136.         
  1137.     }
  1138.     #[Groups(['read'])]
  1139.     public function getPaymentMethodText()
  1140.     {   
  1141.         $value null
  1142.         if($this->paymentMethod){
  1143.             $value $this->paymentMethod->getName();
  1144.         }
  1145.         return $value;
  1146.     }
  1147.     
  1148.     
  1149.         #[Groups(['read'])]
  1150.     public function getStatusText()
  1151.     {
  1152.         //$translated = $this->translator->trans($this->getSatus());
  1153.         
  1154.         
  1155.         $translatedStatusArray = [
  1156.                 "paid"=>"Réglé",
  1157.                 "canceled"=>"annulé",
  1158.                 "waiting"=>"Non réglé",
  1159.                 "partially-paid"=>"Réglé partiellement",
  1160.             ];
  1161.             
  1162.         if(array_key_exists($this->getStatus(),$translatedStatusArray)){
  1163.             return $translatedStatusArray[$this->getStatus()];
  1164.         }
  1165.         
  1166.         return  "Non réglé";
  1167.         
  1168.     }
  1169.     
  1170.     
  1171.     
  1172.     #[Groups(['read'])]
  1173.     public function getTotalProducts()
  1174.     {   
  1175.         $value 0
  1176.         foreach($this->getOrderItems() as $singleOrderItem){
  1177.             $defaultQuantityProduct 1;
  1178.             
  1179.             if($singleOrderItem->getProduct()){
  1180.                 if($singleOrderItem->getProduct()->getDefaultQuantity() > 0){
  1181.                     $defaultQuantityProduct $singleOrderItem->getProduct()->getDefaultQuantity();
  1182.                 }
  1183.             }
  1184.             
  1185.             
  1186.                 $value $value + ($singleOrderItem->getQuantity() * $defaultQuantityProduct );
  1187.             
  1188.             
  1189.         }
  1190.         
  1191.         return $value;
  1192.     }
  1193.     public function getProductSubscription(): ?ProductSubscription
  1194.     {
  1195.         return $this->productSubscription;
  1196.     }
  1197.     public function setProductSubscription(?ProductSubscription $productSubscription): self
  1198.     {
  1199.         // unset the owning side of the relation if necessary
  1200.         if ($productSubscription === null && $this->productSubscription !== null) {
  1201.             $this->productSubscription->setRelatedOrder(null);
  1202.         }
  1203.         // set the owning side of the relation if necessary
  1204.         if ($productSubscription !== null && $productSubscription->getRelatedOrder() !== $this) {
  1205.             $productSubscription->setRelatedOrder($this);
  1206.         }
  1207.         $this->productSubscription $productSubscription;
  1208.         return $this;
  1209.     }
  1210.     /**
  1211.      * Get the value of statusShipping
  1212.      */ 
  1213.     public function getStatusShipping()
  1214.     {
  1215.         return $this->statusShipping;
  1216.     }
  1217.     /**
  1218.      * Set the value of statusShipping
  1219.      *
  1220.      * @return  self
  1221.      */ 
  1222.     public function setStatusShipping($statusShipping)
  1223.     {
  1224.         $this->statusShipping $statusShipping;
  1225.         return $this;
  1226.     }
  1227.     
  1228.     public function getCollectLng()
  1229.     {
  1230.         return $this->collectLng;
  1231.     }
  1232.     public function getCollectLat()
  1233.     {
  1234.         return $this->collectLat;
  1235.     }
  1236.     
  1237.     public function setCollectLng($collectLng)
  1238.     {
  1239.         $this->collectLng $collectLng;
  1240.         return $this;
  1241.     }
  1242.     
  1243.         public function setCollectLat($collectLat)
  1244.     {
  1245.         $this->collectLat $collectLat;
  1246.         return $this;
  1247.     }
  1248.     
  1249.     
  1250.     
  1251.         public function getShippingLng()
  1252.     {
  1253.         return $this->shippingLng;
  1254.     }
  1255.     public function getShippingLat()
  1256.     {
  1257.         return $this->shippingLat;
  1258.     }
  1259.     
  1260.     public function setShippingLng($shippingLng)
  1261.     {
  1262.         $this->shippingLng $shippingLng;
  1263.         return $this;
  1264.     }
  1265.     
  1266.         public function setShippingLat($shippingLat)
  1267.     {
  1268.         $this->shippingLat $shippingLat;
  1269.         return $this;
  1270.     }
  1271.         public function getMetaData(): ?array
  1272.         {
  1273.             return $this->metaData;
  1274.         }
  1275.         public function setMetaData(?array $metaData): static
  1276.         {
  1277.             $this->metaData $metaData;
  1278.             return $this;
  1279.         }
  1280.         public function getDefaultCurrency(): ?string
  1281.         {
  1282.             return $this->defaultCurrency;
  1283.         }
  1284.         public function setDefaultCurrency(?string $defaultCurrency): static
  1285.         {
  1286.             $this->defaultCurrency $defaultCurrency;
  1287.             return $this;
  1288.         }
  1289.         public function getExtraShippingFees(): ?float
  1290.         {
  1291.             return $this->extraShippingFees;
  1292.         }
  1293.         public function setExtraShippingFees(?float $extraShippingFees): static
  1294.         {
  1295.             $this->extraShippingFees $extraShippingFees;
  1296.             return $this;
  1297.         }
  1298.         public function getExtraShippingMethodName(): ?string
  1299.         {
  1300.             return $this->extraShippingMethodName;
  1301.         }
  1302.         public function setExtraShippingMethodName(?string $extraShippingMethodName): static
  1303.         {
  1304.             $this->extraShippingMethodName $extraShippingMethodName;
  1305.             return $this;
  1306.         }
  1307.         public function getExtraShippingInfos(): ?string
  1308.         {
  1309.             return $this->extraShippingInfos;
  1310.         }
  1311.         public function setExtraShippingInfos(?string $extraShippingInfos): static
  1312.         {
  1313.             $this->extraShippingInfos $extraShippingInfos;
  1314.             return $this;
  1315.         }
  1316.     
  1317.     public function getShippingMonth(){
  1318.         $result "";
  1319.         if($this->getStartDeliveryAt()){
  1320.             $result $this->getStartDeliveryAt()->format('M');
  1321.         }
  1322.         return $result;
  1323.     }
  1324.     public function getNotifyCustomer(): ?bool
  1325.     {
  1326.         return $this->notifyCustomer;
  1327.     }
  1328.     public function setNotifyCustomer(?bool $notifyCustomer): static
  1329.     {
  1330.         $this->notifyCustomer $notifyCustomer;
  1331.         return $this;
  1332.     }
  1333.     public function getUpdateNotificationMessage(): ?string
  1334.     {
  1335.         return $this->updateNotificationMessage;
  1336.     }
  1337.     public function setUpdateNotificationMessage(?string $updateNotificationMessage): static
  1338.     {
  1339.         $this->updateNotificationMessage $updateNotificationMessage;
  1340.         return $this;
  1341.     }
  1342.     
  1343. }