src/Framework/AdminBundle/Controller/ResaController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Framework\AdminBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use App\Framework\AppBundle\Entity\Venue;
  8. use App\Framework\AppBundle\Entity\Export;
  9. use App\Framework\AppBundle\Entity\Mail;
  10. use Symfony\Component\Mailer\MailerInterface;
  11. use Symfony\Component\Mime\Email;
  12. class ResaController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/resa_old", name="palace_manager_resa_old_index")
  16.      */
  17.     public function indexOldAction(Request $request)
  18.     {
  19.         $em $this->getDoctrine()->getManager();
  20.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy([], ['id' => 'DESC']);
  21.         $future strtotime('+4 day');
  22.         return $this->render('AdminBundle/Booking/index.html.twig', [
  23.             'bookings' => $bookings,
  24.             'future' => $future,
  25.         ]);
  26.     }
  27.     /**
  28.      * @Route("/resa", name="palace_manager_resa_index")
  29.      */
  30.     public function indexAction(Request $request)
  31.     {
  32.         $em $this->getDoctrine()->getManager();
  33.         $future strtotime('+4 day');
  34.         return $this->render('AdminBundle/Booking/index2.html.twig', [
  35.             'future' => $future,
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/resa/{id}", name="palace_manager_resa_edit", requirements={"id" = "([a-z\-0-9]+)"})
  40.      */
  41.     public function editAction(Request $request$id NULL)
  42.     {
  43.         $em $this->getDoctrine()->getManager();
  44.         $booking $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
  45.         $mails $em->getRepository('FrameworkAppBundle:Mail')->findBy(['booking' => $booking->getId()], ['createdAt' => 'DESC']);
  46.         $venues $em->getRepository('FrameworkAppBundle:Venue')->getNextVenues();
  47.         return $this->render('AdminBundle/Booking/edit.html.twig', [
  48.             'booking' => $booking,
  49.             'mails' => $mails,
  50.             'locale' => 'fr',
  51.             'venues' => $venues,
  52.             'iframe' => $request->get('iframe')
  53.         ]);
  54.     }
  55.     /**
  56.      * @Route("/resa/mailsingle/{id}", name="palace_manager_resa_mailsingle", requirements={"id" = "([a-z\-0-9]+)"})
  57.      */
  58.     public function mailsingleAction(Request $request$id NULLMailerInterface $mailer)
  59.     {
  60.         $em $this->getDoctrine()->getManager();
  61.         $globals $this->get("twig")->getGlobals();
  62.         $success true;
  63.         $error $slug '';
  64.         $booking $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
  65.         // ENREGISTREMENT LOG MAIL
  66.         $mail = New Mail();
  67.         $mail->setBooking($booking);
  68.         $mail->setEmailTitle($request->get('emailTitle'));
  69.         $mail->setEmailContent($request->get('emailContent'));
  70.         $em->persist($mail);
  71.         $em->flush();
  72.         // FIN ENREGISTREMENT LOG MAIL
  73.         $title $request->get('emailTitle');
  74.         $content =  str_replace("\n\r"'<br>'$request->get('emailContent'));
  75.         $content =  str_replace("\n"'<br>'$content);
  76.         //ENVOI EMAIL
  77.         $from $globals['app_email_noreply'];
  78.         $to $booking->getUser()->getEmail();
  79.         $contact $globals['app_email_contact'];
  80.         $email = (new Email())
  81.             ->from($from)
  82.             ->to($to)
  83.             //->cc('cc@example.com')
  84.             //->bcc('bcc@example.com')
  85.             ->replyTo($contact)
  86.             //->priority(Email::PRIORITY_HIGH)
  87.             ->subject($title)
  88.             // ->text($content)
  89.             ->html($this->renderView(
  90.                 'FrontBundle/Emails/general.html.twig', array(
  91.                     'title'   => $title,
  92.                     'content' => $content,
  93.                 )
  94.             ));
  95.         $mailer->send($email);
  96.         //FIN ENVOI EMAIL
  97.         $data = [
  98.             'error' => $error,
  99.             'success' => $success
  100.         ];
  101.         $response = new Response(json_encode($data));
  102.         $response->headers->set('Content-Type''application/json');
  103.         return $response;
  104.     }
  105.     /**
  106.      * @Route("/resa/mailload/{id}", name="palace_manager_resa_mailload", requirements={"id" = "([a-z\-0-9]+)"})
  107.      */
  108.     public function mailloadAction(Request $request$id NULL)
  109.     {
  110.         $em $this->getDoctrine()->getManager();
  111.         $booking $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
  112.         $mails $em->getRepository('FrameworkAppBundle:Mail')->findBy(['booking' => $booking->getId()], ['createdAt' => 'DESC']);
  113.         $mailsArr = [];
  114.         foreach ($mails as $key => $value) {
  115.             $content =  str_replace("\n\r"'<br>'$value->getEmailContent());
  116.             $content =  str_replace("\n"'<br>'$content);
  117.             $title $value->getEmailTitle();
  118.             if($title == null){
  119.                 $title '';
  120.             }
  121.             $mailsArr[] = [
  122.                 'title' => $title,
  123.                 'content' => $content,
  124.                 // 'date' => date("Y-m-d H:i", strtotime($value->getCreatedAt()->format('Y-m-d H:i').' + 2 hours')),
  125.                 'date' => date("Y-m-d H:i"strtotime($value->getCreatedAt()->format('Y-m-d H:i'))),
  126.             ];
  127.         }
  128.         $data = [
  129.             'mails' => $mailsArr
  130.         ];
  131.         $response = new Response(json_encode($data));
  132.         $response->headers->set('Content-Type''application/json');
  133.         return $response;
  134.     }
  135.     /**
  136.      * @Route("/resa/save/{id}", name="palace_manager_resa_save", requirements={"id" = "([a-z\-0-9]+)"})
  137.      */
  138.     public function saveAction(Request $request$id NULL)
  139.     {
  140.         $em $this->getDoctrine()->getManager();
  141.         $success true;
  142.         $error $slug '';
  143.         $booking $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
  144.         $booking->setOptions($request->get('options'));
  145.         $booking->setAmount(floatval(str_replace(',''.'$request->get('amount'))));
  146.         $booking->setAmountShow(floatval(str_replace(',''.'$request->get('amountShow'))));
  147.         $booking->setState(intval($request->get('state')));
  148.         $booking->setAction(NULL);
  149.         $booking->setVenueTitle($request->get('venueTitle'));
  150.         $booking->setEmailContent($request->get('emailContent'));
  151.         if( $request->get('venueId') != $booking->getVenue()->getId() ){
  152.             $venue $em->getRepository('FrameworkAppBundle:Venue')->findOneById($request->get('venueId'));
  153.             if($venue){
  154.                 $booking->setVenue($venue);
  155.             }
  156.         }
  157. //FIX EXPORT ERROR CARD -> MANUAL VALIDATION
  158.         $state intval($request->get('state'));
  159.         if( $booking->getPaymentType() == 'card' || $booking->getPaymentType() == 'klarna' || $booking->getPaymentType() == 'paypal' ){
  160.             if( $state == || $state == ){
  161.                 $booking->setStatus('succeeded');
  162.             }
  163.         }
  164. //END FIX
  165.         $booking->setAlerting(NULL);
  166.         $em->persist($booking);
  167.         $em->flush();
  168.         $data = [
  169.             'error' => $error,
  170.             'success' => $success
  171.         ];
  172.         $response = new Response(json_encode($data));
  173.         $response->headers->set('Content-Type''application/json');
  174.         return $response;
  175.     }
  176.     /**
  177.      * @Route("/export-download/{id}", name="palace_manager_export_download", requirements={"id" = "([a-z\-0-9]+)"})
  178.      */
  179.     public function exportDownloadAction(Request $request$id NULL)
  180.     {
  181.         $em $this->getDoctrine()->getManager();
  182.         $globals $this->get("twig")->getGlobals();
  183.         $export $em->getRepository('FrameworkAppBundle:Export')->findOneById($id);
  184.         header('Content-Description: File Transfer');
  185.         header('Content-Type: application/octet-stream');
  186.         header('Content-Disposition: attachment; filename="'.$export->getName().'"');
  187.         header('Content-Transfer-Encoding: binary');
  188.         header('Expires: 0');
  189.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  190.         header('Pragma: public');
  191.         header('Content-Length: ' filesize($export->getFile())); //Absolute URL
  192.         ob_clean();
  193.         flush();
  194.         readfile($export->getFile()); //Absolute URL
  195.         exit();
  196.     }
  197.     /**
  198.      * @Route("/export-download-full/{id}", name="palace_manager_export_download_full", requirements={"id" = "([a-z\-0-9]+)"})
  199.      */
  200.     public function exportDownloadFullAction(Request $request$id NULL)
  201.     {
  202.         $em $this->getDoctrine()->getManager();
  203.         $globals $this->get("twig")->getGlobals();
  204.         $export $em->getRepository('FrameworkAppBundle:Export')->findOneById($id);
  205.         $csvFile file($export->getFile());
  206.         $data $ids = [];
  207.         foreach ($csvFile as $line) {
  208.             $data[] = str_getcsv($line);
  209.         }
  210.         array_shift($data);
  211.         array_pop($data);
  212.         foreach ($data as $key => $value) {
  213.             $tmp explode(';'$value[0]);
  214.             $ids[] = $tmp[0];
  215.         }
  216.         $total $total_rs $total_am 0;
  217.         $date date('Y-m-d_H-i-s');
  218.         $rows = [];
  219.         $rows[] = [
  220.             'ID',
  221.             'Date de paiement',
  222.             // 'Type',
  223.             'Client',
  224.             'Adresse',
  225.             'Envoi',
  226.             'Commande',
  227.             'Total',
  228.             'AM',
  229.             'RS',
  230.             'Manuel'
  231.             // 'ID Stripe'
  232.         ];
  233.         foreach ($ids as $key => $id) {
  234.             $order $em->getRepository('FrameworkAppBundle:Order')->findOneByBaseId($id);
  235.             $envoi 'E-Billet';
  236.             foreach ($order->getCartArr2() as $item_key => $item) {
  237.                 if( $item['gift'] == 'true' ){
  238.                     $envoi 'Courrier';
  239.                 }
  240.             }
  241.             if($envoi == 'Courrier'){
  242.                 $client ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname'))."\n";
  243.                 if($order->getInfo('company') != ''){
  244.                     $client .= ucwords(strtolower($order->getInfo('company')))."\n";
  245.                 }
  246.                 $client .= $order->getUser()->getEmail()."\n".$order->getInfo('phone');
  247.                 $address $order->getInfo('address')."\n".$order->getInfo('zipcode').' '.$order->getInfo('city')."\n".$order->getInfo('country');
  248.                 $cart '';
  249.                 $index 1;
  250.                 foreach ($order->getCart() as $key => $item) {
  251.                     if($index 1){
  252.                         $cart .= "\n";
  253.                     }
  254.                     $cart .= $order->getBaseId().'-'.$index.' | '.$item->name->fr.' x'.$item->quantity;
  255.                     if($item->for != ''){
  256.                         $cart .= ' pour : '.$item->for;
  257.                     }
  258.                     if(isset($item->options) && $item->options != ''){
  259.                         foreach ($item->options as $key2 => $option) {
  260.                             $cart .= "\n".'+ '.$option->name.' x'.$option->qty;
  261.                         }
  262.                     }
  263.                     $index++;
  264.                 }
  265.                 $rows[] = [
  266.                     $order->getBaseId(),
  267.                     date('d/m/Y'$order->getResult()->created),
  268.                     // 'BON C.',
  269.                     $client,
  270.                     $address,
  271.                     $envoi,
  272.                     // $order->getRecap(true),
  273.                     $cart,
  274.                     ($order->getAmount() + $order->getAmountShow()),
  275.                     $order->getAmount(),
  276.                     $order->getAmountShow(),
  277.                     ($order->getManual()) ? 'M' '',
  278.                     // $order->getResult()->id
  279.                 ];
  280.                 $total $total + ($order->getAmount() + $order->getAmountShow());
  281.                 $total_am $total_am $order->getAmount();
  282.                 $total_rs $total_rs $order->getAmountShow();
  283.             }
  284.         }
  285.         //2D ROUND
  286.         foreach ($ids as $key => $id) {
  287.             $order $em->getRepository('FrameworkAppBundle:Order')->findOneByBaseId($id);
  288.             $envoi 'E-Billet';
  289.             foreach ($order->getCartArr2() as $item_key => $item) {
  290.                 if( $item['gift'] == 'true' ){
  291.                     $envoi 'Courrier';
  292.                 }
  293.             }
  294.             if($envoi == 'E-Billet'){
  295.                 $client ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname'))."\n";
  296.                 if($order->getInfo('company') != ''){
  297.                     $client .= ucwords(strtolower($order->getInfo('company')))."\n";
  298.                 }
  299.                 $client .= $order->getUser()->getEmail()."\n".$order->getInfo('phone');
  300.                 $address $order->getInfo('address')."\n".$order->getInfo('zipcode').' '.$order->getInfo('city')."\n".$order->getInfo('country');
  301.                 $cart '';
  302.                 $index 1;
  303.                 foreach ($order->getCart() as $key => $item) {
  304.                     if($index 1){
  305.                         $cart .= "\n";
  306.                     }
  307.                     $cart .= $order->getBaseId().'-'.$index.' | '.$item->name->fr.' x'.$item->quantity;
  308.                     if($item->for != ''){
  309.                         $cart .= ' pour : '.$item->for;
  310.                     }
  311.                     if(isset($item->options) && $item->options != ''){
  312.                         foreach ($item->options as $key2 => $option) {
  313.                             $cart .= "\n".'+ '.$option->name.' x'.$option->qty;
  314.                         }
  315.                     }
  316.                     $index++;
  317.                 }
  318.                 $rows[] = [
  319.                     $order->getBaseId(),
  320.                     date('d/m/Y'$order->getResult()->created),
  321.                     // 'BON C.',
  322.                     $client,
  323.                     $address,
  324.                     $envoi,
  325.                     // $order->getRecap(true),
  326.                     $cart,
  327.                     ($order->getAmount() + $order->getAmountShow()),
  328.                     $order->getAmount(),
  329.                     $order->getAmountShow(),
  330.                     ($order->getManual()) ? 'M' '',
  331.                     // $order->getResult()->id
  332.                 ];
  333.                 $total $total + ($order->getAmount() + $order->getAmountShow());
  334.                 $total_am $total_am $order->getAmount();
  335.                 $total_rs $total_rs $order->getAmountShow();
  336.             }
  337.         }
  338.         $rows[] = [
  339.             '',
  340.             '',
  341.             '',
  342.             '',
  343.             '',
  344.             'Export détaillé : '.$date,
  345.             $total,
  346.             $total_am,
  347.             $total_rs,
  348.             ''
  349.         ];
  350.         //ENREGISTREMENT DU CSV
  351.         $path str_replace('.csv''_full.csv'$export->getFile());
  352.         $name str_replace('.csv''_full.csv'$export->getName());
  353.         $fp fopen($path'w'); // open in write only mode (write at the start of the file)
  354.         fprintf($fpchr(0xEF).chr(0xBB).chr(0xBF));
  355.         foreach ($rows as $row) {
  356.             fputcsv($fp$row";");
  357.         }
  358.         fclose($fp);
  359.         header('Content-Description: File Transfer');
  360.         header('Content-Type: application/octet-stream');
  361.         header('Content-Disposition: attachment; filename="'.$name.'"');
  362.         header('Content-Transfer-Encoding: binary');
  363.         header('Expires: 0');
  364.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  365.         header('Pragma: public');
  366.         header('Content-Length: ' filesize($path)); //Absolute URL
  367.         ob_clean();
  368.         flush();
  369.         readfile($path); //Absolute URL
  370.         exit();
  371.     }
  372.     /**
  373.      * @Route("/resa-exports", name="palace_manager_resa_exports", requirements={"id" = "([a-z\-0-9]+)"})
  374.      */
  375.     public function exportsResaAction(Request $request$id NULLMailerInterface $mailer)
  376.     {
  377.         $em $this->getDoctrine()->getManager();
  378.         $globals $this->get("twig")->getGlobals();
  379.         $exports $em->getRepository('FrameworkAppBundle:Export')->findBy(['type' => 'resa'], ['createdAt' => 'DESC']);
  380.         return $this->render('AdminBundle/Booking/exports.html.twig', [
  381.             'exports' => $exports,
  382.             'locale' => 'fr',
  383.         ]);
  384.     }
  385.     /**
  386.      * @Route("/resa-exports-ticketing", name="palace_manager_resa_exports_ticketing", requirements={"id" = "([a-z\-0-9]+)"})
  387.      */
  388.     public function exportsTicketingResaAction(Request $request$id NULLMailerInterface $mailer)
  389.     {
  390.         $em $this->getDoctrine()->getManager();
  391.         $globals $this->get("twig")->getGlobals();
  392.         $exports $em->getRepository('FrameworkAppBundle:Export')->findBy(['type' => 'ticketing'], ['createdAt' => 'DESC']);
  393.         return $this->render('AdminBundle/Booking/exports_ticketing.html.twig', [
  394.             'exports' => $exports,
  395.             'locale' => 'fr',
  396.         ]);
  397.     }
  398.     /**
  399.      * @Route("/resa-exports-generate", name="palace_manager_resa_exports_generate", requirements={"id" = "([a-z\-0-9]+)"})
  400.      */
  401.     public function exportResaGenerateAction(Request $request$id NULLMailerInterface $mailer)
  402.     {
  403.         $success false;
  404.         $error $slug '';
  405.         $em $this->getDoctrine()->getManager();
  406.         $globals $this->get("twig")->getGlobals();
  407.         $total $total_rs $total_am 0;
  408.         $date date('Y-m-d_H-i-s');
  409.         $rows = [];
  410.         $rows[] = [
  411.             'ID',
  412.             'Date de paiement',
  413.             'Type',
  414.             'Paiement',
  415.             'Client',
  416.             'Date',
  417.             'Total',
  418.             'AM',
  419.             'RS',
  420.             'ID Stripe'
  421.         ];
  422.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL'isflash' => NULL'status' => 'succeeded''paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC''createdAt' => 'ASC']);
  423.         if( sizeof($bookings) > ){
  424.             foreach ($bookings as $key => $booking) {
  425.                 if($booking->getInfo('gift') == 'true'){
  426.                     if( $booking->getResult() == null ){
  427.                         $created $booking->getCreatedAt()->format('d/m/Y');
  428.                         $result_id '';
  429.                     } else {
  430.                         $created date('d/m/Y'$booking->getResult()->created);
  431.                         $result_id $booking->getResult()->id;
  432.                     }
  433.                     $rows[] = [
  434.                         $booking->getBaseId(),
  435.                         $created,
  436.                         'RESA',
  437.                         $booking->getPaymentType(),
  438.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  439.                         $booking->getVenueTitle(),
  440.                         ($booking->getAmount() + $booking->getAmountShow()),
  441.                         $booking->getAmount(),
  442.                         $booking->getAmountShow(),
  443.                         $result_id
  444.                     ];
  445.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  446.                     $total_am $total_am $booking->getAmount();
  447.                     $total_rs $total_rs $booking->getAmountShow();
  448.                     $booking->setState(6);
  449.                     $booking->setExported(1);
  450.                     $em->persist($booking);
  451.                     $em->flush();
  452.                 }
  453.             }
  454.             //2D ROUND
  455.             foreach ($bookings as $key => $booking) {
  456.                 if($booking->getInfo('gift') != 'true'){
  457.                     if( $booking->getResult() == null ){
  458.                         $created $booking->getCreatedAt()->format('d/m/Y');
  459.                         $result_id '';
  460.                     } else {
  461.                         $created date('d/m/Y'$booking->getResult()->created);
  462.                         $result_id $booking->getResult()->id;
  463.                     }
  464.                     $rows[] = [
  465.                         $booking->getBaseId(),
  466.                         $created,
  467.                         'RESA',
  468.                         $booking->getPaymentType(),
  469.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  470.                         $booking->getVenueTitle(),
  471.                         ($booking->getAmount() + $booking->getAmountShow()),
  472.                         $booking->getAmount(),
  473.                         $booking->getAmountShow(),
  474.                         $result_id
  475.                     ];
  476.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  477.                     $total_am $total_am $booking->getAmount();
  478.                     $total_rs $total_rs $booking->getAmountShow();
  479.                     $booking->setState(6);
  480.                     $booking->setExported(1);
  481.                     $em->persist($booking);
  482.                     $em->flush();
  483.                 }
  484.             }
  485.             $rows[] = [
  486.                 '',
  487.                 '',
  488.                 '',
  489.                 '',
  490.                 'Export : '.$date,
  491.                 $total,
  492.                 $total_am,
  493.                 $total_rs,
  494.                 ''
  495.             ];
  496.             //ENREGISTREMENT DU CSV
  497.             $path $globals['export_folder'].'exports_booking/R_'.$date.'.csv';
  498.             $fp fopen($path'w'); // open in write only mode (write at the start of the file)
  499.             fprintf($fpchr(0xEF).chr(0xBB).chr(0xBF));
  500.             foreach ($rows as $row) {
  501.                 fputcsv($fp$row";");
  502.             }
  503.             fclose($fp);
  504.             //ENREGISTREMENT BASE
  505.             $export = new Export();
  506.             $export->setType('resa');
  507.             $export->setFile($path);
  508.             $export->setName('R_'.$date.'.csv');
  509.             $em->persist($export);
  510.             $em->flush();
  511.             //ENVOI EMAIL COMPTA
  512.             $from $globals['app_email_noreply'];
  513.             $to $globals['app_email_compta'];
  514.             $contact $globals['app_email_contact'];
  515.             $email = (new Email())
  516.                 ->from($from)
  517.                 ->to($to)
  518.                 ->cc($globals['app_email_contact'])
  519.                 //->bcc('bcc@example.com')
  520.                 ->replyTo($contact)
  521.                 //->priority(Email::PRIORITY_HIGH)
  522.                 ->attachFromPath($path)
  523.                 ->subject('Nouvel export RESERVATIONS CB Stripe '.$date)
  524.                 ->text(nl2br('Nouvel export RESERVATIONS CB Stripe généré le '.$date));
  525.             $mailer->send($email);
  526.             //FIN ENVOI EMAIL COMPTA
  527.             $success true;
  528.         } else {
  529.             $error 'Aucun nouveau paiement à exporter';
  530.         }
  531.         $data = [
  532.             'error' => $error,
  533.             'success' => $success
  534.         ];
  535.         $response = new Response(json_encode($data));
  536.         $response->headers->set('Content-Type''application/json');
  537.         return $response;
  538.     }
  539.     /**
  540.      * @Route("/resa-exports-generate-preview", name="palace_manager_resa_exports_generate_preview", requirements={"id" = "([a-z\-0-9]+)"})
  541.      */
  542.     public function exportResaGeneratePreviewAction(Request $request$id NULLMailerInterface $mailer)
  543.     {
  544.         $success false;
  545.         $error $slug $html '';
  546.         $em $this->getDoctrine()->getManager();
  547.         $globals $this->get("twig")->getGlobals();
  548.         $total $total_rs $total_am 0;
  549.         $date date('Y-m-d_H-i-s');
  550.         $rows = [];
  551.         $rows[] = [
  552.             'ID',
  553.             'Date de paiement',
  554.             'Type',
  555.             'Paiement',
  556.             'Client',
  557.             'Date',
  558.             'Total',
  559.             'AM',
  560.             'RS',
  561.             'ID Stripe'
  562.         ];
  563.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL'isflash' => NULL'status' => 'succeeded''paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC''createdAt' => 'ASC']);
  564.         if( sizeof($bookings) > ){
  565.             foreach ($bookings as $key => $booking) {
  566.                 if($booking->getInfo('gift') == 'true'){
  567.                     if( $booking->getResult() == null ){
  568.                         $created $booking->getCreatedAt()->format('d/m/Y');
  569.                         $result_id '';
  570.                     } else {
  571.                         $created date('d/m/Y'$booking->getResult()->created);
  572.                         $result_id $booking->getResult()->id;
  573.                     }
  574.                     $rows[] = [
  575.                         $booking->getBaseId(),
  576.                         $created,
  577.                         'RESA',
  578.                         $booking->getPaymentType(),
  579.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  580.                         $booking->getVenueTitle(),
  581.                         ($booking->getAmount() + $booking->getAmountShow()),
  582.                         $booking->getAmount(),
  583.                         $booking->getAmountShow(),
  584.                         $result_id
  585.                     ];
  586.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  587.                     $total_am $total_am $booking->getAmount();
  588.                     $total_rs $total_rs $booking->getAmountShow();
  589.                 }
  590.             }
  591.             //2D ROUND
  592.             foreach ($bookings as $key => $booking) {
  593.                 if($booking->getInfo('gift') != 'true'){
  594.                     if( $booking->getResult() == null ){
  595.                         $created $booking->getCreatedAt()->format('d/m/Y');
  596.                         $result_id '';
  597.                     } else {
  598.                         $created date('d/m/Y'$booking->getResult()->created);
  599.                         $result_id $booking->getResult()->id;
  600.                     }
  601.                     $rows[] = [
  602.                         $booking->getBaseId(),
  603.                         $created,
  604.                         'RESA',
  605.                         $booking->getPaymentType(),
  606.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  607.                         $booking->getVenueTitle(),
  608.                         ($booking->getAmount() + $booking->getAmountShow()),
  609.                         $booking->getAmount(),
  610.                         $booking->getAmountShow(),
  611.                         $result_id
  612.                     ];
  613.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  614.                     $total_am $total_am $booking->getAmount();
  615.                     $total_rs $total_rs $booking->getAmountShow();
  616.                 }
  617.             }
  618.             $rows[] = [
  619.                 '',
  620.                 '',
  621.                 '',
  622.                 '',
  623.                 'Export : '.$date,
  624.                 $total,
  625.                 $total_am,
  626.                 $total_rs,
  627.                 ''
  628.             ];
  629.             $html '<table class="exporting"><tbody>';
  630.             foreach ($rows as $key => $row) {
  631.                 $html .= '<tr>';
  632.                 foreach ($row as $key2 => $column) {
  633.                     $html .= '<td>'.$column.'</td>';
  634.                 }
  635.                 $html .= '</tr>';
  636.             }
  637.             $html .= '</tbody></table>';
  638.             $success true;
  639.         } else {
  640.             $error 'Aucun nouveau paiement à exporter';
  641.         }
  642.         $data = [
  643.             'error' => $error,
  644.             'success' => $success,
  645.             'html' => $html
  646.         ];
  647.         $response = new Response(json_encode($data));
  648.         $response->headers->set('Content-Type''application/json');
  649.         return $response;
  650.     }
  651.     /**
  652.      * @Route("/resa-exports-generate-ticketing", name="palace_manager_resa_exports_generate_ticketing", requirements={"id" = "([a-z\-0-9]+)"})
  653.      */
  654.     public function exportResaGenerateTicketingAction(Request $request$id NULLMailerInterface $mailer)
  655.     {
  656.         $success false;
  657.         $error $slug '';
  658.         $em $this->getDoctrine()->getManager();
  659.         $globals $this->get("twig")->getGlobals();
  660.         $total $total_rs $total_am 0;
  661.         $date date('Y-m-d_H-i-s');
  662.         $rows = [];
  663.         $rows[] = [
  664.             'ID',
  665.             'Date de paiement',
  666.             'Type',
  667.             'Paiement',
  668.             'Client',
  669.             'Date',
  670.             'Total',
  671.             'AM',
  672.             'RS',
  673.             'ID Stripe'
  674.         ];
  675.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL'isflash' => 1'status' => 'succeeded''paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC''createdAt' => 'ASC']);
  676.         if( sizeof($bookings) > ){
  677.             foreach ($bookings as $key => $booking) {
  678.                 if($booking->getInfo('gift') == 'true'){
  679.                     if( $booking->getResult() == null ){
  680.                         $created $booking->getCreatedAt()->format('d/m/Y');
  681.                         $result_id '';
  682.                     } else {
  683.                         $created date('d/m/Y'$booking->getResult()->created);
  684.                         $result_id $booking->getResult()->id;
  685.                     }
  686.                     $rows[] = [
  687.                         $booking->getBaseId(),
  688.                         $created,
  689.                         'RESA (T)',
  690.                         $booking->getPaymentType(),
  691.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  692.                         $booking->getVenueTitle(),
  693.                         ($booking->getAmount() + $booking->getAmountShow()),
  694.                         $booking->getAmount(),
  695.                         $booking->getAmountShow(),
  696.                         $result_id
  697.                     ];
  698.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  699.                     $total_am $total_am $booking->getAmount();
  700.                     $total_rs $total_rs $booking->getAmountShow();
  701.                     $booking->setState(6);
  702.                     $booking->setExported(1);
  703.                     $em->persist($booking);
  704.                     $em->flush();
  705.                 }
  706.             }
  707.             //2D ROUND
  708.             foreach ($bookings as $key => $booking) {
  709.                 if($booking->getInfo('gift') != 'true'){
  710.                     if( $booking->getResult() == null ){
  711.                         $created $booking->getCreatedAt()->format('d/m/Y');
  712.                         $result_id '';
  713.                     } else {
  714.                         $created date('d/m/Y'$booking->getResult()->created);
  715.                         $result_id $booking->getResult()->id;
  716.                     }
  717.                     $rows[] = [
  718.                         $booking->getBaseId(),
  719.                         $created,
  720.                         'RESA (T)',
  721.                         $booking->getPaymentType(),
  722.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  723.                         $booking->getVenueTitle(),
  724.                         ($booking->getAmount() + $booking->getAmountShow()),
  725.                         $booking->getAmount(),
  726.                         $booking->getAmountShow(),
  727.                         $result_id
  728.                     ];
  729.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  730.                     $total_am $total_am $booking->getAmount();
  731.                     $total_rs $total_rs $booking->getAmountShow();
  732.                     $booking->setState(6);
  733.                     $booking->setExported(1);
  734.                     $em->persist($booking);
  735.                     $em->flush();
  736.                 }
  737.             }
  738.             $rows[] = [
  739.                 '',
  740.                 '',
  741.                 '',
  742.                 '',
  743.                 'Export : '.$date,
  744.                 $total,
  745.                 $total_am,
  746.                 $total_rs,
  747.                 ''
  748.             ];
  749.             //ENREGISTREMENT DU CSV
  750.             $path $globals['export_folder'].'exports_booking/T_'.$date.'.csv';
  751.             $fp fopen($path'w'); // open in write only mode (write at the start of the file)
  752.             fprintf($fpchr(0xEF).chr(0xBB).chr(0xBF));
  753.             foreach ($rows as $row) {
  754.                 fputcsv($fp$row";");
  755.             }
  756.             fclose($fp);
  757.             //ENREGISTREMENT BASE
  758.             $export = new Export();
  759.             $export->setType('ticketing');
  760.             $export->setFile($path);
  761.             $export->setName('T_'.$date.'.csv');
  762.             $em->persist($export);
  763.             $em->flush();
  764.             //ENVOI EMAIL COMPTA
  765.             $from $globals['app_email_noreply'];
  766.             $to $globals['app_email_compta'];
  767.             $contact $globals['app_email_contact'];
  768.             $email = (new Email())
  769.                 ->from($from)
  770.                 ->to($to)
  771.                 ->cc($globals['app_email_contact'])
  772.                 //->bcc('bcc@example.com')
  773.                 ->replyTo($contact)
  774.                 //->priority(Email::PRIORITY_HIGH)
  775.                 ->attachFromPath($path)
  776.                 ->subject('Nouvel export RESERVATIONS CB Stripe '.$date)
  777.                 ->text(nl2br('Nouvel export RESERVATIONS CB Stripe généré le '.$date));
  778.             $mailer->send($email);
  779.             //FIN ENVOI EMAIL COMPTA
  780.             $success true;
  781.         } else {
  782.             $error 'Aucun nouveau paiement à exporter';
  783.         }
  784.         $data = [
  785.             'error' => $error,
  786.             'success' => $success
  787.         ];
  788.         $response = new Response(json_encode($data));
  789.         $response->headers->set('Content-Type''application/json');
  790.         return $response;
  791.     }
  792.     /**
  793.      * @Route("/resa-exports-generate-ticketing-preview", name="palace_manager_resa_exports_generate_ticketing_preview", requirements={"id" = "([a-z\-0-9]+)"})
  794.      */
  795.     public function exportResaGenerateTicketingPreviewAction(Request $request$id NULLMailerInterface $mailer)
  796.     {
  797.         $success false;
  798.         $error $slug $html '';
  799.         $em $this->getDoctrine()->getManager();
  800.         $globals $this->get("twig")->getGlobals();
  801.         $total $total_rs $total_am 0;
  802.         $date date('Y-m-d_H-i-s');
  803.         $rows = [];
  804.         $rows[] = [
  805.             'ID',
  806.             'Date de paiement',
  807.             'Type',
  808.             'Paiement',
  809.             'Client',
  810.             'Date',
  811.             'Total',
  812.             'AM',
  813.             'RS',
  814.             'ID Stripe'
  815.         ];
  816.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL'isflash' => 1'status' => 'succeeded''paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC''createdAt' => 'ASC']);
  817.         if( sizeof($bookings) > ){
  818.             foreach ($bookings as $key => $booking) {
  819.                 if($booking->getInfo('gift') == 'true'){
  820.                     if( $booking->getResult() == null ){
  821.                         $created $booking->getCreatedAt()->format('d/m/Y');
  822.                         $result_id '';
  823.                     } else {
  824.                         $created date('d/m/Y'$booking->getResult()->created);
  825.                         $result_id $booking->getResult()->id;
  826.                     }
  827.                     $rows[] = [
  828.                         $booking->getBaseId(),
  829.                         $created,
  830.                         'RESA (T)',
  831.                         $booking->getPaymentType(),
  832.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  833.                         $booking->getVenueTitle(),
  834.                         ($booking->getAmount() + $booking->getAmountShow()),
  835.                         $booking->getAmount(),
  836.                         $booking->getAmountShow(),
  837.                         $result_id
  838.                     ];
  839.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  840.                     $total_am $total_am $booking->getAmount();
  841.                     $total_rs $total_rs $booking->getAmountShow();
  842.                 }
  843.             }
  844.             //2D ROUND
  845.             foreach ($bookings as $key => $booking) {
  846.                 if($booking->getInfo('gift') != 'true'){
  847.                     if( $booking->getResult() == null ){
  848.                         $created $booking->getCreatedAt()->format('d/m/Y');
  849.                         $result_id '';
  850.                     } else {
  851.                         $created date('d/m/Y'$booking->getResult()->created);
  852.                         $result_id $booking->getResult()->id;
  853.                     }
  854.                     $rows[] = [
  855.                         $booking->getBaseId(),
  856.                         $created,
  857.                         'RESA (T)',
  858.                         $booking->getPaymentType(),
  859.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  860.                         $booking->getVenueTitle(),
  861.                         ($booking->getAmount() + $booking->getAmountShow()),
  862.                         $booking->getAmount(),
  863.                         $booking->getAmountShow(),
  864.                         $result_id
  865.                     ];
  866.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  867.                     $total_am $total_am $booking->getAmount();
  868.                     $total_rs $total_rs $booking->getAmountShow();
  869.                 }
  870.             }
  871.             $rows[] = [
  872.                 '',
  873.                 '',
  874.                 '',
  875.                 '',
  876.                 'Export : '.$date,
  877.                 $total,
  878.                 $total_am,
  879.                 $total_rs,
  880.                 ''
  881.             ];
  882.             $html '<table class="exporting"><tbody>';
  883.             foreach ($rows as $key => $row) {
  884.                 $html .= '<tr>';
  885.                 foreach ($row as $key2 => $column) {
  886.                     $html .= '<td>'.$column.'</td>';
  887.                 }
  888.                 $html .= '</tr>';
  889.             }
  890.             $html .= '</tbody></table>';
  891.             $success true;
  892.         } else {
  893.             $error 'Aucun nouveau paiement à exporter';
  894.         }
  895.         $data = [
  896.             'error' => $error,
  897.             'success' => $success,
  898.             'html' => $html
  899.         ];
  900.         $response = new Response(json_encode($data));
  901.         $response->headers->set('Content-Type''application/json');
  902.         return $response;
  903.     }
  904.     /**
  905.      * @Route("/order-exports", name="palace_manager_order_exports", requirements={"id" = "([a-z\-0-9]+)"})
  906.      */
  907.     public function exportsOrderAction(Request $request$id NULLMailerInterface $mailer)
  908.     {
  909.         $em $this->getDoctrine()->getManager();
  910.         $globals $this->get("twig")->getGlobals();
  911.         $exports $em->getRepository('FrameworkAppBundle:Export')->findBy(['type' => 'order'], ['createdAt' => 'DESC']);
  912.         return $this->render('AdminBundle/Order/exports.html.twig', [
  913.             'exports' => $exports,
  914.             'locale' => 'fr',
  915.         ]);
  916.     }
  917.     /**
  918.      * @Route("/order-exports-generate", name="palace_manager_order_exports_generate", requirements={"id" = "([a-z\-0-9]+)"})
  919.      */
  920.     public function exportOrderGenerateAction(Request $request$id NULLMailerInterface $mailer)
  921.     {
  922.         $success false;
  923.         $error $slug '';
  924.         $em $this->getDoctrine()->getManager();
  925.         $globals $this->get("twig")->getGlobals();
  926.         $total $total_rs $total_am 0;
  927.         $date date('Y-m-d_H-i-s');
  928.         $rows = [];
  929.         $rows[] = [
  930.             'ID',
  931.             'Date de paiement',
  932.             'Type',
  933.             'Paiement',
  934.             'Client',
  935.             'Envoi',
  936.             'Commande',
  937.             'Total',
  938.             'AM',
  939.             'RS',
  940.             'ID Stripe',
  941.             'Manuel'
  942.         ];
  943.         $orders $em->getRepository('FrameworkAppBundle:Order')->findBy(['exported' => NULL'status' => 'succeeded''paymentType' => ['card','klarna','paypal'] ], ['manual' => 'DESC''paymentType' => 'DESC''createdAt' => 'ASC']);
  944.         if( sizeof($orders) > ){
  945.             foreach ($orders as $key => $order) {
  946.                 $envoi 'E-Billet';
  947.                 foreach ($order->getCartArr2() as $item_key => $item) {
  948.                     if( $item['gift'] == 'true' ){
  949.                         $envoi 'Courrier';
  950.                     }
  951.                 }
  952.                 if($envoi == 'Courrier'){
  953.                     $rows[] = [
  954.                         $order->getBaseId(),
  955.                         date('d/m/Y'$order->getResult()->created),
  956.                         'BON C.',
  957.                         $order->getPaymentType(),
  958.                         ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
  959.                         $envoi,
  960.                         $order->getRecap(true),
  961.                         ($order->getAmount() + $order->getAmountShow()),
  962.                         $order->getAmount(),
  963.                         $order->getAmountShow(),
  964.                         $order->getResult()->id,
  965.                         ($order->getManual()) ? 'M' '',
  966.                     ];
  967.                     $total $total + ($order->getAmount() + $order->getAmountShow());
  968.                     $total_am $total_am $order->getAmount();
  969.                     $total_rs $total_rs $order->getAmountShow();
  970.                     $order->setState(6);
  971.                     $order->setExported(1);
  972.                     $em->persist($order);
  973.                     $em->flush();
  974.                 }
  975.             }
  976.             //2d ROUND
  977.             foreach ($orders as $key => $order) {
  978.                 $envoi 'E-Billet';
  979.                 foreach ($order->getCartArr2() as $item_key => $item) {
  980.                     if( $item['gift'] == 'true' ){
  981.                         $envoi 'Courrier';
  982.                     }
  983.                 }
  984.                 if($envoi == 'E-Billet'){
  985.                     $rows[] = [
  986.                         $order->getBaseId(),
  987.                         date('d/m/Y'$order->getResult()->created),
  988.                         'BON C.',
  989.                         $order->getPaymentType(),
  990.                         ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
  991.                         $envoi,
  992.                         $order->getRecap(true),
  993.                         ($order->getAmount() + $order->getAmountShow()),
  994.                         $order->getAmount(),
  995.                         $order->getAmountShow(),
  996.                         $order->getResult()->id,
  997.                         ($order->getManual()) ? 'M' '',
  998.                     ];
  999.                     $total $total + ($order->getAmount() + $order->getAmountShow());
  1000.                     $total_am $total_am $order->getAmount();
  1001.                     $total_rs $total_rs $order->getAmountShow();
  1002.                     $order->setState(6);
  1003.                     $order->setExported(1);
  1004.                     $em->persist($order);
  1005.                     $em->flush();
  1006.                 }
  1007.             }
  1008.             $rows[] = [
  1009.                 '',
  1010.                 '',
  1011.                 '',
  1012.                 '',
  1013.                 '',
  1014.                 'Export : '.$date,
  1015.                 $total,
  1016.                 $total_am,
  1017.                 $total_rs,
  1018.                 '',
  1019.                 ''
  1020.             ];
  1021.             //ENREGISTREMENT DU CSV
  1022.             $path $globals['export_folder'].'exports_order/B_'.$date.'.csv';
  1023.             $fp fopen($path'w'); // open in write only mode (write at the start of the file)
  1024.             fprintf($fpchr(0xEF).chr(0xBB).chr(0xBF));
  1025.             foreach ($rows as $row) {
  1026.                 fputcsv($fp$row";");
  1027.             }
  1028.             fclose($fp);
  1029.             //ENREGISTREMENT BASE
  1030.             $export = new Export();
  1031.             $export->setType('order');
  1032.             $export->setFile($path);
  1033.             $export->setName('B_'.$date.'.csv');
  1034.             $em->persist($export);
  1035.             $em->flush();
  1036.             //ENVOI EMAIL COMPTA
  1037.             $from $globals['app_email_noreply'];
  1038.             $to $globals['app_email_compta'];
  1039.             $contact $globals['app_email_contact'];
  1040.             $email = (new Email())
  1041.                 ->from($from)
  1042.                 ->to($to)
  1043.                 ->cc($globals['app_email_contact'])
  1044.                 //->bcc('bcc@example.com')
  1045.                 ->replyTo($contact)
  1046.                 //->priority(Email::PRIORITY_HIGH)
  1047.                 ->attachFromPath($path)
  1048.                 ->subject('Nouvel export BONS CADEAUX CB Stripe '.$date)
  1049.                 ->text(nl2br('Nouvel export BONS CADEAUX CB Stripe généré le '.$date));
  1050.             $mailer->send($email);
  1051.             //FIN ENVOI EMAIL COMPTA
  1052.             $success true;
  1053.         } else {
  1054.             $error 'Aucun nouveau paiement à exporter';
  1055.         }
  1056.         $data = [
  1057.             'error' => $error,
  1058.             'success' => $success
  1059.         ];
  1060.         $response = new Response(json_encode($data));
  1061.         $response->headers->set('Content-Type''application/json');
  1062.         return $response;
  1063.     }
  1064.     /**
  1065.      * @Route("/order-exports-generate-preview", name="palace_manager_order_exports_generate_preview", requirements={"id" = "([a-z\-0-9]+)"})
  1066.      */
  1067.     public function exportOrderGeneratePreviewAction(Request $request$id NULLMailerInterface $mailer)
  1068.     {
  1069.         $success false;
  1070.         $error $slug $html '';
  1071.         $em $this->getDoctrine()->getManager();
  1072.         $globals $this->get("twig")->getGlobals();
  1073.         $total $total_rs $total_am 0;
  1074.         $date date('Y-m-d_H-i-s');
  1075.         $rows = [];
  1076.         $rows[] = [
  1077.             'ID',
  1078.             'Date de paiement',
  1079.             'Type',
  1080.             'Paiement',
  1081.             'Client',
  1082.             'Envoi',
  1083.             'Commande',
  1084.             'Total',
  1085.             'AM',
  1086.             'RS',
  1087.             'ID Stripe',
  1088.             'Manuel'
  1089.         ];
  1090.         $orders $em->getRepository('FrameworkAppBundle:Order')->findBy(['exported' => NULL'status' => 'succeeded''paymentType' => ['card','klarna','paypal'] ], ['manual' => 'DESC''paymentType' => 'DESC''createdAt' => 'ASC']);
  1091.         if( sizeof($orders) > ){
  1092.             foreach ($orders as $key => $order) {
  1093.                 $envoi 'E-Billet';
  1094.                 foreach ($order->getCartArr2() as $item_key => $item) {
  1095.                     if( $item['gift'] == 'true' ){
  1096.                         $envoi 'Courrier';
  1097.                     }
  1098.                 }
  1099.                 if($envoi == 'Courrier'){
  1100.                     $rows[] = [
  1101.                         $order->getBaseId(),
  1102.                         date('d/m/Y'$order->getResult()->created),
  1103.                         'BON C.',
  1104.                         $order->getPaymentType(),
  1105.                         ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
  1106.                         $envoi,
  1107.                         $order->getRecap(true),
  1108.                         ($order->getAmount() + $order->getAmountShow()),
  1109.                         $order->getAmount(),
  1110.                         $order->getAmountShow(),
  1111.                         $order->getResult()->id,
  1112.                         ($order->getManual()) ? 'M' '',
  1113.                     ];
  1114.                     $total $total + ($order->getAmount() + $order->getAmountShow());
  1115.                     $total_am $total_am $order->getAmount();
  1116.                     $total_rs $total_rs $order->getAmountShow();
  1117.                 }
  1118.             }
  1119.             //2d ROUND
  1120.             foreach ($orders as $key => $order) {
  1121.                 $envoi 'E-Billet';
  1122.                 foreach ($order->getCartArr2() as $item_key => $item) {
  1123.                     if( $item['gift'] == 'true' ){
  1124.                         $envoi 'Courrier';
  1125.                     }
  1126.                 }
  1127.                 if($envoi == 'E-Billet'){
  1128.                     $rows[] = [
  1129.                         $order->getBaseId(),
  1130.                         date('d/m/Y'$order->getResult()->created),
  1131.                         'BON C.',
  1132.                         $order->getPaymentType(),
  1133.                         ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
  1134.                         $envoi,
  1135.                         $order->getRecap(true),
  1136.                         ($order->getAmount() + $order->getAmountShow()),
  1137.                         $order->getAmount(),
  1138.                         $order->getAmountShow(),
  1139.                         $order->getResult()->id,
  1140.                         ($order->getManual()) ? 'M' '',
  1141.                     ];
  1142.                     $total $total + ($order->getAmount() + $order->getAmountShow());
  1143.                     $total_am $total_am $order->getAmount();
  1144.                     $total_rs $total_rs $order->getAmountShow();
  1145.                 }
  1146.             }
  1147.             $rows[] = [
  1148.                 '',
  1149.                 '',
  1150.                 '',
  1151.                 '',
  1152.                 '',
  1153.                 'Export : '.$date,
  1154.                 $total,
  1155.                 $total_am,
  1156.                 $total_rs,
  1157.                 '',
  1158.                 ''
  1159.             ];
  1160.             $html '<table class="exporting"><tbody>';
  1161.             foreach ($rows as $key => $row) {
  1162.                 $html .= '<tr>';
  1163.                 foreach ($row as $key2 => $column) {
  1164.                     $html .= '<td>'.$column.'</td>';
  1165.                 }
  1166.                 $html .= '</tr>';
  1167.             }
  1168.             $html .= '</tbody></table>';
  1169.             $success true;
  1170.         } else {
  1171.             $error 'Aucun nouveau paiement à exporter';
  1172.         }
  1173.         $data = [
  1174.             'error' => $error,
  1175.             'success' => $success,
  1176.             'html' => $html
  1177.         ];
  1178.         $response = new Response(json_encode($data));
  1179.         $response->headers->set('Content-Type''application/json');
  1180.         return $response;
  1181.     }
  1182.     /**
  1183.      * @Route("/resa/sendPayment/{id}", name="palace_manager_resa_sendPayment", requirements={"id" = "([a-z\-0-9]+)"})
  1184.      */
  1185.     public function sendPaymentAction(Request $request$id NULLMailerInterface $mailer)
  1186.     {
  1187.         $em $this->getDoctrine()->getManager();
  1188.         $globals $this->get("twig")->getGlobals();
  1189.         $success true;
  1190.         $error $slug '';
  1191.         $booking $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
  1192.         $booking->setOptions($request->get('options'));
  1193.         $booking->setAmount(floatval(str_replace(',''.'$request->get('amount'))));
  1194.         $booking->setAmountShow(floatval(str_replace(',''.'$request->get('amountShow'))));
  1195.         $booking->setState(1);
  1196.         $booking->setVenueTitle($request->get('venueTitle'));
  1197.         $booking->setEmailContent($request->get('emailContent'));
  1198.         if($request->get('reminder') == 'reminder'){
  1199.             $booking->setMailedCount$booking->getMailedCount() + );
  1200.         }
  1201.         $em->persist($booking);
  1202.         $em->flush();
  1203.         $subject 'Votre réservation Royal Palace : Instructions de règlement';
  1204.         $title 'Votre réservation Royal Palace : Instructions de règlement';
  1205.         $content str_replace("\n"'<br>'$booking->getEmailContent()).'</p><br><a href="'.$globals['app_email_domain'].'fr/mon-compte/paiement/'.$booking->getToken().'" style="text-align:center; width:100%; font-size: 18px; display:block;"><strong>Procéder au paiement</strong></a>';
  1206.         if($request->get('reminder') == 'reminder'){
  1207.             $subject 'Relance commande #'.$booking->getBaseId().' | Votre réservation Royal Palace : Instructions de règlement';
  1208.             $title 'Relance commande #'.$booking->getBaseId().' | Votre réservation Royal Palace : Instructions de règlement';
  1209.         }
  1210.         if($booking->getLang() == 'de'){
  1211.             $subject 'Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
  1212.             $title 'Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
  1213.             $content str_replace("\n"'<br>'$booking->getEmailContent()).'</p><br><a href="'.$globals['app_email_domain'].'de/mon-compte/paiement/'.$booking->getToken().'" style="text-align:center; width:100%; font-size: 18px; display:block;"><strong>Mit der Zahlung fortfahren</strong></a>';
  1214.             if($request->get('reminder') == 'reminder'){
  1215.                 $subject 'Zahlungserinnerung Bestellung #'.$booking->getBaseId().' | Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
  1216.                 $title 'Zahlungserinnerung Bestellung #'.$booking->getBaseId().' | Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
  1217.             }
  1218.         }
  1219.         if($booking->getLang() == 'en'){
  1220.             $subject 'Your Royal Palace reservation: Payment instructions';
  1221.             $title 'Your Royal Palace reservation: Payment instructions';
  1222.             $content str_replace("\n"'<br>'$booking->getEmailContent()).'</p><br><a href="'.$globals['app_email_domain'].'en/mon-compte/paiement/'.$booking->getToken().'" style="text-align:center; width:100%; font-size: 18px; display:block;"><strong>Proceed to payment</strong></a>';
  1223.             if($request->get('reminder') == 'reminder'){
  1224.                 $subject 'Reminder order #'.$booking->getBaseId().' | Your Royal Palace reservation: Payment instructions';
  1225.                 $title 'Reminder order #'.$booking->getBaseId().' | Your Royal Palace reservation: Payment instructions';
  1226.             }
  1227.         }
  1228.         //ENVOI EMAIL
  1229.         $from $globals['app_email_noreply'];
  1230.         $to $booking->getUser()->getEmail();
  1231.         $contact $globals['app_email_contact'];
  1232.         $email = (new Email())
  1233.             ->from($from)
  1234.             ->to($to)
  1235.             //->cc('cc@example.com')
  1236.             //->bcc('bcc@example.com')
  1237.             ->replyTo($contact)
  1238.             //->priority(Email::PRIORITY_HIGH)
  1239.             ->subject($subject)
  1240.             ->text($booking->getEmailContent())
  1241.             ->html($this->renderView(
  1242.                 'FrontBundle/Emails/general.html.twig', array(
  1243.                     'title'   => $title,
  1244.                     'content' => $content,
  1245.                 )
  1246.             ));
  1247.         try{
  1248.             $mailer->send($email);
  1249.         }
  1250.         catch(\Exception $e){
  1251.             $data = [
  1252.                 'error' => 'Une erreur est survenue. Veuillez vérifier l\'adresse email. : '.$e->getMessage(),
  1253.                 'success' => false
  1254.             ];
  1255.             $response = new Response(json_encode($data));
  1256.             $response->headers->set('Content-Type''application/json');
  1257.             return $response;
  1258.         }
  1259.         //FIN ENVOI EMAIL
  1260.         $booking->setMailedPay(1);
  1261.         $em->persist($booking);
  1262.         $em->flush();
  1263.         // ENREGISTREMENT LOG MAIL
  1264.         $mail = New Mail();
  1265.         $mail->setBooking($booking);
  1266.         $mail->setEmailTitle($title);
  1267.         $mail->setEmailContent($content);
  1268.         $em->persist($mail);
  1269.         $em->flush();
  1270.         // FIN ENREGISTREMENT LOG MAIL
  1271.         $data = [
  1272.             'error' => $error,
  1273.             'success' => $success
  1274.         ];
  1275.         $response = new Response(json_encode($data));
  1276.         $response->headers->set('Content-Type''application/json');
  1277.         return $response;
  1278.     }
  1279.     /**
  1280.      * @Route("/order2", name="palace_manager_order2_index")
  1281.      */
  1282.     public function indexOrderAction(Request $request)
  1283.     {
  1284.         $em $this->getDoctrine()->getManager();
  1285.         $orders $em->getRepository('FrameworkAppBundle:Order')->findBy(['status' => ['manual''succeeded']], ['id' => 'DESC']);
  1286.         return $this->render('AdminBundle/Order/index.html.twig', [
  1287.             'orders' => $orders,
  1288.         ]);
  1289.     }
  1290.     /**
  1291.      * @Route("/order", name="palace_manager_order_index")
  1292.      */
  1293.     public function indexOrder2Action(Request $request)
  1294.     {
  1295.         $em $this->getDoctrine()->getManager();
  1296.         // $orders = $em->getRepository('FrameworkAppBundle:Order')->findBy(['status' => ['manual', 'succeeded']], ['id' => 'DESC']);
  1297.         $orders = [];
  1298.         return $this->render('AdminBundle/Order/index2.html.twig', [
  1299.             'orders' => $orders,
  1300.         ]);
  1301.     }
  1302.     /**
  1303.      * @Route("/order/load", name="palace_manager_order_load")
  1304.      */
  1305.     public function orderLoadAction(Request $request$id null)
  1306.     {
  1307.         $em $this->getDoctrine()->getManager();
  1308.         $success true;
  1309.         $error '';
  1310.         $isAjax $request->isXMLHttpRequest();
  1311.         if (!$isAjax) {
  1312.             return $this->redirectToRoute('palace_manager_resa_index');
  1313.         }
  1314.         $currentPage intval$request->get('page') );
  1315.         if($currentPage == null){
  1316.             $currentPage 1;
  1317.         }
  1318.         $limit 50;
  1319.         if($request->get('search') == ''){
  1320.             if($request->get('filter') != 'all' && $request->get('filter') != NULL){
  1321.                 $orders $em->getRepository('FrameworkAppBundle:Order')->findBy(['state' => $request->get('filter')], ['id' => 'DESC'], $limit, ($currentPage-1) * $limit);
  1322.                 $ordersNbr $em->getRepository('FrameworkAppBundle:Order')->count(['state' => $request->get('filter')]);
  1323.             } else {
  1324.                 $orders $em->getRepository('FrameworkAppBundle:Order')->findBy([], ['id' => 'DESC'], $limit, ($currentPage-1) * $limit);
  1325.                 $ordersNbr $em->getRepository('FrameworkAppBundle:Order')->count([]);
  1326.             }
  1327.         } else {
  1328.             $orders $em->getRepository('FrameworkAppBundle:Order')->search($request->get('search'));
  1329.             $ordersNbr sizeof($orders);
  1330.         }
  1331.         $pagesNbr ceil($ordersNbr $limit);
  1332.         $start = ($currentPage-1) * $limit 1;
  1333.         $end = ($currentPage) * $limit;
  1334.         if($end $ordersNbr){
  1335.             $end $ordersNbr;
  1336.         }
  1337.         $orderArr = [];
  1338.         foreach ($orders as $key => $order) {
  1339.             // $createdAt = new \DateTime(date('Y-m-d H:i:s', strtotime($order->getCreatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
  1340.             // $updatedAt = new \DateTime(date('Y-m-d H:i:s', strtotime($order->getUpdatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
  1341.             $createdAt = new \DateTime(date('Y-m-d H:i:s'strtotime($order->getCreatedAt()->format('Y-m-d H:i:s'))));
  1342.             $updatedAt = new \DateTime(date('Y-m-d H:i:s'strtotime($order->getUpdatedAt()->format('Y-m-d H:i:s'))));
  1343.             $sending '<span class="badge badge-secondary">E-Billet</span>';
  1344.             if($order->getCart()){
  1345.                 foreach ($order->getCart() as $key => $item) {
  1346.                     if($item->gift == 'true'){
  1347.                         $sending '<span class="badge badge-primary">Courrier</span>';
  1348.                     }
  1349.                 }
  1350.             }
  1351.             $orderArr[] = [
  1352.                 'id' =>  $order->getId(),
  1353.                 'email' =>  $order->getUser()->getEmail(),
  1354.                 'old_id' =>  $order->getOldId(),
  1355.                 'base_id' =>  $order->getBaseId(),
  1356.                 'infos' =>  $order->getInfos(),
  1357.                 'cart' =>  $order->getCart(),
  1358.                 'state' =>  $order->getState(),
  1359.                 'status' =>  $order->getStatus(),
  1360.                 'paymentType' =>  $order->getPaymentType(),
  1361.                 'amountTotal' =>  $order->getAmountTotal(),
  1362.                 'stateStrAdmin' =>  $order->getStateStrAdmin(),
  1363.                 'manual' =>  intval($order->getManual()),
  1364.                 'sending' =>  $sending,
  1365.                 'createdAt' =>  $createdAt,
  1366.                 'updatedAt' =>  $updatedAt,
  1367.             ];
  1368.         }
  1369.         $data = [
  1370.             'error'   => $error,
  1371.             'success' => $success,
  1372.             'currentPage' => $currentPage,
  1373.             'ordersNbr' => $ordersNbr,
  1374.             'pagesNbr' => $pagesNbr,
  1375.             'orders' => $orderArr,
  1376.             'start' => $start,
  1377.             'end' => $end,
  1378.         ];
  1379.         $response = new Response(json_encode($data));
  1380.         $response->headers->set('Content-Type''application/json');
  1381.         return $response;
  1382.     }
  1383.     /**
  1384.      * @Route("/order/{id}", name="palace_manager_order_edit", requirements={"id" = "([a-z\-0-9]+)"})
  1385.      */
  1386.     public function editOrderAction(Request $request$id NULL)
  1387.     {
  1388.         $em $this->getDoctrine()->getManager();
  1389.         $order $em->getRepository('FrameworkAppBundle:Order')->findOneById($id);
  1390.         $cartTest json_decode('{"11_1685090430143":{"id":"11_1685090430143","image":"image_main.jpg","name":{"de":"Formule Étincelle","en":"Formule Étincelle","fr":"Formule Étincelle"},"slug":"bon-cadeau-4","price":100,"quantity":1,"gift":true,"for":"","attribute":null,"options":[{"id":7,"name":"Bon d’achat boutique 10€ ","qty":2,"sub_total":20},{"id":8,"name":"Bon d’achat boutique 20€ ","qty":1,"sub_total":20}]}}'true);
  1391.         return $this->render('AdminBundle/Order/edit.html.twig', [
  1392.             'cartTest' => $cartTest,
  1393.             'order' => $order,
  1394.         ]);
  1395.     }
  1396.     /**
  1397.      * @Route("/order/save/{id}", name="palace_manager_order_save", requirements={"id" = "([a-z\-0-9]+)"})
  1398.      */
  1399.     public function saveOrderAction(Request $request$id NULL)
  1400.     {
  1401.         $em $this->getDoctrine()->getManager();
  1402.         $success true;
  1403.         $error $slug '';
  1404.         $order $em->getRepository('FrameworkAppBundle:Order')->findOneById($id);
  1405.         $order->setState(intval($request->get('state')));
  1406.         $em->persist($order);
  1407.         $em->flush();
  1408.         $data = [
  1409.             'error' => $error,
  1410.             'success' => $success
  1411.         ];
  1412.         $response = new Response(json_encode($data));
  1413.         $response->headers->set('Content-Type''application/json');
  1414.         return $response;
  1415.     }
  1416.     /**
  1417.      * @Route("/routine", name="palace_manager_routine_index")
  1418.      */
  1419.     public function routineAction(Request $request)
  1420.     {
  1421.         $em $this->getDoctrine()->getManager();
  1422.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy([], ['id' => 'ASC']);
  1423.         // foreach ($bookings as $key => $booking) {
  1424.         //     $booking->setOldId($booking->getBaseId());
  1425.         //     $em->persist($booking);
  1426.         //     $em->flush();
  1427.         // }
  1428.         // $id=0;
  1429.         // foreach ($bookings as $key => $booking) {
  1430.         //   $id++;
  1431.         //     $booking->setBaseId($id);
  1432.         //     $em->persist($booking);
  1433.         //     $em->flush();
  1434.         // }
  1435.         // dump($bookings);
  1436.         echo 'DONE';
  1437.         exit;
  1438.     }
  1439.     /**
  1440.      * @Route("/resa_load", name="framework_admin_resa_load")
  1441.      */
  1442.     public function loadAction(Request $request$id null)
  1443.     {
  1444.         $em $this->getDoctrine()->getManager();
  1445.         $success true;
  1446.         $error '';
  1447.         $isAjax $request->isXMLHttpRequest();
  1448.         if (!$isAjax) {
  1449.             return $this->redirectToRoute('palace_manager_resa_index');
  1450.         }
  1451.         $future strtotime('+4 day');
  1452.         $currentPage intval$request->get('page') );
  1453.         if($currentPage == null){
  1454.             $currentPage 1;
  1455.         }
  1456.         $limit 50;
  1457.         if($request->get('search') == ''){
  1458.             if($request->get('filter') != 'all' && $request->get('filter') != NULL){
  1459.                 $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['state' => $request->get('filter')], ['alerting' => 'DESC''id' => 'DESC'], $limit, ($currentPage-1) * $limit);
  1460.                 $bookingsNbr $em->getRepository('FrameworkAppBundle:Booking')->count(['state' => $request->get('filter')]);
  1461.             } else {
  1462.                 $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy([], ['alerting' => 'DESC''id' => 'DESC'], $limit, ($currentPage-1) * $limit);
  1463.                 $bookingsNbr $em->getRepository('FrameworkAppBundle:Booking')->count([]);
  1464.             }
  1465.         } else {
  1466.             $bookings $em->getRepository('FrameworkAppBundle:Booking')->search($request->get('search'));
  1467.             $bookingsNbr sizeof($bookings);
  1468.         }
  1469.         $pagesNbr ceil($bookingsNbr $limit);
  1470.         $start = ($currentPage-1) * $limit 1;
  1471.         $end = ($currentPage) * $limit;
  1472.         if($end $bookingsNbr){
  1473.             $end $bookingsNbr;
  1474.         }
  1475.         $bookingArr = [];
  1476.         foreach ($bookings as $key => $booking) {
  1477.             // $createdAt = new \DateTime(date('Y-m-d H:i:s', strtotime($booking->getCreatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
  1478.             // $updatedAt = new \DateTime(date('Y-m-d H:i:s', strtotime($booking->getUpdatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
  1479.             $createdAt = new \DateTime(date('Y-m-d H:i:s'strtotime($booking->getCreatedAt()->format('Y-m-d H:i:s'))));
  1480.             $updatedAt = new \DateTime(date('Y-m-d H:i:s'strtotime($booking->getUpdatedAt()->format('Y-m-d H:i:s'))));
  1481.             $bg '';
  1482.             if($booking->getVenue()->getStart()->format('U') < $future){
  1483.                 if(in_array($booking->getState(), [0,1,5])){
  1484.                     $bg 'bg-danger';
  1485.                 }
  1486.             }
  1487.             if($booking->getAlerting()){
  1488.                 $bg 'bg-warning';
  1489.             }
  1490.             if($booking->getIsflash()){
  1491.                 $isflash '<br> (Ticketing)';
  1492.             } else {
  1493.                 $isflash '';
  1494.             }
  1495.             $exporting '';
  1496.             if($booking->getExported() == NULL && $booking->getIsflash() == NULL && $booking->getStatus() == 'succeeded'){
  1497.                 if($booking->getPaymentType() == 'card' || $booking->getPaymentType() == 'klarna' || $booking->getPaymentType() == 'paypal'){
  1498.                     $exporting 'yes';
  1499.                 }
  1500.             }
  1501.             $bookingArr[] = [
  1502.                 'id' =>  $booking->getId(),
  1503.                 'email' =>  $booking->getUser()->getEmail(),
  1504.                 'old_id' =>  $booking->getOldId(),
  1505.                 'base_id' =>  $booking->getBaseId(),
  1506.                 'infos' =>  $booking->getInfos(),
  1507.                 'cart' =>  $booking->getCart(),
  1508.                 'state' =>  $booking->getState(),
  1509.                 'action' =>  $booking->getAction(),
  1510.                 'venueTitle' =>  $booking->getVenuetitle(),
  1511.                 'paymentType' =>  $booking->getPaymentType(),
  1512.                 'amountTotal' =>  $booking->getAmountTotal(),
  1513.                 'stateStrAdmin' =>  $booking->getStateStrAdmin(),
  1514.                 'isflash' => $isflash,
  1515.                 'createdAt' =>  $createdAt,
  1516.                 'updatedAt' =>  $updatedAt,
  1517.                 'exporting' =>  $exporting,
  1518.                 'bg' =>  $bg
  1519.             ];
  1520.         }
  1521.         $data = [
  1522.             'error'   => $error,
  1523.             'success' => $success,
  1524.             'currentPage' => $currentPage,
  1525.             'bookingsNbr' => $bookingsNbr,
  1526.             'pagesNbr' => $pagesNbr,
  1527.             'bookings' => $bookingArr,
  1528.             'start' => $start,
  1529.             'end' => $end,
  1530.         ];
  1531.         $response = new Response(json_encode($data));
  1532.         $response->headers->set('Content-Type''application/json');
  1533.         return $response;
  1534.     }
  1535.     /**
  1536.      * @Route("/resa_refresh", name="framework_admin_resa_refresh")
  1537.      */
  1538.     public function refreshAction(Request $request$id null)
  1539.     {
  1540.         $em $this->getDoctrine()->getManager();
  1541.         $success true;
  1542.         $error '';
  1543.         $isAjax $request->isXMLHttpRequest();
  1544.         if (!$isAjax) {
  1545.             return $this->redirectToRoute('palace_manager_resa_index');
  1546.         }
  1547.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['id' => $request->get('stateArr')]);
  1548.         $refreshArr = [];
  1549.         foreach ($bookings as $key => $booking) {
  1550.             $refreshArr[$booking->getId()]['state'] = $booking->getState();
  1551.             $refreshArr[$booking->getId()]['reminder'] = $booking->getMailedCount();
  1552.             $future strtotime('+4 day');
  1553.             $bg '';
  1554.             if($booking->getVenue()->getStart()->format('U') < $future){
  1555.                 if(in_array($booking->getState(), [0,1,5])){
  1556.                     $bg 'bg-danger';
  1557.                 }
  1558.             }
  1559.             if($booking->getAlerting()){
  1560.                 $bg 'bg-warning';
  1561.             }
  1562.             $refreshArr[$booking->getId()]['bg'] = $bg;
  1563.         }
  1564.         $data = [
  1565.             'refreshArr' => $refreshArr,
  1566.         ];
  1567.         $response = new Response(json_encode($data));
  1568.         $response->headers->set('Content-Type''application/json');
  1569.         return $response;
  1570.     }
  1571.     /**
  1572.      * @Route("/export-download-full-resa/{id}", name="palace_manager_export_download_full_resa", requirements={"id" = "([a-z\-0-9]+)"})
  1573.      */
  1574.     public function exportDownloadFullResaAction(Request $request$id NULL)
  1575.     {
  1576.         $em $this->getDoctrine()->getManager();
  1577.         $globals $this->get("twig")->getGlobals();
  1578.         $export $em->getRepository('FrameworkAppBundle:Export')->findOneById($id);
  1579.         $csvFile file($export->getFile());
  1580.         $data $ids = [];
  1581.         foreach ($csvFile as $line) {
  1582.             $data[] = str_getcsv($line);
  1583.         }
  1584.         array_shift($data);
  1585.         array_pop($data);
  1586.         foreach ($data as $key => $value) {
  1587.             $tmp explode(';'$value[0]);
  1588.             $ids[] = $tmp[0];
  1589.         }
  1590.         $total $total_rs $total_am 0;
  1591.         $date date('Y-m-d_H-i-s');
  1592.         $rows = [];
  1593.         $rows[] = [
  1594.             'ID',
  1595.             'Date de paiement',
  1596.             'KDO',
  1597.             'Type',
  1598.             'Client',
  1599.             'Date',
  1600.             'Total',
  1601.             'AM',
  1602.             'RS',
  1603.             // 'ID Stripe'
  1604.         ];
  1605.         foreach ($ids as $key => $id) {
  1606.             $booking $em->getRepository('FrameworkAppBundle:Booking')->findOneBy(['genId' => $id]);
  1607.             $gift '';
  1608.             if($booking->getInfo('gift') == 'true'){
  1609.                 $gift 'KDO : '.$booking->getInfo('gift_user');
  1610.             }
  1611.             if($booking->getInfo('gift') == 'true'){
  1612.                 if( $booking->getResult() == null ){
  1613.                     $created $booking->getCreatedAt()->format('d/m/Y');
  1614.                     $result_id '';
  1615.                 } else {
  1616.                     $created date('d/m/Y'$booking->getResult()->created);
  1617.                     $result_id $booking->getResult()->id;
  1618.                 }
  1619.                 $rows[] = [
  1620.                     $booking->getBaseId(),
  1621.                     $created,
  1622.                     $gift,
  1623.                     'RESA',
  1624.                     ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  1625.                     $booking->getVenueTitle(),
  1626.                     ($booking->getAmount() + $booking->getAmountShow()),
  1627.                     $booking->getAmount(),
  1628.                     $booking->getAmountShow(),
  1629.                     // $result_id
  1630.                 ];
  1631.                 $total $total + ($booking->getAmount() + $booking->getAmountShow());
  1632.                 $total_am $total_am $booking->getAmount();
  1633.                 $total_rs $total_rs $booking->getAmountShow();
  1634.             }
  1635.         }
  1636.         //2D ROUND
  1637.         foreach ($ids as $key => $id) {
  1638.             $booking $em->getRepository('FrameworkAppBundle:Booking')->findOneBy(['genId' => $id]);
  1639.             $gift '';
  1640.             if($booking->getInfo('gift') == 'true'){
  1641.                 $gift 'KDO : '.$booking->getInfo('gift_user');
  1642.             }
  1643.             if($booking->getInfo('gift') != 'true'){
  1644.                 if( $booking->getResult() == null ){
  1645.                     $created $booking->getCreatedAt()->format('d/m/Y');
  1646.                     $result_id '';
  1647.                 } else {
  1648.                     $created date('d/m/Y'$booking->getResult()->created);
  1649.                     $result_id $booking->getResult()->id;
  1650.                 }
  1651.                 $rows[] = [
  1652.                     $booking->getBaseId(),
  1653.                     $created,
  1654.                     $gift,
  1655.                     'RESA',
  1656.                     ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  1657.                     $booking->getVenueTitle(),
  1658.                     ($booking->getAmount() + $booking->getAmountShow()),
  1659.                     $booking->getAmount(),
  1660.                     $booking->getAmountShow(),
  1661.                     // $result_id
  1662.                 ];
  1663.                 $total $total + ($booking->getAmount() + $booking->getAmountShow());
  1664.                 $total_am $total_am $booking->getAmount();
  1665.                 $total_rs $total_rs $booking->getAmountShow();
  1666.             }
  1667.         }
  1668.         $rows[] = [
  1669.             '',
  1670.             '',
  1671.             '',
  1672.             '',
  1673.             'Export détaillé : '.$date,
  1674.             $total,
  1675.             $total_am,
  1676.             $total_rs,
  1677.             ''
  1678.         ];
  1679.         //ENREGISTREMENT DU CSV
  1680.         $path str_replace('.csv''_full.csv'$export->getFile());
  1681.         $name str_replace('.csv''_full.csv'$export->getName());
  1682.         $fp fopen($path'w'); // open in write only mode (write at the start of the file)
  1683.         fprintf($fpchr(0xEF).chr(0xBB).chr(0xBF));
  1684.         foreach ($rows as $row) {
  1685.             fputcsv($fp$row";");
  1686.         }
  1687.         fclose($fp);
  1688.         header('Content-Description: File Transfer');
  1689.         header('Content-Type: application/octet-stream');
  1690.         header('Content-Disposition: attachment; filename="'.$name.'"');
  1691.         header('Content-Transfer-Encoding: binary');
  1692.         header('Expires: 0');
  1693.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1694.         header('Pragma: public');
  1695.         header('Content-Length: ' filesize($path)); //Absolute URL
  1696.         ob_clean();
  1697.         flush();
  1698.         readfile($path); //Absolute URL
  1699.         exit();
  1700.     }
  1701.     /**
  1702.      * @Route("/resa-exports-generate-manual", name="palace_manager_resa_exports_generate_manual", requirements={"id" = "([a-z\-0-9]+)"})
  1703.      */
  1704.     public function exportResaGenerateManualAction(Request $request$id NULLMailerInterface $mailer)
  1705.     {
  1706.         $success false;
  1707.         $error $slug '';
  1708.         $ids $request->get('manualExport');
  1709.         $em $this->getDoctrine()->getManager();
  1710.         $globals $this->get("twig")->getGlobals();
  1711.         $total $total_rs $total_am 0;
  1712.         $date date('Y-m-d_H-i-s');
  1713.         $rows = [];
  1714.         $rows[] = [
  1715.             'ID',
  1716.             'Date de paiement',
  1717.             'Type',
  1718.             'Paiement',
  1719.             'Client',
  1720.             'Date',
  1721.             'Total',
  1722.             'AM',
  1723.             'RS',
  1724.             'ID Stripe'
  1725.         ];
  1726.         // $bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => 1, 'status' => 'succeeded', 'paymentType' => ['card','klarna'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
  1727.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['id' => $ids], ['paymentType' => 'DESC''createdAt' => 'ASC']);
  1728.         if( sizeof($bookings) > ){
  1729.             foreach ($bookings as $key => $booking) {
  1730.                 if($booking->getInfo('gift') == 'true'){
  1731.                     if( $booking->getResult() == null ){
  1732.                         $created $booking->getCreatedAt()->format('d/m/Y');
  1733.                         $result_id '';
  1734.                     } else {
  1735.                         $created date('d/m/Y'$booking->getResult()->created);
  1736.                         $result_id $booking->getResult()->id;
  1737.                     }
  1738.                     $rows[] = [
  1739.                         $booking->getBaseId(),
  1740.                         $created,
  1741.                         'RESA (T)',
  1742.                         $booking->getPaymentType(),
  1743.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  1744.                         $booking->getVenueTitle(),
  1745.                         ($booking->getAmount() + $booking->getAmountShow()),
  1746.                         $booking->getAmount(),
  1747.                         $booking->getAmountShow(),
  1748.                         $result_id
  1749.                     ];
  1750.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  1751.                     $total_am $total_am $booking->getAmount();
  1752.                     $total_rs $total_rs $booking->getAmountShow();
  1753.                     $booking->setState(6);
  1754.                     $booking->setExported(1);
  1755.                     $em->persist($booking);
  1756.                     $em->flush();
  1757.                 }
  1758.             }
  1759.             //2D ROUND
  1760.             foreach ($bookings as $key => $booking) {
  1761.                 if($booking->getInfo('gift') != 'true'){
  1762.                     if( $booking->getResult() == null ){
  1763.                         $created $booking->getCreatedAt()->format('d/m/Y');
  1764.                         $result_id '';
  1765.                     } else {
  1766.                         $created date('d/m/Y'$booking->getResult()->created);
  1767.                         $result_id $booking->getResult()->id;
  1768.                     }
  1769.                     $rows[] = [
  1770.                         $booking->getBaseId(),
  1771.                         $created,
  1772.                         'RESA (T)',
  1773.                         $booking->getPaymentType(),
  1774.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  1775.                         $booking->getVenueTitle(),
  1776.                         ($booking->getAmount() + $booking->getAmountShow()),
  1777.                         $booking->getAmount(),
  1778.                         $booking->getAmountShow(),
  1779.                         $result_id
  1780.                     ];
  1781.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  1782.                     $total_am $total_am $booking->getAmount();
  1783.                     $total_rs $total_rs $booking->getAmountShow();
  1784.                     $booking->setState(6);
  1785.                     $booking->setExported(1);
  1786.                     $em->persist($booking);
  1787.                     $em->flush();
  1788.                 }
  1789.             }
  1790.             $rows[] = [
  1791.                 '',
  1792.                 '',
  1793.                 '',
  1794.                 '',
  1795.                 'Export : '.$date,
  1796.                 $total,
  1797.                 $total_am,
  1798.                 $total_rs,
  1799.                 ''
  1800.             ];
  1801.             //ENREGISTREMENT DU CSV
  1802.             $path $globals['export_folder'].'exports_booking/R_'.$date.'.csv';
  1803.             $fp fopen($path'w'); // open in write only mode (write at the start of the file)
  1804.             fprintf($fpchr(0xEF).chr(0xBB).chr(0xBF));
  1805.             foreach ($rows as $row) {
  1806.                 fputcsv($fp$row";");
  1807.             }
  1808.             fclose($fp);
  1809.             //ENREGISTREMENT BASE
  1810.             $export = new Export();
  1811.             $export->setType('resa');
  1812.             $export->setFile($path);
  1813.             $export->setName('R_'.$date.'.csv');
  1814.             $em->persist($export);
  1815.             $em->flush();
  1816.             //ENVOI EMAIL COMPTA
  1817.             $from $globals['app_email_noreply'];
  1818.             $to $globals['app_email_compta'];
  1819.             $contact $globals['app_email_contact'];
  1820.             $email = (new Email())
  1821.                 ->from($from)
  1822.                 ->to($to)
  1823.                 ->cc($globals['app_email_contact'])
  1824.                 //->bcc('bcc@example.com')
  1825.                 ->replyTo($contact)
  1826.                 //->priority(Email::PRIORITY_HIGH)
  1827.                 ->attachFromPath($path)
  1828.                 ->subject('Nouvel export RESERVATIONS CB Stripe '.$date)
  1829.                 ->text(nl2br('Nouvel export RESERVATIONS CB Stripe généré le '.$date));
  1830.             $mailer->send($email);
  1831.             //FIN ENVOI EMAIL COMPTA
  1832.             $success true;
  1833.         } else {
  1834.             $error 'Aucun nouveau paiement à exporter';
  1835.         }
  1836.         $data = [
  1837.             'error' => $error,
  1838.             'success' => $success
  1839.         ];
  1840.         $response = new Response(json_encode($data));
  1841.         $response->headers->set('Content-Type''application/json');
  1842.         return $response;
  1843.     }
  1844.     /**
  1845.      * @Route("/resa-exports-generate-manual-preview", name="palace_manager_resa_exports_generate_manual_preview", requirements={"id" = "([a-z\-0-9]+)"})
  1846.      */
  1847.     public function exportResaGenerateManualPreviewAction(Request $request$id NULLMailerInterface $mailer)
  1848.     {
  1849.         $success false;
  1850.         $error $slug $html '';
  1851.         $ids $request->get('manualExport');
  1852.         $em $this->getDoctrine()->getManager();
  1853.         $globals $this->get("twig")->getGlobals();
  1854.         $total $total_rs $total_am 0;
  1855.         $date date('Y-m-d_H-i-s');
  1856.         $rows = [];
  1857.         $rows[] = [
  1858.             'ID',
  1859.             'Date de paiement',
  1860.             'Type',
  1861.             'Paiement',
  1862.             'Client',
  1863.             'Date',
  1864.             'Total',
  1865.             'AM',
  1866.             'RS',
  1867.             'ID Stripe'
  1868.         ];
  1869.         // $bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => 1, 'status' => 'succeeded', 'paymentType' => ['card','klarna'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
  1870.         $bookings $em->getRepository('FrameworkAppBundle:Booking')->findBy(['id' => $ids], ['paymentType' => 'DESC''createdAt' => 'ASC']);
  1871.         if( sizeof($bookings) > ){
  1872.             foreach ($bookings as $key => $booking) {
  1873.                 if($booking->getInfo('gift') == 'true'){
  1874.                     if( $booking->getResult() == null ){
  1875.                         $created $booking->getCreatedAt()->format('d/m/Y');
  1876.                         $result_id '';
  1877.                     } else {
  1878.                         $created date('d/m/Y'$booking->getResult()->created);
  1879.                         $result_id $booking->getResult()->id;
  1880.                     }
  1881.                     $rows[] = [
  1882.                         $booking->getBaseId(),
  1883.                         $created,
  1884.                         'RESA (T)',
  1885.                         $booking->getPaymentType(),
  1886.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  1887.                         $booking->getVenueTitle(),
  1888.                         ($booking->getAmount() + $booking->getAmountShow()),
  1889.                         $booking->getAmount(),
  1890.                         $booking->getAmountShow(),
  1891.                         $result_id
  1892.                     ];
  1893.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  1894.                     $total_am $total_am $booking->getAmount();
  1895.                     $total_rs $total_rs $booking->getAmountShow();
  1896.                 }
  1897.             }
  1898.             //2D ROUND
  1899.             foreach ($bookings as $key => $booking) {
  1900.                 if($booking->getInfo('gift') != 'true'){
  1901.                     if( $booking->getResult() == null ){
  1902.                         $created $booking->getCreatedAt()->format('d/m/Y');
  1903.                         $result_id '';
  1904.                     } else {
  1905.                         $created date('d/m/Y'$booking->getResult()->created);
  1906.                         $result_id $booking->getResult()->id;
  1907.                     }
  1908.                     $rows[] = [
  1909.                         $booking->getBaseId(),
  1910.                         $created,
  1911.                         'RESA (T)',
  1912.                         $booking->getPaymentType(),
  1913.                         ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
  1914.                         $booking->getVenueTitle(),
  1915.                         ($booking->getAmount() + $booking->getAmountShow()),
  1916.                         $booking->getAmount(),
  1917.                         $booking->getAmountShow(),
  1918.                         $result_id
  1919.                     ];
  1920.                     $total $total + ($booking->getAmount() + $booking->getAmountShow());
  1921.                     $total_am $total_am $booking->getAmount();
  1922.                     $total_rs $total_rs $booking->getAmountShow();
  1923.                 }
  1924.             }
  1925.             $rows[] = [
  1926.                 '',
  1927.                 '',
  1928.                 '',
  1929.                 '',
  1930.                 'Export : '.$date,
  1931.                 $total,
  1932.                 $total_am,
  1933.                 $total_rs,
  1934.                 ''
  1935.             ];
  1936.             $html '<table class="exporting"><tbody>';
  1937.             foreach ($rows as $key => $row) {
  1938.                 $html .= '<tr>';
  1939.                 foreach ($row as $key2 => $column) {
  1940.                     $html .= '<td>'.$column.'</td>';
  1941.                 }
  1942.                 $html .= '</tr>';
  1943.             }
  1944.             $html .= '</tbody></table>';
  1945.             $success true;
  1946.         } else {
  1947.             $error 'Aucun nouveau paiement à exporter';
  1948.         }
  1949.         $data = [
  1950.             'error' => $error,
  1951.             'success' => $success,
  1952.             'html' => $html
  1953.         ];
  1954.         $response = new Response(json_encode($data));
  1955.         $response->headers->set('Content-Type''application/json');
  1956.         return $response;
  1957.     }
  1958. }