src/Flexy/ShopBundle/Entity/Order/Order.php line 44

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