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

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