src/Controller/BookingApiController.php line 383

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ProduitThalasso;
  4. use App\Entity\TypeBar;
  5. use App\Entity\Chambre;
  6. use App\Entity\Tag;
  7. use App\Entity\CategorieThalasso;
  8. use App\Entity\Regime;
  9. use App\Entity\Supplement;
  10. use App\Entity\CmsPage;
  11. use App\Entity\CmsPageBlockComposantItems;
  12. use App\Entity\Reservation;
  13. use App\Entity\ReservationCadeau;
  14. use App\Model\Axepta;
  15. use App\Entity\ReservationChambre;
  16. use App\Entity\ReservationSupplement;
  17. use App\Entity\ReservationSoins;
  18. use App\Entity\Curiste;
  19. use App\Entity\ReservationCure;
  20. use App\Entity\ReservationEnfant;
  21. use App\Entity\ReservationParticipant;
  22. use App\Entity\TypeLit;
  23. use App\Entity\TypeArrangement;
  24. use App\Entity\Pays;
  25. use App\Entity\Programme;
  26. use App\Entity\ReservationCodePromo;
  27. use App\Entity\DispoChambre;
  28. use App\Entity\DispoSupplement;
  29. use App\Entity\DispoProduit;
  30. use App\Entity\CodePromo;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Component\Routing\Annotation\Route;
  34. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  35. use Symfony\Component\Translation\TranslatorInterface;
  36. use Symfony\Component\HttpFoundation\JsonResponse;
  37. use App\Service\FrontService;
  38. use Doctrine\ORM\EntityManagerInterface;
  39. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  40. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  41. use Symfony\Component\HttpFoundation\RequestStack;
  42. use Symfony\Component\Mailer\MailerInterface;
  43. use Symfony\Component\Mime\Email;
  44. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  45. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  46. use Knp\Snappy\Pdf;
  47. use Symfony\Component\HttpKernel\KernelInterface;
  48. use Swift_Attachment;
  49. use App\Service\BookingService;
  50. use Symfony\Component\Mailer\Mailer;
  51. use Symfony\Component\Mailer\Transport;
  52. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
  53. class BookingApiController extends AbstractController
  54. {
  55.     private $frontService;
  56.     private $em;
  57.     private $params;
  58.     private $translator;
  59.     public $Your_HMAC "G]a8!5FyBq3?f6_KRp7(*Mw4Pb9=[Hx2";
  60.     public $Your_CRYPTKEY "r*7R=Db2w6Y_)z8W";
  61.     public $Your_MERCHANTID "BNP_MIRAMAR_ECOM_FR_EUR_t";
  62.     public $TEST_PAYMODE false;
  63.     public $mode3dsv2 false;
  64.     private $session;
  65.     private $requestStack;
  66.     public function __construct(FrontService $frontServiceSessionInterface $session,  EntityManagerInterface $emTranslatorInterface $translatorRequestStack $requestStackContainerBagInterface $params)
  67.     {
  68.         $this->frontService $frontService;
  69.         $this->em $em;
  70.         $this->translator $translator;
  71.         $this->session $session;
  72.         $this->requestStack $requestStack;
  73.         $this->params $params;
  74.         //get test mode from parameters
  75.         if ($this->params->get('TEST_PAYMODE') == "true")
  76.             $this->TEST_PAYMODE true;
  77.         if (isset($_SERVER['SERVER_NAME']) && str_contains($_SERVER['SERVER_NAME'], 'digitz.dev')) 
  78.         $this->TEST_PAYMODE true;
  79.         if (!$this->TEST_PAYMODE) {
  80.             $this->Your_HMAC "6z(JD9t_7r=R]3NaEc4)8!qGoC*5Z[2j";
  81.             $this->Your_CRYPTKEY "c(4MZ9o)_L8yw!Y2";
  82.             $this->Your_MERCHANTID "BNP_MIRAMAR_ECOM_FR_EUR";
  83.             $this->mode3dsv2 true;
  84.         } else {
  85.             //Environnement de Test 3DSV2 miramar
  86.             $this->Your_HMAC "G]a8!5FyBq3?f6_KRp7(*Mw4Pb9=[Hx2";
  87.             $this->Your_CRYPTKEY "r*7R=Db2w6Y_)z8W";
  88.             $this->Your_MERCHANTID "BNP_MIRAMAR_ECOM_FR_EUR_t";
  89.             //Environnement de Test 3DSV2 demo BNP
  90.             /*$this->Your_HMAC = "4n!BmF3_?9oJ2Q*z(iD7q6[RSb5)a]A8";
  91.             $this->Your_CRYPTKEY = "Tc5*2D_xs7B[6E?w";
  92.             $this->Your_MERCHANTID = "BNP_DEMO_AXEPTA";
  93.             $this->mode3dsv2 = true;*/
  94.         }
  95.     }
  96.     /**
  97.      * @Route("/bookapi/api-search-params/{lang}")
  98.      */
  99.     public function getSearchParams($lang 'fr'$selected_params = [])
  100.     {
  101.         // $selected_params = [
  102.         //     "type_bar" => "2",
  103.         //     "date_start" => "01/06/2021",
  104.         //     "adults" => "1",
  105.         //     "children" => "1",
  106.         //     "duration" => "1",
  107.         //     "pageSize" => 10,
  108.         //     "page" => 1
  109.         //     ];
  110.         $mode_residence $this->frontService->getResidenceMode();
  111.         $selected_params $this->session->get('search_params');
  112.         if (empty($selected_params) and $this->session->get('search_params')) {
  113.             $selected_params $this->session->get('search_params');
  114.         }
  115.         $setsitems = [];
  116.         # get type bars with there items
  117.         $type_bars $this->em->getRepository(TypeBar::class)->getTypeBar($lang);
  118.         $selected = [];
  119.         foreach ($type_bars as $tb_key => $type_bar) {
  120.             $set_val = [];
  121.             $to_show false;
  122.             if ($type_bar['id'] == $this->getParameter('thalasso_avec_hebergement_id')) {
  123.                 $set_val = ["calendar""nights""program"];
  124.                 $to_show true;
  125.             } elseif ($type_bar['id'] == $this->getParameter('thalasso_sans_hebergement_id')) {
  126.                 $type_bar['nom_type_bar'] = "Thalasso & SPA";
  127.                 $set_val = ["calendar""persons""type"];
  128.                 $to_show true;
  129.             } elseif ($type_bar['id'] == $this->getParameter('hotel_seul_id')) {
  130.                 $set_val =  ["calendar""adults""children""duration"];
  131.                 $to_show true;
  132.             }
  133.             if ($to_show == true) {
  134.                 if ($type_bar['id'] == && $this->frontService->getResidenceMode())
  135.                     $selected[] = ['id' => $type_bar['id'], 'label' => $this->translator->trans("filtre_bar.titre"), 'set' => $set_val];
  136.                 else
  137.                     $selected[] = ['id' => $type_bar['id'], 'label' => $type_bar['nom_type_bar'], 'set' => $set_val];
  138.             }
  139.         }
  140.         $selected[] = ['id' => "Idées cadeaux"'label' => $this->translator->trans("filtre_bar.cadeau"), 'set' => ["persons""cures""price-steps"]];
  141.         # calendar
  142.         if (isset($selected_params['date_start'])) {
  143.             $selected_calendar $selected_params['date_start'];
  144.         } else {
  145.             $selected_calendar date("Y-m-d");
  146.         }
  147.         $setsitems[] = ['item' => 'calendar''icon' => "calendar"'text' => $this->translator->trans("filtre_bar.arrivee"), 'value' => $selected_calendar];
  148.         #
  149.         # adults
  150.         if (isset($selected_params['adults'])) {
  151.             $selected_adulte = ['id' => $selected_params['adults'], "text" => $selected_params['adults']];
  152.         } else {
  153.             $selected_adulte = ['id' => "1""text" => "1"];
  154.         }
  155.         //$selected_adulte=$selected_adulte["id"];
  156.         $setsitems[] = [
  157.             'item' => 'adults''text' => $this->translator->trans("filtre_bar.adults"), 'icon' => "adult"'value' => $selected_adulte,
  158.             'values' => [
  159.                 ['id' => "1""text" => "1"],
  160.                 ['id' => "2""text" => "2"],
  161.                 ['id' => "3""text" => "3"],
  162.                 ['id' => "4""text" => "4"],
  163.                 ['id' => "5""text" => "5"],
  164.                 ['id' => "6""text" => "6"],
  165.             ]
  166.         ];
  167.         # children
  168.         if (isset($selected_params['children'])) {
  169.             $selected_child = ['id' => $selected_params['children'], "text" => $selected_params['children']];
  170.         } else {
  171.             $selected_child = ['id' => "0""text" => "0"];
  172.         }
  173.         $setsitems[] = [
  174.             'item' => 'children''icon' => "child"'text' => $this->translator->trans("filtre_bar.children"), 'value' => $selected_child,
  175.             'values' => [
  176.                 ['id' => "0""text" => "0"],
  177.                 ['id' => "1""text" => "1"],
  178.                 ['id' => "2""text" => "2"],
  179.                 ['id' => "3""text" => "3"],
  180.             ]
  181.         ];
  182.         # person
  183.         if (isset($selected_params['persons'])) {
  184.             $selected_persons = ['id' => $selected_params['persons'], "text" => $selected_params['persons']];
  185.         } else {
  186.             $selected_persons = ['id' => "1""text" => "1"];
  187.         }
  188.         $setsitems[] = [
  189.             'item' => 'persons''icon' => "adult"'text' => $this->translator->trans("filtre_bar.nbrpersonnes"), 'value' => $selected_persons,
  190.             'values' => [
  191.                 ['id' => "1""text" => "1"],
  192.                 ['id' => "2""text" => "2"],
  193.             ]
  194.         ];
  195.         # duration hôtel
  196.         if (!$mode_residence) {
  197.             $duration_values = [
  198.                 ['id' => "1""text" => "1 " $this->translator->trans("filtre_bar.night")],
  199.                 ['id' => "2""text" => "2 " $this->translator->trans("filtre_bar.nights")], ['id' => "3""text" => "3 " $this->translator->trans("filtre_bar.nights")],
  200.                 ['id' => "4""text" => "4 " $this->translator->trans("filtre_bar.nights")], ['id' => "5""text" => "5 " $this->translator->trans("filtre_bar.nights")],
  201.                 ['id' => "6""text" => "6 " $this->translator->trans("filtre_bar.nights")],
  202.                 ['id' => "7""text" => "7 " $this->translator->trans("filtre_bar.nights")], ['id' => "8""text" => "8 " $this->translator->trans("filtre_bar.nights")],
  203.                 ['id' => "9""text" => "9 " $this->translator->trans("filtre_bar.nights")], ['id' => "10""text" => "10 " $this->translator->trans("filtre_bar.nights")],
  204.                 ['id' => "11""text" => "11 " $this->translator->trans("filtre_bar.nights")], ['id' => "12""text" => "12 " $this->translator->trans("filtre_bar.nights")],
  205.                 ['id' => "13""text" => "13 " $this->translator->trans("filtre_bar.nights")], ['id' => "14""text" => "14 " $this->translator->trans("filtre_bar.nights")],
  206.                 ['id' => "15""text" => "15 " $this->translator->trans("filtre_bar.nights")],
  207.             ];
  208.             $selected_duration = ['id' => "1""text" => "1 " $this->translator->trans("filtre_bar.night")];
  209.         } else {
  210.             $duration_values = [
  211.                 ['id' => "2""text" => "2 " $this->translator->trans("filtre_bar.nights")], ['id' => "3""text" => "3 " $this->translator->trans("filtre_bar.nights")],
  212.                 ['id' => "4""text" => "4 " $this->translator->trans("filtre_bar.nights")], ['id' => "5""text" => "5 " $this->translator->trans("filtre_bar.nights")],
  213.                 ['id' => "6""text" => "6 " $this->translator->trans("filtre_bar.nights")],
  214.                 ['id' => "7""text" => "7 " $this->translator->trans("filtre_bar.nights")], ['id' => "8""text" => "8 " $this->translator->trans("filtre_bar.nights")],
  215.                 ['id' => "9""text" => "9 " $this->translator->trans("filtre_bar.nights")], ['id' => "10""text" => "10 " $this->translator->trans("filtre_bar.nights")],
  216.                 ['id' => "11""text" => "11 " $this->translator->trans("filtre_bar.nights")], ['id' => "12""text" => "12 " $this->translator->trans("filtre_bar.nights")],
  217.                 ['id' => "13""text" => "13 " $this->translator->trans("filtre_bar.nights")], ['id' => "14""text" => "14 " $this->translator->trans("filtre_bar.nights")],
  218.                 ['id' => "15""text" => "15 " $this->translator->trans("filtre_bar.nights")],
  219.             ];
  220.             $selected_duration = ['id' => "2""text" => "2 " $this->translator->trans("filtre_bar.nights")];
  221.         }
  222.         if (isset($selected_params['duration'])) {
  223.             $selected_duration = [];
  224.             foreach ($duration_values as $duration_val) {
  225.                 if ($duration_val['id'] == $selected_params['duration']) {
  226.                     //$selected_duration = ['id' => $selected_params['duration'], "text" => $selected_params['duration'] . " " . $this->translator->trans("filtre_bar.nights")];
  227.                     $selected_duration = ['id' => $selected_params['duration'], "text" => $this->translator->trans("filtre_bar.night.selected", ['%count%' => $selected_params['duration']])];
  228.                     break;
  229.                 }
  230.             }
  231.         }
  232.         $setsitems[] = ['item' => 'duration''icon' => "moon"'text' => $this->translator->trans("filtre_bar.stay"), 'value' => $selected_duration'values' => $duration_values];
  233.         # nigths
  234.         $nigths_values = [
  235.             ['id' => "6""text" => $this->translator->trans("filtre_bar.longsejoursix")],
  236.             ['id' => "4""text" => $this->translator->trans("filtre_bar.longsejourquatre")],
  237.             ['id' => "3""text" => $this->translator->trans("filtre_bar.courtsejour")],
  238.         ];
  239.         $selected_nigths = ['id' => "1""text" => $this->translator->trans("filtre_bar.courtsejour")];
  240.         if (isset($selected_params['nigths'])) {
  241.             $selected_nigths = [];
  242.             foreach ($nigths_values as $nigth_vals) {
  243.                 if ($nigth_vals['id'] == $selected_params['nigths']) {
  244.                     $selected_nigths = ['id' => $selected_params['nigths'], "text" => $nigth_vals['text']];
  245.                     break;
  246.                 }
  247.             }
  248.         }
  249.         $setsitems[] = ['item' => 'nights''icon' => "moon"'text' => $this->translator->trans("filtre_bar.stay"), 'value' => $selected_nigths'values' => $nigths_values];
  250.         # nigths cadeau
  251.         $duration_cadeau_values = [
  252.             ['id' => "1""text" => "1 " $this->translator->trans("filtre_bar.night")],
  253.             ['id' => "2""text" => "2 " $this->translator->trans("filtre_bar.nights")], ['id' => "3""text" => "3 " $this->translator->trans("filtre_bar.nights")],
  254.             ['id' => "4""text" => "4 " $this->translator->trans("filtre_bar.nights")], ['id' => "5""text" => "5 " $this->translator->trans("filtre_bar.nights")],
  255.             ['id' => "6""text" => "6 " $this->translator->trans("filtre_bar.nights")],
  256.             ['id' => "7""text" => "7 " $this->translator->trans("filtre_bar.nights")], ['id' => "8""text" => "8 " $this->translator->trans("filtre_bar.nights")],
  257.             ['id' => "9""text" => "9 " $this->translator->trans("filtre_bar.nights")], ['id' => "10""text" => "10 " $this->translator->trans("filtre_bar.nights")],
  258.             ['id' => "11""text" => "11 " $this->translator->trans("filtre_bar.nights")], ['id' => "12""text" => "12 " $this->translator->trans("filtre_bar.nights")],
  259.             ['id' => "13""text" => "13 " $this->translator->trans("filtre_bar.nights")], ['id' => "14""text" => "14 " $this->translator->trans("filtre_bar.nights")],
  260.             ['id' => "15""text" => "15 " $this->translator->trans("filtre_bar.nights")],
  261.         ];
  262.         $selected_duration_cadeau = ['id' => "1""text" => "1 " $this->translator->trans("filtre_bar.night")];
  263.         if (isset($selected_params['duration-cadeau'])) {
  264.             $selected_duration_cadeau = [];
  265.             foreach ($duration_cadeau_values as $duration_val) {
  266.                 if ($duration_val['id'] == $selected_params['duration-cadeau']) {
  267.                     $selected_duration_cadeau = ['id' => $selected_params['duration-cadeau'], "text" => $selected_params['duration-cadeau'] . " " $this->translator->trans("filtre_bar.nights")];
  268.                     break;
  269.                 }
  270.             }
  271.         }
  272.         $setsitems[] = ['item' => 'duration-cadeau''icon' => "moon"'text' => "Nuits"'value' => $selected_duration_cadeau'values' => $duration_cadeau_values];
  273.         # cures
  274.         $cures $this->em->getRepository(Tag::class)->getTags($id false$lang2);
  275.         foreach ($cures as $tg_key => $cure) {
  276.             $cures_vals[] = ['id' => 'tag-' $cure['id'], 'text' => $cure['label']];
  277.         }
  278.         $cure_selected_val $cures_vals[0];
  279.         if (isset($selected_params['cures'])) {
  280.             foreach ($cures_vals as $cure) {
  281.                 if ($selected_params['cures'] == $cure['id']) {
  282.                     $cure_selected_val = ['id' => $cure['id'], 'text' => $cure['text']];
  283.                     break;
  284.                 }
  285.             }
  286.         }
  287.         $setsitems[] = ['item' => 'cures''text' => $this->translator->trans("filtre_bar.objectifs"), 'icon' => "pool-stairs"'value' => $cure_selected_val'values' => $cures_vals];
  288.         # price-steps
  289.         $price_steps_vals = [
  290.             ['id' => 1"text" => $this->translator->trans("filtre_bar.budget.nondefini")],
  291.             ['id' => 2"text" => $this->translator->trans("filtre_bar.budget.entre0et150")],
  292.             ['id' => 3"text" => $this->translator->trans("filtre_bar.budget.entre150et300")],
  293.             ['id' => 4"text" => $this->translator->trans("filtre_bar.budget.plus300")],
  294.         ];
  295.         $price_steps_selected_val $price_steps_vals[0];
  296.         if (isset($selected_params['price-steps'])) {
  297.             foreach ($price_steps_vals as $price_step) {
  298.                 if ($selected_params['price-steps'] == $price_step['id']) {
  299.                     $price_steps_selected_val = ['id' => $price_step['id'], 'text' => $price_step['text']];
  300.                     break;
  301.                 }
  302.             }
  303.         }
  304.         $setsitems[] = [
  305.             'item' => 'price-steps''text' => $this->translator->trans("filtre_bar.prix"), 'icon' => "euro"'value' =>  $price_steps_selected_val,
  306.             'values' => $price_steps_vals
  307.         ];
  308.         # get tags
  309.         $tags $this->em->getRepository(Tag::class)->getTags($id false$lang9);
  310.         $tag_holder = [];
  311.         $tag_holder['item'] = 'program';
  312.         $tag_holder['icon'] = 'pool-stairs';
  313.         $tag_holder['text'] = $this->translator->trans("filtre_bar.objectifs");
  314.         $tag_holder['value'] = ['id' => "tous""text" => $this->translator->trans("filtre_bar.tous")];
  315.         $tag_holder['values'][] = ['id' => "tous""text" => $this->translator->trans("filtre_bar.tous")];
  316.         foreach ($tags as $tg_key => $tag) {
  317.             if (isset($selected_params['program']) and $tag['id'] == $selected_params['program']) {
  318.                 $tag_holder['value'] = ['id' => $tag['id'], "text" => $tag['label']];
  319.             }
  320.             $tag_holder['values'][] = ['id' => $tag['id'], "text" => $tag['label']];
  321.         }
  322.         $setsitems[] = $tag_holder;
  323.         unset($tags);
  324.         unset($tag_holder);
  325.         # get categorie thalasso 
  326.         $tags $this->em->getRepository(Tag::class)->getTags($id false$lang2);
  327.         foreach ($tags as $tg_key => $tag) {
  328.             $type_sejour_vals[] = ['id' => 'tag-' $tag['id'], 'text' => $tag['label']];
  329.         }
  330.         $type_sejour_selected_val $type_sejour_vals[0];
  331.         if (isset($selected_params['type'])) {
  332.             foreach ($type_sejour_vals as $type_sejour) {
  333.                 if ($selected_params['type'] == $type_sejour['id']) {
  334.                     $type_sejour_selected_val = ['id' => $type_sejour['id'], 'text' => $type_sejour['text']];
  335.                     break;
  336.                 }
  337.             }
  338.         }
  339.         $categ_prod_holder = [];
  340.         $categ_prod_holder['item'] = 'type';
  341.         $categ_prod_holder['icon'] = 'pool-stairs';
  342.         $categ_prod_holder['text'] = $this->translator->trans("filtre_bar.categories");
  343.         $categ_prod_holder['value'] = $type_sejour_selected_val;
  344.         $categ_prod_holder['values'] = $type_sejour_vals;
  345.         $setsitems[] = $categ_prod_holder;
  346.         #
  347.         return new JsonResponse(['selected' => $selected'setsitems' => $setsitems]);
  348.     }
  349.     /**
  350.      * @Route("/api-recherche", name="api_search")
  351.      * 
  352.      */
  353.     public function getSearchResult($searchParams = [], $lang 'fr')
  354.     {
  355.         // if(isset($_POST)){
  356.         //     dump($_POST);exit;
  357.         // }
  358.         # init
  359.         $params $searchParams;
  360.         // reformat date
  361.         if (isset($params['date_start'])) {
  362.             $params['date_start'] = date("Y-m-d"strtotime(str_replace('/''-'$params['date_start'])));
  363.         }
  364.         # verify type_bar 
  365.         if (!empty($params)) {
  366.             if (in_array($params['type_bar'], [$this->getParameter('thalasso_avec_hebergement_id'), $this->getParameter('thalasso_sans_hebergement_id')])) {
  367.                 # prepare params that need to be sent to get the data
  368.                 # extract date_arrivee_exigee from date_start
  369.                 # Arrivée le même jour' => '0',
  370.                 if ($params['date_start'] == date("Y-m-d")) {
  371.                     $params['date_arrivee_exigee'] = "0";
  372.                 }
  373.                 # Arrivée la veille' => '-1',
  374.                 else {
  375.                     $params['date_arrivee_exigee'] = "-1";
  376.                 }
  377.                 #
  378.                 if ($params['type_bar'] == $this->getParameter('thalasso_avec_hebergement_id')) {
  379.                     # type tarif
  380.                     $params['tbl_tarif'] = 'tarifProduitThalassoChambres';
  381.                     # type hebergement
  382.                     $params['hebergement'] = "'avec', 'avec_sans_hebergement'";
  383.                 } else {
  384.                     # type tarif
  385.                     $params['tbl_tarif'] = 'tarifProduitThalassos';
  386.                     # type hebergement
  387.                     $params['hebergement'] = "'sans'";
  388.                 }
  389.                 # get date end from range between (nights) and date start
  390.                 if (isset($params['nights']) and intval($params['nights']) != 0) {
  391.                     $nbr_nights  intval($params['nights']);
  392.                 }
  393.                 if (isset($params['duration'])  and intval($params['duration']) != 0) {
  394.                     $nbr_nights  intval($params['duration']);
  395.                 }
  396.                 if (isset($nbr_nights)) {
  397.                     # nbr nuit to jours 
  398.                     $nbr_jours intval($nbr_nights);
  399.                     # date end val
  400.                     $date_end = new \DateTime($params['date_start']);
  401.                     $date_end->modify('+' $nbr_jours ' days');
  402.                     $params['date_end'] = $date_end->format("Y-m-d");
  403.                 } else {
  404.                     $nbr_nights 1;
  405.                 }
  406.                 if ($params['type_bar'] == $this->getParameter('thalasso_sans_hebergement_id')) {
  407.                     $date_end = new \DateTime($params['date_start']);
  408.                     $date_end->modify('+1 days');
  409.                     $params['date_end'] = $date_end->format("Y-m-d");
  410.                     $nbr_nights 1;
  411.                 }
  412.                 # get nbr days between start and end 
  413.                 $params['nbr_duration'] = $nbr_nights;
  414.                 #
  415.                 # count data
  416.                 /*$data_count = $this->em->getRepository(ProduitThalasso::class)->getApiSearchProducts($params, $lang, $count_data = true);
  417.                 $max_page = ceil($data_count / $params['pageSize']);*/
  418.                 $max_page 10;
  419.                 # get data
  420.                 if (false or intval($params['page']) > $max_page) {
  421.                     $jsn_res = ['response' => ['type_bar' => $this->getParameter('thalasso_avec_hebergement'), 'id_type_bar' => $params['type_bar'], 'type_result' => 'produit''msg' => "La page numéro '" $params['page'] . "' n'existe pas. Le numéro de page maximal est '" $max_page "'"], 'status' => 204];
  422.                 } else {
  423.                     $result $this->em->getRepository(ProduitThalasso::class)->getApiSearchProducts($params$lang$count_data false$params['pageSize'], $params['page']);
  424.                     // return new JsonResponse($result);
  425.                     # integrate media to the result
  426.                     $result $this->integrateMedia($result'ProduitThalasso''id_produit'$lang);
  427.                     # type bar
  428.                     if ($params['type_bar'] == $this->getParameter('thalasso_avec_hebergement_id')) {
  429.                         $type_bar $this->getParameter('thalasso_avec_hebergement');
  430.                     } elseif ($params['type_bar'] == $this->getParameter('thalasso_sans_hebergement_id')) {
  431.                         $type_bar $this->getParameter('thalasso_spa');
  432.                     }
  433.                     #
  434.                     $jsn_res = [
  435.                         'response' => [
  436.                             'arrival' => date("d-m-Y"strtotime($params['date_start'])),
  437.                             'departure' => date("d-m-Y"strtotime($params['date_end'])),
  438.                             'type_bar' => $type_bar,
  439.                             'id_type_bar' => $params['type_bar'],
  440.                             'type_result' => 'produit',
  441.                             'results' => $result
  442.                         ],
  443.                         'status' => 200
  444.                     ];
  445.                 }
  446.                 #
  447.             } elseif ($params['type_bar'] == $this->getParameter('hotel_seul_id')) {
  448.                 # prepare params that need to be sent to get the data
  449.                 # get date end from range between (nights) and date start
  450.                 if (isset($params['nights']) and intval($params['nights']) != 0) {
  451.                     $nbr_nights  intval($params['nights']);
  452.                 }
  453.                 if (isset($params['duration'])  and intval($params['duration']) != 0) {
  454.                     $nbr_nights  intval($params['duration']);
  455.                 }
  456.                 if (isset($nbr_nights) and intval($nbr_nights) != 0) {
  457.                     # nbr nuit to jours 
  458.                     $nbr_jours intval($nbr_nights);
  459.                     # date end val
  460.                     $date_end = new \DateTime($params['date_start']);
  461.                     $date_end->modify('+' $nbr_jours ' days');
  462.                     $params['date_end'] = $date_end->format("Y-m-d");
  463.                 } else {
  464.                     $nbr_nights 1;
  465.                 }
  466.                 # get nbr days between start and end 
  467.                 $params['nbr_duration'] = $nbr_nights;
  468.                 #
  469.                 # count data
  470.                 $mode_residence $this->frontService->getResidenceMode();
  471.                 /*$data_count = $this->em->getRepository(Chambre::class)->getApiSearchChambres($params, $lang, $count_data = true, 10, 1, $mode_residence);
  472.                 # get data for group if data_count = 0
  473.                 // if($data_count == 0){
  474.                 //     # remove children and adultes capisity from the params
  475.                 //         unset($params['children']);
  476.                 //         unset($params['adults']);
  477.                 //     # check availability 
  478.                 //     $data_count = $this->em->getRepository(Chambre::class)->getApiSearchChambres($params, $lang, $count_data = true);
  479.                 //     # change type results to chambres_group
  480.                 //         $type_results = 'chambres_group';
  481.                 //     #
  482.                 // }else{
  483.                 //     $type_results = 'chambre';
  484.                 // }
  485.                 # get data
  486.                 $max_page = ceil($data_count / $params['pageSize']);*/
  487.                 $max_page 10;
  488.                 if (false or intval($params['page']) > $max_page) {
  489.                     $jsn_res = ['response' => ['type_bar' => $this->getParameter('hotel_seul'), 'id_type_bar' => $params['type_bar'], 'type_result' => 'chambre''msg' => "La page numéro '" $params['page'] . "' n'existe pas. Le numéro de page maximal est '" $max_page "'"], 'status' => 204];
  490.                 } else {
  491.                     $result $this->em->getRepository(Chambre::class)->getApiSearchChambres($params$lang$count_data false$params['pageSize'], $params['page'], $mode_residence);
  492.                     # integrate media to the result
  493.                     $result $this->integrateMedia($result'Chambre''id'$lang);
  494.                     #
  495.                     $jsn_res = [
  496.                         'response' => [
  497.                             'arrival' => date("d-m-Y"strtotime($params['date_start'])),
  498.                             'departure' => date("d-m-Y"strtotime($params['date_end'])),
  499.                             'type_bar' => $this->getParameter('hotel_seul'),
  500.                             'id_type_bar' => $params['type_bar'],
  501.                             'type_result' => 'chambre',
  502.                             'results' => $result
  503.                         ],
  504.                         'status' => 200
  505.                     ];
  506.                 }
  507.                 #
  508.             } elseif ($params['type_bar'] == "Idées cadeaux") {
  509.                 # type tarif
  510.                 $params['tbl_tarif'] = 'tarifProduitThalassos';
  511.                 # type hebergement
  512.                 $params['hebergement'] = "'sans'";
  513.                 # init date start date end
  514.                 $params['date_start'] = date("Y-m-d");
  515.                 $date_end = new \DateTime($params['date_start']);
  516.                 $date_end->modify('+1 days');
  517.                 $params['date_end'] = $date_end->format("Y-m-d");
  518.                 # init type bar
  519.                 $type_bar $params['type_bar'];
  520.                 # init type bar
  521.                 $params['type'] = $params['cures'];
  522.                 $result $this->em->getRepository(ProduitThalasso::class)->getApiSearchCadeau($params$lang$count_data false$params['pageSize'], $params['page']);
  523.                 // return new JsonResponse($result);
  524.                 # integrate media to the result
  525.                 $result $this->integrateMedia($result'ProduitThalasso''id_produit'$lang);
  526.                 # type bar
  527.                 if ($params['type_bar'] == $this->getParameter('thalasso_avec_hebergement_id')) {
  528.                     $type_bar $this->getParameter('thalasso_avec_hebergement');
  529.                 } elseif ($params['type_bar'] == $this->getParameter('thalasso_sans_hebergement_id')) {
  530.                     $type_bar $this->getParameter('thalasso_spa');
  531.                 }
  532.                 #
  533.                 //unset results not in rangeprice
  534.                 $min 0;
  535.                 $max 10000000;
  536.                 if ($params['price-steps'] == 2) {
  537.                     $min 0;
  538.                     $max 150;
  539.                 }
  540.                 if ($params['price-steps'] == 3) {
  541.                     $min 150;
  542.                     $max 300;
  543.                 }
  544.                 if ($params['price-steps'] == 4) {
  545.                     $min 300;
  546.                     $max 10000000;
  547.                 }
  548.                 foreach ($result as $key => $res) {
  549.                     if (!(intval($res["price"]) >= $min &&  intval($res["price"]) <= $max))
  550.                         unset($result[$key]);
  551.                 }
  552.                 $jsn_res = [
  553.                     'response' => [
  554.                         'arrival' => date("d-m-Y"strtotime($params['date_start'])),
  555.                         'departure' => date("d-m-Y"strtotime($params['date_end'])),
  556.                         'type_bar' => $type_bar,
  557.                         'id_type_bar' => $params['type_bar'],
  558.                         'type_result' => 'produit',
  559.                         'results' => $result
  560.                     ],
  561.                     'status' => 200
  562.                 ];
  563.             } else {
  564.                 $jsn_res = ['response' => ['msg' => 'in dev phase'], 'status' => 501];
  565.             }
  566.         } else {
  567.             $jsn_res = ['response' => ['msg' => 'redirect'], 'status' => 404];
  568.         }
  569.         return new JsonResponse(array_merge($jsn_res, ['params' => $params]));
  570.         #
  571.     }
  572.     public function integrateMedia($data$class_name$id_name$lang$media_format 'search')
  573.     {
  574.         $result $data;
  575.         /*echo "<pre>";
  576.         var_dump($result);
  577.         echo "</pre>"; 
  578.         die;*/
  579.         # loop through result 
  580.         foreach ($result as $item_key => $item) {
  581.             # get item-object by id
  582.             $item_obj $this->em->getRepository('App\Entity\\' $class_name)->findOneById($item[$id_name]);
  583.             # get item-media loop througth the media 
  584.             $cover_exist false;
  585.             $media_data null;
  586.             $getter_name 'get' $class_name 'Photos';
  587.             $nbr_media $item_obj->$getter_name()->count() - 1;
  588.             foreach ($item_obj->$getter_name() as $media_key => $media) {
  589.                 # get cover if not exist get last media image
  590.                 if ($media->getCover()) {
  591.                     $media_obj $media;
  592.                 } elseif ($nbr_media == $media_key and !$cover_exist) {
  593.                     $cover_exist true;
  594.                     $media_obj $media;
  595.                 } else {
  596.                     $media_obj false;
  597.                 }
  598.                 # get media url
  599.                 if ($media_obj) {
  600.                     $media_data $this->frontService->getMediaPublicUrl($media->getSonataImage(), $media_format$media->getTranslation('alt_img'$lang));
  601.                     unset($media_data['placement']);
  602.                     break;
  603.                 }
  604.                 #
  605.             }
  606.             $result[$item_key]['image'] = $media_data;
  607.             # rform duration if exist 
  608.             if (isset($item['duration']) && isset($item['duree_jours']) && isset($item['duree_nuitee'])) {
  609.                 $result[$item_key]['duration'] = (intval($item['duree_jours'])) . " " $this->translator->trans("result.hotelSeul.jours") . " " intval($item['duree_nuitee']) . " " $this->translator->trans("result.hotelSeul.nuits");
  610.             } else
  611.                 $result[$item_key]['duration'] = "";
  612.             # rform price if exist 
  613.             if (isset($item['tarif_ids']) and $item['tarif_ids'] != null) {
  614.                 //  split tarif 
  615.                 $nbr_tarif count(explode(','$result[$item_key]['tarif_ids']));
  616.                 $prix_total 0;
  617.                 // loop through tarif hoolder and store prices 
  618.                 foreach (explode(','$result[$item_key]['tarif_ids']) as $trf_prix) {
  619.                     $prix_total intval(explode('|'$trf_prix)[1]) + $prix_total;
  620.                 }
  621.                 $result[$item_key]['price'];
  622.                 //
  623.                 $result[$item_key]['price'] = $prix_total "€";
  624.                 $result[$item_key]['realPrice'] = ($prix_total $nbr_tarif) . "€";
  625.                 //fix for supplement and soin
  626.                 if ($media_format == "soinsreservation")
  627.                     $result[$item_key]['price'] = $result[$item_key]['realPrice'];
  628.             }
  629.             # this is for products
  630.             // list:'<ul><li>prix par personne, base 2 curiste(s) en chambre "Passerelle"</li><li>demi pension</li></ul>',
  631.             $list_holder "";
  632.             if (isset($item['id_produit'])) {
  633.                 if (isset($item['chambre_data']) and isset($item['regime_data'])) {
  634.                     $list_holder .= '<ul data-chambres = "' $item['chambre_data'] . '" data-regime = "' $item['regime_data'] . '" >';
  635.                     # get chambre data  [id, label, icon]
  636.                     if ($item['chambre_data'] != null) {
  637.                         $chambre_data = [];
  638.                         if ($item['chambre_data'] != null) {
  639.                             $chambr_trf_holder = [];
  640.                             $chmbr_label_holder = []; // prevent duplicated chambre name
  641.                             foreach (explode(','$item['chambre_data']) as $index => $chambre) {
  642.                                 # get min produitChambre price 
  643.                                 foreach (explode(','$item['tarif_ids']) as $key => $tarif_id) {
  644.                                     //  (($chambre[0], $tarif_id[0]) tarif_id) and (chambre[1] is chmbr-id ) and ( $tarif_id is prix id)
  645.                                     if (explode('|'$chambre)[0] == explode('|'$tarif_id)[0]) {
  646.                                         if (!isset($chambr_trf_holder['chmbr-' explode('|'$chambre)[1]])) {
  647.                                             $chambr_trf_holder['chmbr-' explode('|'$chambre)[1]] = 0;
  648.                                         }
  649.                                         $chambr_trf_holder['chmbr-' explode('|'$chambre)[1]] += floatval(number_format(explode('|'$tarif_id)[1], 2));
  650.                                     }
  651.                                 }
  652.                                 # get chambre label (explode('|', $chambre)[2] ==> chambre label)
  653.                                 /*  if(in_array(explode('|', $chambre)[2], $chmbr_label_holder)){
  654.                                                 continue;
  655.                                             }else{
  656.                                                 $chmbr_label_holder[] = explode('|', $chambre)[2];
  657.                                             }
  658.                                             $chmbr_label = explode('|', $chambre)[2];
  659.                                             $chmbr_id = explode('|', $chambre)[1];
  660.                                             $list_holder .= "<li >";
  661.                                             $list_holder .= "static[prix par personne, base 2 curiste(s) en chambre] ";
  662.                                             $list_holder .= '"'.$chmbr_label.'"';
  663.                                             $list_holder .= "</li>";*/
  664.                                 #
  665.                             }
  666.                             # get min tarif price 
  667.                             $result[$item_key]['price'] = min(array_values($chambr_trf_holder)) . "€";
  668.                         }
  669.                     }
  670.                     # get regime data
  671.                     if ($item['regime_data'] != null) {
  672.                         $regime_names = [];
  673.                         $list_holder .= "<li >";
  674.                         if ($item['regime_data'] != null)
  675.                             foreach (explode(','$item['regime_data']) as $regimekey => $regime) {
  676.                                 $regime_names[] = explode('|'$regime)[1];
  677.                             }
  678.                         $list_holder .= implode(', '$regime_names) . "</li>";
  679.                     }
  680.                     #
  681.                     $list_holder .= "</ul>";
  682.                     # generate link url
  683.                     # get page slug by product id
  684.                     $page_route_item $this->em->getRepository(CmsPageBlockComposantItems::class)->GetSlugByProduct($item['id_produit'], $lang);
  685.                     $page_route_cmspage $this->em->getRepository(CmsPage::class)->GetSlugByProduct($item['id_produit'], $lang);
  686.                     $page_route_signature $this->generateUrl('process_choice_signature', ['idp' => $item['id_produit']]);
  687.                     $page_route_signature_gift $this->generateUrl('process_choice_signature_gift', ['idp' => $item['id_produit'], "g" => 1]);
  688.                     # case page by category                                        
  689.                     $page_route "";
  690.                     if (array_key_exists('id_cat'$item)) {
  691.                         if (in_array($item['id_cat'], [345]))
  692.                             $page_route $page_route_signature;
  693.                         if (in_array($item['id_cat'], [1]))
  694.                             $page_route $this->generateUrl('render_mlc_pages', ['_locale' => $lang'slug' => $page_route_item['content'], 'hostname' => $_SERVER['HTTP_HOST']]);
  695.                         if (in_array($item['id_cat'], [2]))
  696.                             $page_route $this->generateUrl('render_mlc_pages', ['_locale' => $lang'slug' => $page_route_cmspage['content'], 'hostname' => $_SERVER['HTTP_HOST']]);
  697.                     }
  698.                     # generate link 
  699.                     if ($page_route != null) {
  700.                         $result[$item_key]['link'] = ['title' => 'Réserver''to' => $page_route'togift' => $page_route_signature_gift];
  701.                     } else {
  702.                         $result[$item_key]['link'] = ['title' => 'Réserver''to' => $this->generateUrl('render_mlc_pages', ['slug' => "miramar-la-cigale"'hostname' => $_SERVER['HTTP_HOST']])];
  703.                     }
  704.                     #
  705.                     #
  706.                 } else {
  707.                     # generate link url
  708.                     # get page slug by product id
  709.                     $page_route_item $this->em->getRepository(CmsPageBlockComposantItems::class)->GetSlugByProduct($item['id_produit'], $lang);
  710.                     $page_route_cmspage $this->em->getRepository(CmsPage::class)->GetSlugByProduct($item['id_produit'], $lang);
  711.                     $page_route_signature $this->generateUrl('process_choice_signature', ['idp' => $item['id_produit']]);
  712.                     $page_route_signature_gift $this->generateUrl('process_choice_signature_gift', ['idp' => $item['id_produit'], "g" => 1]);
  713.                     # case page by category 
  714.                     $page_route "";
  715.                     if (array_key_exists('id_cat'$item)) {
  716.                         if (in_array($item['id_cat'], [345]))
  717.                             $page_route $page_route_signature;
  718.                         if (in_array($item['id_cat'], [1]))
  719.                             $page_route $this->generateUrl('render_mlc_pages', ['_locale' => $lang'slug' => $page_route_item['content'], 'hostname' => $_SERVER['HTTP_HOST']]);
  720.                         if (in_array($item['id_cat'], [2]))
  721.                             $page_route $this->generateUrl('render_mlc_pages', ['_locale' => $lang'slug' => $page_route_cmspage['content'], 'hostname' => $_SERVER['HTTP_HOST']]);
  722.                     }
  723.                     # generate link 
  724.                     if ($page_route != null) {
  725.                         $result[$item_key]['link'] = ['title' => 'Réserver''to' => $page_route'togift' => $page_route_signature_gift];
  726.                     } else {
  727.                         $result[$item_key]['link'] = ['title' => 'Réserver''to' => $this->generateUrl('render_mlc_pages', ['lang' => $lang'slug' => "miramar-la-cigale"'hostname' => $_SERVER['HTTP_HOST']])];
  728.                     }
  729.                     #
  730.                     #
  731.                 }
  732.                 # get duration data  [label, icon]
  733.                 $result[$item_key]['list'] = $list_holder;
  734.                 # add details 
  735.                 $result[$item_key]['details'] = [
  736.                     'title' => '',
  737.                     'list' => '',
  738.                     'description' => '',
  739.                     'button' => [
  740.                         'text' => '',
  741.                         'to' => $this->generateUrl('render_mlc_recherche', ['lang' => $lang]),
  742.                     ]
  743.                 ];
  744.             }
  745.             # this is for chambre
  746.             if (isset($item['type_chmbr_id'])) {
  747.                 # regime
  748.                 $regime_names = [];
  749.                 if (isset($item['regime_data'])) {
  750.                     foreach (explode(','$item['regime_data']) as $regimekey => $regime) {
  751.                         $regime_names[] = ['id' => explode('|'$regime)[0], 'label' => explode('|'$regime)[1], 'value' => explode('|'$regime)[1]];
  752.                     }
  753.                 }
  754.                 #nbr person options
  755.                 $numoptions = ['adultes''enfants'];
  756.                 $numoptions_holder = [];
  757.                 foreach ($numoptions as $type_opts) {
  758.                     $numoptions_holder[$type_opts] = [
  759.                         'result' => intval($item['nbr_' $type_opts]),
  760.                         'min' => intval($item['min_' $type_opts]),
  761.                         'max' => intval($item['max_' $type_opts])
  762.                     ];
  763.                 }
  764.                 // static 
  765.                 $item['stock_dispo'] = isset($item['stock_dispo']) ? $item['stock_dispo'] : 1;
  766.                 $numoptions_holder['chambres'] = ['result' => 1'min' => 1'max' => min(explode(','$item['stock_dispo']))];
  767.                 //
  768.                 # person
  769.                 $result[$item_key]['person'] = $result[$item_key]['person'];
  770.                 # form
  771.                 $result[$item_key]['form'] = [
  772.                     'action' => $this->generateUrl('render_mlc_reservation', ['_locale' => $lang]),
  773.                     'numoptions' => $numoptions_holder,
  774.                     'board' => $regime_names,
  775.                 ];
  776.                 # generate link 
  777.                 $prices_val = ['realPrice' => $result[$item_key]['realPrice'], 'price' => $result[$item_key]['price']];
  778.                 $result[$item_key]['chambre_data'] = array_merge($result[$item_key]['form'], $prices_val);
  779.                 $result[$item_key]['link'] = ['text' => 'Réserver''to' => $this->generateUrl('render_mlc_reservation', ['_locale' => $lang])];
  780.             }
  781.             #
  782.         }
  783.         #
  784.         return $result;
  785.     }
  786.     public function getPensions()
  787.     {
  788.         // get pension base on 
  789.         $regimes $this->em->getRepository(Regime::class)->getRegime(null$this->requestStack->getCurrentRequest()->getLocale());
  790.         return new JsonResponse($regimes);
  791.     }
  792.     public function getSuplementsForResrvation($date_start$date_end$chmbr_val false)
  793.     {
  794.         // get supplement
  795.         $supps $this->em->getRepository(Supplement::class)->getSupplementResrvation(['date_start' => $date_start'date_end' => $date_end], $this->requestStack->getCurrentRequest()->getLocale(), $count_data false$pageSize 100$page 1$chmbr_val);
  796.         if ($supps) {
  797.             $result $this->integrateMedia($supps'Supplement''id'$this->requestStack->getCurrentRequest()->getLocale(), 'soinsreservation');
  798.         } else {
  799.             $result = [];
  800.         }
  801.         return new JsonResponse($result);
  802.     }
  803.     /**
  804.      * @Route("/api-get_cure_prods", name="get_products_ers")
  805.      * 
  806.      */
  807.     public function getProductsForResrvation($date_start$date_end$type 'cures'$chmbr_val false$prod_val false$litemode false)
  808.     {
  809.         // get pension base on 
  810.         if ($type == 'soins') {
  811.             $context "soinsreservation";
  812.             $params = ['hebergement' => "'sans'"'type' => $this->getParameter('soins_id'), 'noCMS' => 1];
  813.             $params['tbl_tarif'] = 'tarifProduitThalassos';
  814.         } elseif ($type == 'soinsrituels') {
  815.             $context "soinsreservation";
  816.             $params = ['hebergement' => "'sans'"'type' => [$this->getParameter('soins_id'), $this->getParameter('rituel')], 'noCMS' => 1];
  817.             $params['tbl_tarif'] = 'tarifProduitThalassos';
  818.         } elseif ($type == 'cures') {
  819.             $type_cure = [$this->getParameter('cure_court_sejour'), $this->getParameter('cure_long_sejour')];
  820.             $context "curesreservation";
  821.             $params = ['hebergement' => "'avec_sans_hebergement', 'avec'"'type' => $type_cure];
  822.             $params['tbl_tarif'] = 'tarifProduitThalassoChambres';
  823.         } elseif ($type == 'soinsall') {
  824.             $context "soinsreservation";
  825.             $params['tbl_tarif'] = 'tarifProduitThalassos';
  826.         } 
  827.         elseif ($type == 'caresallgift') {
  828.             $context "search";
  829.             $params = ['type' => array(345), 'noCMS' => 1'noDISPO' => 1'isgiftcare' => 1];
  830.             $params['tbl_tarif'] = 'tarifProduitThalassos';
  831.         }
  832.         elseif ($type == 'caresall') {
  833.             $context "search";
  834.             $params = ['type' => array(345), 'noCMS' => 1'noDISPO' => 1];
  835.             $params['tbl_tarif'] = 'tarifProduitThalassos';
  836.         } else {
  837.             $params = ['type' => []];
  838.             $context "curesreservation";
  839.         }
  840.         $date1 = new \DateTime($date_start);
  841.         $date2 = new \DateTime($date_end);
  842.         $nbr_duration $date2->diff($date1)->format("%a");
  843.         if ($litemode)
  844.             $products $this->em->getRepository(ProduitThalasso::class)->getApiSearchProductsLite(array_merge($params, ['nbr_duration' => $nbr_duration'date_start' => $date_start'date_end' => $date_end'chambre_val' => $chmbr_val'prod_val' => $prod_val]), $this->requestStack->getCurrentRequest()->getLocale());
  845.         else
  846.             $products $this->em->getRepository(ProduitThalasso::class)->getApiSearchProducts(array_merge($params, ['nbr_duration' => $nbr_duration'date_start' => $date_start'date_end' => $date_end'chambre_val' => $chmbr_val'prod_val' => $prod_val]), $this->requestStack->getCurrentRequest()->getLocale());
  847.         $result $this->integrateMedia($products'ProduitThalasso''id_produit'$this->requestStack->getCurrentRequest()->getLocale(), $context);
  848.         return new JsonResponse($result);
  849.     }
  850.     public function getRoomsForResrvation($adults$children$date_start$date_end$mode_residence false$mode_restrict_dispo true)
  851.     {
  852.         $date1 = new \DateTime($date_start);
  853.         $date2 = new \DateTime($date_end);
  854.         $params['type_bar'] = $this->getParameter('hotel_seul_id');
  855.         $params['nbr_duration'] = $date2->diff($date1)->format("%a");
  856.         $params['date_end'] = $date_end;
  857.         $params['date_start'] = $date_start;
  858.         $params['adults'] = $adults;
  859.         $params['children'] = $children;
  860.         $chambres $this->em->getRepository(Chambre::class)->getApiSearchChambres($params$this->requestStack->getCurrentRequest()->getLocale(), false201$mode_residence$mode_restrict_dispo);
  861.         $result $this->integrateMedia($chambres'Chambre''id'$this->requestStack->getCurrentRequest()->getLocale(), $media_format 'search');
  862.         return new JsonResponse($result);
  863.     }
  864.     /**
  865.      * @Route("/{_locale}/reservation/insertion", defaults={"_locale": "fr"}, name="new_reservation")
  866.      * 
  867.      */
  868.     public function newReservation($_localeRequest $req)
  869.     {
  870.         //verif session and redirect to homepage if lost 
  871.         if ($this->verifRedirectSession())
  872.             return $this->verifRedirectSession();
  873.         # begin pages versions
  874.         #fr
  875.         $page_versions[] = array(
  876.             "to" => "/fr",
  877.             "value" => "fr",
  878.             "active" => ($_locale == "fr") ? true false
  879.         );
  880.         #en
  881.         $page_versions[] = array(
  882.             "to" => "/en",
  883.             "value" => "en",
  884.             "active" => ($_locale == "en") ? true false
  885.         );
  886.         # end pages versions
  887.         //get nrr
  888.         $pourcentage_nrr 0;
  889.         $TotalTtcNrr 0;
  890.         $arrhes_100 0;
  891.         $pourcentage_nrr $this->session->get('nrr_toapply');
  892.         //Verify if user is logged else redirect to login
  893.         if ($this->isGranted('ROLE_USER') == true) {
  894.             //Get vars from session
  895.             $search_params $this->session->get('search_params');
  896.             $selected_search $this->session->get('selected_search');
  897.             $booking_cart $this->session->get('booking_cart');
  898.             if (isset($booking_cart["tab_cures"])) {
  899.                 $prd_id $booking_cart["tab_cures"][0]["cure_id"];
  900.             } else {
  901.                 $prd_id 0;
  902.             }
  903.             //    echo "<pre>";
  904.             //     var_dump($prd_id);
  905.             //     echo "</pre>";
  906.             //     die;
  907.             //Detect envoi postal
  908.             $mt_envoi_postal 0;
  909.             if ($booking_cart && array_key_exists("tab_curistes"$booking_cart)) {
  910.                 foreach ($booking_cart["tab_curistes"] as $key => $curiste) {
  911.                     if ($curiste["postal"] == 1)
  912.                         $mt_envoi_postal += 10;
  913.                 }
  914.             }
  915.             $this->session->set('mt_envoi_postal'$mt_envoi_postal);
  916.             //Get amounts
  917.             if (array_key_exists("isGiftCard"$booking_cart) && $booking_cart["isGiftCard"] == 1) {
  918.                 $TotalSoins $booking_cart["price"];
  919.                 $TotalSejour $booking_cart["price"];
  920.                 $TotalSupplements 0;
  921.                 $TotalTtc $booking_cart["price"] + $mt_envoi_postal;
  922.                 $AccomptePourcentage 30;
  923.                 $TotalAccompte $TotalTtc $AccomptePourcentage 100;
  924.                 $AccomptePourcentage 30;
  925.                 $TotalAccompte_30 $TotalTtc $AccomptePourcentage 100;
  926.                 $AccomptePourcentage 100;
  927.                 $TotalAccompte_100 $TotalTtc $AccomptePourcentage 100;
  928.             } else {
  929.                 $produit_test $this->em->getRepository(ProduitThalasso::class)->findOneById($prd_id);
  930.                 if($produit_test && $produit_test->getArrhes100())
  931.                 $arrhes_100 $produit_test->getArrhes100();
  932.                 $TotalSoins $booking_cart["TotalSoins"];
  933.                 $TotalSejour $booking_cart["TotalSejour"];
  934.                 $TotalSupplements $booking_cart["TotalSupplements"];
  935.                 $TotalTtc $booking_cart["TotalTtc"] + $mt_envoi_postal;
  936.                 $TotalAccompte $TotalTtc
  937.                     $AccomptePourcentage 30;
  938.                     $TotalAccompte_30 $TotalTtc $AccomptePourcentage 100;
  939.                     $AccomptePourcentage 100;
  940.                     $TotalAccompte_100 $TotalTtc $AccomptePourcentage 100;
  941.             }
  942.             # change arrhes_100 if promotion
  943.             $promotions_list $this->session->get('promotions_list');
  944.             if ($promotions_list && is_object($promotions_list)) {
  945.                 $promotions_list get_object_vars($promotions_list);
  946.                 if ($promotions_list && array_key_exists("message"$promotions_list) && $promotions_list["message"] != "" && $promotions_list["arrhes_100"] !== false) {
  947.                     $arrhes_100 $promotions_list["arrhes_100"];
  948.                 }
  949.             }
  950.             if ($pourcentage_nrr  0) {
  951.                 $TotalTtcNrr $TotalTtc * (- (intval($pourcentage_nrr) / 100));
  952.             } else {
  953.                 $TotalTtcNrr $TotalTtc;
  954.             }
  955.         }
  956.         //round amounts
  957.         $TotalTtc round($TotalTtc0);
  958.         $TotalTtcNrr round($TotalTtcNrr0);
  959.         $TotalAccompte round($TotalAccompte0);
  960.         $TotalAccompte_30 round($TotalAccompte_300);
  961.         $TotalAccompte_100 round($TotalAccompte_1000);
  962.         return $this->render(
  963.             'pages/akaru/reservations/paiement.html.twig',
  964.             array(
  965.                 "_locale" => $_locale,
  966.                 "TotalTtc" => $TotalTtc,
  967.                 "TotalTtcNrr" => $TotalTtcNrr,
  968.                 "TotalAccompte" => $TotalAccompte,
  969.                 "TotalAccompte_30" => $TotalAccompte_30,
  970.                 "TotalAccompte_100" => $TotalAccompte_100,
  971.                 "product_id" => $prd_id,
  972.                 "page_versions" => $page_versions,
  973.                 "arrhes_100" => $arrhes_100
  974.             )
  975.         );
  976.     }
  977.     /**
  978.      * @Route("/{_locale}/api-pay-step1", name="api_pay_step1", defaults={"_locale": "fr"}, requirements={"_locale": "en|fr|de"})
  979.      * 
  980.      */
  981.     public function initPay(Request $requestMailerInterface $mailer$_locale)
  982.     {
  983.         //verif session and redirect to homepage if lost 
  984.         if ($this->verifRedirectSession())
  985.             return $this->verifRedirectSession();
  986.         //get posted data
  987.         $dataChoice $request->request->all();
  988.         //detect envoi postal
  989.         $mt_envoi_postal $this->session->get('mt_envoi_postal');
  990.         //Verify if user is logged else redirect to login
  991.         if ($this->isGranted('ROLE_USER') == true) {
  992.             //Get vars from session
  993.             $search_params $this->session->get('search_params');
  994.             $selected_search $this->session->get('selected_search');
  995.             $booking_cart $this->session->get('booking_cart');
  996.             $id_res_cadeau false;
  997.             $reservationCadeau null;
  998.             if (array_key_exists("isGiftCard"$booking_cart) && $booking_cart["isGiftCard"] == 1) {
  999.                 //Get amounts
  1000.                 $TotalSoins $booking_cart["price"];
  1001.                 $TotalSejour $booking_cart["price"];
  1002.                 $TotalSupplements 0;
  1003.                 $TotalTtc $booking_cart["price"] + $mt_envoi_postal;
  1004.                 $search_params["date_start"] = "Now";
  1005.                 $search_params["date_end"] = "Now";
  1006.                 $search_params["duration"] = 1;
  1007.                 $selected_search["total_adults"] = 1;
  1008.                 $selected_search["total_children"] = 0;
  1009.                 //insert reservation cadeau 
  1010.                 $reservationCadeau = new ReservationCadeau();
  1011.                 /* echo "<pre>";
  1012.             var_dump($booking_cart['tab_curistes']);
  1013.             echo "</pre>";*/
  1014.                 $TokenCadeau rtrim(strtr(base64_encode(random_bytes(32)), '+/''-_'), '=');
  1015.                 $reservationCadeau->setRefCadeau(""); //????
  1016.                 $reservationCadeau->setCiviliteBeneficiaire($booking_cart['tab_curistes'][0]['civilite_curiste']);
  1017.                 $reservationCadeau->setNomBeneficiaire($booking_cart['tab_curistes'][0]['nom_curiste']);
  1018.                 $reservationCadeau->setPrenomBeneficiaire($booking_cart['tab_curistes'][0]['prenom_curiste']);
  1019.                 $reservationCadeau->setDateNaissanceBeneficiaireText($booking_cart['tab_curistes'][0]['date_naissance_curiste']);
  1020.                 $reservationCadeau->setAdresse($booking_cart['tab_curistes'][0]['adresse']);
  1021.                 $reservationCadeau->setCompAdresse($booking_cart['tab_curistes'][0]['comp_adresse']);
  1022.                 $reservationCadeau->setCp($booking_cart['tab_curistes'][0]['cp']);
  1023.                 $reservationCadeau->setVille($booking_cart['tab_curistes'][0]['ville']);
  1024.                 $pay $this->em->getRepository(Pays::class)->findOneById((int)$booking_cart['tab_curistes'][0]['pays_curiste']);
  1025.                 if ($pay)
  1026.                     $reservationCadeau->setPays($pay);
  1027.                 $reservationCadeau->setEmailBeneficiaire($booking_cart['tab_curistes'][0]['email_curiste']);
  1028.                 $reservationCadeau->setTelBeneficiaire($booking_cart['tab_curistes'][0]['tel1_curiste']);
  1029.                 $reservationCadeau->setNewsletterClient(1);
  1030.                 $reservationCadeau->setDestinataireEnvoi((int)$booking_cart['tab_curistes'][0]['beneficiaire']);
  1031.                 $reservationCadeau->setTypeEnvoi((int)$booking_cart['tab_curistes'][0]['postal']);
  1032.                 $reservationCadeau->setCommentaire($booking_cart['tab_curistes'][0]['comment_curiste']);
  1033.                 $reservationCadeau->setMessage($booking_cart['tab_curistes'][0]['message_curiste']);
  1034.                 $reservationCadeau->setTokenCadeau($TokenCadeau);
  1035.                 $reservationCadeau->setDateCadeau(new \DateTime("Now"));
  1036.                 $reservationCadeau->setDateFinCadeau(new \DateTime("Now"));
  1037.                 // Persist reservation
  1038.                 $this->em->persist($reservationCadeau);
  1039.                 // Flush reservation
  1040.                 $this->em->flush();
  1041.                 $id_res_cadeau $reservationCadeau->getId();
  1042.                 //empty tab curiste
  1043.                 $booking_cart['tab_curistes'] = array();
  1044.             } else {
  1045.                 //Get amounts
  1046.                 $TotalSoins $booking_cart["TotalSoins"];
  1047.                 $TotalSejour $booking_cart["TotalSejour"];
  1048.                 $TotalSupplements $booking_cart["TotalSupplements"];
  1049.                 $TotalTtc $booking_cart["TotalTtc"] + $mt_envoi_postal;
  1050.             }
  1051.             //fix temporaire
  1052.             if (isset($booking_cart["tab_cures"])) {
  1053.                 $prd_id $booking_cart["tab_cures"][0]["cure_id"];
  1054.             } else {
  1055.                 $prd_id 0;
  1056.             }
  1057.             $pourcentage_nrr 0;
  1058.             if ($dataChoice["accompte30"] == 1) {
  1059.                 $TotalAccompte $TotalTtc 30 100;
  1060.                 $AccomptePourcentage 30;
  1061.                 $totalite 0;
  1062.             } 
  1063.             elseif ($dataChoice["accompte30"] == 2){
  1064.                 $TotalAccompte $TotalTtc;
  1065.                 $AccomptePourcentage 100;
  1066.                 $totalite 1;
  1067.             }
  1068.             else {
  1069.                 $TotalAccompte $TotalTtc;
  1070.                 $AccomptePourcentage 100;
  1071.                 $totalite 1;
  1072.                 //get nrr
  1073.                 $pourcentage_nrr $this->session->get('nrr_toapply');
  1074.                 $TotalAccompte $TotalAccompte * ($pourcentage_nrr 100);
  1075.             }
  1076.             //Get current user Id
  1077.             $user_id $this->getUser()->getId();
  1078.             //Get Client / id 
  1079.             $client $this->em->getRepository('App\Entity\Client')->findOneByUser($user_id);
  1080.             //round amounts
  1081.             $TotalTtc round($TotalTtc0);
  1082.             $TotalAccompte round($TotalAccompte0);
  1083.             // Create reservation
  1084.             //Generate token 
  1085.             $token rtrim(strtr(base64_encode(random_bytes(32)), '+/''-_'), '=');
  1086.             //$ref resa
  1087.             $ref "BK-" date("Ymd");
  1088.             /*echo "<pre>";
  1089.             var_dump($search_params);
  1090.             echo "</pre>";
  1091.             echo "<pre>";
  1092.             var_dump($selected_search);
  1093.             echo "</pre>";*/
  1094.             $reservation = new Reservation();
  1095.             $reservation->setTokenReservation($token);
  1096.             $reservation->setClient($client);
  1097.             $reservation->setRefReservation($ref);
  1098.             $date_start = new \DateTime($search_params["date_start"]);
  1099.             $reservation->setDateReservation($date_start);
  1100.             $date_end = new \DateTime($search_params["date_end"]);
  1101.             $reservation->setDateDepart($date_end);
  1102.             $reservation->setDureeSejour($search_params["duration"]);
  1103.             $reservation->setNbrParticipants($selected_search["total_adults"]);
  1104.             $reservation->setNbrEnfants($selected_search["total_children"]);
  1105.             $reservation->setTotalSoins($TotalSoins);
  1106.             $reservation->setTotalSejour($TotalSejour);
  1107.             $reservation->setTotalSupplements($TotalSupplements);
  1108.             $reservation->setAccomptePourcentage($AccomptePourcentage);
  1109.             $reservation->setTotalAccompte($TotalAccompte);
  1110.             $reservation->setTotalTtc($TotalTtc);
  1111.             $reservation->setTotalite($totalite);
  1112.             $reservation->setValide(0);
  1113.             $reservation->setPaye(0);
  1114.             if (array_key_exists('comments'$booking_cart))
  1115.                 $reservation->setComment($booking_cart['comments']);
  1116.             $reservation->setTauxNrr($pourcentage_nrr);
  1117.             //verifier si reservation est offerte
  1118.             $offert $this->session->get('sisGift');
  1119.             if ($offert == "true")
  1120.                 $offert 1;
  1121.             else
  1122.                 $offert 0;
  1123.             $reservation->setOffert($offert);
  1124.             //verifier si une resevation avec accompagnant
  1125.             if (array_key_exists('curiste-number'$booking_cart) && $booking_cart['curiste-number'] == "3")
  1126.                 $reservation->setAccompagnant(1);
  1127.             $modecare 0;
  1128.             if (array_key_exists('numcares'$booking_cart) && array_key_exists('tab_participants'$booking_cart) && (count($booking_cart['tab_participants']) > || (array_key_exists('tab_curistes'$booking_cart) && count($booking_cart['tab_curistes']) > 0)))
  1129.                 $modecare 1;
  1130.             $reservation->setCare($modecare);
  1131.             //set part gift
  1132.             if ($id_res_cadeau) {
  1133.                 $reservation->setChequecadeau(1);
  1134.                 $reservation->setReservationCadeau($reservationCadeau);
  1135.             } else {
  1136.                 $reservation->setChequecadeau(0);
  1137.                 $reservation->setReservationCadeau(null);
  1138.             }
  1139.             // send mail when reservation is created_at
  1140.             // Persist reservation
  1141.             $this->em->persist($reservation);
  1142.             // Flush reservation
  1143.             $this->em->flush();
  1144.             //get reservation id
  1145.             $id_reservation $reservation->getId();
  1146.             // persisting multiple translations, assume default locale is EN
  1147.             $repository $this->em->getRepository('Gedmo\\Translatable\\Entity\\Translation');
  1148.             //create linked objects
  1149.             //1- rooms
  1150.             if (array_key_exists('tab_rooms'$booking_cart))
  1151.                 foreach ($booking_cart['tab_rooms'] as $key => $room) {
  1152.                     //get objects
  1153.                     $chambre $this->em->getRepository('App\Entity\Chambre')->findOneById($room["chambre_id"]);
  1154.                     $typelit $this->em->getRepository('App\Entity\TypeLit')->findOneById($room["type_lit_id"]);
  1155.                     $regime $this->em->getRepository('App\Entity\Regime')->findOneById($room["regime_id"]);
  1156.                     $typearrangement $this->em->getRepository('App\Entity\TypeArrangement')->findOneById($room["type_arrangement_id"]);
  1157.                     $reservationChambre = new ReservationChambre();
  1158.                     $reservationChambre->setQteChambre($room["qte_chambre"]);
  1159.                     $reservationChambre->setMtChambreUnite($room["mt_chambre_unite"]);
  1160.                     $reservationChambre->setMtChambreTotal($room["mt_chambre_total"]);
  1161.                     $reservationChambre->setNomTypeLit("debug translation");
  1162.                     $reservationChambre->setNomTypeArrangement("debug translation");
  1163.                     $reservationChambre->setNomChambre("debug translation");
  1164.                     $reservationChambre->setNbrAdultes((int)$room["total_adults"]);
  1165.                     $reservationChambre->setNbrEnfants((int)$room["total_children"]);
  1166.                     $reservationChambre->setChambre($chambre);
  1167.                     $reservationChambre->setTypeLit($typelit);
  1168.                     $reservationChambre->setReservation($reservation);
  1169.                     $reservationChambre->setTypeArrangement($typearrangement);
  1170.                     $reservationChambre->setRegime($regime);
  1171.                     $reservation->addReservationChambre($reservationChambre);
  1172.                     $this->em->persist($reservationChambre);
  1173.                     $this->em->persist($reservation);
  1174.                     $this->em->flush();
  1175.                     //translate
  1176.                     /*$repository
  1177.                 ->translate($reservationChambre, 'nom_type_lit', 'en', 'debug en')
  1178.                 ->translate($reservationChambre, 'nom_type_arrangement', 'en', 'debug en');*/
  1179.                 }
  1180.             //2- addons
  1181.             if (array_key_exists('tab_addons'$booking_cart))
  1182.                 foreach ($booking_cart['tab_addons'] as $key => $addon) {
  1183.                     //get objects
  1184.                     $supplement $this->em->getRepository('App\Entity\Supplement')->findOneById($addon["supplement_id"]);
  1185.                     $reservationsup = new ReservationSupplement();
  1186.                     $reservationsup->setNomSupplement("debug translation");
  1187.                     $reservationsup->setQteSupplement($addon["qte_supplement"]);
  1188.                     $reservationsup->setMtSupplementUnite($addon["mt_supplement_unite"]);
  1189.                     $reservationsup->setMtSupplementTotal($addon["mt_supplement_total"]);
  1190.                     $reservationsup->setReservation($reservation);
  1191.                     $reservationsup->setSupplement($supplement);
  1192.                     $this->em->persist($reservationsup);
  1193.                     $this->em->flush();
  1194.                     //translate
  1195.                     /*$repository               
  1196.                 ->translate($reservationsup, 'nom_supplement', 'en', 'debug en');*/
  1197.                 }
  1198.             //3- cares
  1199.             if (array_key_exists('tab_cares'$booking_cart))
  1200.                 foreach ($booking_cart['tab_cares'] as $key => $care) {
  1201.                     //get objects
  1202.                     $produit $this->em->getRepository('App\Entity\ProduitThalasso')->findOneById($care["produit_thalasso_id"]);
  1203.                     //get beneficiaire en fonction des tab_participants ou tab_curistes
  1204.                     $beneficiaire $client->getNomClient() . " " $client->getPrenomClient();
  1205.                     $keybeneficiare intval($care["beneficiaire_soin"]) - 1;
  1206.                     if (count($booking_cart['tab_participants']) > 0) {
  1207.                         if (array_key_exists($keybeneficiare$booking_cart['tab_participants']))
  1208.                             $beneficiaire $booking_cart['tab_participants'][$keybeneficiare]["nom_participant"] . " " $booking_cart['tab_participants'][$keybeneficiare]["prenom_participant"];
  1209.                     }
  1210.                     if (count($booking_cart['tab_curistes']) > 0) {
  1211.                         $keybeneficiare intval($care["beneficiaire_soin"]) - 1;
  1212.                         if (array_key_exists($keybeneficiare$booking_cart['tab_curistes']))
  1213.                             $beneficiaire $booking_cart['tab_curistes'][$keybeneficiare]["nom_curiste"] . " " $booking_cart['tab_curistes'][$keybeneficiare]["prenom_curiste"];
  1214.                     }
  1215.                     $reservationsoin = new ReservationSoins();
  1216.                     $reservationsoin->setBeneficiaireSoin($beneficiaire);
  1217.                     $reservationsoin->setNomSoin("debug translation");
  1218.                     $reservationsoin->setQteSoin($care["qte_soin"]);
  1219.                     $reservationsoin->setMtSoinUnite($care["mt_soin_unite"]);
  1220.                     $reservationsoin->setMtSoinTotal($care["mt_soin_total"]);
  1221.                     $reservationsoin->setReservation($reservation);
  1222.                     $reservationsoin->setProduitThalasso($produit);
  1223.                     $this->em->persist($reservationsoin);
  1224.                     $this->em->flush();
  1225.                     //translate
  1226.                     /*$repository               
  1227.                 ->translate($reservationsup, 'nom_supplement', 'en', 'debug en');*/
  1228.                 }
  1229.             //3- cares only case
  1230.             if (array_key_exists('numcares'$booking_cart) && array_key_exists('tab_participants'$booking_cart) && count($booking_cart['tab_participants']) > 0)
  1231.                 foreach ($booking_cart['tab_cures'] as $key => $cure) {
  1232.                     //get objects
  1233.                     $produit $this->em->getRepository('App\Entity\ProduitThalasso')->findOneById($cure["cure_id"]);
  1234.                     $prixunitsoin $TotalTtc / (int)$booking_cart["numcares"];
  1235.                     $reservationsoin = new ReservationSoins();
  1236.                     $reservationsoin->setBeneficiaireSoin($booking_cart['tab_participants'][$key]["nom_participant"] . " " $booking_cart['tab_participants'][$key]["prenom_participant"]);
  1237.                     $reservationsoin->setNomSoin("debug translation");
  1238.                     $reservationsoin->setQteSoin(1);
  1239.                     $reservationsoin->setMtSoinUnite($prixunitsoin);
  1240.                     $reservationsoin->setMtSoinTotal($prixunitsoin);
  1241.                     $reservationsoin->setReservation($reservation);
  1242.                     $reservationsoin->setProduitThalasso($produit);
  1243.                     $reservation->addReservationSoin($reservationsoin);
  1244.                     $this->em->persist($reservationsoin);
  1245.                     $this->em->persist($reservation);
  1246.                     $this->em->flush();
  1247.                     //translate
  1248.                     /*$repository               
  1249.                 ->translate($reservationsup, 'nom_supplement', 'en', 'debug en');*/
  1250.                 }
  1251.             //4-0- curistes
  1252.             $tab_curistes_insert = array();
  1253.             if (array_key_exists('tab_curistes'$booking_cart))
  1254.                 foreach ($booking_cart['tab_curistes'] as $key => $curiste) {
  1255.                     $reservationcuriste = new Curiste();
  1256.                     $reservationcuriste->setCiviliteCuriste($curiste["civilite_curiste"]);
  1257.                     $reservationcuriste->setNomCuriste($curiste["nom_curiste"]);
  1258.                     $reservationcuriste->setPrenomCuriste($curiste["prenom_curiste"]);
  1259.                     $reservationcuriste->setAdresse($curiste["adresse"]);
  1260.                     $reservationcuriste->setCompAdresse($curiste["comp_adresse"]);
  1261.                     $reservationcuriste->setCp($curiste["cp"]);
  1262.                     $reservationcuriste->setVille($curiste["ville"]);
  1263.                     $pay $this->em->getRepository(Pays::class)->findOneById((int)$curiste["pays_curiste"]);
  1264.                     if ($pay)
  1265.                         $reservationcuriste->setPays($pay);
  1266.                     $reservationcuriste->setEmailCuriste($curiste["email_curiste"]);
  1267.                     $reservationcuriste->setTel1Curiste($curiste["tel1_curiste"]);
  1268.                     $reservationcuriste->setTel2Curiste($curiste["tel2_curiste"]);
  1269.                     $reservationcuriste->setBeneficiaire($curiste["beneficiaire"]);
  1270.                     $reservationcuriste->setPostal($curiste["postal"]);
  1271.                     $reservationcuriste->setComment($curiste["comment_curiste"]);
  1272.                     $reservationcuriste->setMessage($curiste["message_curiste"]);
  1273.                     //var_dump($curiste["date_naissance_curiste"]); die;
  1274.                     //$reservationcuriste->setDateNaissanceCuriste(date("Y-m-d", strtotime(str_replace('/', '-',$curiste["date_naissance_curiste"]))));
  1275.                     $reservationcuriste->setDateNaissanceCuriste(null);
  1276.                     $reservationcuriste->setDateNaissanceCuristeText($curiste["date_naissance_curiste"]);
  1277.                     $this->em->persist($reservationcuriste);
  1278.                     $this->em->flush();
  1279.                     $tab_curistes_insert[$key] = $reservationcuriste->getId();
  1280.                 }
  1281.             //4- cures
  1282.             if (array_key_exists('tab_cures'$booking_cart) && count($tab_curistes_insert) > 0)
  1283.                 foreach ($booking_cart['tab_cures'] as $key => $cure) {
  1284.                     //get objects
  1285.                     $produit $this->em->getRepository('App\Entity\ProduitThalasso')->findOneById($cure["cure_id"]);
  1286.                     $programme $this->em->getRepository('App\Entity\Programme')->findOneById($cure["programme"]);
  1287.                     $regime $this->em->getRepository('App\Entity\Regime')->findOneById($cure["regime_id"]);
  1288.                     if (array_key_exists($key$tab_curistes_insert))
  1289.                         $curiste $this->em->getRepository('App\Entity\Curiste')->findOneById($tab_curistes_insert[$key]);
  1290.                     $reservationcure = new ReservationCure();
  1291.                     $reservationcure->setBeneficiaireCure($curiste->getNomCuriste() . " " $curiste->getPrenomCuriste());
  1292.                     $reservationcure->setNomCure("debug translation");
  1293.                     $reservationcure->setProgramme($programme);
  1294.                     $reservationcure->setRegime($regime);
  1295.                     $reservationcure->setQteCure(1);
  1296.                     $reservationcure->setMtCureUnite(0);
  1297.                     $reservationcure->setMtCureTotal(0);
  1298.                     $reservationcure->setReservation($reservation);
  1299.                     $reservationcure->setProduitThalasso($produit);
  1300.                     $reservationcure->setCuriste($curiste);
  1301.                     $reservation->addReservationCure($reservationcure);
  1302.                     $this->em->persist($reservationcure);
  1303.                     $this->em->persist($reservation);
  1304.                     $this->em->flush();
  1305.                     //translate
  1306.                     /*$repository               
  1307.                 ->translate($reservationsup, 'nom_supplement', 'en', 'debug en');*/
  1308.                 }
  1309.             //4- ages enfants
  1310.             if (array_key_exists('tab_ages'$booking_cart))
  1311.                 foreach ($booking_cart['tab_ages'] as $key => $age) {
  1312.                     $reservationenfant = new ReservationEnfant();
  1313.                     $reservationenfant->setAgeEnfant($age["age_enfant"]);
  1314.                     $reservationenfant->setReservation($reservation);
  1315.                     $this->em->persist($reservationenfant);
  1316.                     $this->em->flush();
  1317.                 }
  1318.             //5- participants
  1319.             if (array_key_exists('tab_participants'$booking_cart))
  1320.                 foreach ($booking_cart['tab_participants'] as $key => $participant) {
  1321.                     $reservationparticipant = new ReservationParticipant();
  1322.                     $reservationparticipant->setNomParticipant($participant["nom_participant"]);
  1323.                     $reservationparticipant->setPrenomParticipant($participant["prenom_participant"]);
  1324.                     $reservationparticipant->setAdulte($participant["adulte"]);
  1325.                     $reservationparticipant->setReservation($reservation);
  1326.                     $this->em->persist($reservationparticipant);
  1327.                     $this->em->flush();
  1328.                 }
  1329.             //update ref 
  1330.             $ref "BK-" date("Ymd-Hi") . "-" $id_reservation;
  1331.             $reservation->setRefReservation($ref);
  1332.             $this->em->persist($reservation);
  1333.             $this->em->flush();
  1334.             /*echo "<pre>";
  1335.         var_dump($booking_cart);
  1336.         echo "</pre>";
  1337.         die;*/
  1338.             // dump($reservation);
  1339.             // dump(count($reservation->getReservationChambres()), $reservation->getId());
  1340.             //ajouter la promo à la réservation (hôtel seul)
  1341.             if (count($reservation->getReservationCures()) == && count($reservation->getReservationChambres()) >= && ($reservation->getReservationCadeau()) == null && ($reservation->getOffert()) == 0) {
  1342.                 $chambre_promos = [];
  1343.                 $i 0;
  1344.                 foreach ($reservation->getReservationChambres() as $resChambre) {
  1345.                     foreach ($resChambre->getChambre()->getPromotionChambre() as $promo) {
  1346.                         if ($promo->getActif() == true) {
  1347.                             if (count($promo->getPromotionThalasso()) == 0) {
  1348.                                 foreach ($promo->getPromotionValidites() as $promo_validite) {
  1349.                                     if (date_create($promo_validite->getDateDebutValidite()->format('d-m-Y')) <= date_create($reservation->getDateReservation()->format('d-m-Y')) && date_create($promo_validite->getDateFinValidite()->format('d-m-Y')) >= date_create($reservation->getDateReservation()->format('d-m-Y'))) {
  1350.                                         // dump($promo->getTitrePdf());
  1351.                                         $chambre_promos[$i]['chambre'] = $resChambre->getId();
  1352.                                         $chambre_promos[$i]['promo'] = $promo->getTitrePdf();
  1353.                                         $reservation->setPromotions($chambre_promos);
  1354.                                         $this->em->persist($reservation);
  1355.                                         $this->em->flush();
  1356.                                     }
  1357.                                     $i++;
  1358.                                 }
  1359.                             }
  1360.                         }
  1361.                     }
  1362.                 }
  1363.                 // dump($reservation->getPromotions());
  1364.                 // dd('hotel seul');
  1365.             }
  1366.             //ajouter promo à la réservation (cure avec hébergement)
  1367.             if (count($reservation->getReservationCures()) > && count($reservation->getReservationChambres()) > && ($reservation->getReservationCadeau()) == null) {
  1368.                 $cure_promos = [];
  1369.                 $i 0;
  1370.                 foreach ($reservation->getReservationCures() as $res_cure) {
  1371.                     foreach ($res_cure->getProduitThalasso()->getPromotionThalasso() as $promo) {
  1372.                         if ($promo->getActif() == true) {
  1373.                             foreach ($promo->getPromotionValidites() as $promo_validite) {
  1374.                                 foreach ($reservation->getReservationChambres() as $res_chambre) {
  1375.                                     foreach ($promo->getPromotionChambre() as $promo_chambre) {
  1376.                                         if ($promo_chambre == $res_chambre->getChambre()) {
  1377.                                             if (date_create($promo_validite->getDateDebutValidite()->format('d-m-Y')) <= date_create($reservation->getDateReservation()->format('d-m-Y')) && date_create($promo_validite->getDateFinValidite()->format('d-m-Y')) >= date_create($reservation->getDateReservation()->format('d-m-Y'))) {
  1378.                                                 // dump($promo->getTitrePdf());
  1379.                                                 $cure_promos[$i]['cure'] = $res_cure->getId();
  1380.                                                 $cure_promos[$i]['promo'] = $promo->getTitrePdf();
  1381.                                                 $reservation->setPromotions($cure_promos);
  1382.                                                 $this->em->persist($reservation);
  1383.                                                 $this->em->flush();
  1384.                                             }
  1385.                                         }
  1386.                                     }
  1387.                                 }
  1388.                                 $i++;
  1389.                             }
  1390.                         }
  1391.                     }
  1392.                 }
  1393.                 // dump($reservation->getPromotions());
  1394.                 // dd('cure avec heb');
  1395.             }
  1396.             //ajouter promo à la réservation (cure sans hébergement)
  1397.             if (count($reservation->getReservationCures()) > && count($reservation->getReservationChambres()) == 0  && ($reservation->getReservationCadeau()) == null) {
  1398.                 $cure_promos = [];
  1399.                 $i 0;
  1400.                 foreach ($reservation->getReservationCures() as $res_cure) {
  1401.                     foreach ($res_cure->getProduitThalasso()->getPromotionThalasso() as $promo) {
  1402.                         if ($promo->getActif() == true) {
  1403.                             foreach ($promo->getPromotionValidites() as $promo_validite) {
  1404.                                 if (date_create($promo_validite->getDateDebutValidite()->format('d-m-Y')) <= date_create($reservation->getDateReservation()->format('d-m-Y')) && date_create($promo_validite->getDateFinValidite()->format('d-m-Y')) >= date_create($reservation->getDateReservation()->format('d-m-Y'))) {
  1405.                                     // dump($promo->getTitrePdf());
  1406.                                     $cure_promos[$i]['cure'] = $res_cure->getId();
  1407.                                     $cure_promos[$i]['promo'] = $promo->getTitrePdf();
  1408.                                     $reservation->setPromotions($cure_promos);
  1409.                                     $this->em->persist($reservation);
  1410.                                     $this->em->flush();
  1411.                                 }
  1412.                                 $i++;
  1413.                             }
  1414.                         }
  1415.                     }
  1416.                 }
  1417.                 // dump($reservation->getPromotions());
  1418.                 // dd('cure sans heb');
  1419.             }
  1420.             //ajouter promo à la réservation (soin)
  1421.             if (($reservation->getCare()) == 1) {
  1422.                 $care_promos = [];
  1423.                 foreach ($reservation->getReservationSoins() as $res_care) {
  1424.                     foreach ($res_care->getProduitThalasso()->getPromotionThalasso() as $promo) {
  1425.                         if ($promo->getActif() == true) {
  1426.                             foreach ($promo->getPromotionValidites() as $promo_validite) {
  1427.                                 if (date_create($promo_validite->getDateDebutValidite()->format('d-m-Y')) <= date_create($reservation->getDateReservation()->format('d-m-Y')) && date_create($promo_validite->getDateFinValidite()->format('d-m-Y')) >= date_create($reservation->getDateReservation()->format('d-m-Y'))) {
  1428.                                     // dump($promo->getTitrePdf());
  1429.                                     $cure_promos[0]['care'] = $res_care->getId();
  1430.                                     $cure_promos[0]['promo'] = $promo->getTitrePdf();
  1431.                                     $reservation->setPromotions($cure_promos);
  1432.                                     $this->em->persist($reservation);
  1433.                                     $this->em->flush();
  1434.                                 }
  1435.                             }
  1436.                         }
  1437.                     }
  1438.                 }
  1439.                 // dump($reservation->getPromotions());
  1440.                 // dd('soin');
  1441.             }
  1442.             //ajout code promo à la reservation
  1443.             $code_promocheck_res $this->session->get('s_code_promotion_step');
  1444.             if ($code_promocheck_res && $code_promocheck_res != "") {
  1445.                 $codepromo $this->em->getRepository('App\Entity\CodePromo')->findOneBy(array("code_promo" => $code_promocheck_res));
  1446.                 if ($codepromo) {
  1447.                     $rcp = new ReservationCodePromo();
  1448.                     $rcp->setNomCodePromo($codepromo->getNomCodePromo());
  1449.                     $rcp->setDescCodePromo($codepromo->getDescCodePromo());
  1450.                     $rcp->setCodePromo($codepromo->getCodePromo());
  1451.                     $rcp->setCodePromoToutSite($codepromo->getCodePromoToutSite());
  1452.                     $rcp->setTypeCodePromo($codepromo->getTypeCodePromo());
  1453.                     $rcp->setPourcentageCodePromo($codepromo->getPourcentageCodePromo());
  1454.                     $rcp->setMontantCodePromo($codepromo->getMontantCodePromo());
  1455.                     $rcp->setQteCodePromo($codepromo->getQteCodePromo());
  1456.                     $rcp->setReservation($reservation);
  1457.                     $this->em->persist($rcp);
  1458.                     $this->em->flush();
  1459.                 }
  1460.             }
  1461.             //process payment
  1462.             if ($id_reservation) {
  1463.                 //Inital Vars
  1464.                 /*
  1465.             Master MID : BNP_MIRAMAR
  1466.             Test MID(s) : BNP_MIRAMAR_ECOM_FR_EUR_t
  1467.             Prod MID(s) : BNP_MIRAMAR_ECOM_FR_EUR
  1468.                     */
  1469.                 /*
  1470.             Identifiant commerçant (MID)
  1471.             BNP_MIRAMAR_ECOM_FR_EUR
  1472.             Clé de chiffrement Blowfish
  1473.             c(4MZ9o)_L8yw!Y2
  1474.             Clé HMAC
  1475.             6z(JD9t_7r=R]3NaEc4)8!qGoC*5Z[2j
  1476.             Identifiant commerçant (MID)
  1477.             BNP_MIRAMAR_ECOM_FR_EUR_t
  1478.             Clé de chiffrement Blowfish
  1479.             r*7R=Db2w6Y_)z8W
  1480.             Clé HMAC
  1481.             G]a8!5FyBq3?f6_KRp7(*Mw4Pb9=[Hx2
  1482.             Lorsque vous effectuez vos tests, nous vous recommandons de limiter le montant des transactions de 15 à 99 centimes. La remise en banque (capture) n'est pas activée sur les comptes de test mais sera disponible sur les comptes de production.
  1483.             */
  1484.                 $Your_MERCHANTID $this->Your_MERCHANTID;
  1485.                 $urlPageConfirm $this->generateUrl('api_pay_confirm', ['_locale' => $_locale], UrlGeneratorInterface::ABSOLUTE_URL);
  1486.                 $urlPageBack $this->generateUrl('default_hotel_page', ['_locale' => $_locale'hostname' => $_SERVER['HTTP_HOST']], UrlGeneratorInterface::ABSOLUTE_URL);
  1487.                 $Your_Payment_id $token;
  1488.                 $Your_Amount $TotalAccompte;
  1489.                 $Your_Ref $id_reservation//replace with unique database id
  1490.                 $Your_logo_img "";
  1491.                 $Your_miscelaneous "";
  1492.                 //Init the class
  1493.                 $paymentRequest = new Axepta($this->Your_HMAC$this->mode3dsv2);
  1494.                 $paymentRequest->setCryptKey($this->Your_CRYPTKEY);
  1495.                 //Set data payments
  1496.                 $paymentRequest->setUrl(Axepta::PAYSSL);
  1497.                 $paymentRequest->setMerchantID($Your_MERCHANTID);
  1498.                 $paymentRequest->setTransID("PM-" $id_reservation "-" rand(100000999999));
  1499.                 $paymentRequest->setAmount((int)($Your_Amount 100));
  1500.                 $paymentRequest->setCurrency('EUR');
  1501.                 $paymentRequest->setRefNr($Your_Ref);
  1502.                 $paymentRequest->setURLSuccess($urlPageConfirm);
  1503.                 $paymentRequest->setURLFailure($urlPageConfirm);
  1504.                 $paymentRequest->setURLNotify($urlPageConfirm);
  1505.                 $paymentRequest->setURLBack($urlPageBack);
  1506.                 $paymentRequest->setReponse('encrypt');
  1507.                 $paymentRequest->setLanguage('fr');
  1508.                 // Evolution vers le 3DSV2
  1509.                 if ($paymentRequest->getMode3dsv2()) {
  1510.                     $paymentRequest->setMsgVer('2.0');
  1511.                 }
  1512.                 if ($this->TEST_PAYMODE)
  1513.                     $paymentRequest->setOrderDesc('Test:0000');
  1514.                 else
  1515.                     $paymentRequest->setOrderDesc('Your Order description text');
  1516.                 // check your data
  1517.                 $paymentRequest->validate();
  1518.                 // compute
  1519.                 $mac $paymentRequest->getShaSign();      // run HMAC hash
  1520.                 $data $paymentRequest->getBfishCrypt();   // run Crypt & retrieve Data
  1521.                 $len $paymentRequest->getLen();           // retrieve Crypt length
  1522.                 //generate form for payment
  1523.                 $TransID $paymentRequest->getTransID();
  1524.                 $reservation->setTransid($TransID);
  1525.                 $this->em->persist($reservation);
  1526.                 $this->em->flush();
  1527.                 echo "<html><body>
  1528.             <form name=\"redirectForm\" method=\"GET\" action=\"" $paymentRequest->getUrl() . "\">" .
  1529.                     "<input type=\"hidden\" name=\"MerchantID\" value=\"" $paymentRequest->getMerchantID() . "\">" .
  1530.                     "<input type=\"hidden\" name=\"Len\" value=\"" $paymentRequest->getLen() . "\">" .
  1531.                     "<input type=\"hidden\" name=\"Data\" value=\"" $paymentRequest->getBfishCrypt() . "\">" .
  1532.                     "<input type=\"hidden\" name=\"URLBack\" value=\"" $paymentRequest->getURLBack() . "\">" .
  1533.                     "<input type=\"hidden\" name=\"CustomField1\" value=\"" $paymentRequest->getAmount() / 100 "\">" .
  1534.                     "<input type=\"hidden\" name=\"CustomField2\" value=\"" $TransID "\">" .
  1535.                     "<input type=\"hidden\" name=\"CustomField3\" value=\"" $Your_logo_img "\">" .
  1536.                     "<input type=\"hidden\" name=\"CustomField8\" value=\"" $Your_miscelaneous "\">" .
  1537.                     "<noscript><input type=\"submit\" name=\"Go\" value=\"Click to continue\"/></noscript>
  1538.             </form>" .
  1539.                     "<script type=\"text/javascript\">document.redirectForm.submit(); </script>" .
  1540.                     "</body></html>";
  1541.             } else
  1542.                 return new JsonResponse("Error creating Booking");
  1543.         } else
  1544.             return new JsonResponse(['response' => ['msg' => 'in dev phase'], 'status' => 501]);
  1545.         // return new JsonResponse(['response' =>['msg' => 'in dev phase'], 'status' => 501]);
  1546.     }
  1547.     /**
  1548.      * @Route("/{_locale}/api-pay-confirm", name="api_pay_confirm", defaults={"_locale": "fr"}, requirements={"_locale": "en|fr|de"})
  1549.      * 
  1550.      */
  1551.     public function confirmPay(MailerInterface $mailerKernelInterface $appRequest $request$_locale)
  1552.     {
  1553.         # begin pages versions
  1554.         #fr
  1555.         $page_versions[] = array(
  1556.             "to" => "/fr",
  1557.             "value" => "fr",
  1558.             "active" => ($_locale == "fr") ? true false
  1559.         );
  1560.         #en
  1561.         $page_versions[] = array(
  1562.             "to" => "/en",
  1563.             "value" => "en",
  1564.             "active" => ($_locale == "en") ? true false
  1565.         );
  1566.         # end pages versions
  1567.         $paymentResponse = new Axepta($this->Your_HMAC$this->mode3dsv2);
  1568.         $paymentResponse->setCryptKey($this->Your_CRYPTKEY);
  1569.         // Evolution vers le 3DSV2 change get to request to accept both get and post         
  1570.         $paymentResponse->setResponse($_REQUEST);
  1571.         //debug 3ds vars
  1572.         /*echo "<pre>";
  1573.         var_dump($_GET);
  1574.         var_dump($_POST); //not working
  1575.         var_dump($_REQUEST);
  1576.         var_dump($paymentResponse->getParameters());
  1577.         var_dump($paymentResponse->isSuccessful());
  1578.         var_dump($paymentResponse->isValid());
  1579.         echo "</pre>";
  1580.         die;*/
  1581.         $mode_residence $this->frontService->getResidenceMode();
  1582.         $token null;
  1583.         $reservationmail null;
  1584.         if ($paymentResponse->isValid() && $paymentResponse->isSuccessful()) {
  1585.             $TransID $paymentResponse->getPayID();
  1586.             $PCNr $paymentResponse->getPCNr();
  1587.             $CCBrand  $paymentResponse->getCCBrand();
  1588.             $CCExpiry $paymentResponse->getCCExpiry();
  1589.             $retour 1;
  1590.             /* ------------- Begin send email ------------- */
  1591.             $reservationmail $this->em->getRepository('App\Entity\Reservation')->findOneBy([
  1592.                 'transid' => $paymentResponse->getTransID()
  1593.             ]);
  1594.             $token $reservationmail->getTokenReservation();
  1595.             $templatePdf $this->getBookingPdfTemplate($token);
  1596.             //join PDF
  1597.             $myProjectDirectory $app->getRootDir() . "/..";
  1598.             $snappy = new Pdf($myProjectDirectory '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
  1599.             if (!$reservationmail->getPaye()) {
  1600.                 //     // Envoi confirmation réservation au client
  1601.                 //     if (!$mode_residence) {
  1602.                 //         $email = (new TemplatedEmail())
  1603.                 //             ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1604.                 //             ->to($reservationmail->getClient()->getEmailClient())
  1605.                 //             //->cc('cc@example.com')
  1606.                 //             ->bcc('reservation@miramar-lacigale.com')
  1607.                 //             //->replyTo('replyTo@example.com')
  1608.                 //             //->priority(Email::PRIORITY_HIGH)
  1609.                 //             ->subject('CONFIRMATION DE RÉSERVATION')
  1610.                 //             //->text('Sending emails is fun again!')
  1611.                 //             //->html('<p>See Twig integration for better HTML integration!</p>');
  1612.                 //             // path of the Twig template to render
  1613.                 //             ->htmlTemplate($templatePdf)
  1614.                 //             // pass variables (name => value) to the template
  1615.                 //             ->context([
  1616.                 //                 "res" => $reservationmail
  1617.                 //             ]);
  1618.                 //         $mailer->send($email);
  1619.                 //     }else {
  1620.                 //         $email = (new TemplatedEmail())
  1621.                 //             ->from($this->params->get('EMAIL_FROM_RESIDENCE'))
  1622.                 //             ->to($reservationmail->getClient()->getEmailClient())
  1623.                 //             //->cc('cc@example.com')
  1624.                 //             ->bcc('reservation@miramar-lacigale.com')
  1625.                 //             //->replyTo('replyTo@example.com')
  1626.                 //             //->priority(Email::PRIORITY_HIGH)
  1627.                 //             ->subject('CONFIRMATION DE RÉSERVATION')
  1628.                 //             //->text('Sending emails is fun again!')
  1629.                 //             //->html('<p>See Twig integration for better HTML integration!</p>');
  1630.                 //             // path of the Twig template to render
  1631.                 //             ->htmlTemplate($templatePdf)
  1632.                 //             // pass variables (name => value) to the template
  1633.                 //             ->context([
  1634.                 //                 "res" => $reservationmail
  1635.                 //             ]);
  1636.                 //         $mailer->send($email);
  1637.                 //     }
  1638.                 $reservationmail->setPaye(1);
  1639.                 $this->em->persist($reservationmail);
  1640.                 $this->em->flush();
  1641.                 //change stock for current booking
  1642.                 $logstocks $this->changeBookingStock($token);
  1643.                 $html $this->renderView(
  1644.                     $templatePdf,
  1645.                     array(
  1646.                         "res" => $reservationmail,
  1647.                         "dir" => $myProjectDirectory
  1648.                     )
  1649.                 );
  1650.                 $attachement $snappy->getOutputFromHtml($html, [
  1651.                     'encoding' => 'utf-8',
  1652.                     'images' => true
  1653.                 ]);
  1654.                 // Envoi confirmation réservation au client
  1655.                 if (!$mode_residence) {
  1656.                     $email = (new TemplatedEmail())
  1657.                         ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1658.                         ->to($reservationmail->getClient()->getEmailClient())
  1659.                         //->cc('cc@example.com')
  1660.                         ->bcc('reservation@miramar-lacigale.com')
  1661.                         ->addBcc('digital@miramar-lacigale.com')
  1662.                         //->replyTo('replyTo@example.com')
  1663.                         //->priority(Email::PRIORITY_HIGH)
  1664.                         ->subject($this->translator->trans("objet.confirmation"))
  1665.                         //->text('Sending emails is fun again!')
  1666.                         //->html('<p>See Twig integration for better HTML integration!</p>');
  1667.                         // path of the Twig template to render
  1668.                         ->htmlTemplate($templatePdf)
  1669.                         // pass variables (name => value) to the template
  1670.                         ->context([
  1671.                             "res" => $reservationmail
  1672.                         ])
  1673.                         ->attach($attachement'confirmation_de_reservation.pdf');
  1674.                         //add conditionnal fix for pool and lunch 191
  1675.                         $add_custom_mails false;
  1676.                         foreach ($reservationmail->getReservationSoins() as $res_care) {                            
  1677.                             if( ($res_care->getProduitThalasso()->getId() == 191) || ($res_care->getProduitThalasso()->getId() == 197) ) {
  1678.                                 $add_custom_mails true;
  1679.                             }
  1680.                         }
  1681.                         if($add_custom_mails)
  1682.                         {
  1683.                             if($res_care->getProduitThalasso()->getId() == 191){
  1684.                                 $email->addBcc('f.massot@miramar-lacigale.com')
  1685.                                 ->addBcc('lechef@miramar-lacigale.com')
  1686.                                 ->addBcc('chefpatissier@miramar-lacigale.com')
  1687.                                 ->addBcc('restauration@miramar-lacigale.com')
  1688.                                 ->addBcc('reception@miramar-lacigale.com')
  1689.                                 ->addBcc('receptionthalasso@miramar-lacigale.com');
  1690.                             }
  1691.                             elseif($res_care->getProduitThalasso()->getId() == 197){
  1692.                                 $email->addBcc('restauration@miramar-lacigale.com')
  1693.                                 ->addBcc('lechef@miramar-lacigale.com')
  1694.                                 ->addBcc('chefpatissier@miramar-lacigale.com')
  1695.                                 ->addBcc('f.massot@miramar-lacigale.com');
  1696.                             }
  1697.                         }
  1698.                     $mailer->send($email);
  1699.                 } else {
  1700.                     $transport Transport::fromDsn($this->getParameter('app.mailerDsnResidence'));
  1701.                     $mailer = new Mailer($transport);
  1702.                     $email = (new TemplatedEmail())
  1703.                         ->from($this->params->get('EMAIL_FROM_RESIDENCE'))
  1704.                         ->to($reservationmail->getClient()->getEmailClient())
  1705.                         //->cc('cc@example.com')
  1706.                         ->bcc('reservation@miramar-lacigale.com')
  1707.                         ->addBcc('digital@miramar-lacigale.com')
  1708.                         //->replyTo('replyTo@example.com')
  1709.                         //->priority(Email::PRIORITY_HIGH)
  1710.                         ->subject($this->translator->trans("objet.confirmation"))
  1711.                         //->text('Sending emails is fun again!')
  1712.                         //->html('<p>See Twig integration for better HTML integration!</p>');
  1713.                         // path of the Twig template to render
  1714.                         ->html($html)
  1715.                         // pass variables (name => value) to the template
  1716.                         ->context([
  1717.                             "res" => $reservationmail
  1718.                         ])
  1719.                         ->attach($attachement'confirmation_de_reservation.pdf');
  1720.                     $mailer->send($email);
  1721.                 }
  1722.                 // Envoi cheque cadeau
  1723.                 if (($reservationmail->getReservationCadeau()) != null) {
  1724.                     $cheque_cadeau "pdfs/cheque_cadeau.html.twig";
  1725.                     $email_beneficiare $reservationmail->getReservationCadeau()->getEmailBeneficiaire();
  1726.                     $html $this->renderView(
  1727.                         $cheque_cadeau,
  1728.                         array(
  1729.                             "res" => $reservationmail,
  1730.                             "dir" => $myProjectDirectory'_locale' => $_locale
  1731.                         )
  1732.                     );
  1733.                     $filename 'cheque_cadeau.pdf';
  1734.                    
  1735.                     $attachement $snappy->getOutputFromHtml($html, [
  1736.                         'encoding' => 'utf-8',
  1737.                         'images' => true,
  1738.                         'orientation' => 'Landscape'
  1739.                     ]);
  1740.                     if (($reservationmail->getReservationCadeau()->getTypeEnvoi()) == 0) {
  1741.                         if (($reservationmail->getReservationCadeau()->getDestinataireEnvoi()) == 1) {
  1742.                             $email = (new TemplatedEmail())
  1743.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1744.                                 ->to($email_beneficiare)
  1745.                                 //->cc('cc@example.com')
  1746.                                 ->bcc('reservation@miramar-lacigale.com')
  1747.                                 ->addBcc('digital@miramar-lacigale.com')
  1748.                                 ->addBcc('loubna@alphalab72.com')
  1749.                                 //->replyTo('replyTo@example.com')
  1750.                                 //->priority(Email::PRIORITY_HIGH)
  1751.                                 ->subject($this->translator->trans("objet.chequeBeneficiaire"))
  1752.                                 //->text('Sending emails is fun again!')
  1753.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  1754.                                 // path of the Twig template to render
  1755.                                 ->htmlTemplate($cheque_cadeau)
  1756.                                 // pass variables (name => value) to the template
  1757.                                 ->context([
  1758.                                     "res" => $reservationmail
  1759.                                 ])
  1760.                                 ->attach($attachement$filename)
  1761.                                 // ->attach(new \Swift_Attachment($pdf, $filename, 'application/pdf'))
  1762.                             ;
  1763.                             $mailer->send($email);
  1764.                         } else {
  1765.                             $email = (new TemplatedEmail())
  1766.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1767.                                 ->to($reservationmail->getClient()->getEmailClient())
  1768.                                 //->cc('cc@example.com')
  1769.                                 ->bcc('reservation@miramar-lacigale.com')
  1770.                                 ->addBcc('digital@miramar-lacigale.com')
  1771.                                 ->addBcc('loubna@alphalab72.com')
  1772.                                 //->replyTo('replyTo@example.com')
  1773.                                 //->priority(Email::PRIORITY_HIGH)
  1774.                                 ->subject($this->translator->trans("objet.chequeVousMeme"))
  1775.                                 //->text('Sending emails is fun again!')
  1776.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  1777.                                 // path of the Twig template to render
  1778.                                 ->htmlTemplate($cheque_cadeau)
  1779.                                 // pass variables (name => value) to the template
  1780.                                 ->context([
  1781.                                     "res" => $reservationmail
  1782.                                 ])
  1783.                                 ->attach($attachement$filename);
  1784.                             $mailer->send($email);
  1785.                         }
  1786.                     }
  1787.                 } elseif ($reservationmail->getOffert() == 1) {
  1788.                     // Envoi Bon cadeau
  1789.                     $bon_cadeau "pdfs/bon_cadeau.html.twig";
  1790.                     $email_beneficiare $reservationmail->getReservationCures()[0]->getCuriste()->getEmailCuriste();
  1791.                     $html $this->renderView(
  1792.                         $bon_cadeau,
  1793.                         array(
  1794.                             "res" => $reservationmail,
  1795.                             "dir" => $myProjectDirectory'_locale' => $_locale
  1796.                         )
  1797.                     );
  1798.                     $filename 'bon_cadeau.pdf';
  1799.                     $attachement $snappy->getOutputFromHtml($html, [
  1800.                         'encoding' => 'utf-8',
  1801.                         'images' => true,
  1802.                         'orientation' => 'Landscape'
  1803.                     ]);
  1804.                     if (($reservationmail->getReservationCures()[0]->getCuriste()->getPostal()) == 0) {
  1805.                         if (($reservationmail->getReservationCures()[0]->getCuriste()->getBeneficiaire()) == 1) {
  1806.                             $email = (new TemplatedEmail())
  1807.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1808.                                 ->to($email_beneficiare)
  1809.                                 //->cc('cc@example.com')
  1810.                                 ->bcc('reservation@miramar-lacigale.com')
  1811.                                 ->addBcc('digital@miramar-lacigale.com')
  1812.                                 //->replyTo('replyTo@example.com')
  1813.                                 //->priority(Email::PRIORITY_HIGH)
  1814.                                 ->subject($this->translator->trans("objet.bonBeneficiaire"))
  1815.                                 //->text('Sending emails is fun again!')
  1816.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  1817.                                 // path of the Twig template to render
  1818.                                 ->htmlTemplate($bon_cadeau)
  1819.                                 // pass variables (name => value) to the template
  1820.                                 ->context([
  1821.                                     "res" => $reservationmail
  1822.                                 ])
  1823.                                 ->attach($attachement$filename);
  1824.                             $mailer->send($email);
  1825.                         } else {
  1826.                             $email = (new TemplatedEmail())
  1827.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1828.                                 ->to($reservationmail->getClient()->getEmailClient())
  1829.                                 //->cc('cc@example.com')
  1830.                                 ->bcc('reservation@miramar-lacigale.com')
  1831.                                 ->addBcc('digital@miramar-lacigale.com')
  1832.                                 //->replyTo('replyTo@example.com')
  1833.                                 //->priority(Email::PRIORITY_HIGH)
  1834.                                 ->subject($this->translator->trans("objet.bonVousMeme"))
  1835.                                 //->text('Sending emails is fun again!')
  1836.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  1837.                                 // path of the Twig template to render
  1838.                                 ->htmlTemplate($bon_cadeau)
  1839.                                 // pass variables (name => value) to the template
  1840.                                 ->context([
  1841.                                     "res" => $reservationmail
  1842.                                 ])
  1843.                                 ->attach($attachement$filename);
  1844.                             $mailer->send($email);
  1845.                         }
  1846.                     }
  1847.                 }
  1848.             }
  1849.             //
  1850.             if ($reservationmail->getPaye()) {
  1851.             }
  1852.             /* ------------- End send email ------------- */
  1853.         } else {
  1854.             // Fail ....
  1855.             $retour 0;
  1856.         }
  1857.         return $this->render('pages/akaru/reservations/confirmation.html.twig', array("retour" => $retour"token" => $token"res" => $reservationmail"page_versions" => $page_versions));
  1858.     }
  1859.     /**
  1860.      * @Route("/debug-email-verify/{token_reservation}/{email_to}", name="verifysendemail", defaults={"_locale": "fr"}, requirements={"_locale": "en|fr|de"})
  1861.      * @return void
  1862.      */
  1863.     public function emailSendVerify(MailerInterface $mailerKernelInterface $appRequest $request$_localestring $token_reservationstring $email_to){
  1864.         $to $email_to;
  1865.         $subject "Test Email from PHP";
  1866.         $message "Hello,\nThis is a test email sent from a PHP script.";
  1867.         $headers "From: ".$this->params->get('EMAIL_FROM_MIRAMAR');
  1868.         
  1869.         if (mail($to$subject$message$headers)) {
  1870.             echo "Email sent successfully.";
  1871.         } else {
  1872.             echo "Failed to send email.";
  1873.         }
  1874.         $reservationmail $this->em->getRepository('App\Entity\Reservation')->findOneBy([
  1875.             'token_reservation' => $token_reservation
  1876.         ]);
  1877.         $token $token_reservation;
  1878.         $templatePdf $this->getBookingPdfTemplate($token);
  1879.             //join PDF
  1880.             $myProjectDirectory $app->getRootDir() . "/..";
  1881.             $snappy = new Pdf($myProjectDirectory '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
  1882.             $html $this->renderView(
  1883.                 $templatePdf,
  1884.                 array(
  1885.                     "res" => $reservationmail,
  1886.                     "dir" => $myProjectDirectory
  1887.                 )
  1888.             );
  1889.             $attachement $snappy->getOutputFromHtml($html, [
  1890.                 'encoding' => 'utf-8',
  1891.                 'images' => true
  1892.             ]);
  1893.             $email = (new TemplatedEmail())
  1894.             ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1895.             //->to($reservationmail->getClient()->getEmailClient())
  1896.             ->to($email_to)
  1897.             //->bcc('reservation@miramar-lacigale.com')
  1898.             //->addBcc('digital@miramar-lacigale.com')
  1899.             ->subject($this->translator->trans("objet.confirmation"))
  1900.             // path of the Twig template to render
  1901.             ->htmlTemplate($templatePdf)
  1902.             // pass variables (name => value) to the template
  1903.             ->context([
  1904.                 "res" => $reservationmail
  1905.             ])
  1906.             ->attach($attachement'confirmation_de_reservation.pdf');
  1907.             $mailer->send($email);
  1908.             return new Response("verify email");
  1909.     }
  1910.     /**
  1911.  * @Route("/debug-ipn-booking/{token_reservation}", name="debugpaymentIpn", defaults={"_locale": "fr"}, requirements={"_locale": "en|fr|de"})
  1912.  * @return void
  1913.  */
  1914. public function paymentdebuger(MailerInterface $mailerKernelInterface $appRequest $request$_localestring $token_reservation){
  1915.     # begin pages versions
  1916.         #fr
  1917.         $page_versions[] = array(
  1918.             "to" => "/fr",
  1919.             "value" => "fr",
  1920.             "active" => ($_locale == "fr") ? true false
  1921.         );
  1922.         #en
  1923.         $page_versions[] = array(
  1924.             "to" => "/en",
  1925.             "value" => "en",
  1926.             "active" => ($_locale == "en") ? true false
  1927.         );
  1928.         # end pages versions
  1929.        // $paymentResponse = new Axepta($this->Your_HMAC, $this->mode3dsv2);
  1930.        // $paymentResponse->setCryptKey($this->Your_CRYPTKEY);
  1931.         // Evolution vers le 3DSV2 change get to request to accept both get and post         
  1932.        // $paymentResponse->setResponse($_REQUEST);
  1933.         //debug 3ds vars
  1934.         /*echo "<pre>";
  1935.         var_dump($_GET);
  1936.         var_dump($_POST); //not working
  1937.         var_dump($_REQUEST);
  1938.         var_dump($paymentResponse->getParameters());
  1939.         var_dump($paymentResponse->isSuccessful());
  1940.         var_dump($paymentResponse->isValid());
  1941.         echo "</pre>";
  1942.         die;*/
  1943.         $mode_residence $this->frontService->getResidenceMode();
  1944.         $token null;
  1945.         $reservationmail null;
  1946.         //if ($paymentResponse->isValid() && $paymentResponse->isSuccessful()) {
  1947.             //$TransID = $paymentResponse->getPayID();
  1948.             //$PCNr = $paymentResponse->getPCNr();
  1949.             //$CCBrand  = $paymentResponse->getCCBrand();
  1950.             //$CCExpiry = $paymentResponse->getCCExpiry();
  1951.             //$retour = 1;
  1952.             /* ------------- Begin send email ------------- */
  1953.             $reservationmail $this->em->getRepository('App\Entity\Reservation')->findOneBy([
  1954.                 'token_reservation' => $token_reservation
  1955.             ]);
  1956.             $token $token_reservation;
  1957.             $templatePdf $this->getBookingPdfTemplate($token);
  1958.             //join PDF
  1959.             $myProjectDirectory $app->getRootDir() . "/..";
  1960.             $snappy = new Pdf($myProjectDirectory '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
  1961.            // if (!$reservationmail->getPaye()) {
  1962.                 //     // Envoi confirmation réservation au client
  1963.                 //     if (!$mode_residence) {
  1964.                 //         $email = (new TemplatedEmail())
  1965.                 //             ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  1966.                 //             ->to($reservationmail->getClient()->getEmailClient())
  1967.                 //             //->cc('cc@example.com')
  1968.                 //             ->bcc('reservation@miramar-lacigale.com')
  1969.                 //             //->replyTo('replyTo@example.com')
  1970.                 //             //->priority(Email::PRIORITY_HIGH)
  1971.                 //             ->subject('CONFIRMATION DE RÉSERVATION')
  1972.                 //             //->text('Sending emails is fun again!')
  1973.                 //             //->html('<p>See Twig integration for better HTML integration!</p>');
  1974.                 //             // path of the Twig template to render
  1975.                 //             ->htmlTemplate($templatePdf)
  1976.                 //             // pass variables (name => value) to the template
  1977.                 //             ->context([
  1978.                 //                 "res" => $reservationmail
  1979.                 //             ]);
  1980.                 //         $mailer->send($email);
  1981.                 //     }else {
  1982.                 //         $email = (new TemplatedEmail())
  1983.                 //             ->from($this->params->get('EMAIL_FROM_RESIDENCE'))
  1984.                 //             ->to($reservationmail->getClient()->getEmailClient())
  1985.                 //             //->cc('cc@example.com')
  1986.                 //             ->bcc('reservation@miramar-lacigale.com')
  1987.                 //             //->replyTo('replyTo@example.com')
  1988.                 //             //->priority(Email::PRIORITY_HIGH)
  1989.                 //             ->subject('CONFIRMATION DE RÉSERVATION')
  1990.                 //             //->text('Sending emails is fun again!')
  1991.                 //             //->html('<p>See Twig integration for better HTML integration!</p>');
  1992.                 //             // path of the Twig template to render
  1993.                 //             ->htmlTemplate($templatePdf)
  1994.                 //             // pass variables (name => value) to the template
  1995.                 //             ->context([
  1996.                 //                 "res" => $reservationmail
  1997.                 //             ]);
  1998.                 //         $mailer->send($email);
  1999.                 //     }
  2000.                 //$reservationmail->setPaye(1);
  2001.                 //$this->em->persist($reservationmail);
  2002.                 //$this->em->flush();
  2003.                 //change stock for current booking
  2004.                 $logstocks $this->changeBookingStock($token);
  2005.                 $html $this->renderView(
  2006.                     $templatePdf,
  2007.                     array(
  2008.                         "res" => $reservationmail,
  2009.                         "dir" => $myProjectDirectory
  2010.                     )
  2011.                 );
  2012.                 $attachement $snappy->getOutputFromHtml($html, [
  2013.                     'encoding' => 'utf-8',
  2014.                     'images' => true
  2015.                 ]);
  2016.                 // Envoi confirmation réservation au client
  2017.                 if (!$mode_residence) {
  2018.                     $email = (new TemplatedEmail())
  2019.                         ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  2020.                         ->to($reservationmail->getClient()->getEmailClient())
  2021.                         //->cc('cc@example.com')
  2022.                         ->bcc('reservation@miramar-lacigale.com')
  2023.                         ->addBcc('digital@miramar-lacigale.com')
  2024.                         //->replyTo('replyTo@example.com')
  2025.                         //->priority(Email::PRIORITY_HIGH)
  2026.                         ->subject($this->translator->trans("objet.confirmation"))
  2027.                         //->text('Sending emails is fun again!')
  2028.                         //->html('<p>See Twig integration for better HTML integration!</p>');
  2029.                         // path of the Twig template to render
  2030.                         ->htmlTemplate($templatePdf)
  2031.                         // pass variables (name => value) to the template
  2032.                         ->context([
  2033.                             "res" => $reservationmail
  2034.                         ])
  2035.                         ->attach($attachement'confirmation_de_reservation.pdf');
  2036.                         //add conditionnal fix for pool and lunch 191
  2037.                         $add_custom_mails false;
  2038.                         foreach ($reservationmail->getReservationSoins() as $res_care) {                            
  2039.                             if( ($res_care->getProduitThalasso()->getId() == 191) || ($res_care->getProduitThalasso()->getId() == 197) ) {
  2040.                                 $add_custom_mails true;
  2041.                             }
  2042.                         }
  2043.                         if($add_custom_mails)
  2044.                         {
  2045.                             if($res_care->getProduitThalasso()->getId() == 191){
  2046.                                 $email->addBcc('f.massot@miramar-lacigale.com')
  2047.                                 ->addBcc('lechef@miramar-lacigale.com')
  2048.                                 ->addBcc('chefpatissier@miramar-lacigale.com')
  2049.                                 ->addBcc('restauration@miramar-lacigale.com')
  2050.                                 ->addBcc('reception@miramar-lacigale.com')
  2051.                                 ->addBcc('receptionthalasso@miramar-lacigale.com');
  2052.                             }
  2053.                             elseif($res_care->getProduitThalasso()->getId() == 197){
  2054.                                 $email->addBcc('restauration@miramar-lacigale.com')
  2055.                                 ->addBcc('lechef@miramar-lacigale.com')
  2056.                                 ->addBcc('chefpatissier@miramar-lacigale.com')
  2057.                                 ->addBcc('f.massot@miramar-lacigale.com');
  2058.                             }
  2059.                         }
  2060.                     //$mailer->send($email);
  2061.                 } else {
  2062.                     $transport Transport::fromDsn($this->getParameter('app.mailerDsnResidence'));
  2063.                     $mailer = new Mailer($transport);
  2064.                     $email = (new TemplatedEmail())
  2065.                         ->from($this->params->get('EMAIL_FROM_RESIDENCE'))
  2066.                         ->to($reservationmail->getClient()->getEmailClient())
  2067.                         //->cc('cc@example.com')
  2068.                         ->bcc('reservation@miramar-lacigale.com')
  2069.                         ->addBcc('digital@miramar-lacigale.com')
  2070.                         //->replyTo('replyTo@example.com')
  2071.                         //->priority(Email::PRIORITY_HIGH)
  2072.                         ->subject($this->translator->trans("objet.confirmation"))
  2073.                         //->text('Sending emails is fun again!')
  2074.                         //->html('<p>See Twig integration for better HTML integration!</p>');
  2075.                         // path of the Twig template to render
  2076.                         ->html($html)
  2077.                         // pass variables (name => value) to the template
  2078.                         ->context([
  2079.                             "res" => $reservationmail
  2080.                         ])
  2081.                         ->attach($attachement'confirmation_de_reservation.pdf');
  2082.                    // $mailer->send($email);
  2083.                 }
  2084.                 // Envoi cheque cadeau
  2085.                 if (($reservationmail->getReservationCadeau()) != null) {
  2086.                     $cheque_cadeau "pdfs/cheque_cadeau.html.twig";
  2087.                     $email_beneficiare $reservationmail->getReservationCadeau()->getEmailBeneficiaire();
  2088.                     $html $this->renderView(
  2089.                         $cheque_cadeau,
  2090.                         array(
  2091.                             "res" => $reservationmail,
  2092.                             "dir" => $myProjectDirectory'_locale' => $_locale
  2093.                         )
  2094.                     );
  2095.                     $filename 'cheque_cadeau.pdf';
  2096.                     echo $html; die;
  2097.                    
  2098.                     $attachement $snappy->getOutputFromHtml($html, [
  2099.                         'encoding' => 'utf-8',
  2100.                         'images' => true,
  2101.                         'orientation' => 'Landscape'
  2102.                     ]);
  2103.                     if (($reservationmail->getReservationCadeau()->getTypeEnvoi()) == 0) {
  2104.                         if (($reservationmail->getReservationCadeau()->getDestinataireEnvoi()) == 1) {
  2105.                             $email = (new TemplatedEmail())
  2106.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  2107.                                 ->to($email_beneficiare)
  2108.                                 //->cc('cc@example.com')
  2109.                                 ->bcc('reservation@miramar-lacigale.com')
  2110.                                 ->addBcc('digital@miramar-lacigale.com')
  2111.                                 ->addBcc('loubna@alphalab72.com')
  2112.                                 //->replyTo('replyTo@example.com')
  2113.                                 //->priority(Email::PRIORITY_HIGH)
  2114.                                 ->subject($this->translator->trans("objet.chequeBeneficiaire"))
  2115.                                 //->text('Sending emails is fun again!')
  2116.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  2117.                                 // path of the Twig template to render
  2118.                                 ->htmlTemplate($cheque_cadeau)
  2119.                                 // pass variables (name => value) to the template
  2120.                                 ->context([
  2121.                                     "res" => $reservationmail
  2122.                                 ])
  2123.                                 ->attach($attachement$filename)
  2124.                                 // ->attach(new \Swift_Attachment($pdf, $filename, 'application/pdf'))
  2125.                             ;
  2126.                             $mailer->send($email);
  2127.                         } else {
  2128.                             $email = (new TemplatedEmail())
  2129.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  2130.                                 ->to($reservationmail->getClient()->getEmailClient())
  2131.                                 //->cc('cc@example.com')
  2132.                                 ->bcc('reservation@miramar-lacigale.com')
  2133.                                 ->addBcc('digital@miramar-lacigale.com')
  2134.                                 ->addBcc('loubna@alphalab72.com')
  2135.                                 //->replyTo('replyTo@example.com')
  2136.                                 //->priority(Email::PRIORITY_HIGH)
  2137.                                 ->subject($this->translator->trans("objet.chequeVousMeme"))
  2138.                                 //->text('Sending emails is fun again!')
  2139.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  2140.                                 // path of the Twig template to render
  2141.                                 ->htmlTemplate($cheque_cadeau)
  2142.                                 // pass variables (name => value) to the template
  2143.                                 ->context([
  2144.                                     "res" => $reservationmail
  2145.                                 ])
  2146.                                 ->attach($attachement$filename);
  2147.                             $mailer->send($email);
  2148.                         }
  2149.                     }
  2150.                 } elseif ($reservationmail->getOffert() == 1) {
  2151.                     // Envoi Bon cadeau
  2152.                     $bon_cadeau "pdfs/bon_cadeau.html.twig";
  2153.                     $email_beneficiare $reservationmail->getReservationCures()[0]->getCuriste()->getEmailCuriste();
  2154.                     $html $this->renderView(
  2155.                         $bon_cadeau,
  2156.                         array(
  2157.                             "res" => $reservationmail,
  2158.                             "dir" => $myProjectDirectory'_locale' => $_locale
  2159.                         )
  2160.                     );
  2161.                     $filename 'bon_cadeau.pdf';
  2162.                     $attachement $snappy->getOutputFromHtml($html, [
  2163.                         'encoding' => 'utf-8',
  2164.                         'images' => true,
  2165.                         'orientation' => 'Landscape'
  2166.                     ]);
  2167.                     if (($reservationmail->getReservationCures()[0]->getCuriste()->getPostal()) == 0) {
  2168.                         if (($reservationmail->getReservationCures()[0]->getCuriste()->getBeneficiaire()) == 1) {
  2169.                             $email = (new TemplatedEmail())
  2170.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  2171.                                 ->to($email_beneficiare)
  2172.                                 //->cc('cc@example.com')
  2173.                                 ->bcc('reservation@miramar-lacigale.com')
  2174.                                 ->addBcc('digital@miramar-lacigale.com')
  2175.                                 //->replyTo('replyTo@example.com')
  2176.                                 //->priority(Email::PRIORITY_HIGH)
  2177.                                 ->subject($this->translator->trans("objet.bonBeneficiaire"))
  2178.                                 //->text('Sending emails is fun again!')
  2179.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  2180.                                 // path of the Twig template to render
  2181.                                 ->htmlTemplate($bon_cadeau)
  2182.                                 // pass variables (name => value) to the template
  2183.                                 ->context([
  2184.                                     "res" => $reservationmail
  2185.                                 ])
  2186.                                 ->attach($attachement$filename);
  2187.                             $mailer->send($email);
  2188.                         } else {
  2189.                             $email = (new TemplatedEmail())
  2190.                                 ->from($this->params->get('EMAIL_FROM_MIRAMAR'))
  2191.                                 ->to($reservationmail->getClient()->getEmailClient())
  2192.                                 //->cc('cc@example.com')
  2193.                                 ->bcc('reservation@miramar-lacigale.com')
  2194.                                 ->addBcc('digital@miramar-lacigale.com')
  2195.                                 //->replyTo('replyTo@example.com')
  2196.                                 //->priority(Email::PRIORITY_HIGH)
  2197.                                 ->subject($this->translator->trans("objet.bonVousMeme"))
  2198.                                 //->text('Sending emails is fun again!')
  2199.                                 //->html('<p>See Twig integration for better HTML integration!</p>');
  2200.                                 // path of the Twig template to render
  2201.                                 ->htmlTemplate($bon_cadeau)
  2202.                                 // pass variables (name => value) to the template
  2203.                                 ->context([
  2204.                                     "res" => $reservationmail
  2205.                                 ])
  2206.                                 ->attach($attachement$filename);
  2207.                             $mailer->send($email);
  2208.                         }
  2209.                     }
  2210.                 }
  2211.             //}
  2212.             //
  2213.             //if ($reservationmail->getPaye()) {
  2214.             //}
  2215.             /* ------------- End send email ------------- */
  2216.         //} else {
  2217.             // Fail ....
  2218.          //   $retour = 0;
  2219.        // }
  2220.         //return $this->render('pages/akaru/reservations/confirmation.html.twig', array("retour" => $retour, "token" => $token, "res" => $reservationmail, "page_versions" => $page_versions));
  2221.         return new Response("paymentIpn call");
  2222. }
  2223.     // /**
  2224.     //  * @Route("/{_locale}/bon-cadeau-pdf-{token}/{fromBo}", name="bon-pdf", defaults={"fromBo": "", "_locale": "fr"}, requirements={"_locale": "en|fr|de"})
  2225.     //  * 
  2226.     //  */
  2227.     // public function bonCadeauPDF($fromBo, $token = null, KernelInterface $app, $_locale)
  2228.     // {
  2229.     //     $reservation = $this->em->getRepository('App\Entity\Reservation')->findOneBy([
  2230.     //         'token_reservation' => $token
  2231.     //     ]);
  2232.     //     $templatePdf = 'pdfs/bon_cadeau.html.twig';
  2233.     //     $myProjectDirectory = $app->getRootDir() . "/..";
  2234.     //     $snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
  2235.     //     $html = $this->renderView(
  2236.     //         $templatePdf,
  2237.     //         array("token" => $token, "res" => $reservation, 'dir' => $myProjectDirectory, '_locale' => $_locale)
  2238.     //     );
  2239.     //     if ($fromBo == "") {
  2240.     //         return new PdfResponse(
  2241.     //             $snappy->getOutputFromHtml($html),
  2242.     //             'confirmation-'. $reservation->getRefReservation().'.pdf'
  2243.     //         );
  2244.     //     } else {
  2245.     //         $response = new Response();
  2246.     //         $response->setContent($snappy->getOutputFromHtml($html));
  2247.     //         $response->headers->set('Content-Type', 'application/pdf');
  2248.     //         //$response->headers->set('Content-Type: application/pdf', 'application/force-download');
  2249.     //         $response->headers->set('Content-disposition', 'filename=test.pdf');
  2250.     //         return $response;
  2251.     //     }
  2252.     //             // return $this->render($templatePdf, array("res" => $reservation, '_locale' => $_locale));
  2253.     // }
  2254.     /**
  2255.      * @Route("/{_locale}/booking-pdf-{token}/{fromBo}", name="booking-pdf", defaults={"fromBo": "", "_locale": "fr"}, requirements={"_locale": "en|fr|de"})
  2256.      * 
  2257.      */
  2258.     public function bookingPdf($fromBo$token nullKernelInterface $app$_locale)
  2259.     {
  2260.         $reservation $this->em->getRepository('App\Entity\Reservation')->findOneBy([
  2261.             'token_reservation' => $token
  2262.         ]);
  2263.         $templatePdf $this->getBookingPdfTemplate($token);
  2264.         $myProjectDirectory $app->getRootDir() . "/..";
  2265.         $snappy = new Pdf($myProjectDirectory '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
  2266.         $html $this->renderView(
  2267.             $templatePdf,
  2268.             array("token" => $token"res" => $reservation'dir' => $myProjectDirectory'_locale' => $_locale)
  2269.         );
  2270.         if ($fromBo == "") {
  2271.             return new PdfResponse(
  2272.                 $snappy->getOutputFromHtml($html),
  2273.                 'confirmation-' $reservation->getRefReservation() . '.pdf'
  2274.             );
  2275.         } else {
  2276.             $response = new Response();
  2277.             $response->setContent($snappy->getOutputFromHtml($html));
  2278.             $response->headers->set('Content-Type''application/pdf');
  2279.             //$response->headers->set('Content-Type: application/pdf', 'application/force-download');
  2280.             $response->headers->set('Content-disposition''filename=test.pdf');
  2281.             return $response;
  2282.         }
  2283.         // $bookingService->downloadAPdf($html);
  2284.         // return $this->render($templatePdf, array("res" => $reservation, '_locale' => $_locale));
  2285.     }
  2286.     public function getBookingPdfTemplate($token null)
  2287.     {
  2288.         $reservation $this->em->getRepository('App\Entity\Reservation')->findOneBy([
  2289.             'token_reservation' => $token
  2290.         ]);
  2291.         $templatePdf "pdfs/confirmation.html.twig";
  2292.         //thalasso avec hebergement 
  2293.         if (count($reservation->getReservationCures()) > && count($reservation->getReservationChambres()) > && ($reservation->getReservationCadeau()) == null)
  2294.             $templatePdf "pdfs/confirmation-index.html.twig";
  2295.         //thalasso sans hebergement
  2296.         if (count($reservation->getReservationCures()) > && count($reservation->getReservationChambres()) == 0  && ($reservation->getReservationCadeau()) == null)
  2297.             $templatePdf "pdfs/confirmation-cure.html.twig";
  2298.         //hotel seul / residence
  2299.         if (count($reservation->getReservationCures()) == && count($reservation->getReservationChambres()) == && ($reservation->getReservationCadeau()) == null && ($reservation->getOffert()) == 0) {
  2300.             $templatePdf "pdfs/confirmation-room.html.twig";
  2301.         }
  2302.         if (count($reservation->getReservationCures()) == && count($reservation->getReservationChambres()) > && ($reservation->getReservationCadeau()) == null)
  2303.             $templatePdf "pdfs/confirmation_multi_room.html.twig";
  2304.         //Cheque cadeau
  2305.         if (($reservation->getReservationCadeau()) != null && ($reservation->getChequeCadeau()) == 1) {
  2306.             $templatePdf "pdfs/confirmation-cheque-cadeau.html.twig";
  2307.         }
  2308.         //Bon cadeau
  2309.         if (($reservation->getOffert()) == && ($reservation->getReservationCadeau()) == null)
  2310.             $templatePdf "pdfs/confirmation-cadeau.html.twig";
  2311.         //Care
  2312.         if (($reservation->getCare()) == 1)
  2313.             $templatePdf "pdfs/confirmation-care.html.twig";
  2314.         if (($reservation->getCare()) == && ($reservation->getOffert()) == 1)
  2315.             $templatePdf "pdfs/confirmation-care-cadeau.html.twig";
  2316.         return $templatePdf;
  2317.     }
  2318.     /**
  2319.      * @Route("/process-search", name="process_search")
  2320.      * 
  2321.      */
  2322.     public function processSearch()
  2323.     {
  2324.         return new Response("process_search");
  2325.     }
  2326.     /**
  2327.      * @Route("/process-choice", name="process_choice")
  2328.      * 
  2329.      */
  2330.     public function processChoice()
  2331.     {
  2332.         return new Response("process_choice");
  2333.     }
  2334.     /**
  2335.      * @Route("/process-gift", name="process_choice_gift")
  2336.      * 
  2337.      */
  2338.     public function processChoiceGift(Request $request)
  2339.     {
  2340.         //get posted data
  2341.         $dataChoice $request->request->all();
  2342.         //remove old session thalasso
  2343.         $this->session->remove('selected_thalasso');
  2344.         //remove old session room
  2345.         $this->session->remove('selected_room');
  2346.         $this->session->remove('s_code_promotion_step');
  2347.         return $this->redirectToRoute('render_mlc_gift');
  2348.     }
  2349.     /**
  2350.      * @Route("/{_locale}/process-choice-thalasso", defaults={"_locale": "fr"}, name="process_choice_thalasso")
  2351.      * 
  2352.      */
  2353.     public function processChoiceThalasso(Request $request$_locale)
  2354.     {
  2355.         //get posted data
  2356.         $dataChoice $request->request->all();
  2357.         /*echo "<pre>";
  2358.         var_dump($dataChoice);
  2359.         echo "</pre>";
  2360.         die;*/
  2361.         //produit thalasso 
  2362.         $produit $this->em->getRepository('App\Entity\ProduitThalasso')->findOneById((int)$dataChoice["id"]);
  2363.         $dataChoice["duree"] = $produit->getDureeJours();
  2364.         //init program id
  2365.         $dataChoice["program"] = $dataChoice["program-id"];
  2366.         //get posted data
  2367.         $this->session->set('selected_thalasso'$dataChoice);
  2368.         //remove old session room
  2369.         $this->session->remove('selected_room');
  2370.         $this->session->remove('booking_cart');
  2371.         $this->session->remove('s_code_promotion_step');
  2372.         if (array_key_exists("isGift"$dataChoice))
  2373.             $this->session->set('sisGift'$dataChoice["isGift"]);
  2374.         else
  2375.             $this->session->set('sisGift'"false");
  2376.         //$params['date_start'] = date("Y-m-d", strtotime(str_replace('/', '-',$params['date_start'])));
  2377.         //return new Response("process_choice_thalasso");
  2378.         return $this->redirectToRoute('render_mlc_reservation', ['_locale' => $_locale]);
  2379.     }
  2380.     /**
  2381.      * @Route("/{_locale}/process-choice-vente-{idp}-g{g}-vp{vp}",defaults={"_locale": "fr"}, name="process_choice_vp_gift", requirements={"idp"="\d+"})
  2382.      * @Route("/{_locale}/process-choice-signature-{idp}-g{g}",defaults={"_locale": "fr"}, name="process_choice_signature_gift", requirements={"idp"="\d+"})
  2383.      * @Route("/{_locale}/process-choice-signature-{idp}",defaults={"_locale": "fr"}, name="process_choice_signature", requirements={"idp"="\d+"})
  2384.      * 
  2385.      */
  2386.     public function processChoiceSignature(Request $requestint $idp$g 0$vp 0$_locale)
  2387.     {
  2388.         #get refere route
  2389.         $force_today true;
  2390.         $referer $request->headers->get('referer');
  2391.         if ((strpos($referer'/recherche') !== false) or  (strpos($referer'/search') !== false)) {
  2392.             $force_today false;
  2393.         }
  2394.         $selected_params $this->session->get('search_params');
  2395.         //get date if selected in cure
  2396.         if ($request->request->get("departure")) {
  2397.             $idp $request->get("id");
  2398.             $selected_calendar $request->request->get("departure");
  2399.             $force_today false;
  2400.         }
  2401.         //get date if selected in search
  2402.         else if (isset($selected_params['date_start'])) {
  2403.             $selected_calendar $selected_params['date_start'];
  2404.         } else {
  2405.             $selected_calendar date("Y-m-d");
  2406.         }
  2407.         //if vente privee date now
  2408.         if ($vp == "1" or $force_today)
  2409.             $selected_calendar date("Y-m-d");
  2410.         $nextday = new \DateTime($selected_calendar ' 00:00:00');
  2411.         $nextday->modify('+1 day');
  2412.         //produit thalasso 
  2413.         $produit $this->em->getRepository('App\Entity\ProduitThalasso')->findOneById((int)$idp);
  2414.         if ($g == 1)
  2415.             $valisGift "true";
  2416.         else
  2417.             $valisGift "false";
  2418.         //set data
  2419.         $dataChoice = array(
  2420.             "title" => ($produit) ? $produit->getNomProduitThalasso() : "",
  2421.             "id" => "" $idp,
  2422.             "duration" => "1",
  2423.             "program" => "",
  2424.             "departure" => "" $selected_calendar,
  2425.             "arrival" => "" $nextday->format('Y-m-d'),
  2426.             "price" => "0",
  2427.             "accomodation" => "false",
  2428.             "isGift" => $valisGift,
  2429.             "ventePrivee" => $vp,
  2430.             "soin" => "true",
  2431.             "duree" => ($produit) ? $produit->getDureeJours() : ""
  2432.         );
  2433.         //
  2434.         //var_dump($dataChoice["departure"]);
  2435.         //get posted data
  2436.         $this->session->set('selected_thalasso'$dataChoice);
  2437.         //remove old session room
  2438.         $this->session->remove('selected_room');
  2439.         $this->session->remove('booking_cart');
  2440.         $this->session->remove('s_code_promotion_step');
  2441.         if (array_key_exists("isGift"$dataChoice))
  2442.             $this->session->set('sisGift'$dataChoice["isGift"]);
  2443.         else
  2444.             $this->session->set('sisGift'"false");
  2445.         /* echo "<pre>";
  2446.         var_dump($g, $dataChoice);
  2447.         echo "</pre>";
  2448.         die;*/
  2449.         //$params['date_start'] = date("Y-m-d", strtotime(str_replace('/', '-',$params['date_start'])));
  2450.         //return new Response("process_choice_thalasso");
  2451.         return $this->redirectToRoute('render_mlc_reservation', ['_locale' => $_locale]);
  2452.     }
  2453.     /**
  2454.      * @Route("/{_locale}/process-choice-room", defaults={"_locale": "fr"}, name="process_choice_room")
  2455.      * 
  2456.      */
  2457.     public function processChoiceRoom(Request $request$_locale)
  2458.     {
  2459.         //get posted data
  2460.         $dataChoice $request->request->all();
  2461.         $this->session->set('selected_room'$dataChoice);
  2462.         //remove old session thalasso
  2463.         $this->session->remove('selected_thalasso');
  2464.         $this->session->remove('booking_cart');
  2465.         $this->session->remove('s_code_promotion_step');
  2466.         if (array_key_exists("isGift"$dataChoice))
  2467.             $this->session->set('sisGift'$dataChoice["isGift"]);
  2468.         else
  2469.             $this->session->set('sisGift'"false");
  2470.         /*$epoch = $dataChoice["departure"]/1000;
  2471.         $date_depart = new \DateTime("@$epoch");
  2472.         echo $date_depart->format('Y-m-d') . "\n";
  2473.         $epoch = $dataChoice["arrival"]/1000;
  2474.         $date_arrival = new \DateTime("@$epoch");
  2475.         echo $date_arrival->format('Y-m-d') . "\n";*/
  2476.         /*echo "<pre>";
  2477.         var_dump($dataChoice);
  2478.         echo "</pre>";
  2479.         die;*/
  2480.         return $this->redirectToRoute('render_mlc_reservation', ['_locale' => $_locale]);
  2481.     }
  2482.     /**
  2483.      * @Route("/{_locale}/process-booking-gift", name="process_booking_gift")
  2484.      * 
  2485.      */
  2486.     public function processBookingGift(Request $request$_locale)
  2487.     {
  2488.         //get posted data
  2489.         $dataChoice $request->request->all();
  2490.         $dataChoice["isGiftCard"] = 1;
  2491.         # store dataChoice in session
  2492.         $this->session->set('booking_cart'$dataChoice);
  2493.         /*echo "<pre>";
  2494.         var_dump($dataChoice);
  2495.         echo "</pre>"; 
  2496.         die;*/
  2497.         return $this->redirectToRoute('reservation_login', ["_locale" => $_locale]);
  2498.     }
  2499.     /**
  2500.      * @Route("/{_locale}/process-booking", name="process_booking")
  2501.      * 
  2502.      */
  2503.     public function processBooking(Request $request$_locale)
  2504.     {
  2505.         //default room number
  2506.         $nbr_rooms 1;
  2507.         //get posted data
  2508.         $dataChoice $request->request->all();
  2509.         //get room number if is set
  2510.         if (array_key_exists("number-room"$dataChoice))
  2511.             $nbr_rooms $dataChoice["number-room"];
  2512.         /*echo "<pre>";
  2513.         var_dump($dataChoice);
  2514.         echo "</pre>"; 
  2515.         die;*/
  2516.         //get selected search 
  2517.         $selected_search $this->session->get('selected_search');
  2518.         //reset numbers adults and children if posted
  2519.         if (isset($_POST["room-chambre-1-persons"])) {
  2520.             $selected_search["total_adults"] = 0;
  2521.             $selected_search["total_children"] = 0;
  2522.             for ($key 1$key <= $nbr_rooms$key++) {
  2523.                 if (isset($_POST["room-chambre-" $key "-persons"])) {
  2524.                     $nbrPersRoom explode(","$_POST["room-chambre-" $key "-persons"]);
  2525.                     $selected_search["total_adults"] += (int)$nbrPersRoom[0];
  2526.                     $selected_search["total_children"] += (int)$nbrPersRoom[1];
  2527.                     $selected_search["adults"][$key 1] = (int)$nbrPersRoom[0];
  2528.                     $selected_search["children"][$key 1] = (int)$nbrPersRoom[1];
  2529.                     if (isset($_POST["room-chambre-" $key "-pension"])) $selected_search["board"][$key 1] = (int)$_POST["room-chambre-" $key "-pension"];
  2530.                     else $selected_search["board"][$key 1] = "";
  2531.                 }
  2532.             }
  2533.         }
  2534.         //reset numbers adults and children if posted
  2535.         if (isset($_POST["numcares"])) {
  2536.             $selected_search["total_adults"] = (int)$_POST["numcares"];
  2537.             $selected_search["total_children"] = 0;
  2538.         }
  2539.         $this->session->set('selected_search'$selected_search);
  2540.         //get room
  2541.         $rooms = [];
  2542.         if (array_key_exists("room"$dataChoice))
  2543.             $rooms[] = json_decode($dataChoice["room"], true);
  2544.         elseif (array_key_exists("room1"$dataChoice)) {
  2545.             for ($key 1$key <= $nbr_rooms$key++) {
  2546.                 $rooms[] = json_decode($dataChoice["room" $key], true);
  2547.             }
  2548.         }
  2549.         //get prices
  2550.         $prices json_decode($dataChoice["prices"], true);
  2551.         //get supplements
  2552.         $complements = [];
  2553.         if (array_key_exists("room-1-complements-sejour"$dataChoice)) {
  2554.             for ($key 1$key <= $nbr_rooms$key++) {
  2555.                 $tabdet json_decode($dataChoice["room-" $key "-complements-sejour"], true);
  2556.                 $complements[$key]["beneficiaire_comp"] =  $key;
  2557.                 $complements[$key]["list_comp"] =  $tabdet;
  2558.                 //var_dump($complements); die;
  2559.             }
  2560.         }
  2561.         //get cares
  2562.         $cares = array();
  2563.         foreach ($rooms as $key => $room) {
  2564.             $cares[] = array("chambre_id" => (isset($room["id"]) ? $room["id"] : intval($room)), "list-cares" => json_decode($dataChoice["room-" . ($key 1) . "-cares"], true));
  2565.         }
  2566.         /*echo "<pre>";
  2567.         var_dump($complements);
  2568.         echo "</pre>"; 
  2569.         die;*/
  2570.         //init static amounts
  2571.         $dataChoice["TotalSoins"] = $prices["totalSoins"];
  2572.         $dataChoice["TotalSejour"] = $prices["totalSejour"];
  2573.         $dataChoice["TotalSupplements"] = $prices["totalSupplements"];
  2574.         $dataChoice["TotalTtc"] = $prices["totalTtc"];
  2575.         //init rooms
  2576.         $tab_rooms = array();
  2577.         foreach ($rooms as $key => $room) {
  2578.             $type_lit_id 0;
  2579.             $regime_id 0;
  2580.             if (isset($dataChoice["curiste-" . ($key 1) . "-pension"])) $regime_id = ((int) $dataChoice["curiste-" . ($key 1) . "-pension"]);
  2581.             if (isset($dataChoice["room-chambre-" . ($key 1) . "-pension"])) $regime_id = ((int) $dataChoice["room-chambre-" . ($key 1) . "-pension"]);
  2582.             if (isset($dataChoice["room-" . ($key 1) . "-bed"])) $type_lit_id = ((int) $dataChoice["room-" . ($key 1) . "-bed"]);
  2583.             $nbrPersRoom = array(00);
  2584.             if (isset($_POST["room-chambre-" . ($key 1) . "-persons"])) $nbrPersRoom explode(","$_POST["room-chambre-" . ($key 1) . "-persons"]);
  2585.             $tab_rooms[] = array('chambre_id' => (isset($room["id"]) ? $room["id"] : intval($room)), "type_arrangement_id" => 1"type_lit_id" => $type_lit_id"regime_id" => $regime_id"qte_chambre" => 1"mt_chambre_unite" => 150"mt_chambre_total" => 150"total_adults" => $nbrPersRoom[0], "total_children" => $nbrPersRoom[1]);
  2586.             $dataChoice["tab_rooms"] = $tab_rooms;
  2587.         }
  2588.         /*echo "<pre>";
  2589.         var_dump($cares);
  2590.         echo "</pre>"; 
  2591.         die;*/
  2592.         //init soins
  2593.         $tab_cares = array();
  2594.         foreach ($cares as $keyc => $care) {
  2595.             if ($care["list-cares"])
  2596.                 foreach ($care["list-cares"] as $key => $caredet) {
  2597.                     $produit $this->em->getRepository('App\Entity\ProduitThalasso')->findOneById($caredet["id"]);
  2598.                     $tab_cares[] = array('beneficiaire_soin' => $keyc 1'chambre_id' => $care["chambre_id"], "produit_thalasso_id" => $caredet["id"], "qte_soin" => $caredet["value"], "mt_soin_unite" => $caredet["price"], "mt_soin_total" => $caredet["totalPrice"], "label" => $produit->getNomProduitThalasso());
  2599.                 }
  2600.         }
  2601.         //init cures        
  2602.         if (array_key_exists("curiste-number"$dataChoice)) {
  2603.             $tab_cares = array();
  2604.             for ($i 1$i <= $dataChoice["curiste-number"]; $i++) {
  2605.                 if (isset($dataChoice["curiste-" $i "-cure"])) {
  2606.                     if (isset($dataChoice["curiste-" $i "-pension"])) $regime_id $dataChoice["curiste-" $i "-pension"];
  2607.                     else $regime_id null;
  2608.                     //static curiste program
  2609.                     $num_programme 0;
  2610.                     if (isset($dataChoice["curiste-" $i "-cure"]))
  2611.                         $num_programme $dataChoice["curiste-" $i "-program"];
  2612.                     $tab_cures[] = array('cure_id' => $dataChoice["curiste-" $i "-cure"], "regime_id" => $regime_id"programme" => $num_programme"curiste_index" => $i);
  2613.                     foreach (json_decode($dataChoice["curiste-" $i "-cares"], true) as $key => $caredet) {
  2614.                         $produit $this->em->getRepository('App\Entity\ProduitThalasso')->findOneById($caredet["id"]);
  2615.                         $tab_cares[] = array('beneficiaire_soin' => $i"produit_thalasso_id" => $caredet["id"], "qte_soin" => $caredet["value"], "mt_soin_unite" => $caredet["price"], "mt_soin_total" => $caredet["totalPrice"], "label" => $produit->getNomProduitThalasso());
  2616.                     }
  2617.                 }
  2618.             }
  2619.             $dataChoice["tab_cures"] = $tab_cures;
  2620.         }
  2621.         $dataChoice["tab_cares"] = $tab_cares;
  2622.         //init cures simples
  2623.         if (array_key_exists("numcares"$dataChoice)) {
  2624.             for ($i 1$i <= $dataChoice["numcares"]; $i++) {
  2625.                 $tab_cures[] = array('cure_id' => $dataChoice["curiste-1"], "regime_id" => ((int) 0), "programme" => """curiste_index" => $i);
  2626.             }
  2627.             $dataChoice["tab_cures"] = $tab_cures;
  2628.         }
  2629.         //init supplements
  2630.         $tab_addons = array();
  2631.         if ($complements)
  2632.             foreach ($complements as $keyr => $complementT) {
  2633.                 $beneficiaire $complementT["beneficiaire_comp"];
  2634.                 if ($complementT["list_comp"])
  2635.                     foreach ($complementT["list_comp"] as $keyr => $complement) {
  2636.                         $supplement $this->em->getRepository('App\Entity\Supplement')->findOneById($complement["id"]);
  2637.                         $tab_addons[] = array('beneficiaire_complement' => $beneficiaire'supplement_id' => $complement["id"], "qte_supplement" => $complement["value"], "mt_supplement_unite" => $complement["price"], "mt_supplement_total" => $complement["totalPrice"], "label" => $supplement->getNomSupplement());
  2638.                     }
  2639.             }
  2640.         $dataChoice["tab_addons"] = $tab_addons;
  2641.         //init ages
  2642.         $tab_ages = array();
  2643.         $ages = array();
  2644.         if (array_key_exists("ages"$dataChoice))
  2645.             $ages json_decode($dataChoice["ages"], true);
  2646.         if ($ages)
  2647.             foreach ($ages as $key => $age) {
  2648.                 $tab_ages[] = array('age_enfant' => $age["value"]);
  2649.             }
  2650.         $dataChoice["tab_ages"] = $tab_ages;
  2651.         # store dataChoice in session
  2652.         $this->session->set('booking_cart'$dataChoice);
  2653.         # disable nrr if promotion
  2654.         $promotions_list $this->session->get('promotions_list');
  2655.         if ($promotions_list && is_object($promotions_list)) {
  2656.             $promotions_list get_object_vars($promotions_list);
  2657.             if ($promotions_list && array_key_exists("message"$promotions_list) && $promotions_list["message"] != "") {
  2658.                 $this->session->set('nrr_toapply'0);
  2659.             }
  2660.         }
  2661.         return $this->redirectToRoute('reservation_login', ["_locale" => $_locale]);
  2662.     }
  2663.     /**
  2664.      * @Route("/reservations/promotion",  name="reservations_promotion")
  2665.      */
  2666.     public function reservationsPromotion(Request $request)
  2667.     {
  2668.         /* thalasso avec heberegement :{"calendar-start":"2021-09-13","calendar-end":"2021-09-19","nights":"6","curiste-number":"2","children-number":"1","curiste-1-cure":"1","curiste-1-pension":"1","curiste-1-program":"1","curiste-2-cure":"1","curiste-2-pension":"1","curiste-2-program":"1","room":"1","comments":"","visit":"visit-no","curiste-1-cares":"","curiste-2-cares":"","room-1-cares":"","room-1-complements-sejour":"","room-1-bed":"","ages":"","prices":""}*/
  2669.         /* thalasso avec heberegement 
  2670.  {"calendar-start":"2021-11-16","calendar-end":"2021-11-22","nights":"6","curiste-number":"2","children-number":"1","curiste-1-cure":"1","curiste-1-pension":"1","curiste-1-program":"1","curiste-2-cure":"1","curiste-2-pension":"1","curiste-2-program":"1","room":"1","code_promotion":"","comments":"","visit":"visit-no","curiste-1-cares":"","curiste-2-cares":"","room-1-cares":"","room-1-complements-sejour":"","room-1-bed":"","ages":"","prices":"","room-chambre-1-bed":""}
  2671. */
  2672.         /* cure
  2673. {"calendar-start":"2021-11-17","calendar-end":"2021-11-21","nights":"4","curiste-number":"2","curiste-1-cure":"1","curiste-1-pension":"1","curiste-1-program":"1","curiste-2-cure":"1","curiste-2-pension":"1","curiste-2-program":"1","code_promotion":"","comments":"","visit":"visit-no","curiste-1-cares":"","curiste-2-cares":"","room-1-cares":"","room-1-complements-sejour":"","room-1-bed":"","ages":"","prices":"","room-chambre-1-bed":""}
  2674. */
  2675.         /* care
  2676. {"calendar-start":"2021-09-15","numcares":"1","curiste-1":"1","code_promotion":"","comments":"","visit":"visit-no","curiste-1-cares":"","curiste-2-cares":"","room-1-cares":"","room-1-complements-sejour":"","room-1-bed":"","ages":"","prices":"","room-chambre-1-bed":""}
  2677. */
  2678.         $mode_debug false;
  2679.         $msgdebug "";
  2680.         $today date("Y-m-d");
  2681.         $days_earlybooking false;
  2682.         if ($request && $request->getContent()) {
  2683.             $params json_decode($request->getContent(), true);
  2684.             $id_chambre null;
  2685.             if ($params) {
  2686.                 if (array_key_exists("number-room"$params)) $nbr_rooms $params["number-room"];
  2687.                 else $nbr_rooms 1;
  2688.                 if (array_key_exists("curiste-1"$params)) $id_thalasso $params["curiste-1"];
  2689.                 elseif (array_key_exists("curiste-1-cure"$params)) $id_thalasso $params["curiste-1-cure"];
  2690.                 else $id_thalasso null;
  2691.                 if (array_key_exists("numcares"$params)) $qte_thalasso $params["numcares"];
  2692.                 else $qte_thalasso 1;
  2693.                 for ($i 1$i <= 1$i++) {
  2694.                     if (array_key_exists("room" $i$params)) $id_chambre $params["room" $i];
  2695.                 }
  2696.                 if (array_key_exists("room"$params)) $id_chambre $params["room"];
  2697.                 $date_begin $params["calendar-start"];
  2698.                 if (array_key_exists("calendar-end"$params)) $date_end $params["calendar-end"];
  2699.                 else $date_end $params["calendar-start"];
  2700.                 if (array_key_exists("curiste-1-pension"$params)) $regime $params["curiste-1-pension"];
  2701.                 else $regime null;
  2702.                 if (array_key_exists("nights"$params)) $duration $params["nights"];
  2703.                 else $duration 1;
  2704.             }
  2705.             $days_earlybooking round((strtotime($date_begin) - strtotime($today)) / (60 60 24));
  2706.         }
  2707.         if ($mode_debug)
  2708.             $msgdebug "<br><h3>Values send from page :</h3>" $request->getContent();
  2709.         $params_promo_dyn = [
  2710.             'today' => $today,
  2711.             'id_thalasso' => $id_thalasso,
  2712.             'qte_thalasso' => $qte_thalasso,
  2713.             'id_chambre' => $id_chambre,
  2714.             'date_debut' => $date_begin,
  2715.             'date_fin' => $date_end,
  2716.             'regime' => $regime,
  2717.             'duration' => $duration,
  2718.         ];
  2719.         if ($mode_debug)
  2720.             $msgdebug .= "<br><h3>Dynamic values for promo :</h3>" json_encode($params_promo_dyn);
  2721.         //for static test
  2722.         ///debug/promo-test?today=2021-09-02&id_thalasso=26&qte_thalasso=3&id_chambre=51&date_debut=2021-09-03&date_fin=2021-09-04&regime=2&duration=2
  2723.         $params_promo = [
  2724.             'today' => "2021-11-02",
  2725.             'id_thalasso' => 88,
  2726.             'qte_thalasso' => 1,
  2727.             'id_chambre' => 51,
  2728.             'date_debut' => "2021-11-02",
  2729.             'date_fin' => "2021-11-08",
  2730.             'regime' => 4,
  2731.             'duration' => 6,
  2732.         ];
  2733.         $params_promo_calcul $params_promo_dyn;
  2734.         $promos $this->em->getRepository('App\Entity\Promotion')->getPomotionsSteps($params_promo_calcul);
  2735.         // switch nrr
  2736.         $nrr_last_value $this->getNrrLastValue($params_promo_calcul);
  2737.         //disable promo if gift
  2738.         if ($this->session->get('sisGift') == "true")
  2739.             $promos = [];
  2740.         $caseIndex 0;
  2741.         $status_globale 1;
  2742.         //Init variables
  2743.         $messages[] = "";
  2744.         $types[] = "message";
  2745.         $values[] = 0;
  2746.         $arrhes_100[] = false;
  2747.         //promotions dynmiques
  2748.         foreach ($promos as $key => $promo) {
  2749.             $promocurrent $this->em->getRepository('App\Entity\Promotion')->findOneById($promo["id_promotion"]);
  2750.             $status_globale 1;
  2751.             if ($promocurrent) {
  2752.                 //tab application 1curiste 2 curiste etc
  2753.                 $tab_application = [];
  2754.                 foreach ($promocurrent->getApplications() as $key => $appli) {
  2755.                     $tab_application[] = $appli->getId();
  2756.                 }
  2757.                 //case (promo % type id =2, $params["curiste-number"]
  2758.                 if (in_array($promo["id_type_promotion"], [2])) {
  2759.                     $messages[] = $promocurrent->getNomPromotion();
  2760.                     $arrhes_100[] = $promocurrent->getArrhes100();
  2761.                     $types[] = "message"//case type promotion
  2762.                     $values[] = 0//case type promotion 
  2763.                     $caseIndex++;
  2764.                 }
  2765.                 //case (promo -x euros type id =3, $params["curiste-number"]
  2766.                 if (in_array($promo["id_type_promotion"], [3])) {
  2767.                     if (
  2768.                         !array_key_exists("curiste-number"$params)
  2769.                         or (array_key_exists("curiste-number"$params) && in_array(intval($params["curiste-number"]), $tab_application))
  2770.                     ) {
  2771.                         $messages[] = $promocurrent->getNomPromotion();
  2772.                         $arrhes_100[] = $promocurrent->getArrhes100();
  2773.                         $types[] = "message"//case type promotion
  2774.                         $values[] = 0//case type promotion 
  2775.                         $caseIndex++;
  2776.                     }
  2777.                 }
  2778.                 //case pourcentage (promo volume type id =6,
  2779.                 if (in_array($promo["id_type_promotion"], [6])) {
  2780.                     $dispos $this->em->getRepository('App\Entity\DispoProduit')->getApiProductCalendar($params_promo_calcul["id_thalasso"], $params_promo_calcul["id_chambre"], truefalse'fr'$date_begin$date_end);
  2781.                     if (count($dispos) > 0) {
  2782.                         $dispo $dispos[0];
  2783.                         $regime_data $dispo["regime_data"];
  2784.                         $regime_data explode(","$regime_data);
  2785.                         foreach ($regime_data as $key => $regime_price) {
  2786.                             $regime_price explode("|"$regime_price);
  2787.                             $prix_formule1_sejour = ($dispo["price_simple_individuelle"] * $dispo["multiplicateur_regime_promo"] * 1);
  2788.                             $prix_formule2_sejour = ($dispo["price_simple"] * $dispo["multiplicateur_regime_promo"]  * 1);
  2789.                             $prix_formule3_sejour = ($dispo["prix_accompagnant"] * $dispo["multiplicateur_regime_promo"] * $dispo["duree"] * 1);
  2790.                             $prix_formule1_regime = ($regime_price[3] * $dispo["multiplicateur_regime_promo"] * $dispo["duree"] * 1);
  2791.                             $prix_formule2_regime = ($regime_price[3] * $dispo["multiplicateur_regime_promo"] * $dispo["duree"] * 1);
  2792.                             $prix_formule3_regime = ($regime_price[3] * $dispo["multiplicateur_regime_promo"] * $dispo["duree"] * 2);
  2793.                             $prices[$regime_price[0]][$params_promo_calcul["id_chambre"]] = array("formule1" => $prix_formule1_sejour"formule2" => $prix_formule2_sejour"formule3" => $prix_formule3_sejour);
  2794.                             $prices_regimes[$regime_price[0]][$params_promo_calcul["id_chambre"]] = array("formule1" => $prix_formule1_regime"formule2" => $prix_formule2_regime"formule3" => $prix_formule3_regime);
  2795.                         }
  2796.                     }
  2797.                     if ($mode_debug)
  2798.                         $msgdebug .= "<br><h3>prices :</h3>" json_encode($prices);
  2799.                     if ($mode_debug)
  2800.                         $msgdebug .= "<br><h3>prices regimes :</h3>" json_encode($prices_regimes);
  2801.                     //cases of type prestation  ************************
  2802.                     $value_to_substract 0;
  2803.                     $display_promo false;
  2804.                     $types_msg "message";
  2805.                     $comp_title_promo "";
  2806.                     //case accompagnant
  2807.                     if ($promo["id_type_prestation"] == && array_key_exists("curiste-number"$params) && $params["curiste-number"] == "3") {
  2808.                         if (array_key_exists($regime$prices_regimes))
  2809.                             $value_to_substract $prices[$regime][$params_promo_calcul["id_chambre"]]["formule3"];
  2810.                         $display_promo true;
  2811.                         $types_msg "substraction";
  2812.                     }
  2813.                     //case arrangement
  2814.                     if ($promo["id_type_prestation"] == && array_key_exists("curiste-number"$params)) {
  2815.                         if (array_key_exists($regime$prices_regimes))
  2816.                             $value_to_substract $prices_regimes[$regime][$params_promo_calcul["id_chambre"]]["formule" $params["curiste-number"]];
  2817.                         $display_promo true;
  2818.                         $types_msg "substraction";
  2819.                     }
  2820.                     //case nuit offerte
  2821.                     if ($promo["id_type_prestation"] == 4) {
  2822.                         $value_to_substract 0;
  2823.                         $display_promo true;
  2824.                         $types_msg "message";
  2825.                     }
  2826.                     //case supplement offert
  2827.                     if ($promo["id_type_prestation"] == 5) {
  2828.                         //get supplements
  2829.                         $label_tab_suuplement_offert = [];
  2830.                         foreach ($promocurrent->getSupplement() as $key => $supplement) {
  2831.                             if ($supplement$label_tab_suuplement_offert[] = $supplement->getNomSupplement();
  2832.                         }
  2833.                         if (count($label_tab_suuplement_offert) > 0$comp_title_promo "(" implode(", "$label_tab_suuplement_offert) . ")";
  2834.                         $value_to_substract 0;
  2835.                         $display_promo true;
  2836.                         $types_msg "message";
  2837.                     }
  2838.                     //case thalasso offert
  2839.                     if ($promo["id_type_prestation"] == 3) {
  2840.                         //get supplements
  2841.                         $label_tab_prod_offert = [];
  2842.                         foreach ($promocurrent->getPromotionSoins() as $key => $produit) {
  2843.                             if ($produit$label_tab_prod_offert[] = $produit->getNomProduitThalasso();
  2844.                         }
  2845.                         if (count($label_tab_prod_offert) > 0$comp_title_promo "(" implode(", "$label_tab_prod_offert) . ")";
  2846.                         $value_to_substract 0;
  2847.                         $display_promo true;
  2848.                         $types_msg "message";
  2849.                     }
  2850.                     //case perso
  2851.                     if ($promo["id_type_prestation"] == 6) {
  2852.                         $value_to_substract 0;
  2853.                         $display_promo true;
  2854.                         $types_msg "message";
  2855.                     }
  2856.                     //End cases of type prestation  ************************
  2857.                     if ($display_promo) {
  2858.                         $messages[] = $promocurrent->getNomPromotion() . " " $comp_title_promo;
  2859.                         $arrhes_100[] = $promocurrent->getArrhes100();
  2860.                         $types[] = $types_msg//case type promotion
  2861.                         $values[] = $value_to_substract;
  2862.                         $caseIndex++;
  2863.                     }
  2864.                 }
  2865.                 //case display only (promo surclassement type id =7, promo Xnuit achetees Y nuits offertes type id =5, promo Xnuit achetees Y nuits offertes type id =6)
  2866.                 if (in_array($promo["id_type_promotion"], [5])) {
  2867.                     $montant_sejour 0;
  2868.                     if (isset($params_promo_calcul["duration"]) && isset($params["prices"])) {
  2869.                         $montant_sejour $params["prices"]["stay"];
  2870.                     }
  2871.                     $montant_sejour $montant_sejour $params_promo_calcul["duration"];
  2872.                     $messages[] = $promocurrent->getNomPromotion();
  2873.                     $arrhes_100[] = $promocurrent->getArrhes100();
  2874.                     $types[] = "substraction"//case type promotion
  2875.                     $values[] = $montant_sejour//case type promotion 
  2876.                     $caseIndex++;
  2877.                 }
  2878.                 //case display only (promo surclassement type id =7, promo Xnuit achetees Y nuits offertes type id =5, promo Xnuit achetees Y nuits offertes type id =6)
  2879.                 if (in_array($promo["id_type_promotion"], [7])) {
  2880.                     $messages[] = $promocurrent->getNomPromotion();
  2881.                     $arrhes_100[] = $promocurrent->getArrhes100();
  2882.                     $types[] = "message"//case type promotion
  2883.                     $values[] = 0//case type promotion 
  2884.                     $caseIndex++;
  2885.                 }
  2886.                 //case promo volume type id =8,
  2887.                 if (in_array($promo["id_type_promotion"], [8])) {
  2888.                     $messages[] = $promocurrent->getNomPromotion();
  2889.                     $arrhes_100[] = $promocurrent->getArrhes100();
  2890.                     $types[] = "percentage"//case type promotion
  2891.                     $values[] = - (intval($promo["pourcentage"]) / 100); //case type promotion  
  2892.                     $caseIndex++;
  2893.                 }
  2894.             }
  2895.         }
  2896.         //promotion early booking
  2897.         if ($days_earlybooking && ($caseIndex == 0)) {
  2898.             $earlybooking $this->em->getRepository('App\Entity\EarlyBooking')->getEarlyreduction($days_earlybooking);
  2899.             if (count($earlybooking) > && array_key_exists("pourcentage"$earlybooking)) {
  2900.                 $messages[] = "Early booking " intval($earlybooking["pourcentage"]) . "%";
  2901.                 $types[] = "percentage"//case type promotion
  2902.                 $values[] = - (intval($earlybooking["pourcentage"]) / 100); //case pmailerpmailer   
  2903.             }
  2904.         }
  2905.         //promotion code promo 
  2906.         $code_promocheck "";
  2907.         if (array_key_exists("code_promotion"$params))
  2908.             $code_promocheck $params["code_promotion"];
  2909.         elseif ($this->session->get('s_code_promotion_step') && $this->session->get('s_code_promotion_step') != "") {
  2910.             $code_promocheck $this->session->get('s_code_promotion_step');
  2911.         }
  2912.         if (($caseIndex == 0) && $code_promocheck != "") {
  2913.             $codepromo $this->em->getRepository('App\Entity\CodePromo')->findOneByParams($code_promocheck$params_promo_calcul);
  2914.             if ($codepromo) {
  2915.                 if ($codepromo->getPourcentageCodePromo() > && strtolower($codepromo->getTypeCodePromo()) == "pourcentage") {
  2916.                     $messages[] = $codepromo->getNomCodePromo();
  2917.                     $types[] = "percentage";
  2918.                     $values[] = - ($codepromo->getPourcentageCodePromo() * 100);
  2919.                     $this->session->set('s_code_promotion_step'$codepromo->getCodePromo());
  2920.                     $caseIndex++;
  2921.                 } elseif ($codepromo->getMontantCodePromo() > && strtolower($codepromo->getTypeCodePromo()) == "montant") {
  2922.                     $messages[] = $codepromo->getNomCodePromo();
  2923.                     $types[] = "substraction";
  2924.                     $values[] = $codepromo->getMontantCodePromo() * 1;
  2925.                     $this->session->set('s_code_promotion_step'$codepromo->getCodePromo());
  2926.                     $caseIndex++;
  2927.                 }
  2928.             } else {
  2929.                 $messages[] = 'Code promo "' $code_promocheck '" invalide.';
  2930.                 $types[] = "message";
  2931.                 $values[] = 0;
  2932.                 $status_globale 0;
  2933.                 $caseIndex++;
  2934.             }
  2935.         }
  2936.         if ($mode_debug && $caseIndex == 0) {
  2937.             //promotion pour debug
  2938.             $messages[] = "Promotion for debug only";
  2939.             $types[] = "message"//case type promotion
  2940.             $values[] = 0//case type promotion
  2941.             $caseIndex++;
  2942.         }
  2943.         //exit;
  2944.         /*$messages = [
  2945.       "",
  2946.       "Promotion cas 1 avec soustraction -200€ ".$params["calendar-start"],
  2947.       "Promotion cas 2 avec pourcentage 80%",
  2948.       "Promotion cas 3 avec juste un message",
  2949.     ];
  2950.     $types = [
  2951.       "",
  2952.       "substraction",
  2953.       "percentage",
  2954.       "message"
  2955.     ];
  2956.     $values = [
  2957.       0,
  2958.       200,
  2959.       0.8,
  2960.       0
  2961.     ];*/
  2962.         $data = (object)[
  2963.             "show" => $caseIndex !== 0,
  2964.             "message" => $messages[$caseIndex] . $msgdebug,
  2965.             "arrhes_100" => $arrhes_100[$caseIndex] ,
  2966.             "type" => $types[$caseIndex],
  2967.             "value" => $values[$caseIndex],
  2968.             "status" => $status_globale,
  2969.             "nrr" => $caseIndex && $nrr_last_value true false,
  2970.         ];
  2971.         //create session for promotion
  2972.         $this->session->set('promotions_list'$data);
  2973.         return new JsonResponse($data);
  2974.     }
  2975.     public function changeBookingStock($token null)
  2976.     {
  2977.         //find resrvation by token
  2978.         $reservation $this->em->getRepository(Reservation::class)->findOneBy(["token_reservation" => $token]);
  2979.         $log_changebook "";
  2980.         if ($reservation) {
  2981.             $date_start $reservation->getDateReservation() ? $reservation->getDateReservation()->format('Y-m-d') : null;
  2982.             $date_end $reservation->getDateDepart() ? $reservation->getDateDepart()->format('Y-m-d') : null;
  2983.             // Case thalasso
  2984.             $log_changebook .= "<br><br>*********** destockage cures ";
  2985.             foreach ($reservation->getReservationCures() as $key => $cure) {
  2986.                 // Case thalasso
  2987.                 $prod_id $cure->getProduitThalasso()->getId();
  2988.                 $value $cure->getQteCure();
  2989.                 $type "down";
  2990.                 if ($date_start != null && $date_end != null && $value 0) {
  2991.                     $dispoproduit $this->em->getRepository(DispoProduit::class)->changeStock($prod_id$date_start$date_end$value$type);
  2992.                     $log_changebook .= "<br>- La cure id : " $prod_id " a été destocké de " $value " entre le : " $date_start " et " $date_end;
  2993.                 }
  2994.             }
  2995.             $log_changebook .=  "<br><br>*********** destockage soins ";
  2996.             // Case soins     
  2997.             foreach ($reservation->getReservationSoins() as $key => $soin) {
  2998.                 $prod_id $soin->getProduitThalasso()->getId();
  2999.                 $value $soin->getQteSoin();
  3000.                 $type "down";
  3001.                 if ($date_start != null && $date_end != null && $value 0) {
  3002.                     $dispoproduit $this->em->getRepository(DispoProduit::class)->changeStock($prod_id$date_start$date_end$value$type);
  3003.                     $log_changebook .= "<br>- Le soin id : " $prod_id " a été destocké de " $value " entre le : " $date_start " et " $date_end;
  3004.                 }
  3005.             }
  3006.             $log_changebook .=  "<br><br>*********** destockage chambres ";
  3007.             // Case chambre     
  3008.             foreach ($reservation->getReservationChambres() as $key => $chambre) {
  3009.                 $room_id $chambre->getChambre()->getId();
  3010.                 $value $chambre->getQteChambre();
  3011.                 $type "down";
  3012.                 if ($date_start != null && $date_end != null && $value 0) {
  3013.                     $dispoproduit $this->em->getRepository(DispoChambre::class)->changeStock($room_id$date_start$date_end$value$type);
  3014.                     $log_changebook .= "<br>- La chambre id : " $room_id " a été destocké de " $value " entre le : " $date_start " et " $date_end;
  3015.                 }
  3016.             }
  3017.             $log_changebook .=  "<br><br>*********** destockage supplements ";
  3018.             // Case chambre     
  3019.             foreach ($reservation->getReservationSupplements() as $key => $supp) {
  3020.                 $supplement_id $supp->getSupplement()->getId();
  3021.                 $value $supp->getQteSupplement();
  3022.                 $type "down";
  3023.                 if ($date_start != null && $date_end != null && $value 0) {
  3024.                     $dispoproduit $this->em->getRepository(DispoSupplement::class)->changeStock($supplement_id$date_start$date_end$value$type);
  3025.                     $log_changebook .=  "<br>- Le supplement id : " $supplement_id " a été destocké de " $value " entre le : " $date_start " et " $date_end;
  3026.                 }
  3027.             }
  3028.             //reduce code promo if existe   
  3029.             $log_changebook .=  "<br><br>*********** destockage code promo ";
  3030.             foreach ($reservation->getReservationCodePromos() as $key => $cp) {
  3031.                 $codepromo $this->em->getRepository(CodePromo::class)->changeStock($cp->getCodePromo());
  3032.                 $log_changebook .=  "<br>- Le code promo  : " $cp->getCodePromo() . " a été destocké de 1 ";
  3033.             }
  3034.         } else {
  3035.             $log_changebook .=  "<br><br>!!!! aucune reservation avec le token :" $token;
  3036.         }
  3037.         return $log_changebook;
  3038.     }
  3039.     /**
  3040.      * @Route("/bookapi/boking-stock/{token}")
  3041.      */
  3042.     public function debugChangeBookingStock($token null)
  3043.     {
  3044.         $logs $this->changeBookingStock($token);
  3045.         echo $logs;
  3046.         return new Response("<br><br><br>Change stock for booking " $token);
  3047.     }
  3048.     public function verifRedirectSession()
  3049.     {
  3050.       $search_params $this->session->get('search_params');
  3051.   
  3052.       $booking_cart_sess $this->session->get('booking_cart');
  3053.   
  3054.       if( (!$search_params  || !isset($search_params['date_start']) || !isset($search_params['date_end']) || !isset($search_params['duration']) ) && !isset($booking_cart_sess['isGiftCard']) )
  3055.       return $this->redirect($this->generateUrl('default_hotel_page', ['hostname' => $_SERVER['HTTP_HOST']]));
  3056.       else
  3057.       return false;
  3058.     }  
  3059.     public function verifProductNrr($id_product=0)
  3060.     {
  3061.       $nrr_val false;
  3062.       $search_params=$this->session->get('search_params');
  3063.   
  3064.       $produit $this->em->getRepository(ProduitThalasso::class)->findOneById($id_product);
  3065.   
  3066.       if($produit && $produit->getNrr())
  3067.       {
  3068.         $nrr_val true;
  3069.       }
  3070.   
  3071.   
  3072.       return $nrr_val;
  3073.     }  
  3074.     public function verifRoomNrr($id_chambre=0)
  3075.     {
  3076.       $nrr_val false;
  3077.       $search_params=$this->session->get('search_params');
  3078.   
  3079.       $chambre $this->em->getRepository(Chambre::class)->findOneById($id_chambre);
  3080.   
  3081.       if($chambre && $chambre->getNrr())
  3082.       {
  3083.         $nrr_val true;
  3084.       }
  3085.   
  3086.   
  3087.       return $nrr_val;
  3088.     }  
  3089.     public function getNrrLastValue($datacheck)
  3090.     {
  3091.                     
  3092.                     $search_params $this->session->get('search_params');
  3093.                     $this->session->set('nrr_toapply'0);
  3094.                     $pourcentage_nrr0;
  3095.                 //apply NRR to room 
  3096.                 if($datacheck["id_thalasso"] == && $datacheck["id_chambre"] !=0)
  3097.                 {
  3098.                     $parm_pourcentage_nrr$this->em->getRepository("App\Entity\Parametrage")->findOneByCode("nrr_hotel");
  3099.                     if($parm_pourcentage_nrr && $parm_pourcentage_nrr->getvarValue() && $this->verifRoomNrr($datacheck["id_chambre"]))
  3100.                     {
  3101.                         $pourcentage_nrr=$parm_pourcentage_nrr->getvarValue();
  3102.                         $this->session->set('nrr_toapply'$pourcentage_nrr);
  3103.                     }
  3104.                     return $pourcentage_nrr;
  3105.                 }
  3106.                 //apply NRR to thalasso 
  3107.                 if($datacheck["id_thalasso"] != 0)
  3108.                 {
  3109.                         if($search_params['type_bar'] == 4
  3110.                         { 
  3111.                                 if(false)
  3112.                                 {
  3113.                                 
  3114.                                         //apply NRR 
  3115.                                         $parm_pourcentage_nrr$this->em->getRepository("App\Entity\Parametrage")->findOneByCode("nrr_soins");
  3116.                                         if($parm_pourcentage_nrr && $parm_pourcentage_nrr->getvarValue() && $this->verifProductNrr($datacheck["id_thalasso"]) )
  3117.                                         {
  3118.                                             $pourcentage_nrr=$parm_pourcentage_nrr->getvarValue();
  3119.                                             $this->session->set('nrr_toapply'$pourcentage_nrr);
  3120.                                         }
  3121.                                 }
  3122.                                 else {
  3123.                                         //apply NRR 
  3124.                                         $parm_pourcentage_nrr$this->em->getRepository("App\Entity\Parametrage")->findOneByCode("nrr_thalasso_sans_hebergement");
  3125.                                         if($parm_pourcentage_nrr && $parm_pourcentage_nrr->getvarValue() && $this->verifProductNrr($datacheck["id_thalasso"]))
  3126.                                         {
  3127.                                             $pourcentage_nrr=$parm_pourcentage_nrr->getvarValue();
  3128.                                             $this->session->set('nrr_toapply'$pourcentage_nrr);
  3129.                                         }                  
  3130.                                 }
  3131.                         }
  3132.                     if($search_params['type_bar'] == 3) {
  3133.                                 //apply NRR 
  3134.                                 $parm_pourcentage_nrr$this->em->getRepository("App\Entity\Parametrage")->findOneByCode("nrr_thalasso_avec_hebergement");
  3135.                                 if($parm_pourcentage_nrr && $parm_pourcentage_nrr->getvarValue() && $this->verifProductNrr($datacheck["id_thalasso"]))
  3136.                                 {
  3137.                                     $pourcentage_nrr=$parm_pourcentage_nrr->getvarValue();
  3138.                                     $this->session->set('nrr_toapply'$pourcentage_nrr);
  3139.                                 }                  
  3140.                             
  3141.                     }
  3142.                 }
  3143.             return $pourcentage_nrr;
  3144.     }
  3145. }