src/Controller/higotrigo/CateringCalendarController.php line 192

Open in your IDE?
  1. <?php
  2. namespace App\Controller\higotrigo;
  3. use App\Entity\HtFile;
  4. use App\Entity\User;
  5. use App\Entity\WidgetNotes;
  6. use App\Form\WidgetNotesType;
  7. use App\MDS\GreenPatioBundle\Entity\Reservation;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\Session\Session;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Google_Client;
  16. use Google_Service_Calendar;
  17. use Psr\Log\LoggerInterface;
  18. use Google_Service_Calendar_Event;
  19. use Google_Service_Calendar_EventDateTime;
  20. use FOS\RestBundle\Controller\Annotations as Rest;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  22. use DateTime;
  23. use App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice;
  24. use App\MDS\GreenPatioBundle\Entity\ReservationInvoice;
  25. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
  26. use App\MDS\GreenPatioBundle\Entity\ReservationPaymentsClient;
  27. use DatePeriod;
  28. use DateInterval;
  29. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  30. class CateringCalendarController extends AbstractController
  31. {
  32.     /**
  33.      * @Route("/higotrigo/calendar", name="ht_calendar")
  34.      */
  35.     public function calendarCateringAction(Request $request) {
  36.         $session = new Session();
  37.         $token=$session->get('tokenGoogleCalendar');
  38.         if (!is_null($token)) {
  39.             $this->googleCalendar->setAccessToken($token);
  40.             $connectGoogle "1";
  41.         }else{
  42.             $connectGoogle "0";
  43.         }
  44.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  45.         $user_id $user_logueado->getId();
  46.         $wnotes = new WidgetNotes();
  47.         $wnotes->setDateAt(new \DateTime("now"));
  48.         $form $this->createWidgetNotesCreateForm($wnotes);
  49.         return $this->render('higotrigo/calendar-ht-caterings.html.twig',
  50.             array(
  51.                 'form' => $form->createView(),
  52.                 'user'=> $user_id,
  53.                 'connectGoogle' => $connectGoogle,
  54.             )
  55.         );
  56.     }
  57.     /**
  58.      * @Route("/higotrigo/calendarwaiter", name="ht_calendar_waiter")
  59.      */
  60.     public function calendarCateringWaiterAction(Request $request) {
  61.         $session = new Session();
  62.         $token=$session->get('tokenGoogleCalendar');
  63.         if (!is_null($token)) {
  64.             $this->googleCalendar->setAccessToken($token);
  65.             $connectGoogle "1";
  66.         }else{
  67.             $connectGoogle "0";
  68.         }
  69.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  70.         $user_id $user_logueado->getId();
  71.         $wnotes = new WidgetNotes();
  72.         $wnotes->setDateAt(new \DateTime("now"));
  73.         $form $this->createWidgetNotesCreateForm($wnotes);
  74.         return $this->render('higotrigo/calendar-ht-waiters.html.twig',
  75.             array(
  76.                 'form' => $form->createView(),
  77.                 'user'=> $user_id,
  78.                 'connectGoogle' => $connectGoogle,
  79.             )
  80.         );
  81.     }
  82.     /**
  83.      * @Route("/widget/notes/calendarht/create/", name="widget_notes_calendar_ht_create")
  84.      */
  85.     public function addNotesAction(Request $requestLoggerInterface $logger)
  86.     {
  87.         $em $this->getDoctrine()->getManager();
  88.         $wnotes = new WidgetNotes();
  89.         $form $this->createWidgetNotesCreateForm($wnotes);
  90.         $form->handleRequest($request);
  91.         $forAgent $form->get('forAgent')->getData();
  92.         if(!is_null($forAgent)){ $wnotes->setForAgent($forAgent->getId()); }
  93.         if($form->isValid())
  94.         {
  95.             /* Obtengo usuario logueado */
  96.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  97.             $user_id $user_logueado->getId();
  98.             $wnotes->setCreatedId($user_id);
  99.             $wnotes->setUpdatedId($user_id);
  100.             /* Gestión de eventos en Log */
  101.             $user_lastname $user_logueado->getLastname();
  102.             $user_name $user_logueado->getName();
  103.             $user_email $user_logueado->getEmail();
  104.             $user_rol $user_logueado->getRoles();
  105.             $event_url $request->getPathInfo();
  106.             $event_complete $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  107.             try{
  108.                 $em->persist($wnotes);
  109.                 $em->flush();
  110.                 $event 'The Note has been created succesfully.';
  111.                 $successMessage $this->get('translator')->trans($event);
  112.                 $this->addFlash('mensaje'$successMessage);
  113.                 $logger->info($event_complete.' | '.$event);
  114.             } catch (\Exception $e){
  115.                 $event 'An error occurred: '.$e->getMessage();
  116.                 /* Para el log */
  117.                 $logger->error($event_complete.' | '.$event);
  118.                 /* Para el usuario */
  119.                 $errorMessage $this->get('translator')->trans($event);
  120.                 $this->addFlash('mensajeerror'$errorMessage);
  121.             }
  122.         }else{
  123.             $errorMessage $this->get('translator')->trans('Error, some fields are empty');
  124.             $this->addFlash('mensajeerror'$errorMessage);
  125.         }
  126. //        return $this->redirectToRoute('homepage');
  127.         return $this->redirectToRoute('ht_calendar');
  128.     }
  129.     /**
  130.      * @Route("/higotrigo/eventsht_OLD", name="get_caterings_ht_OLD")
  131.      */
  132.     public function htEventsOLDAction(EntityManagerInterface $em)
  133.     {
  134.         $todayOneYearAgo = new \DateTime('first day of January last year');
  135.         $parameters = array('dateStart' => $todayOneYearAgo, );
  136.         $dql 'SELECT p
  137.                 FROM App:HtFile p                         
  138.                 WHERE p.dateStart >= :dateStart AND p.dateEnd >= p.dateStart
  139.                 AND p.reservation IS NULL 
  140.                 ORDER BY p.dateStart ASC ';
  141.         $query $em->createQuery($dql)->setParameters($parameters);
  142.         $reservation $query->getResult();
  143.         $datos = array();
  144.         if (!empty($reservation)) {
  145.             foreach ($reservation as $reserva) {
  146.                 if ($reserva->getDateStart()->format('d') == $reserva->getDateEnd()->format('d')) {
  147.                     $tooltip $reserva->getTitle() . ' - Del'$reserva->getDateStart()->format('d/m') . ' desde ' $reserva->getDateStart()->format('H:i') . " a " $reserva->getDateEnd()->format('H:i');
  148.                 } else {
  149.                     $tooltip $reserva->getTitle() . ' - Del'$reserva->getDateStart()->format('d/m') . ' desde ' $reserva->getDateStart()->format('H:i') . " a " $reserva->getDateEnd()->format('d/m') . " a " $reserva->getDateEnd()->format('H:i');
  150.                 }
  151.                 $color "#c4771a";
  152.                 // Si el que crea la reserva es un agente de GP, se asigna el color #dd610b (naranja)
  153.                 $agent $reserva->getCreatedId();
  154.                 if ($agent->getTeam() == 17) {
  155. //                    $color = "#d9023d";
  156.                     $color "#ba0d0d";
  157.                 }
  158.                 // Iniciado o Cotizando
  159.                 if (($reserva->getStatus() == 'Iniciado') or ($reserva->getStatus() == 'Quoting')){ $color '#ed3939'; }
  160.                 // Cancelado
  161.                 if ($reserva->getStatus() == 'Cancel'){ $color '#000000'; }
  162.                 $datos[] = array(
  163.                     "title" => $reserva->getDateStart()->format('d/m/Y H:i') . ' ' '<br>' '<br>' $reserva->getTitle(),
  164.                     "titleOne" => $reserva->getDateStart()->format('H:i') . '<br>',
  165.                     "titleTwo" => $reserva->getDateEnd()->format('H:i') . '<br>',
  166.                     "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  167.                     "type" => '',
  168.                     "id" => $reserva->getId(),
  169.                     "tooltip" => $tooltip,
  170.                     "start" => $reserva->getDateStart(),
  171.                     "end" => $reserva->getDateEnd(),
  172.                     "color" => $color,
  173.                     "loungeId" => 1,
  174.                     "url" => "/higotrigo/ht/file/".$reserva->getId()."/edit",
  175.                     "status" => $reserva->getStatus(),
  176.                 );
  177.             }
  178.         }
  179.         $return = array( 
  180.             'reservation' => $datos,
  181.         );
  182.         $response = new JsonResponse($return);
  183.         return $response;
  184.     }
  185.     /**
  186.      * @Route("/higotrigo/eventsht", name="get_caterings_ht")
  187.      */
  188.     public function htEventsAction(UrlGeneratorInterface $urlGenerator)
  189.     {
  190.         $em $this->getDoctrine()->getManager();
  191.         // Buscamos las reservas desde 1 aƱo atras en adelante para no traer exceso de datos
  192.         $todayOneYearAgo = new DateTime('now -180 days');
  193.         $parameters = array('dateStart' => $todayOneYearAgo,);
  194.         $dql 'SELECT p
  195.                 FROM GreenPatioBundle:ReservationLoungeSimple p                         
  196.                 WHERE p.dateStart >= :dateStart  
  197.                 ORDER BY p.dateStart ASC ';
  198.         $query $em->createQuery($dql)->setParameters($parameters);
  199.         $reservation $query->getResult();
  200.         // Buscamos las visitas desde 1 semana atras en adelante para no traer exceso de datos (Tiempo confirmado por Gabriela Bracho)
  201.         $todayOneWeekAgo = new DateTime('now -1 week');
  202.         $parameters = array('dateStart' => $todayOneWeekAgo,);
  203.         $dql 'SELECT p
  204.                 FROM GreenPatioBundle:ReservationVisit p                         
  205.                 WHERE p.dateStart >= :dateStart  
  206.                 ORDER BY p.dateStart ASC ';
  207.         $query $em->createQuery($dql)->setParameters($parameters);
  208.         $visitas $query->getResult();
  209.         $arrayFechaVisitas = array();
  210.         foreach ($visitas as $item) {
  211.             //Se agrupan las visitas por fechas
  212.             $arrayFechaVisitas[$item->getDateStart()->format('Y-m-d')][] = $item;
  213.         }
  214.         $newArrayVisitas = array();
  215.         //Se agrupan las visitas por agente
  216.         foreach ($arrayFechaVisitas as $fecha) {
  217.             foreach ($fecha as $item) {
  218.                 //Se van concatenando los titulos de las visitas en una sola
  219.                 $loungeNameTemp '';
  220.                 $idAgentLounge = ($item->getIdLounge() == 0) ? $item->getAgentId() : '0';
  221.                 if (!empty($newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge])) {
  222.                     $loungeNameTemp $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge]->getLoungeName();
  223.                 }
  224.                 $item->setLoungeName($loungeNameTemp $item->getDateStart()->format('H:i') . ' ' $item->getLoungeName() . '<br>');
  225.                 $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge] = $item;
  226.             }
  227.         }
  228.         $visitas $newArrayVisitas;
  229.         foreach ($visitas as $item) { array_push($reservation$item); }
  230.         $datos = array();
  231.         if (!empty($reservation)) {
  232.             foreach ($reservation as $reservaSala) {
  233.                 if (!empty($reservaSala->getIdReservation())) {
  234.                     $reserva $em->getRepository(Reservation::class)->findOneById($reservaSala->getIdReservation());
  235.                     if ($reservaSala->getType() == 'Visit') {
  236.                         $reserva->setStatus('Visit');
  237.                     }
  238.                 } else {
  239.                     // Estamos con una visita
  240.                     $reserva = new Reservation();
  241.                     $reserva->setStatus('Visit');
  242.                     $reserva->setTitle($reservaSala->getLoungeName());
  243.                 }
  244.                 if ($reservaSala->getDateStart()->format('d') == $reservaSala->getDateEnd()->format('d')) {
  245.                     $tooltip $reserva->getTitle() . ' - <b><h3>' $reservaSala->getLoungeName() . "</h3></b> Del " $reservaSala->getDateStart()->format('d/m') . ' desde ' $reservaSala->getHourStart() . ":" $reservaSala->getMinStart() . " a " $reservaSala->getHourEnd() . ":" $reservaSala->getMinEnd();
  246.                 } else {
  247.                     $tooltip $reserva->getTitle() . ' - <b><h3>' $reservaSala->getLoungeName() . "</h3></b> Del " $reservaSala->getDateStart()->format('d/m') . ' desde ' $reservaSala->getHourStart() . ":" $reservaSala->getMinStart() . " al " $reservaSala->getDateEnd()->format('d/m') . ' hasta ' $reservaSala->getHourEnd() . ":" $reservaSala->getMinEnd();
  248.                 }
  249.                 $logicoVisita false;
  250.                 if (!is_null($reserva->getStatus())) {
  251.                     $statusColorMap = [
  252.                         'Bloqueo' => function($reservaSala) { return ($reservaSala->getIdLounge() > 21) ? "#b873bf" "#ffaa00"; },
  253.                         'Confirmed' => "#13ad27",
  254.                         'Invoiced' => "#13ad27",
  255.                         'Deleted' => "#ff0000",
  256.                         'Cotizado' => "#faafc3",
  257.                         'Reservado' => "#13ad27",
  258.                         'Visit' => function($reservaSala) {
  259.                             if ($reservaSala->getIdLounge() == 0) {
  260.                                 $agentColorMap = [
  261.                                     77 => "#22cbf5",
  262.                                     82 => "#f5229a",
  263.                                     106 => "#157cc2",
  264.                                 ];
  265.                                 return $agentColorMap[$reservaSala->getAgentId()] ?? "";
  266.                             } else {
  267.                                 return '#f0d800';
  268.                             }
  269.                         },
  270.                         'default' => "",
  271.                     ];
  272.                     $color "";
  273.                     $logicoVisita false;
  274.                     if (array_key_exists($reserva->getStatus(), $statusColorMap)) {
  275.                         $value $statusColorMap[$reserva->getStatus()];
  276.                         // Si el valor es una función, la ejecutamos para obtener el color.
  277.                         $color is_callable($value) ? $value($reservaSala) : $value;
  278.                         if ($reserva->getStatus() === 'Visit') {
  279.                             $logicoVisita true;
  280.                         }
  281.                     } else {
  282.                         $color $statusColorMap['default'];
  283.                     }
  284.                     if (!empty($reservaSala->getType()) and !($reservaSala->getType() == 'Visit')) {
  285.                         //Es un montaje o desmontaje
  286.                         $color "#a5b8a2";
  287.                         // Si es un montaje o desmontaje pero esta cancelado debe prevalecer el color de cancelado
  288.                         if ($reserva->getStatus() == 'Deleted') { $color "#ff0000"; }
  289.                     }
  290.                     if (($reservaSala->getIdLounge() == 22) or  ($reservaSala->getIdLounge() == 23) or
  291.                         ($reservaSala->getIdLounge() == 24) or ($reservaSala->getIdLounge() == 25)){
  292.                         //Ajustamos el color a una sala de covarrubia
  293.                         switch ($color) {
  294.                             case '#ffaa00'$color "#b873bf"; break; //naranja (bloqueo) => morado
  295.                             case '#13ad27'$color "#017362"; break; //verde (Confirmed) => verde olivo
  296.                             case '#ff0000'$color "#ff0000"; break; //rojo
  297.                             case '#faafc3'$color "#faafc3"; break; //Rojo claro
  298.                             default: break; //no modificar el color
  299.                         }
  300.                     }
  301.                 }
  302.                 $ht "";
  303.                 if ($reserva->getCateringName() == 'HIGO & TRIGO, S.L.') {
  304.                     $ht "<a style='color: #000 !important;'><strong>H&T</strong></a>";      // Es una reserva con servicio de Catering Higo & Trigo
  305.                 }
  306.                 // Pagos parciales y totales
  307.                 $pago1 ""$pago2 ""// En HT no son relevantes los pagos de GP
  308.                 if (!empty($reserva)) {
  309.                     if (!$logicoVisita) {
  310.                         $urlReserva "#";
  311.                         if($reserva->getHtFile() != Null){
  312.                             $urlReserva $urlGenerator->generate('app_ht_file_edit', ['id' => $reserva->getHtFile()->getId()]);
  313.                         }
  314.                         $datos[] = array(
  315.                             "title" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . '<br>' $reservaSala->getLoungeName() . '<br>' '<br>' $reserva->getTitle(),
  316.                             "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . '<br>',
  317.                             "titleTwo" => $reservaSala->getLoungeName(),
  318.                             "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  319.                             "type" => $reservaSala->getType(),
  320.                             "id" => $reserva->getId(),
  321.                             "tooltip" => $tooltip,
  322.                             "start" => $reservaSala->getDateStart(),
  323.                             "end" => $reservaSala->getDateEnd(),
  324.                             "color" => $color,
  325.                             "loungeId" => $reservaSala->getIdLounge(),
  326.                             "url" => $urlReserva,
  327.                             "status" => $reserva->getStatus(),
  328.                         );
  329.                     } else {
  330.                         // Es una visita
  331.                         $datos[] = array(
  332.                             "title" => $reservaSala->getLoungeName(),
  333.                             "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' ' ' $reservaSala->getType() . '<br>',
  334.                             "titleTwo" => $reservaSala->getLoungeName(),
  335.                             "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  336.                             "type" => $reservaSala->getType(),
  337.                             "id" => $reservaSala->getId() . 'V',
  338.                             "tooltip" => $tooltip,
  339.                             "start" => $reservaSala->getDateStart(),
  340.                             "end" => $reservaSala->getDateEnd(),
  341.                             "color" => $color,
  342.                             "loungeId" => $reservaSala->getIdLounge(),
  343.                             "url" => '/reservations-greenpatio/addvisit',
  344.                             "status" => $reserva->getStatus(),
  345.                             "agentId" => $reservaSala->getAgentId(),
  346.                         );
  347.                     }
  348.                 } else {
  349.                     $datos = [];
  350.                 }
  351.             }
  352.         }
  353.         $newDatos = array();
  354.         // INICIO: Se unen las salas en una sola reserva por ID de reserva
  355.         foreach ($datos as $dato) {
  356.             // Inicializamos el arreglo para crear los indices
  357.             switch ($dato['color']){
  358.                 case '#a5b8a2':              //Montaje o Desmontaje
  359.                     if ($dato['type'] == 'Montaje'){
  360.                         $newDatos[$dato['id'].'M'] = null;
  361.                     } else {
  362.                         $newDatos[$dato['id'].'D'] = null;
  363.                     }
  364.                     break;
  365.                 default:                    //Dia de reserva o Visita (la visita ya viene con su indice #V )
  366.                     $newDatos[$dato['id']] = null;
  367.                     break;
  368.             }
  369.         }
  370.         foreach ($datos as $dato) {
  371.             switch ($dato['color']){
  372.                 //Montaje o Desmontaje
  373.                 case '#a5b8a2':
  374.                     if ($dato['type'] == "Montaje") {
  375.                         if (!empty($newDatos[$dato['id'] . 'M'])) {
  376.                             // El Montaje esta ocupando mas de 1 dia, se deben unir los dias de montaje
  377.                             if ($newDatos[$dato['id'] . 'M']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'M']['start'] = $dato['start']; }
  378.                             if ($newDatos[$dato['id'] . 'M']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'M']['end'] = $dato['end']; }
  379.                         } else {
  380.                             $newDatos[$dato['id'] . 'M'] = $dato;
  381.                         }
  382.                     } else {
  383.                         if ($dato['type'] == "Desmontaje") {
  384.                             if (!empty($newDatos[$dato['id'] . 'D'])) {
  385.                                 // El Desmontaje esta ocupando mas de 1 dia, se deben unir los dias de desmontaje
  386.                                 if ($newDatos[$dato['id'] . 'D']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'D']['start'] = $dato['start']; }
  387.                                 if ($newDatos[$dato['id'] . 'D']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'D']['end'] = $dato['end']; }
  388.                             } else {
  389.                                 $newDatos[$dato['id'] . 'D'] = $dato;
  390.                             }
  391.                         }
  392.                     }
  393.                     break;
  394.                 //Visita Angie (id user 77)
  395.                 case '#22cbf5':
  396.                     if ($dato['type'] == "Visit") {
  397.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V77'])) {
  398.                             // Hay varias visitas ese mismo dia para el agente
  399.                             $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] . $dato['tooltip'];
  400.                         } else {
  401.                             $newDatos[$dato['start']->format('Ymd').'V77'] = $dato;
  402.                         }
  403.                     }
  404.                     break;
  405.                 //Visita Gabriela (id user 82)
  406.                 case '#f5229a':
  407.                     if ($dato['type'] == "Visit") {
  408.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V82'])) {
  409.                             // Hay varias visitas ese mismo dia para el agente
  410.                             $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] . $dato['tooltip'];
  411.                         } else {
  412.                             $newDatos[$dato['start']->format('Ymd').'V82'] = $dato;
  413.                         }
  414.                     }
  415.                     break;
  416.                 //Visita MarĆ­a (id user 106)
  417.                 case '#157cc2':
  418.                     if ($dato['type'] == "Visit") {
  419.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V106'])) {
  420.                             // Hay varias visitas ese mismo dia para el agente
  421.                             $newDatos[$dato['start']->format('Ymd').'V106']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V106']['tooltip'] . $dato['tooltip'];
  422.                         } else {
  423.                             $newDatos[$dato['start']->format('Ymd').'V106'] = $dato;
  424.                         }
  425.                     }
  426.                     break;
  427.                 //Visita Generica para agentes a Covarrubias
  428.                 case '#f0d800':
  429.                     if ($dato['type'] == "Visit") {
  430.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V0'])) {
  431.                             // Hay varias visitas ese mismo dia para el agente
  432.                             $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] . $dato['tooltip'];
  433.                         } else {
  434.                             $newDatos[$dato['start']->format('Ymd').'V0'] = $dato;
  435.                         }
  436.                     }
  437.                     break;
  438.                 //Reserva color naranja Bloqueo
  439.                 case '#ffaa00':
  440.                     if (empty($newDatos[$dato['id']])){
  441.                         $newDatos[$dato['id']] = $dato;
  442.                     } else {
  443.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  444.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  445.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  446.                         }
  447.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  448.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  449.                         }
  450.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  451.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  452.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  453.                             // No se encontro la cadena, debemos agregar
  454.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  455.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  456.                         }
  457.                     }
  458.                     break;
  459.                 //Reserva color morado Bloqueo (Covarrubias)
  460.                 case '#b873bf':
  461.                     if (empty($newDatos[$dato['id']])){
  462.                         $newDatos[$dato['id']] = $dato;
  463.                     } else {
  464.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  465.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  466.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  467.                         }
  468.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  469.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  470.                         }
  471.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  472.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  473.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  474.                             // No se encontro la cadena, debemos agregar
  475.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  476.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  477.                         }
  478.                     }
  479.                     break;
  480.                 //Reserva color Rojo claro Cotizado
  481.                 case '#faafc3':
  482.                     if (empty($newDatos[$dato['id']])){
  483.                         $newDatos[$dato['id']] = $dato;
  484.                     } else {
  485.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  486.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  487.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  488.                         }
  489.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  490.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  491.                         }
  492.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  493.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  494.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  495.                             // No se encontro la cadena, debemos agregar
  496.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  497.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  498.                         }
  499.                     }
  500.                     break;
  501.                 //Reserva color Rojo Reserva Cancelada
  502.                 // Revisar el caso de una reserva externa para el calendario y el caso de una reserva cancelada de GP pero sigue firme para HT
  503.                 case '#ff0000':
  504.                     //Las canceladas no se muestran en el calendario
  505.                     break;
  506.                 //Reserva color Verde Reserva Confirmada, Facturada, (se ha adelantado un pago parcial)
  507.                 case '#13ad27':
  508.                     if (empty($newDatos[$dato['id']])){
  509.                         $newDatos[$dato['id']] = $dato;
  510.                     } else {
  511.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  512.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  513.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  514.                         }
  515.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  516.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  517.                         }
  518.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  519.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  520.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  521.                             // No se encontro la cadena, debemos agregar
  522.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  523.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  524.                         }
  525.                     }
  526.                     break;
  527.                 //Reserva color Verde Reserva Confirmada, Facturada, (Covarrubias)
  528.                 case '#017362':
  529.                     if (empty($newDatos[$dato['id']])){
  530.                         $newDatos[$dato['id']] = $dato;
  531.                     } else {
  532.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  533.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  534.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  535.                         }
  536.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  537.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  538.                         }
  539.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  540.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  541.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  542.                             // No se encontro la cadena, debemos agregar
  543.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  544.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  545.                         }
  546.                     }
  547.                     break;
  548.                 //Se pondra color a negro para resaltar este cualquier caso que no haya sido considerado (status Pendiente)
  549.                 default:
  550.                     if (empty($newDatos[$dato['id']])){
  551.                         $newDatos[$dato['id']] = $dato;
  552.                     } else {
  553.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  554.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  555.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  556.                         }
  557.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  558.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  559.                         }
  560.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  561.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  562.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  563.                             // No se encontro la cadena, debemos agregar
  564.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  565.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  566.                         }
  567.                     }
  568.                     // Se pone en color amarillo para resaltar este caso que no esta entrando en ninguno de los casos anteriores
  569.                     $newDatos[$dato['id']]['color'] = '#f0d800';
  570.                     break;
  571.             }
  572.         }
  573.         $datos0 = array();
  574.         foreach ($newDatos as $key => $item) {
  575.             if (!empty($item['id'])) {
  576.                 $datos0[$key] = array('title' => $item['title'],
  577.                     'titleOne' => $item['titleOne'],
  578.                     'titleTwo' => $item['titleTwo'],
  579.                     'titleThree' => $item['titleThree'],
  580.                     'type' => $item['type'],
  581.                     'id' => $item['id'],
  582.                     'tooltip' => $item['tooltip'],
  583.                     'start' => $item['start'],
  584.                     'end' => $item['end'],
  585.                     'color' => $item['color'],
  586.                     'loungeId' => $item['loungeId'],
  587.                     'url' => $item['url'],
  588.                     'status' => $item['status'],
  589.                 );
  590.             }
  591.         }
  592.         $newDatos $datos0;
  593.         $datos = array();
  594.         foreach ($newDatos as $item) {
  595.             if ($item['color'] != '#ff0000') {
  596.                 // No se agregan al calendario los elementos eliminados o elementos vacios
  597.                 if (!empty($item)) {
  598.                     //INICIO: Verificamos por huecos dentro de la reserva
  599.                     if (empty($item['type'])) {
  600.                         // solo las reservas se van a verificar en este if
  601.                         if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el evento tiene mas de 2 dias, puede haber huecos
  602.                             $resSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($item['id']);
  603.                             $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  604.                             $arrayPeriod = array();
  605.                             foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  606.                             $logAllDiasEnReserva false;
  607.                             $logDiaEnReserva false;
  608.                             //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  609.                             foreach ($arrayPeriod as $day) {
  610.                                 foreach ($resSimples as $resSimple) {
  611.                                     if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  612.                                         $logDiaEnReserva true;
  613.                                         break;
  614.                                     }
  615.                                 }
  616.                                 if (!$logDiaEnReserva) {
  617.                                     //Un dia no se encontraba, hay un hueco
  618.                                     foreach ($resSimples as $resDayToAdd) {
  619.                                         if (empty($resDayToAdd->getType())) {       // Solo se deben agregar salsa los montajes y desmontajes aqui no van
  620.                                             $item['start'] = $resDayToAdd->getDateStart();
  621.                                             $item['end'] = $resDayToAdd->getDateEnd();
  622.                                             $br '<br>';
  623.                                             $br strpos($item['title'], $br);
  624.                                             $tempText substr($item['title'], $br 4);
  625.                                             $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  626.                                             $datos[] = $item;
  627.                                         }
  628.                                     }
  629.                                     break;
  630.                                 } else {
  631.                                     //Se debe evaluar el siguiente dia
  632.                                     $logDiaEnReserva false;
  633.                                     if ($day->format('Y-m-d') == (end($arrayPeriod))->format('Y-m-d')) {   //Si es el ultimo elemento evaluado, todos los dias se encontraban en Reservas Simple
  634.                                         $logAllDiasEnReserva true;
  635.                                     }
  636.                                 }
  637.                             }
  638.                             if ($logAllDiasEnReserva) { $datos[] = $item; }
  639.                         } else {
  640.                             // El evento es de 1 o 2 dias, no hay posibilidad de hueco
  641.                             $datos[] = $item;
  642.                         }
  643.                     } else {
  644.                         //Es Visita Las visitas son las unicas entradas que no tienen hueco
  645.                         if ($item['type'] == 'Visit'){
  646.                             $datos[] = $item;
  647.                         } else {
  648.                             // es montaje o desmontaje, se va verificar por huecos
  649.                             if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el item tiene mas de 2 dias, puede haber huecos
  650.                                 $parameters = array(
  651.                                     'id' => $item['id'],
  652.                                     'type' => $item['type'],
  653.                                 );
  654.                                 $dql 'SELECT i
  655.                                         FROM GreenPatioBundle:ReservationLoungeSimple i
  656.                                         WHERE  i.idReservation = :id
  657.                                           and i.type = :type';
  658.                                 $query $em->createQuery($dql)->setParameters($parameters);
  659.                                 $resSimples $query->getResult();
  660.                                 $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  661.                                 $arrayPeriod = array();
  662.                                 foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  663.                                 $logAllDiasEnReserva false;
  664.                                 $logDiaEnReserva false;
  665.                                 //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  666.                                 foreach ($arrayPeriod as $day) {
  667.                                     foreach ($resSimples as $resSimple) {
  668.                                         if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  669.                                             $logDiaEnReserva true;
  670.                                             break;
  671.                                         }
  672.                                     }
  673.                                     if (!$logDiaEnReserva) {
  674.                                         //Un dia no se encontraba, hay un hueco
  675.                                         foreach ($resSimples as $resDayToAdd) {
  676.                                             if (!empty($resDayToAdd->getType())) {       // Solo se deben agregar montajes y desmontajes aqui
  677.                                                 $item['start'] = $resDayToAdd->getDateStart();
  678.                                                 $item['end'] = $resDayToAdd->getDateEnd();
  679.                                                 $br '<br>';
  680.                                                 $br strpos($item['title'], $br);
  681.                                                 $tempText substr($item['title'], $br 4);
  682.                                                 $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  683.                                                 $datos[] = $item;
  684.                                             }
  685.                                         }
  686.                                         break;
  687.                                     } else {
  688.                                         //Se debe evaluar el siguiente dia
  689.                                         $logDiaEnReserva false;
  690.                                         if ($day->format('Y-m-d') == (end($arrayPeriod))->format('Y-m-d')) {   //Si es el ultimo elemento evaluado, todos los dias se encontraban en Reservas Simple
  691.                                             $logAllDiasEnReserva true;
  692.                                         }
  693.                                     }
  694.                                 }
  695.                                 if ($logAllDiasEnReserva) { $datos[] = $item; }
  696.                             } else {
  697.                                 // El montaje o desmontaje es de 1 o 2 dias, no hay posibilidad de hueco
  698.                                 $datos[] = $item;
  699.                             }
  700.                         }
  701.                     }
  702.                     //FIN: Verificamos por huecos dentro de la reserva
  703.                 }
  704.             }
  705.         }
  706.         // Buscamos las pruebas de menu desde 6 meses atras
  707.         $todayHalfYearAgo = new DateTime('now -180 days');
  708.         $parameters = array('dateStart' => $todayHalfYearAgo,);
  709.         $dql 'SELECT p
  710.                 FROM App:HtVisit p                         
  711.                 WHERE p.dateStart >= :dateStart  
  712.                 ORDER BY p.dateStart ASC ';
  713.         $query $em->createQuery($dql)->setParameters($parameters);
  714.         $pmenu $query->getResult();
  715.         $arrayPmenu = array(); $color '#ccad11';
  716.         foreach ($pmenu as $item){
  717.             $agent = (!empty($item->getAgentId())) ? ($item->getAgentId())->getName() : 'Sin agente';
  718.             $pax = (!empty($item->getPax())) ? (' - '.$item->getPax() . ' PAX') : null;
  719.             $title =''$titleOne =''$titleTwo =''$titleThree =''$type =''$id =''$tooltip =''$start =''$end =''$loungeId =''$url ='';
  720.             if(!empty($item->getReservation())){
  721.                 $title = ($item->getDateStart())->format('H:i'). ' PRUEBA DE MENU ( '.$agent' )<br>' $item->getName(). $pax ' - ' . ($item->getReservation())->getTitle();
  722.                 $titleOne '$titleOne';
  723.                 $titleTwo '$titleTwo';
  724.                 $titleThree '$titleThree';
  725.                 $type 'Prueba Menu';
  726.                 $id $item->getId();
  727.                 $loungeId = (!empty(($item->getLounge()))) ? '<b> - '. ($item->getLounge())->getName() : null;
  728.                 $tooltip '<b>'. ($item->getReservation())->getTitle() .$loungeId;
  729.                 $start $item->getDateStart();
  730.                 $end $item->getDateEnd();
  731.                 $end->modify('+1 hour');
  732.                 $loungeId = ($item->getLounge())->getId();
  733.                 $url '/higotrigo/ht/file/'.($item->getReservation())->getId().'/edit';
  734.             } else {
  735.                 $title = ($item->getDateStart())->format('H:i'). ' PRUEBA DE MENU ( '.$agent' )<br>' $item->getName() . $pax;
  736.                 $titleOne '$titleOne';
  737.                 $titleTwo '$titleTwo';
  738.                 $titleThree '$titleThree';
  739.                 $type 'Prueba Menu';
  740.                 $id $item->getId();
  741.                 $loungeId = (!empty(($item->getLounge()))) ? '<b> '. ($item->getLounge())->getName() : null;
  742.                 $tooltip '<b>' $loungeId;
  743.                 $start $item->getDateStart();
  744.                 $end $item->getDateEnd();
  745.                 $end->modify('+1 hour');
  746.                 $loungeId = ($item->getLounge())->getId();
  747.                 $url '/#';
  748.             }
  749.             $arrayPmenu[] = array(
  750.                 'title' => $title,
  751.                 'titleOne' => $titleOne,
  752.                 'titleTwo' => $titleTwo,
  753.                 'titleThree' => $titleThree,
  754.                 'type' => $type,
  755.                 'id' => $id,
  756.                 'tooltip' => $tooltip,
  757.                 'start' => $start,
  758.                 'end' => $end,
  759.                 'color' => $color,
  760.                 'loungeId' => $loungeId,
  761.                 'url' => $url,
  762.             );
  763.         }
  764.         foreach ($arrayPmenu as $item){ array_push($datos$item); }
  765.         $return = array( 'reservation' => $datos, );
  766.         $response = new JsonResponse($return);
  767.         return $response;
  768.     }
  769.     /**
  770.      * @Route("/higotrigo/eventsht_OLD_waiter", name="get_caterings_ht_OLD_waiter")
  771.      */
  772.     public function htEventsOLDWaiterAction(EntityManagerInterface $em)
  773.     {
  774.         $todayOneYearAgo = new \DateTime('first day of January last year');
  775.         $parameters = array('dateStart' => $todayOneYearAgo, );
  776.         $dql 'SELECT p
  777.                 FROM App:HtFile p                         
  778.                 WHERE p.dateStart >= :dateStart AND p.dateEnd >= p.dateStart
  779.                 AND p.reservation IS NULL 
  780.                 ORDER BY p.dateStart ASC ';
  781.         $query $em->createQuery($dql)->setParameters($parameters);
  782.         $reservation $query->getResult();
  783.         $datos = array();
  784.         if (!empty($reservation)) {
  785.             foreach ($reservation as $reserva) {
  786.                 if ($reserva->getDateStart()->format('d') == $reserva->getDateEnd()->format('d')) {
  787.                     $tooltip $reserva->getTitle() . ' - Del'$reserva->getDateStart()->format('d/m') . ' desde ' $reserva->getDateStart()->format('H:i') . " a " $reserva->getDateEnd()->format('H:i');
  788.                 } else {
  789.                     $tooltip $reserva->getTitle() . ' - Del'$reserva->getDateStart()->format('d/m') . ' desde ' $reserva->getDateStart()->format('H:i') . " a " $reserva->getDateEnd()->format('d/m') . " a " $reserva->getDateEnd()->format('H:i');
  790.                 }
  791.                 $color "#c4771a";
  792.                 // Si el que crea la reserva es un agente de GP, se asigna el color #dd610b (naranja)
  793.                 $agent $reserva->getCreatedId();
  794.                 if ($agent->getTeam() == 17) {
  795.                     $color "#ba0d0d";
  796.                 }
  797.                 // Iniciado o Cotizando
  798.                 if (($reserva->getStatus() == 'Iniciado') or ($reserva->getStatus() == 'Quoting')){ $color '#ed3939'; }
  799.                 // Cancelado
  800.                 if ($reserva->getStatus() == 'Cancel'){ $color '#000000'; }
  801.                 $datos[] = array(
  802.                     "title" => $reserva->getDateStart()->format('d/m/Y H:i') . ' ' '<br>' '<br>' $reserva->getTitle(),
  803.                     "titleOne" => $reserva->getDateStart()->format('H:i') . '<br>',
  804.                     "titleTwo" => $reserva->getDateEnd()->format('H:i') . '<br>',
  805.                     "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  806.                     "type" => '',
  807.                     "id" => $reserva->getId(),
  808.                     "tooltip" => $tooltip,
  809.                     "start" => $reserva->getDateStart(),
  810.                     "end" => $reserva->getDateEnd(),
  811.                     "color" => $color,
  812.                     "loungeId" => 1,
  813.                     "url" => "/higotrigo/ht/file/htexternal/".$reserva->getId()."/summary",
  814.                     "status" => $reserva->getStatus(),
  815.                 );
  816.             }
  817.         }
  818.         $return = array(
  819.             'reservation' => $datos,
  820.         );
  821.         $response = new JsonResponse($return);
  822.         return $response;
  823.     }
  824.     /**
  825.      * @Route("/higotrigo/eventshtwaiter", name="get_caterings_ht_waiter")
  826.      */
  827.     public function htEventsWaiterAction(UrlGeneratorInterface $urlGenerator)
  828.     {
  829.         $em $this->getDoctrine()->getManager();
  830.         // Buscamos las reservas desde 1 aƱo atras en adelante para no traer exceso de datos
  831.         $todayOneYearAgo = new DateTime('now -180 days');
  832.         $parameters = array('dateStart' => $todayOneYearAgo,);
  833.         $dql 'SELECT p
  834.                 FROM GreenPatioBundle:ReservationLoungeSimple p                         
  835.                 WHERE p.dateStart >= :dateStart  
  836.                 ORDER BY p.dateStart ASC ';
  837.         $query $em->createQuery($dql)->setParameters($parameters);
  838.         $reservation $query->getResult();
  839.         $datos = array();
  840.         if (!empty($reservation)) {
  841.             foreach ($reservation as $reservaSala) {
  842.                 if (!empty($reservaSala->getIdReservation())) {
  843.                     $reserva $em->getRepository(Reservation::class)->findOneById($reservaSala->getIdReservation());
  844.                     if ($reservaSala->getType() == 'Visit') {
  845.                         $reserva->setStatus('Visit');
  846.                     }
  847.                 } else {
  848.                     // Estamos con una visita
  849.                     $reserva = new Reservation();
  850.                     $reserva->setStatus('Visit');
  851.                     $reserva->setTitle($reservaSala->getLoungeName());
  852.                 }
  853.                 if ($reservaSala->getDateStart()->format('d') == $reservaSala->getDateEnd()->format('d')) {
  854.                     $tooltip $reserva->getTitle() . ' - <b><h3>' $reservaSala->getLoungeName() . "</h3></b> Del " $reservaSala->getDateStart()->format('d/m') . ' desde ' $reservaSala->getHourStart() . ":" $reservaSala->getMinStart() . " a " $reservaSala->getHourEnd() . ":" $reservaSala->getMinEnd();
  855.                 } else {
  856.                     $tooltip $reserva->getTitle() . ' - <b><h3>' $reservaSala->getLoungeName() . "</h3></b> Del " $reservaSala->getDateStart()->format('d/m') . ' desde ' $reservaSala->getHourStart() . ":" $reservaSala->getMinStart() . " al " $reservaSala->getDateEnd()->format('d/m') . ' hasta ' $reservaSala->getHourEnd() . ":" $reservaSala->getMinEnd();
  857.                 }
  858.                 $logicoVisita false;
  859.                 if (!is_null($reserva->getStatus())) {
  860.                     $statusColorMap = [
  861.                         'Bloqueo' => function($reservaSala) { return ($reservaSala->getIdLounge() > 21) ? "#b873bf" "#ffaa00"; },
  862.                         'Confirmed' => "#13ad27",
  863.                         'Invoiced' => "#13ad27",
  864.                         'Deleted' => "#ff0000",
  865.                         'Cotizado' => "#faafc3",
  866.                         'Reservado' => "#13ad27",
  867.                         'Visit' => function($reservaSala) {
  868.                             if ($reservaSala->getIdLounge() == 0) {
  869.                                 $agentColorMap = [
  870.                                     77 => "#22cbf5",
  871.                                     82 => "#f5229a",
  872.                                     106 => "#157cc2",
  873.                                 ];
  874.                                 return $agentColorMap[$reservaSala->getAgentId()] ?? "";
  875.                             } else {
  876.                                 return '#f0d800';
  877.                             }
  878.                         },
  879.                         'default' => "",
  880.                     ];
  881.                     $color "";
  882.                     $logicoVisita false;
  883.                     if (array_key_exists($reserva->getStatus(), $statusColorMap)) {
  884.                         $value $statusColorMap[$reserva->getStatus()];
  885.                         // Si el valor es una función, la ejecutamos para obtener el color.
  886.                         $color is_callable($value) ? $value($reservaSala) : $value;
  887.                         if ($reserva->getStatus() === 'Visit') {
  888.                             $logicoVisita true;
  889.                         }
  890.                     } else {
  891.                         $color $statusColorMap['default'];
  892.                     }
  893.                     if (!empty($reservaSala->getType()) and !($reservaSala->getType() == 'Visit')) {
  894.                         //Es un montaje o desmontaje
  895.                         $color "#a5b8a2";
  896.                         // Si es un montaje o desmontaje pero esta cancelado debe prevalecer el color de cancelado
  897.                         if ($reserva->getStatus() == 'Deleted') { $color "#ff0000"; }
  898.                     }
  899.                     if (($reservaSala->getIdLounge() == 22) or  ($reservaSala->getIdLounge() == 23) or
  900.                         ($reservaSala->getIdLounge() == 24) or ($reservaSala->getIdLounge() == 25)){
  901.                         //Ajustamos el color a una sala de covarrubia
  902.                         switch ($color) {
  903.                             case '#ffaa00'$color "#b873bf"; break; //naranja (bloqueo) => morado
  904.                             case '#13ad27'$color "#017362"; break; //verde (Confirmed) => verde olivo
  905.                             case '#ff0000'$color "#ff0000"; break; //rojo
  906.                             case '#faafc3'$color "#faafc3"; break; //Rojo claro
  907.                             default: break; //no modificar el color
  908.                         }
  909.                     }
  910.                 }
  911.                 $ht "";
  912.                 if ($reserva->getCateringName() == 'HIGO & TRIGO, S.L.') {
  913.                     $ht "<a style='color: #000 !important;'><strong>H&T</strong></a>";      // Es una reserva con servicio de Catering Higo & Trigo
  914.                 }
  915.                 // Pagos parciales y totales
  916.                 $pago1 ""$pago2 ""// En HT no son relevantes los pagos de GP
  917.                 if (!empty($reserva)) {
  918.                     if (!$logicoVisita) {
  919.                         $urlReserva "#";
  920.                         if($reserva->getHtFile() != Null){
  921.                             $urlReserva $urlGenerator->generate('app_ht_file_summary', ['id' => $reserva->getHtFile()->getId()]);
  922.                         }
  923.                         $datos[] = array(
  924.                             "title" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . '<br>' $reservaSala->getLoungeName() . '<br>' '<br>' $reserva->getTitle(),
  925.                             "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . '<br>',
  926.                             "titleTwo" => $reservaSala->getLoungeName(),
  927.                             "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  928.                             "type" => $reservaSala->getType(),
  929.                             "id" => $reserva->getId(),
  930.                             "tooltip" => $tooltip,
  931.                             "start" => $reservaSala->getDateStart(),
  932.                             "end" => $reservaSala->getDateEnd(),
  933.                             "color" => $color,
  934.                             "loungeId" => $reservaSala->getIdLounge(),
  935.                             "url" => $urlReserva,
  936.                             "status" => $reserva->getStatus(),
  937.                         );
  938.                     } else {
  939.                         // Es una visita
  940.                         $datos[] = array(
  941.                             "title" => $reservaSala->getLoungeName(),
  942.                             "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' ' ' $reservaSala->getType() . '<br>',
  943.                             "titleTwo" => $reservaSala->getLoungeName(),
  944.                             "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  945.                             "type" => $reservaSala->getType(),
  946.                             "id" => $reservaSala->getId() . 'V',
  947.                             "tooltip" => $tooltip,
  948.                             "start" => $reservaSala->getDateStart(),
  949.                             "end" => $reservaSala->getDateEnd(),
  950.                             "color" => $color,
  951.                             "loungeId" => $reservaSala->getIdLounge(),
  952.                             "url" => '/reservations-greenpatio/addvisit',
  953.                             "status" => $reserva->getStatus(),
  954.                             "agentId" => $reservaSala->getAgentId(),
  955.                         );
  956.                     }
  957.                 } else {
  958.                     $datos = [];
  959.                 }
  960.             }
  961.         }
  962.         $newDatos = array();
  963.         // INICIO: Se unen las salas en una sola reserva por ID de reserva
  964.         foreach ($datos as $dato) {
  965.             // Inicializamos el arreglo para crear los indices
  966.             switch ($dato['color']){
  967.                 case '#a5b8a2':              //Montaje o Desmontaje
  968.                     if ($dato['type'] == 'Montaje'){
  969.                         $newDatos[$dato['id'].'M'] = null;
  970.                     } else {
  971.                         $newDatos[$dato['id'].'D'] = null;
  972.                     }
  973.                     break;
  974.                 default:                    //Dia de reserva o Visita (la visita ya viene con su indice #V )
  975.                     $newDatos[$dato['id']] = null;
  976.                     break;
  977.             }
  978.         }
  979.         foreach ($datos as $dato) {
  980.             switch ($dato['color']){
  981.                 //Montaje o Desmontaje
  982.                 case '#a5b8a2':
  983.                     if ($dato['type'] == "Montaje") {
  984.                         if (!empty($newDatos[$dato['id'] . 'M'])) {
  985.                             // El Montaje esta ocupando mas de 1 dia, se deben unir los dias de montaje
  986.                             if ($newDatos[$dato['id'] . 'M']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'M']['start'] = $dato['start']; }
  987.                             if ($newDatos[$dato['id'] . 'M']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'M']['end'] = $dato['end']; }
  988.                         } else {
  989.                             $newDatos[$dato['id'] . 'M'] = $dato;
  990.                         }
  991.                     } else {
  992.                         if ($dato['type'] == "Desmontaje") {
  993.                             if (!empty($newDatos[$dato['id'] . 'D'])) {
  994.                                 // El Desmontaje esta ocupando mas de 1 dia, se deben unir los dias de desmontaje
  995.                                 if ($newDatos[$dato['id'] . 'D']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'D']['start'] = $dato['start']; }
  996.                                 if ($newDatos[$dato['id'] . 'D']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'D']['end'] = $dato['end']; }
  997.                             } else {
  998.                                 $newDatos[$dato['id'] . 'D'] = $dato;
  999.                             }
  1000.                         }
  1001.                     }
  1002.                     break;
  1003.                 //Visita Angie (id user 77)
  1004.                 case '#22cbf5':
  1005.                     if ($dato['type'] == "Visit") {
  1006.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V77'])) {
  1007.                             // Hay varias visitas ese mismo dia para el agente
  1008.                             $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] . $dato['tooltip'];
  1009.                         } else {
  1010.                             $newDatos[$dato['start']->format('Ymd').'V77'] = $dato;
  1011.                         }
  1012.                     }
  1013.                     break;
  1014.                 //Visita Gabriela (id user 82)
  1015.                 case '#f5229a':
  1016.                     if ($dato['type'] == "Visit") {
  1017.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V82'])) {
  1018.                             // Hay varias visitas ese mismo dia para el agente
  1019.                             $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] . $dato['tooltip'];
  1020.                         } else {
  1021.                             $newDatos[$dato['start']->format('Ymd').'V82'] = $dato;
  1022.                         }
  1023.                     }
  1024.                     break;
  1025.                 //Visita MarĆ­a (id user 106)
  1026.                 case '#157cc2':
  1027.                     if ($dato['type'] == "Visit") {
  1028.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V106'])) {
  1029.                             // Hay varias visitas ese mismo dia para el agente
  1030.                             $newDatos[$dato['start']->format('Ymd').'V106']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V106']['tooltip'] . $dato['tooltip'];
  1031.                         } else {
  1032.                             $newDatos[$dato['start']->format('Ymd').'V106'] = $dato;
  1033.                         }
  1034.                     }
  1035.                     break;
  1036.                 //Visita Generica para agentes a Covarrubias
  1037.                 case '#f0d800':
  1038.                     if ($dato['type'] == "Visit") {
  1039.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V0'])) {
  1040.                             // Hay varias visitas ese mismo dia para el agente
  1041.                             $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] . $dato['tooltip'];
  1042.                         } else {
  1043.                             $newDatos[$dato['start']->format('Ymd').'V0'] = $dato;
  1044.                         }
  1045.                     }
  1046.                     break;
  1047.                 //Reserva color naranja Bloqueo
  1048.                 case '#ffaa00':
  1049.                     if (empty($newDatos[$dato['id']])){
  1050.                         $newDatos[$dato['id']] = $dato;
  1051.                     } else {
  1052.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1053.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  1054.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  1055.                         }
  1056.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  1057.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  1058.                         }
  1059.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1060.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1061.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1062.                             // No se encontro la cadena, debemos agregar
  1063.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  1064.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1065.                         }
  1066.                     }
  1067.                     break;
  1068.                 //Reserva color morado Bloqueo (Covarrubias)
  1069.                 case '#b873bf':
  1070.                     if (empty($newDatos[$dato['id']])){
  1071.                         $newDatos[$dato['id']] = $dato;
  1072.                     } else {
  1073.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1074.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  1075.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  1076.                         }
  1077.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  1078.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  1079.                         }
  1080.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1081.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1082.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1083.                             // No se encontro la cadena, debemos agregar
  1084.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  1085.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1086.                         }
  1087.                     }
  1088.                     break;
  1089.                 //Reserva color Rojo claro Cotizado
  1090.                 case '#faafc3':
  1091.                     if (empty($newDatos[$dato['id']])){
  1092.                         $newDatos[$dato['id']] = $dato;
  1093.                     } else {
  1094.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1095.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  1096.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  1097.                         }
  1098.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  1099.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  1100.                         }
  1101.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1102.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1103.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1104.                             // No se encontro la cadena, debemos agregar
  1105.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  1106.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1107.                         }
  1108.                     }
  1109.                     break;
  1110.                 //Reserva color Rojo Reserva Cancelada
  1111.                 // Revisar el caso de una reserva externa para el calendario y el caso de una reserva cancelada de GP pero sigue firme para HT
  1112.                 case '#ff0000':
  1113.                     //Las canceladas no se muestran en el calendario
  1114.                     break;
  1115.                 //Reserva color Verde Reserva Confirmada, Facturada, (se ha adelantado un pago parcial)
  1116.                 case '#13ad27':
  1117.                     if (empty($newDatos[$dato['id']])){
  1118.                         $newDatos[$dato['id']] = $dato;
  1119.                     } else {
  1120.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1121.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  1122.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  1123.                         }
  1124.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  1125.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  1126.                         }
  1127.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1128.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1129.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1130.                             // No se encontro la cadena, debemos agregar
  1131.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  1132.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1133.                         }
  1134.                     }
  1135.                     break;
  1136.                 //Reserva color Verde Reserva Confirmada, Facturada, (Covarrubias)
  1137.                 case '#017362':
  1138.                     if (empty($newDatos[$dato['id']])){
  1139.                         $newDatos[$dato['id']] = $dato;
  1140.                     } else {
  1141.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1142.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  1143.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  1144.                         }
  1145.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  1146.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  1147.                         }
  1148.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1149.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1150.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1151.                             // No se encontro la cadena, debemos agregar
  1152.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  1153.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1154.                         }
  1155.                     }
  1156.                     break;
  1157.                 //Se pondra color a negro para resaltar este cualquier caso que no haya sido considerado (status Pendiente)
  1158.                 default:
  1159.                     if (empty($newDatos[$dato['id']])){
  1160.                         $newDatos[$dato['id']] = $dato;
  1161.                     } else {
  1162.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1163.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  1164.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  1165.                         }
  1166.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  1167.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  1168.                         }
  1169.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1170.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1171.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1172.                             // No se encontro la cadena, debemos agregar
  1173.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  1174.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1175.                         }
  1176.                     }
  1177.                     // Se pone en color amarillo para resaltar este caso que no esta entrando en ninguno de los casos anteriores
  1178.                     $newDatos[$dato['id']]['color'] = '#f0d800';
  1179.                     break;
  1180.             }
  1181.         }
  1182.         $datos0 = array();
  1183.         foreach ($newDatos as $key => $item) {
  1184.             if (!empty($item['id'])) {
  1185.                 $datos0[$key] = array('title' => $item['title'],
  1186.                     'titleOne' => $item['titleOne'],
  1187.                     'titleTwo' => $item['titleTwo'],
  1188.                     'titleThree' => $item['titleThree'],
  1189.                     'type' => $item['type'],
  1190.                     'id' => $item['id'],
  1191.                     'tooltip' => $item['tooltip'],
  1192.                     'start' => $item['start'],
  1193.                     'end' => $item['end'],
  1194.                     'color' => $item['color'],
  1195.                     'loungeId' => $item['loungeId'],
  1196.                     'url' => $item['url'],
  1197.                     'status' => $item['status'],
  1198.                 );
  1199.             }
  1200.         }
  1201.         $newDatos $datos0;
  1202.         $datos = array();
  1203.         foreach ($newDatos as $item) {
  1204.             if ($item['color'] != '#ff0000') {
  1205.                 // No se agregan al calendario los elementos eliminados o elementos vacios
  1206.                 if (!empty($item)) {
  1207.                     //INICIO: Verificamos por huecos dentro de la reserva
  1208.                     if (empty($item['type'])) {
  1209.                         // solo las reservas se van a verificar en este if
  1210.                         if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el evento tiene mas de 2 dias, puede haber huecos
  1211.                             $resSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($item['id']);
  1212.                             $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  1213.                             $arrayPeriod = array();
  1214.                             foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  1215.                             $logAllDiasEnReserva false;
  1216.                             $logDiaEnReserva false;
  1217.                             //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  1218.                             foreach ($arrayPeriod as $day) {
  1219.                                 foreach ($resSimples as $resSimple) {
  1220.                                     if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  1221.                                         $logDiaEnReserva true;
  1222.                                         break;
  1223.                                     }
  1224.                                 }
  1225.                                 if (!$logDiaEnReserva) {
  1226.                                     //Un dia no se encontraba, hay un hueco
  1227.                                     foreach ($resSimples as $resDayToAdd) {
  1228.                                         if (empty($resDayToAdd->getType())) {       // Solo se deben agregar salsa los montajes y desmontajes aqui no van
  1229.                                             $item['start'] = $resDayToAdd->getDateStart();
  1230.                                             $item['end'] = $resDayToAdd->getDateEnd();
  1231.                                             $br '<br>';
  1232.                                             $br strpos($item['title'], $br);
  1233.                                             $tempText substr($item['title'], $br 4);
  1234.                                             $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  1235.                                             $datos[] = $item;
  1236.                                         }
  1237.                                     }
  1238.                                     break;
  1239.                                 } else {
  1240.                                     //Se debe evaluar el siguiente dia
  1241.                                     $logDiaEnReserva false;
  1242.                                     if ($day->format('Y-m-d') == (end($arrayPeriod))->format('Y-m-d')) {   //Si es el ultimo elemento evaluado, todos los dias se encontraban en Reservas Simple
  1243.                                         $logAllDiasEnReserva true;
  1244.                                     }
  1245.                                 }
  1246.                             }
  1247.                             if ($logAllDiasEnReserva) { $datos[] = $item; }
  1248.                         } else {
  1249.                             // El evento es de 1 o 2 dias, no hay posibilidad de hueco
  1250.                             $datos[] = $item;
  1251.                         }
  1252.                     } else {
  1253.                         //Es Visita Las visitas son las unicas entradas que no tienen hueco
  1254.                         if ($item['type'] == 'Visit'){
  1255.                             $datos[] = $item;
  1256.                         } else {
  1257.                             // es montaje o desmontaje, se va verificar por huecos
  1258.                             if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el item tiene mas de 2 dias, puede haber huecos
  1259.                                 $parameters = array(
  1260.                                     'id' => $item['id'],
  1261.                                     'type' => $item['type'],
  1262.                                 );
  1263.                                 $dql 'SELECT i
  1264.                                         FROM GreenPatioBundle:ReservationLoungeSimple i
  1265.                                         WHERE  i.idReservation = :id
  1266.                                           and i.type = :type';
  1267.                                 $query $em->createQuery($dql)->setParameters($parameters);
  1268.                                 $resSimples $query->getResult();
  1269.                                 $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  1270.                                 $arrayPeriod = array();
  1271.                                 foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  1272.                                 $logAllDiasEnReserva false;
  1273.                                 $logDiaEnReserva false;
  1274.                                 //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  1275.                                 foreach ($arrayPeriod as $day) {
  1276.                                     foreach ($resSimples as $resSimple) {
  1277.                                         if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  1278.                                             $logDiaEnReserva true;
  1279.                                             break;
  1280.                                         }
  1281.                                     }
  1282.                                     if (!$logDiaEnReserva) {
  1283.                                         //Un dia no se encontraba, hay un hueco
  1284.                                         foreach ($resSimples as $resDayToAdd) {
  1285.                                             if (!empty($resDayToAdd->getType())) {       // Solo se deben agregar montajes y desmontajes aqui
  1286.                                                 $item['start'] = $resDayToAdd->getDateStart();
  1287.                                                 $item['end'] = $resDayToAdd->getDateEnd();
  1288.                                                 $br '<br>';
  1289.                                                 $br strpos($item['title'], $br);
  1290.                                                 $tempText substr($item['title'], $br 4);
  1291.                                                 $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  1292.                                                 $datos[] = $item;
  1293.                                             }
  1294.                                         }
  1295.                                         break;
  1296.                                     } else {
  1297.                                         //Se debe evaluar el siguiente dia
  1298.                                         $logDiaEnReserva false;
  1299.                                         if ($day->format('Y-m-d') == (end($arrayPeriod))->format('Y-m-d')) {   //Si es el ultimo elemento evaluado, todos los dias se encontraban en Reservas Simple
  1300.                                             $logAllDiasEnReserva true;
  1301.                                         }
  1302.                                     }
  1303.                                 }
  1304.                                 if ($logAllDiasEnReserva) { $datos[] = $item; }
  1305.                             } else {
  1306.                                 // El montaje o desmontaje es de 1 o 2 dias, no hay posibilidad de hueco
  1307.                                 $datos[] = $item;
  1308.                             }
  1309.                         }
  1310.                     }
  1311.                     //FIN: Verificamos por huecos dentro de la reserva
  1312.                 }
  1313.             }
  1314.         }
  1315.         // Buscamos las pruebas de menu desde 6 meses atras
  1316.         $todayHalfYearAgo = new DateTime('now -180 days');
  1317.         $parameters = array('dateStart' => $todayHalfYearAgo,);
  1318.         $dql 'SELECT p
  1319.                 FROM App:HtVisit p                         
  1320.                 WHERE p.dateStart >= :dateStart  
  1321.                 ORDER BY p.dateStart ASC ';
  1322.         $query $em->createQuery($dql)->setParameters($parameters);
  1323.         $pmenu $query->getResult();
  1324.         $arrayPmenu = array(); $color '#ccad11';
  1325.         foreach ($pmenu as $item){
  1326.             $agent = (!empty($item->getAgentId())) ? ($item->getAgentId())->getName() : 'Sin agente';
  1327.             $pax = (!empty($item->getPax())) ? (' - '.$item->getPax() . ' PAX') : null;
  1328.             $title =''$titleOne =''$titleTwo =''$titleThree =''$type =''$id =''$tooltip =''$start =''$end =''$loungeId =''$url ='';
  1329.             if(!empty($item->getReservation())){
  1330.                 $title = ($item->getDateStart())->format('H:i'). ' PRUEBA DE MENU ( '.$agent' )<br>' $item->getName(). $pax ' - ' . ($item->getReservation())->getTitle();
  1331.                 $titleOne '$titleOne';
  1332.                 $titleTwo '$titleTwo';
  1333.                 $titleThree '$titleThree';
  1334.                 $type 'Prueba Menu';
  1335.                 $id $item->getId();
  1336.                 $loungeId = (!empty(($item->getLounge()))) ? '<b> - '. ($item->getLounge())->getName() : null;
  1337.                 $tooltip '<b>'. ($item->getReservation())->getTitle() .$loungeId;
  1338.                 $start $item->getDateStart();
  1339.                 $end $item->getDateEnd();
  1340.                 $end->modify('+1 hour');
  1341.                 $loungeId = ($item->getLounge())->getId();
  1342.                 $url '/higotrigo/ht/file/'.($item->getReservation())->getId().'/edit';
  1343.             } else {
  1344.                 $title = ($item->getDateStart())->format('H:i'). ' PRUEBA DE MENU ( '.$agent' )<br>' $item->getName() . $pax;
  1345.                 $titleOne '$titleOne';
  1346.                 $titleTwo '$titleTwo';
  1347.                 $titleThree '$titleThree';
  1348.                 $type 'Prueba Menu';
  1349.                 $id $item->getId();
  1350.                 $loungeId = (!empty(($item->getLounge()))) ? '<b> '. ($item->getLounge())->getName() : null;
  1351.                 $tooltip '<b>' $loungeId;
  1352.                 $start $item->getDateStart();
  1353.                 $end $item->getDateEnd();
  1354.                 $end->modify('+1 hour');
  1355.                 $loungeId = ($item->getLounge())->getId();
  1356.                 $url '/#';
  1357.             }
  1358.             $arrayPmenu[] = array(
  1359.                 'title' => $title,
  1360.                 'titleOne' => $titleOne,
  1361.                 'titleTwo' => $titleTwo,
  1362.                 'titleThree' => $titleThree,
  1363.                 'type' => $type,
  1364.                 'id' => $id,
  1365.                 'tooltip' => $tooltip,
  1366.                 'start' => $start,
  1367.                 'end' => $end,
  1368.                 'color' => $color,
  1369.                 'loungeId' => $loungeId,
  1370.                 'url' => $url,
  1371.             );
  1372.         }
  1373.         foreach ($arrayPmenu as $item){ array_push($datos$item); }
  1374.         $return = array( 'reservation' => $datos, );
  1375.         $response = new JsonResponse($return);
  1376.         return $response;
  1377.     }
  1378.     private function createWidgetNotesCreateForm(WidgetNotes $entity)
  1379.     {
  1380.         $form $this->createForm(WidgetNotesType::class, $entity, array(
  1381.             'action' => $this->generateUrl('widget_notes_calendar_ht_create'),
  1382.             'method' => 'POST'
  1383.         ));
  1384.         return $form;
  1385.     }
  1386. };