src/Controller/OrderController.php line 103

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Controller;
  12. use App\Entity\Order\Order;
  13. use App\Service\SynapsService;
  14. use FOS\RestBundle\View\View;
  15. use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
  16. use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
  17. use Sylius\Component\Order\Context\CartContextInterface;
  18. use Sylius\Component\Order\Model\OrderInterface;
  19. use Sylius\Component\Order\Repository\OrderRepositoryInterface;
  20. use Sylius\Component\Order\SyliusCartEvents;
  21. use Sylius\Component\Resource\ResourceActions;
  22. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  23. use Symfony\Component\EventDispatcher\GenericEvent;
  24. use Symfony\Component\Finder\Finder;
  25. use Symfony\Component\Finder\SplFileInfo;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\HttpKernel\Exception\HttpException;
  29. use App\Repository\GiftcardRepository;
  30. use App\Entity\Giftcard;
  31. use Sylius\Bundle\OrderBundle\Controller\OrderController as OrderControllerBase;
  32. use Sylius\Component\Channel\Context\ChannelContextInterface;
  33. use Sylius\Component\Core\Model\ChannelInterface;
  34. use Sylius\Component\Locale\Context\LocaleContextInterface;
  35. use Spipu\Html2Pdf\Html2Pdf;
  36. use Spipu\Html2Pdf\Exception\Html2PdfException;
  37. use Spipu\Html2Pdf\Exception\ExceptionFormatter;
  38. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  39. use Twig\Environment;
  40. use App\Service\FideliumService;
  41. use Sylius\Component\Core\Model\AdjustmentInterface;
  42. class OrderController extends OrderControllerBase
  43. {
  44.     public function summaryAction(Request $request): Response
  45.     {
  46.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  47.         $cart $this->getCurrentCart();
  48.         //$cart->getTotalWithOutAdjustments ();
  49.         //$adj = $cart->getFideliumAdjustments();
  50.         if (null !== $cart->getId()) {
  51.             $cart $this->getOrderRepository()->findCartById($cart->getId());
  52.         }
  53.         if (!$configuration->isHtmlRequest()) {
  54.             return $this->viewHandler->handle($configurationView::create($cart));
  55.         }
  56.         $fideliumCard false;
  57.         $listBoxFidelium false;
  58.         $orderpoints "";
  59.         $customer $cart->getCustomer();
  60.         if (isset($customer) && !empty($customer->getFideliumcard()))
  61.         {
  62.             $orderpoints $cart->getFideliumpoints();
  63.             $cardnumber $customer->getFideliumcard();
  64.             $fs = new FideliumService ($cardnumber);
  65.             $fideliumCard $fs->getInfosCard();
  66.             $listBoxFidelium $fs->getListBoxFidelium ();
  67.         }
  68.         if (isset($customer))
  69.             $is_logged_in true;
  70.         else
  71.             $is_logged_in false;
  72.         $form $this->resourceFormFactory->create($configuration$cart);
  73.         return $this->render(
  74.             $configuration->getTemplate('summary.html'),
  75.             [
  76.                 'is_logged_in' => $is_logged_in,
  77.                 'customer' => $customer,
  78.                 'fideliumCard' => $fideliumCard,
  79.                 'listBoxFidelium' => $listBoxFidelium,
  80.                 'orderpoint' => $orderpoints,
  81.                 'cart' => $cart,
  82.                 'form' => $form->createView(),
  83.             ]
  84.         );
  85.     }
  86.     public function widgetAction(Request $request): Response
  87.     {
  88.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  89.         $cart $this->getCurrentCart();
  90.         $fideliumCard false;
  91.         $listBoxFidelium false;
  92.         $orderpoints "";
  93.         $customer $cart->getCustomer();
  94.         if (isset($customer) && !empty($customer->getFideliumcard()))
  95.         {
  96.             $orderpoints $cart->getFideliumpoints();
  97.             $cardnumber $customer->getFideliumcard();
  98.             $fs = new FideliumService ($cardnumber);
  99.             $fideliumCard $fs->getInfosCard();
  100.             $listBoxFidelium $fs->getListBoxFidelium ();
  101.         }
  102.         if (isset($customer) && !empty($customer->getFideliumcard()))
  103.         {
  104.             $orderpoints $cart->getFideliumpoints();
  105.             $cardnumber $customer->getFideliumcard();
  106.             $fs = new FideliumService ($cardnumber);
  107.             $fideliumCard $fs->getInfosCard();
  108.             $listBoxFidelium $fs->getListBoxFidelium ();
  109.         }
  110.         if (!$configuration->isHtmlRequest()) {
  111.             //return $this->viewHandler->handle($configuration, View::create($cart));
  112.         }
  113.         return $this->render(
  114.             $configuration->getTemplate('summary.html'),
  115.             [
  116.                 'fideliumCard' => $fideliumCard,
  117.                 'listBoxFidelium' => $listBoxFidelium,
  118.                 'orderpoint' => $orderpoints,
  119.                 'cart' => $cart,
  120.             ]
  121.         );
  122.     }
  123.     public function saveAction(Request $request): Response
  124.     {
  125.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  126.         $this->isGrantedOr403($configurationResourceActions::UPDATE);
  127.         $resource $this->getCurrentCart();
  128.         $form $this->resourceFormFactory->create($configuration$resource);
  129.         //TODO
  130.         /*
  131.         foreach ($resource->getAdjustments(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT) as $adjustment) {
  132.             if ($adjustment->getLabel() == "Fidelium") {
  133.                 $resource->removeAdjustment($adjustment);
  134.             }
  135.         } */
  136.         if ($resource->hasGiftCards()) {
  137.          }
  138.          if ( $request->get("fideliumupdate") != "")
  139.          {
  140.             $fideliumpoints $request->get("fidelium");
  141.             if (is_numeric($fideliumpoints))
  142.             {
  143.                 $customer $resource->getCustomer();
  144.                 $cardnumber $customer->getFideliumcard();
  145.                 $fs = new FideliumService ($cardnumber);
  146.                 if ($fs->IsValidePoints ($fideliumpoints))
  147.                 {
  148.                     $resource->setFideliumpoints((int)$fideliumpoints);
  149.                 }
  150.                 else
  151.                     $resource->setFideliumpoints(0);
  152.             }
  153.             else
  154.                 $resource->setFideliumpoints(0);
  155.          }
  156.         if ( array_key_exists("promotionCoupon"$request->get("sylius_cart") ))
  157.         {
  158.             $promotioncode $request->get("sylius_cart")["promotionCoupon"];
  159.             if ($promotioncode != "")
  160.             {
  161.                 $giftCardRepository $this->getDoctrine()->getRepository(Giftcard::class);
  162.                 $giftCard $giftCardRepository->findOneByCode($promotioncode);
  163.                 //$giftCard = $giftCardRepository->findOneByCode("9E4BEDC2F78E2BAC");
  164.                 if ($giftCard)
  165.                 {
  166.                     $resource->addGiftCard($giftCard);
  167.                     $this->manager->persist($giftCard);
  168.                     $this->manager->flush();
  169.                 }
  170.             }
  171.         }
  172.         if (in_array($request->getMethod(), ['POST''PUT''PATCH'], true) && $form->handleRequest($request)->isValid()) {
  173.             $resource $form->getData();
  174.             $event $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE$configuration$resource);
  175.             if ($event->isStopped() && !$configuration->isHtmlRequest()) {
  176.                 throw new HttpException($event->getErrorCode(), $event->getMessage());
  177.             }
  178.             if ($event->isStopped()) {
  179.                 $this->flashHelper->addFlashFromEvent($configuration$event);
  180.                 return $this->redirectHandler->redirectToResource($configuration$resource);
  181.             }
  182.             if ($configuration->hasStateMachine()) {
  183.                 $this->stateMachine->apply($configuration$resource);
  184.             }
  185.             $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE$configuration$resource);
  186.             $this->getEventDispatcher()->dispatch(new GenericEvent($resource), SyliusCartEvents::CART_CHANGE);
  187.             $this->manager->flush();
  188.             if (!$configuration->isHtmlRequest()) {
  189.                 return $this->viewHandler->handle($configurationView::create(nullResponse::HTTP_NO_CONTENT));
  190.             }
  191.             $this->flashHelper->addSuccessFlash($configurationResourceActions::UPDATE$resource);
  192.             return $this->redirectHandler->redirectToResource($configuration$resource);
  193.         }
  194.         if (!$configuration->isHtmlRequest()) {
  195.             return $this->viewHandler->handle($configurationView::create($formResponse::HTTP_BAD_REQUEST));
  196.         }
  197.         return $this->render(
  198.             $configuration->getTemplate(ResourceActions::UPDATE '.html'),
  199.             [
  200.                 'configuration' => $configuration,
  201.                 $this->metadata->getName() => $resource,
  202.                 'form' => $form->createView(),
  203.                 'cart' => $resource,
  204.             ]
  205.         );
  206.     }
  207.     /*public function clearAction(Request $request): Response
  208.     {
  209.         $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
  210.         $this->isGrantedOr403($configuration, ResourceActions::DELETE);
  211.         $resource = $this->getCurrentCart();
  212.         if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid((string) $resource->getId(), $request->get('_csrf_token'))) {
  213.             throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.');
  214.         }
  215.         $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource);
  216.         if ($event->isStopped() && !$configuration->isHtmlRequest()) {
  217.             throw new HttpException($event->getErrorCode(), $event->getMessage());
  218.         }
  219.         if ($event->isStopped()) {
  220.             $this->flashHelper->addFlashFromEvent($configuration, $event);
  221.             return $this->redirectHandler->redirectToIndex($configuration, $resource);
  222.         }
  223.         $this->repository->remove($resource);
  224.         $this->eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource);
  225.         if (!$configuration->isHtmlRequest()) {
  226.             return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
  227.         }
  228.         $this->flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource);
  229.         return $this->redirectHandler->redirectToIndex($configuration, $resource);
  230.     }
  231.     protected function redirectToCartSummary(RequestConfiguration $configuration): Response
  232.     {
  233.         if (null === $configuration->getParameters()->get('redirect')) {
  234.             return $this->redirectHandler->redirectToRoute($configuration, $this->getCartSummaryRoute());
  235.         }
  236.         return $this->redirectHandler->redirectToRoute($configuration, $configuration->getParameters()->get('redirect'));
  237.     }
  238.     protected function getCartSummaryRoute(): string
  239.     {
  240.         return 'sylius_cart_summary';
  241.     }
  242.     protected function getCurrentCart(): OrderInterface
  243.     {
  244.         return $this->getContext()->getCart();
  245.     }
  246.     protected function getContext(): CartContextInterface
  247.     {
  248.         return $this->get('sylius.context.cart');
  249.     }
  250.     protected function getOrderRepository(): OrderRepositoryInterface
  251.     {
  252.         return $this->get('sylius.repository.order');
  253.     }
  254.     protected function getEventDispatcher(): EventDispatcherInterface
  255.     {
  256.         return $this->container->get('event_dispatcher');
  257.     }*/
  258.     public function thankYouAction(Request $request): Response
  259.     {
  260.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  261.         $orderId $request->getSession()->get('sylius_order_id'null);
  262.         if (null === $orderId) {
  263.             $options $configuration->getParameters()->get('after_failure');
  264.             return $this->redirectHandler->redirectToRoute(
  265.                 $configuration,
  266.                 $options['route'] ?? 'sylius_shop_homepage',
  267.                 $options['parameters'] ?? []
  268.             );
  269.         }
  270.         $request->getSession()->remove('sylius_order_id');
  271.         $order $this->repository->find($orderId);
  272.         //Assert::notNull($order);
  273.         return $this->render(
  274.             $configuration->getParameters()->get('template'),
  275.             [
  276.                 'order' => $order,
  277.             ]
  278.         );
  279.     }
  280.     private function totalWeight($order)
  281.     {
  282.         $totawweights 0;
  283.         foreach ($order->GetItems() as $item){
  284.             $weight $item->getVariant()->getWeight();
  285.             if (isset($weight) && !empty($weight)  && is_numeric($weight) )
  286.                 $totawweights =  $totawweights + ($weight $item->getQuantity());
  287.         }
  288.         if ($totawweights !=0)
  289.             $totawweights $totawweights;
  290.         return  $totawweights;
  291.     }
  292.     public function getExpeditionDate ($date)
  293.     {
  294.         $wdate = clone $date;
  295.         //Date de commande
  296.         $days =  (int)$date->format('w');
  297.         if ($days == 1$dateenvoie $wdate->add(new \DateInterval('P1D'));  // +1 lundi --> mardi
  298.         elseif ($days == 2$dateenvoie $wdate->add(new \DateInterval('P2D'));  // +2 mardi --> jeudi
  299.         elseif ($days == 3$dateenvoie $wdate->add(new \DateInterval('P1D'));  // +1 mercredi --> jeudi
  300.         elseif ($days == 4$dateenvoie $wdate->add(new \DateInterval('P5D'));  // +5 jeudi --> mardi
  301.         elseif ($days == 5$dateenvoie $wdate->add(new \DateInterval('P4D'));  // +4 vendredi --> mardi
  302.         elseif ($days == 6$dateenvoie $wdate->add(new \DateInterval('P3D'));   // +3 samedi --> mardi
  303.         elseif ($days == 7$dateenvoie $wdate->add(new \DateInterval('P2D'));   // +2 dimanche --> mardi
  304.         return $dateenvoie->format('d-m-Y');
  305.     }
  306.     //Calcul :
  307.     //Si date de la commande = lundi, mardi ou mercredi avant midi alors date = vendredi suivant.
  308.     //Si date de commande = mercredi après 12h00 (midi), jeudi, vendredi, samedi ou dimanche alors date = mercredi suivant.
  309.     public function getExpeditionDate2 ($date)
  310.     {
  311.         $wdate = clone $date;
  312.         //Date de commande
  313.         $days =  (int)$date->format('w');
  314.         $hour =  (int)$date->format('H');
  315.         if ($days == 1$dateenvoie $wdate->add(new \DateInterval('P4D'));  // +4 lundi --> vendredi
  316.         elseif ($days == 2$dateenvoie $wdate->add(new \DateInterval('P3D'));  // +3 mardi --> vendredi
  317.         elseif ($days == and $hour 12$dateenvoie $wdate->add(new \DateInterval('P2D'));  // +3 mercredi --> vendredi
  318.         elseif ($days == 3$dateenvoie $wdate->add(new \DateInterval('P7D'));  // +7 mercredi --> mercredi
  319.         elseif ($days == 4$dateenvoie $wdate->add(new \DateInterval('P6D'));  // +6 jeudi --> mercredi
  320.         elseif ($days == 5$dateenvoie $wdate->add(new \DateInterval('P5D'));  // +5 vendredi --> mercredi
  321.         elseif ($days == 6$dateenvoie $wdate->add(new \DateInterval('P4D'));   // +4 samedi --> mercredi
  322.         elseif ($days == 7$dateenvoie $wdate->add(new \DateInterval('P3D'));   // +3 dimanche --> mercredi
  323.         return $dateenvoie->format('d-m-Y');
  324.     }
  325.     public function ordersExport (Request $request =null)
  326.     {
  327.         $criteria $request->get('criteria');
  328.         $orderRepository $this->getOrderRepository();
  329.         $orders $orderRepository->exportOrderPaid ($criteria);
  330.         $elem = array();
  331.         $lines = array();
  332.         $separator ";";
  333.         foreach ($orders as $order){
  334.             $lastShipment $order->getShipments()->last();
  335.             $shippingmethod $lastShipment->getMethod()->getCode();
  336.             $shippingmethodname $lastShipment->getMethod()->getName();
  337.             $boutique "";
  338.             if ($shippingmethod == "collect")
  339.             {
  340.                 $boutique $lastShipment->getBoutiqueId();
  341.             }
  342.             $shippingAddresse $order->getShippingAddress();
  343.             $customer $order->getCustomer();
  344.             $email $customer->getEmail();
  345.             $cie $shippingAddresse->getCompany();
  346.             if (isset($cie) && !empty($cie))
  347.                 $shippingName $shippingAddresse->getCompany();  //Société destinataire
  348.             else
  349.                 $shippingName $shippingAddresse->getLastName() . " " $shippingAddresse->getFirstName() ;  //Société destinataire
  350.             $shippingPhone $customer->getPhoneNumber();
  351.             $customerPhone $shippingAddresse->getPhoneNumber();
  352.             if (isset($shippingPhone) && !empty($shippingPhone))
  353.                 $phoneNumber $shippingPhone;
  354.             elseif (isset($customerPhone) && !empty($customerPhone))
  355.                 $phoneNumber $customerPhone;
  356.             $date $order->getCheckoutCompletedAt();
  357.             $total_livraison $order->getAdjustmentsTotalRecursively(AdjustmentInterface::SHIPPING_ADJUSTMENT);
  358.             $total_remise $order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT);
  359.             foreach ($order->getAdjustmentsRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT) as $adjustment)
  360.             {
  361.             }
  362.             foreach ( $order->getItems() as $item)
  363.             {
  364.                 $variant $item->getVariant();
  365.                 $elem = array();
  366.                 $elem["Numero de la commande"] = $order->getNumber();
  367.                 $elem["Date de la commande"] = $order->getCheckoutCompletedAt()->format('d-m-Y H:i');
  368.                 //Date de départ des caves
  369.                 if ($shippingmethod == "chronofresh")
  370.                     $departcave $this->getExpeditionDate2 ($date);
  371.                 else
  372.                     $departcave "";
  373.                 $elem["Date de depart des caves"] = $departcave;
  374.                 $elem["Article CODE"] = $variant->getCode();
  375.                 //$elem["Nom du produit"] = $item->getVariantName();
  376.                 $elem["Nom du produit"] = $item->getProductName();
  377.                 $shortname $variant->getShortname();
  378.                 if (isset($shortname) && $shortname != "")
  379.                     $elem["Conditionnement"] = $variant->getShortname();
  380.                 else
  381.                     $elem["Conditionnement"] = $variant->getName();
  382.                 $elem["Quantite commandee"] = $item->getQuantity();
  383.                 //$taxs  = $item->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT);
  384.                 $tva 0;
  385.                 foreach ( $item->getUnits() as $unit)
  386.                 {
  387.                     $taxes $unit->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
  388.                     foreach ( $taxes as $tax)
  389.                     {
  390.                         $tva $tva $tax->getAmount();
  391.                     }
  392.                 }
  393.                 $elem["Montant HT"] = $this->formatMoney ($item->getTotal() - $tva);
  394.                 $elem["Montant TVA"] = $this->formatMoney ($tva);
  395.                 $elem["Montant TTC"] = $this->formatMoney ($item->getTotal());
  396.                 //$elem["Total livraison"] = $this->formatMoney ($total_livraison);
  397.                 //$elem["Total remise"] = $this->formatMoney ($total_remise);
  398.                 if ($order->getState() == "cancelled")
  399.                     $elem["Statut"] = $order->getState();
  400.                 else
  401.                     $elem["Statut"] = "";
  402.                 $elem["Expedition"] = $shippingmethodname;
  403.                 $elem["boutique"] = $boutique;
  404.                 $elem["client"] = $email;
  405.                 $elem["numero_facture"] = $order->getInvoiceNumber();
  406.                 $elem["Dateretrait"] = $lastShipment->getDateretrait();
  407.                 $elem["Heureretrait"] = $lastShipment->getHeureretrait();
  408.                 $lines[] = implode($separator$elem);
  409.             }
  410.         }
  411.         $header implode($separatorarray_keys ($elem));
  412.         $filename "commande-"date('dmyHm') . ".csv";
  413.         $content $header "\r\n"implode("\r\n"$lines);
  414.         $response = new Response($contentResponse::HTTP_OK, ['Content-Type' => 'text/csv']);
  415.         $response->setPublic();
  416.         $response->setMaxAge(0);
  417.         $response->headers->add([
  418.             'Content-Disposition' => $response->headers->makeDisposition('attachment'$filename),
  419.         ]);
  420.         return $response;
  421.     }
  422.     public function formatMoney ($value)
  423.     {
  424.         if (isset($value))
  425.         {
  426.             $value $value 100;
  427.             return number_format($value2","" ");
  428.         }
  429.     }
  430.     public function chronofreshExport ()
  431.     {
  432.         $orderRepository $this->getOrderRepository();
  433.         $orders $orderRepository->exportForChronoFresh ();
  434.         $lines = array();
  435.         $separator ";";
  436.         //Société destinataire Ou NOM et PRENOM
  437.         foreach ($orders as $order){
  438.             $lastShipment $order->getShipments()->last();
  439.             $method $lastShipment->getMethod()->getCode();
  440.             if ($method != "chronofresh")
  441.                 $continue;
  442.             $shippingAddresse $order->getShippingAddress();
  443.             $customer $order->getCustomer();
  444.             $email $customer->getEmail();
  445.             $cie $shippingAddresse->getCompany();
  446.             if (isset($cie) && !empty($cie))
  447.                 $shippingName $shippingAddresse->getCompany();  //Société destinataire
  448.             else
  449.                 $shippingName $shippingAddresse->getLastName() . " " $shippingAddresse->getFirstName() ;  //Société destinataire
  450.             $shippingPhone $customer->getPhoneNumber();
  451.             $customerPhone $shippingAddresse->getPhoneNumber();
  452.             if (isset($shippingPhone) && !empty($shippingPhone))
  453.                 $phoneNumber $shippingPhone;
  454.             elseif (isset($customerPhone) && !empty($customerPhone))
  455.                 $phoneNumber $customerPhone;
  456.             #    - indiquer "2R" dans la colonne "Produit" (col O) à la place de Food.
  457.             #    - indiquer une DLC (col DLC ou AG) avec minimum égale à la date d'envoi + 5 jours
  458.             #    Je vous conseille également de figer les champs "Compte" (col P) et "Sous-compte" (col Q) que vous pouvez laisser vider si le client n'utilise pas de sous compte spécifique.
  459.             $Date date('Y-m-d');
  460.             $dlc date('d/m/y'strtotime($Date' + 14 days'));
  461.             $elem[0] = $customer->getId();  //Référence destinataire
  462.             $elem[1] = $shippingName;  //Société destinataire
  463.             $elem[2] = $shippingAddresse->getLastName();  //Nom destinataire
  464.             $elem[3] = $shippingAddresse->getFirstName();  //Prénom destinataire
  465.             $elem[4] = $shippingAddresse->getStreet();  //Adresse destinataire
  466.             $elem[5] = "";  //Adresse 2 destinataire
  467.             $elem[6] = "";  //Code porte destinataire
  468.             $elem[7] =  $shippingAddresse->getPostcode();  //Code postal destinataire
  469.             $elem[8] = $shippingAddresse->getCity(); //Ville destinataire
  470.             $elem[9] = $shippingAddresse->getCountryCode();  //Code pays destinataire  Code pays ISO, si vide FR
  471.             $elem[10] = $phoneNumber;  //Téléphone destinataire
  472.             $elem[11] = $email;  //E-Mail destinataire
  473.             $elem[12] = $order->getNumber();  //Référence 1
  474.             $elem[13] = "";  //Code barre client
  475.             $elem[14] = "2R";  //Produit
  476.             $elem[15] = "16217950";  //Numéro de compte
  477.             $elem[16] = "001";  //Numéro de sous compte
  478.             $elem[17] = "";  //Assurance
  479.             $elem[18] = "";  //Valeur en douane
  480.             $elem[19] = "M";  //Type de colis
  481.             $elem[20] = "";  //Description
  482.             $elem[21] = "";  //Livraison Samedi
  483.             $elem[22] = "";  //ID Chrono Relais  Obligatoire si Produit Chrono Relais
  484.             $elem[23] =  $this->totalWeight($order);  //Poids
  485.             $elem[24] = "";  //Largeur
  486.             $elem[25] = "";  //Longueur
  487.             $elem[26] = "";  //Hauteur
  488.             $elem[27] = "O";  //Alerter destinataire
  489.             $elem[28] = "1";  //Nombre de colis
  490.             $date $order->getCheckoutCompletedAt();
  491.             $dateenvoie $this->getExpeditionDate ($date);
  492.             $elem[29] = $dateenvoie;  // vide autorisé //Date d’envoi
  493.             $elem[30] = "";  //Inutilisé
  494.             $elem[31] = "";  //Alerter expéditeur
  495.             $elem[32] = $dlc"JJ/MM/AAAA";  //DLC  // Obligatoire si Produit FOOD
  496.             $elem[33] = "";  //Début du créneau  Voir avec votre contact informatique Chronopost  JJMMAAHHmm
  497.             $elem[34] = "";  //Fin du créneau Voir avec votre contact informatique Chronopost   JJMMAAHHmm
  498.             $elem[35] = "";  //Niveau tarifaire Voir avec votre contact informatique Chronopost
  499.             $elem[36] = "";  //Code service Voir avec votre contact informatique Chronopost
  500.             $lines[] = implode($separator$elem);
  501.         }
  502.         $filename "chronofresh-"date('dmyHm') . ".csv";
  503.         $content implode("\r\n"$lines);
  504.         $response = new Response($contentResponse::HTTP_OK, ['Content-Type' => 'text/csv']);
  505.         $response->setPublic();
  506.         $response->setMaxAge(0);
  507.         $response->headers->add([
  508.             'Content-Disposition' => $response->headers->makeDisposition('attachment'$filename),
  509.         ]);
  510.         return $response;
  511.     }
  512.     public function CancelAction (Request $requeststring $idSenderInterface $emailSender)
  513.     {
  514.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  515.         $order $this->getOrderRepository()->findOneById($id);
  516.         //Email pour l'admin
  517.         $emailSender->send(
  518.             'nouvelle_commande',
  519.              $emailsAdmin,
  520.              ['order' => $order'boutique' => $boutique'channel' => $channel'shopillingData' => $shopillingData'localeCode' => $localeCode],
  521.         );
  522.         return $this->redirectHandler->redirectToRoute(
  523.             $configuration,
  524.             $options['route'] ?? 'sylius_shop_homepage',
  525.             $options['parameters'] ?? []
  526.         );
  527.         return $this->redirectToRoute('app_admin_boutique', [], 301);
  528.     }
  529.     public function CloseAction (Request $requeststring $id)
  530.     {
  531.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  532.         $order $this->getOrderRepository()->findOneById($id);
  533.         foreach ($order->getShipments() as $shipment) {
  534.             $stateMachine $this->stateMachineFactory->get($shipmentShipmentTransitions::GRAPH);
  535.             if ($stateMachine->can(ShipmentTransitions::TRANSITION_SHIP)) {
  536.                 $stateMachine->apply(ShipmentTransitions::TRANSITION_SHIP);
  537.             }
  538.         }
  539.         return $this->redirectToRoute('homepage', [], 301);
  540.     }
  541.     public function DownloadInvoiceAction(Request $requeststring $id): Response
  542.     {
  543.         $synaps $this->get('app.service.synaps');
  544.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  545.         /** @var Order $order */
  546.         $order $this->getOrderRepository()->find($id);
  547.         $locale $request->getLocale();
  548.         $localeCode $request->getDefaultLocale();
  549.         $channel $order->getChannel();
  550.         if ($channel->getCode() === 'Mons') {
  551.             $invoice $synaps->fetchInvoice($order);
  552.             if (!$invoice) {
  553.                 throw new NotFoundHttpException('La facture n\'est pas disponible actuellement. Veuillez réessayer plus tard.');
  554.             }
  555.             $response = new Response($invoice->getContents(), Response::HTTP_OK, ['Content-Type' => 'application/pdf']);
  556.             $response->headers->add([
  557.                 'Content-Disposition' => $response->headers->makeDisposition('attachment''Facture-'.$order->getNumber().'.pdf'),
  558.             ]);
  559.             return $response;
  560.         } else {
  561.             $footer "";
  562.             $wfooter $channel->getFooterInvoice();
  563.             if (isset($wfooter))
  564.                 $footer nl2br($wfooter);
  565.             $shippingmethods $order->getShipments();
  566.             $boutique false;
  567.             $shopillingData $channel->getShopbillingData();
  568.             foreach ($shippingmethods as $shipping) {
  569.                 $shippingmethod $shipping->getMethod()->getCode();
  570.                 if ($shippingmethod == "collect") {
  571.                     $boutique $shipping->getBoutiqueId();
  572.                 }
  573.             }
  574.             if ($boutique) {
  575.                 $wfooter $boutique->getFooterInvoice();
  576.                 if (isset($wfooter))
  577.                     $footer nl2br($wfooter);
  578.                 $emailboutique $boutique->getEmailCommande();
  579.                 if (isset($emailboutique) && !empty($emailboutique)) {
  580.                     $emailsAdmin[] = $emailboutique;
  581.                 }
  582.             }
  583.             $contents $this->render('@SyliusShop/facture.html.twig', ['order' => $order'footer' => $footer'boutique' => $boutique'shopillingData' => $shopillingData'channel' => $channel'localeCode' => $localeCode]);
  584.             $filename "MONS-" $order->getNumber() . ".pdf";
  585.             $html2pdf = new Html2Pdf('P''A4''fr'true'UTF-8', array(6666));
  586.             //$html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', array(15, 5, 15, 5));
  587.             $html2pdf->pdf->SetDisplayMode('fullpage');
  588.             $html2pdf->writeHTML($contents);
  589.             $pdfContent $html2pdf->output($filename'D');
  590.             return null;
  591.             // $response = new Response($pdfContent->content(), Response::HTTP_OK, ['Content-Type' => 'application/pdf']);
  592.             //$response->headers->add([
  593.             //    'Content-Disposition' => $response->headers->makeDisposition('attachment', $pdfContent->filename()),
  594.             //]);
  595.             //return $response;
  596.         }
  597.     }
  598. }