src/MDS/GreenPatioBundle/Controller/CvrGPReservationsCalendarController.php line 118

Open in your IDE?
  1. <?php
  2. namespace App\MDS\GreenPatioBundle\Controller;
  3. use App\Entity\User;
  4. use App\Entity\WidgetNotes;
  5. use App\Form\WidgetNotesType;
  6. use App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice;
  7. use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice;
  8. use App\MDS\GreenPatioBundle\Entity\Reservation;
  9. use App\MDS\GreenPatioBundle\Entity\ReservationInvoice;
  10. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
  11. use App\MDS\GreenPatioBundle\Entity\ReservationPaymentsClient;
  12. use App\Service\AlertService;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Session\Session;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use Psr\Log\LoggerInterface;
  18. use DateTime;
  19. use DatePeriod;
  20. use DateInterval;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. // Controlador para el calendario UNIFICADO de las salas de Green Patio y Covarrubias (excluyendo las visitas)
  24. class CvrGPReservationsCalendarController extends AbstractController
  25. {
  26.     private EntityManagerInterface $em;
  27.     public function __construct(EntityManagerInterface $em) {
  28.         $this->em $em;
  29.     }
  30.     /**
  31.      * @Route("/gp-cvr/calendar", name="gp_cvr_calendar")
  32.      */
  33.     public function calendarCvrGpReservationsAction(Request $requestAlertService $alertService) {
  34.         $session = new Session();
  35.         $token=$session->get('tokenGoogleCalendar');
  36.         if (!is_null($token)) {
  37.             $this->googleCalendar->setAccessToken($token);
  38.             $connectGoogle "1";
  39.         }else{
  40.             $connectGoogle "0";
  41.         }
  42.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  43.         $user_id $user_logueado->getId();
  44.         $wnotes = new WidgetNotes();
  45.         $wnotes->setDateAt(new \DateTime("now"));
  46.         $form $this->createWidgetNotesCreateForm($wnotes);
  47.         $alertService->loadGpAlerts($user_logueado);
  48.         return $this->render('MDS/GreenPatioBundle/reservations/calendar-gp-cvr-reservations.html.twig',
  49.             array(
  50.                 'form' => $form->createView(),
  51.                 'user'=> $user_id,
  52.                 'connectGoogle' => $connectGoogle,
  53.             )
  54.         );
  55.     }
  56.     /**
  57.      * @Route("/widget/notes/calendargpcvr/create/", name="widget_notes_calendar_gp_cvr_create")
  58.      */
  59.     public function addNotesAction(Request $requestLoggerInterface $logger)
  60.     {
  61.         $em $this->getDoctrine()->getManager();
  62.         $notes $em->getRepository(WidgetNotes::class)->findAll();
  63.         $wnotes = new WidgetNotes();
  64.         $form $this->createWidgetNotesCreateForm($wnotes);
  65.         $form->handleRequest($request);
  66.         $forAgent $form->get('forAgent')->getData();
  67.         if(!is_null($forAgent)){ $wnotes->setForAgent($forAgent->getId()); }
  68.         if($form->isValid())
  69.         {
  70.             /* Obtengo usuario logueado */
  71.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  72.             $user_id $user_logueado->getId();
  73.             $wnotes->setCreatedId($user_id);
  74.             $wnotes->setUpdatedId($user_id);
  75.             /* Gestión de eventos en Log */
  76.             $user_lastname $user_logueado->getLastname();
  77.             $user_name $user_logueado->getName();
  78.             $user_email $user_logueado->getEmail();
  79.             $user_rol $user_logueado->getRoles();
  80.             $event_url $request->getPathInfo();
  81.             $event_complete $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  82.             try{
  83.                 $em->persist($wnotes);
  84.                 $em->flush();
  85.                 $event 'The Note has been created succesfully.';
  86.                 $successMessage $this->get('translator')->trans($event);
  87.                 $this->addFlash('mensaje'$successMessage);
  88.                 $logger->info($event_complete.' | '.$event);
  89.             } catch (\Exception $e){
  90.                 $event 'An error occurred: '.$e->getMessage();
  91.                 /* Para el log */
  92.                 $logger->error($event_complete.' | '.$event);
  93.                 /* Para el usuario */
  94.                 $errorMessage $this->get('translator')->trans($event);
  95.                 $this->addFlash('mensajeerror'$errorMessage);
  96.             }
  97.         }else{
  98.             $errorMessage $this->get('translator')->trans('Error, some fields are empty');
  99.             $this->addFlash('mensajeerror'$errorMessage);
  100.         }
  101.         return $this->redirectToRoute('homepage');
  102.     }
  103.     /**
  104.      * @Route("/gp-cvr/eventsgpcvrnew", name="get_reservations_gp_cvr_new")
  105.      * Cambio en como se muestran y se envían los datos a la vista del calendario
  106.      */
  107.     public function reservationGpCvrEventsActionNew()
  108.     {
  109.         // 1) Traemos las reservas de hace 1 año en adelante
  110.         $todayOneYearAgo = new \DateTime('now -365 days');
  111.         $parameters = ['dateStart' => $todayOneYearAgo];
  112.         $dql '
  113.             SELECT r
  114.             FROM GreenPatioBundle:Reservation r
  115.             WHERE r.dateStart >= :dateStart
  116.             AND r.status != \'Deleted\'
  117.             ORDER BY
  118.                 CASE WHEN r.status = \'Confirmed\' THEN 0 ELSE 1 END ASC,
  119.                 r.dateStart ASC
  120.         ';
  121.         $query $this->em->createQuery($dql)->setParameters($parameters);
  122.         $reservations $query->getResult();
  123.         $datos = [];
  124.         if (!empty($reservations)) {
  125.             foreach ($reservations as $reservation) {
  126.                 // 1.1) Obtenemos todos los lounges de la reserva
  127.                 $loungesAll $this->em
  128.                     ->getRepository(ReservationLoungeSimple::class)
  129.                     ->findByIdReservation($reservation->getId());
  130.                 if (empty($loungesAll)) {
  131.                     continue;
  132.                 }
  133.                 // 2) Separamos primero los lounges “normales” (no montaje ni desmontaje)
  134.                 $loungesNormales = [];
  135.                 $loungesMontaje   = [];
  136.                 $loungesDesmontaje= [];
  137.                 foreach ($loungesAll as $lounge) {
  138.                     if ($lounge->getType() === 'Montaje') {
  139.                         $loungesMontaje[] = $lounge;
  140.                     } elseif ($lounge->getType() === 'Desmontaje') {
  141.                         $loungesDesmontaje[] = $lounge;
  142.                     } else {
  143.                         $loungesNormales[] = $lounge;
  144.                     }
  145.                 }
  146.                 // 3) Agrupamos los lounges normales en bloques de fechas consecutivas
  147.                 $bloquesNormales $this->_splitLoungesByConsecutiveDays($loungesNormales);
  148.                 // 4) Por cada bloque, montamos un evento
  149.                 foreach ($bloquesNormales as $bloque) {
  150.                     $evento $this->_getEventsData($reservation$bloquefalse);
  151.                     if (!empty($evento)) {
  152.                         $datos[] = $evento;
  153.                     }
  154.                 }
  155.                 // 5) Si hay bloques de montaje, hacemos lo mismo (pero marcando isMontajeDesmontaje=true)
  156.                 $bloquesMontaje $this->_splitLoungesByConsecutiveDays($loungesMontaje);
  157.                 foreach ($bloquesMontaje as $bloqueMontaje) {
  158.                     $eventoMontaje $this->_getEventsData($reservation$bloqueMontajetrue);
  159.                     if (!empty($eventoMontaje)) {
  160.                         $datos[] = $eventoMontaje;
  161.                     }
  162.                 }
  163.                 // 6) Si hay bloques de desmontaje, idem
  164.                 $bloquesDesmontaje $this->_splitLoungesByConsecutiveDays($loungesDesmontaje);
  165.                 foreach ($bloquesDesmontaje as $bloqueDesmontaje) {
  166.                     $eventoDesmontaje $this->_getEventsData($reservation$bloqueDesmontajetrue);
  167.                     if (!empty($eventoDesmontaje)) {
  168.                         $datos[] = $eventoDesmontaje;
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.         // 7) Lo mismo para visitas (no cambia la lógica original)
  174.         $todayOneWeekAgo = new \DateTime('now -1 week');
  175.         $parameters = ['dateStart' => $todayOneWeekAgo];
  176.         $dql '
  177.             SELECT p
  178.             FROM GreenPatioBundle:ReservationVisit p
  179.             WHERE p.dateStart >= :dateStart
  180.             ORDER BY p.dateStart ASC
  181.         ';
  182.         $query $this->em->createQuery($dql)->setParameters($parameters);
  183.         $visitas $query->getResult();
  184.         if (!empty($visitas)) {
  185.             foreach ($visitas as $visita) {
  186.                 $eventoVisita $this->_getVisitEventsData($visita);
  187.                 if (!empty($eventoVisita)) {
  188.                     $datos[] = $eventoVisita;
  189.                 }
  190.             }
  191.         }
  192.         return new JsonResponse(['reservation' => $datos]);
  193.     }
  194.     /**
  195.      * Función auxiliar: recibe un array de ReservationLoungeSimple y devuelve un array
  196.      * de “bloques” (sub-arrays), de forma que cada bloque contenga lounges cuyas
  197.      * fechas (dateStart) sean días consecutivos.
  198.      */
  199.     private function _splitLoungesByConsecutiveDays(array $lounges): array
  200.     {
  201.         // 1) Si no hay ninguno, devolvemos array vacío
  202.         if (empty($lounges)) {
  203.             return [];
  204.         }
  205.         // 2) Ordenamos los lounges por fecha (dateStart) ascendente
  206.         usort($lounges, function (ReservationLoungeSimple $aReservationLoungeSimple $b) {
  207.             // Suponemos que getDateStart() devuelve DateTime
  208.             return $a->getDateStart() <=> $b->getDateStart();
  209.         });
  210.         $bloques = [];
  211.         $bloqueActual = [];
  212.         // 3) Recorremos los lounges uno a uno y los vamos agrandando en bloqueActual
  213.         foreach ($lounges as $lounge) {
  214.             if (empty($bloqueActual)) {
  215.                 // Si el bloque está vacío, arrancamos con este lounge
  216.                 $bloqueActual[] = $lounge;
  217.             } else {
  218.                 // Vemos la última fecha del bloque actual
  219.                 $ultimoLounge       end($bloqueActual);
  220.                 $fechaUltimo        $ultimoLounge->getDateStart();
  221.                 $fechaActualLounge  $lounge->getDateStart();
  222.                 // Calculamos la diferencia en días (entero) entre ambas fechas
  223.                 /** @var \DateInterval $interval */
  224.                 $interval $fechaUltimo->diff($fechaActualLounge);
  225.                 $diasDif  = (int) $interval->format('%r%a'); // número de días; si son negativos, no deberían darse por cómo ordenamos
  226.                 if ($diasDif === || $diasDif === 1) {
  227.                     // Mismo día (0) o día siguiente (1) → consideramos que se incluyen en este mismo bloque
  228.                     $bloqueActual[] = $lounge;
  229.                 } else {
  230.                     // Hay un salto mayor a 1 día → cerramos el bloque actual y empezamos uno nuevo
  231.                     $bloques[] = $bloqueActual;
  232.                     $bloqueActual = [$lounge];
  233.                 }
  234.             }
  235.         }
  236.         // 4) Al salir, añadimos el último bloque si no estaba vacío
  237.         if (!empty($bloqueActual)) {
  238.             $bloques[] = $bloqueActual;
  239.         }
  240.         return $bloques;
  241.     }
  242.     /**
  243.      * función privada para crear el $datos[] con las reservas de GP y CVR
  244.      */
  245.     private function _getEventsData($reservation$lounges$isMontajeDesmontaje false)
  246.     {
  247.         $primerLounge $lounges[0];
  248.         // Montamos el icono de pagos
  249.         $pago1 "";
  250.         $pago2 "";
  251.         $ht "";
  252.         $paymentsAll $this->em->getRepository(ReservationPaymentsClient::class)
  253.                             ->findOneByReservationId($reservation->getId());
  254.         if (!empty($paymentsAll)) {
  255.             $pago2 "<i class='icon-coin-euro' style='color: #000 !important;'></i>";
  256.         }
  257.         // Facturas (GP y CVR)
  258.         $facturas   $this->em->getRepository(ReservationInvoice::class)
  259.                             ->findByReservationId($reservation->getId());
  260.         $facturasCVR$this->em->getRepository(CvrReservationInvoice::class)
  261.                             ->findByReservationId($reservation->getId());
  262.         foreach ($facturasCVR as $item) {
  263.             array_push($facturas$item);
  264.         }
  265.         foreach ($facturas as $factura) {
  266.             if ($factura->getMaster() === "master") {
  267.                 $pago1 "<i class='icon-thumbs-up3' style='color: #000 !important;'></i>";
  268.             }
  269.             if ($factura->getMaster() !== "master") {
  270.                 $pago2 "<i class='icon-coin-euro' style='color: #000 !important;'></i>";
  271.             }
  272.         }
  273.         // Catering HIGO & TRIGO
  274.         if ($reservation->getCateringName() === 'HIGO & TRIGO, S.L.') {
  275.             $ht "<a style='color: #000 !important;'><strong>H&T</strong></a>";
  276.         }
  277.         // Tipo (Montaje/Desmontaje o null)
  278.         $type $isMontajeDesmontaje $primerLounge->getType() : null;
  279.         // 1) Calculamos el inicio y fin del bloque de lounges (función que tú ya tenías)
  280.         list($start$end) = $this->_getStartEnd($lounges$isMontajeDesmontaje);
  281.         if (is_null($start) || is_null($end)) {
  282.             return []; // Si no hay inicio o fin válido, devolvemos vacío
  283.         }
  284.         // 2) Title: hora de inicio, iconos, tipo, etc.
  285.         $title $start->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $type;
  286.         // 3) Color según estado y sala principal
  287.         $color $this->_getColor($reservation->getStatus(), $primerLounge->getIdLounge(), $isMontajeDesmontaje);
  288.         // 4) Tooltip: título base de reserva
  289.         $tooltip $reservation->getTitle();
  290.         // 5) Si hay varias salas dentro del bloque, las incluimos en title y tooltip
  291.         if (count($lounges) >= 1) {
  292.             $loungesName = [];
  293.             foreach ($lounges as $key => $lounge) {
  294.                 // Solo mostramos salas normales si no es bloque montaje/desmontaje
  295.                 if (!in_array($lounge->getLoungeName(), $loungesName)
  296.                     && ($isMontajeDesmontaje
  297.                         || ($lounge->getType() !== 'Montaje' && $lounge->getType() !== 'Desmontaje'))
  298.                 ) {
  299.                     $loungesName[] = $lounge->getLoungeName();
  300.                     $title .= '<br>&nbsp;&nbsp;&nbsp; ' $lounge->getLoungeName();
  301.                 }
  302.                 if ($isMontajeDesmontaje
  303.                     || ($lounge->getType() !== 'Montaje' && $lounge->getType() !== 'Desmontaje')
  304.                 ) {
  305.                     $horaInicio  sprintf('%02d:%02d'$lounge->getHourStart(), $lounge->getMinStart());
  306.                     $horaFin     sprintf('%02d:%02d'$lounge->getHourEnd(),   $lounge->getMinEnd());
  307.                     $fechaInicio $lounge->getDateStart()->format('d/m/Y'); // añadí “Y” para ver bien el año
  308.                     $tooltip   .= sprintf(
  309.                         '<br/><b><h3>%s</h3></b> Del %s desde %s hasta %s',
  310.                         $lounge->getLoungeName(),
  311.                         $fechaInicio,
  312.                         $horaInicio,
  313.                         $horaFin
  314.                     );
  315.                 }
  316.             }
  317.         }
  318.         $title .= '<br>' $reservation->getTitle();
  319.         // 6) Status parseado (tu función original)
  320.         $status $this->_getStatus($reservation->getStatus());
  321.         // 7) Construimos el array final de datos para este evento
  322.         $datos = [
  323.             'title'   => $title,
  324.             'type'    => $type,
  325.             'id'      => $reservation->getId(),
  326.             'tooltip' => $tooltip,
  327.             'start'   => $start,
  328.             'end'     => $end,
  329.             'color'   => $color,
  330.             'url'     => "/reservations-greenpatio/edit/" $reservation->getId(),
  331.             'status'  => $status
  332.         ];
  333.         return $datos;
  334.     }
  335.     /**
  336.      * Función para crear el $datos[] con las visitas de GP y CVR
  337.      */
  338.     private function _getVisitEventsData($visita)
  339.     {
  340.         $start = (new \DateTime($visita->getDateStart()->format('Y-m-d') . ' ' sprintf('%02d'$visita->getHourStart()) . ':' sprintf('%02d'$visita->getMinStart())));
  341.         $end = (new \DateTime($visita->getDateEnd()->format('Y-m-d') . ' ' sprintf('%02d'$visita->getHourEnd()) . ':' sprintf('%02d'$visita->getMinEnd())));
  342.         if (is_null($start) || is_null($end)) {
  343.             return []; // Si no hay inicio o fin, no devolvemos nada
  344.         }
  345.         $title $visita->getHourStart() . ":" $visita->getMinStart() . ' ' .  $visita->getLoungeName();
  346.         $tooltip $visita->getLoungeName() . ' - <b><h3>' $visita->getLoungeName() . "</h3></b> Del " $visita->getDateStart()->format('d/m') . ' desde ' $visita->getHourStart() . ":" $visita->getMinStart() . " a " $visita->getHourEnd() . ":" $visita->getMinEnd();
  347.         $color $this->_getColorVisit($visita->getAgentId(), $visita->getIdLounge());
  348.         if ($visita->getIdLounge() != 0) {
  349.             // Si la visita no tiene sala asignada, usamos el color por defecto
  350.             $color $this->_getColorVisit(0$visita->getIdLounge());
  351.         }
  352.         return [
  353.             'title' => $title,
  354.             'type' => 'Visit',
  355.             'id' => $visita->getId() . 'V',
  356.             'tooltip' => $tooltip,
  357.             'start' => $start,
  358.             'end' => $end,
  359.             'color' => $color// Color específico para visitas
  360.             'url' => '/reservations-greenpatio/addvisit',
  361.             'status' => $this->_getStatus('visit'), // Status específico para visitas
  362.             'agentId' => $visita->getAgentId(),
  363.         ];
  364.     }
  365.     /**
  366.      * Devuelve el color de la reserva según su estado
  367.      */
  368.     private function _getColor($status$loungeId$isMontajeDesmontaje)
  369.     {
  370.         if($isMontajeDesmontaje){
  371.             return "#a5b8a2";
  372.         }
  373.         $statusColorMap = [
  374.             'Bloqueo' => ($loungeId 21) ? "#b873bf" "#ffaa00",
  375.             'Confirmed' => "#13ad27",
  376.             'Invoiced' => "#13ad27",
  377.             'Deleted' => "#ff0000",
  378.             'Cotizado' => "#faafc3",
  379.             'Reservado' => "#13ad27",
  380.             'default' => "",
  381.         ];
  382.         $color $statusColorMap[$status] ?? $statusColorMap['default'];
  383.         if (in_array($loungeId, [22232425])){
  384.             //Ajustamos el color a una sala de covarrubia
  385.             switch ($color) {
  386.                 case '#ffaa00'$color "#b873bf"; break; //naranja (bloqueo) => morado
  387.                 case '#13ad27'$color "#017362"; break; //verde (Confirmed) => verde olivo
  388.                 case '#ff0000'$color "#ff0000"; break; //rojo
  389.                 case '#faafc3'$color "#faafc3"; break; //Rojo claro
  390.                 default: break; //no modificar el color
  391.             }
  392.         }
  393.         return $color;
  394.     }
  395.     /**
  396.      * Devuelve el color de la visita según el agente o el venue
  397.      */
  398.     private function _getColorVisit($agentId$venue)
  399.     {
  400.         // Si el venue determina directamente el color, lo devolvemos
  401.         if (($venue === 0) or (is_null($venue))) {
  402.             return '#f0d800'// Color Covarrubias
  403.         }
  404.         if ($venue === 2) {
  405.             return '#990202'// Color Bella View
  406.         }
  407.         // Si el venue es 1, buscamos el color del agente
  408.         if ($venue === && !is_null($agentId)) {
  409.             $agent $this->em->getRepository(User::class)->find($agentId);
  410.             if ($agent && $agent->getColor()) {
  411.                 return $agent->getColor();
  412.             }
  413.         }
  414.         // Si no se encuentra nada, retornamos null
  415.         return null;
  416.     }
  417.     /**
  418.      * Calcula el inicio y el fin de la reserva en función de las salas que no sean montaje o desmontaje
  419.      */
  420.     private function _getStartEnd($lounges$isMontajeDesmontaje false)
  421.     {
  422.         $start null;
  423.         $end null;
  424.         foreach ($lounges as $lounge) {
  425.             if ($isMontajeDesmontaje || ($lounge->getType() != 'Montaje' && $lounge->getType() != 'Desmontaje')) {
  426.                 if (is_null($start) || $lounge->getDateStart() < $start) {
  427.                     $start = (new \DateTime($lounge->getDateStart()->format('Y-m-d') . ' ' sprintf('%02d'$lounge->getHourStart()) . ':' sprintf('%02d'$lounge->getMinStart())));
  428.                 }
  429.                 if (is_null($end) || $lounge->getDateEnd() > $end) {
  430.                     $end = (new \DateTime($lounge->getDateEnd()->format('Y-m-d') . ' 23:59:59'));
  431.                 }
  432.             }
  433.         }
  434.         // Sumar un minuto al final para que no se vea el evento cortado
  435.         if (!is_null($end)) {
  436.             $end->modify('+1 minute');
  437.         }
  438.         return [$start$end];
  439.     }
  440.     /**
  441.      * Devuelve el status de la reserva según su estado como un número
  442.      */
  443.     private function _getStatus($status)
  444.     {
  445.         $statusMap = [
  446.             'Bloqueo' => 1,
  447.             'Confirmed' => 2,
  448.             'Invoiced' => 3,
  449.             'Deleted' => 4,
  450.             'Cotizado' => 5,
  451.             'Reservado' => 6,
  452.             'default' => 0,
  453.         ];
  454.         return $statusMap[$status] ?? $statusMap['default'];
  455.     }
  456.     /**
  457.      * @Route("/gp-cvr/eventsgpcvr", name="get_reservations_gp_cvr")
  458.      */
  459.     public function reservationGpCvrEventsAction(Request $request)
  460.     {
  461.         $em $this->getDoctrine()->getManager();
  462.         // Buscamos las reservas desde 1 año atras en adelante para no traer exceso de datos
  463.         $todayOneYearAgo = new DateTime('now -365 days');
  464.         $parameters = array('dateStart' => $todayOneYearAgo,);
  465.         $dql 'SELECT p
  466.                 FROM GreenPatioBundle:ReservationLoungeSimple p                         
  467.                 WHERE p.dateStart >= :dateStart  
  468.                 ORDER BY p.dateStart ASC';
  469.         $query $em->createQuery($dql)->setParameters($parameters);
  470.         $reservation $query->getResult();
  471.         // Buscamos las visitas desde 1 semana atras en adelante para no traer exceso de datos (Tiempo confirmado por Gabriela Bracho)
  472.         $todayOneWeekAgo = new DateTime('now -1 week');
  473.         $parameters = array('dateStart' => $todayOneWeekAgo,);
  474.         $dql 'SELECT p
  475.                 FROM GreenPatioBundle:ReservationVisit p                         
  476.                 WHERE p.dateStart >= :dateStart  
  477.                 ORDER BY p.dateStart ASC';
  478.         $query $em->createQuery($dql)->setParameters($parameters);
  479.         $visitas $query->getResult();
  480.         $arrayFechaVisitas = [];
  481.         foreach ($visitas as $item) {
  482.             //Se agrupan las visitas por fechas
  483.             $arrayFechaVisitas[$item->getDateStart()->format('Y-m-d').$item->getId()][] = $item;
  484.         }
  485.         $newArrayVisitas = [];
  486.         //Se agrupan las visitas por agente
  487.         foreach ($arrayFechaVisitas as $fecha) {
  488.             foreach ($fecha as $item) {
  489.                 //Se van concatenando los titulos de las visitas en una sola
  490.                 $loungeNameTemp '';
  491.                 $idAgentLounge = ($item->getIdLounge() == 0) ? $item->getAgentId() : '0';
  492.                 if (!empty($newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge])) {
  493. //                    $loungeNameTemp = $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' . $idAgentLounge]->getLoungeName();
  494.                 }
  495.                 $item->setLoungeName($loungeNameTemp $item->getDateStart()->format('H:i') . ' ' $item->getLoungeName() . '<br>');
  496.                 $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge] = $item;
  497.             }
  498.         }
  499.         $visitas $newArrayVisitas;
  500.         $xArray = [];
  501.         foreach ($arrayFechaVisitas as $elem) { foreach ($elem as $item) { $xArray[] = $item; } }
  502.         foreach ($xArray as $item) { array_push($reservation$item); }
  503.         $datos = [];
  504.         $agentColorMap = [
  505.             77 => "#22cbf5",
  506.             82 => "#f5229a",
  507.             120 => "#157cc2",
  508.         ];
  509.         if (!empty($reservation)) {
  510.             foreach ($reservation as $reservaSala) {
  511.                 if (!empty($reservaSala->getIdReservation())) {
  512.                     $reserva $em->getRepository(Reservation::class)->findOneById($reservaSala->getIdReservation());
  513.                     if ($reservaSala->getType() == 'Visit') {
  514.                         $reserva->setStatus('Visit');
  515.                     }
  516.                 } else {
  517.                     // Estamos con una visita
  518.                     $reserva = new Reservation();
  519.                     $reserva->setStatus('Visit');
  520.                     $reserva->setTitle($reservaSala->getLoungeName());
  521.                 }
  522.                 if ($reservaSala->getDateStart()->format('d') == $reservaSala->getDateEnd()->format('d')) {
  523.                     $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();
  524.                 } else {
  525.                     $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();
  526.                 }
  527.                 $logicoVisita false;
  528.                 if (!is_null($reserva->getStatus())) {
  529.                     $statusColorMap = [
  530.                         'Bloqueo' => function($reservaSala) {
  531.                             $idLounge $reservaSala->getIdLounge();
  532.                             if ($idLounge 29) {
  533.                                 return "#964B00"// Marrón (Bella View)
  534.                             } elseif ($idLounge 21) {
  535.                                 return "#b873bf"// Morado (Covarrubias)
  536.                             } else {
  537.                                 return "#ffaa00"// Naranja (Green Patio)
  538.                             }
  539.                         },
  540.                         'Confirmed' => "#13ad27",
  541.                         'Invoiced' => "#13ad27",
  542.                         'Deleted' => "#ff0000",
  543.                         'Cotizado' => "#faafc3",
  544.                         'Reservado' => "#13ad27",
  545.                         'Visit' => function($reservaSala) {
  546.                             if ($reservaSala->getIdLounge() == 0) {
  547.                                 return $agentColorMap[$reservaSala->getAgentId()] ?? "";
  548.                             } else {
  549.                                 if ($reservaSala->getIdLounge() == 1) {
  550.                                     return '#f0d800';   //  Color Covarrubias
  551.                                 } else {
  552.                                     return '#9e6c3a';   //  Color Bella View
  553.                                 }
  554.                             }
  555.                         },
  556.                         'default' => "",
  557.                     ];
  558.                     
  559.                     $color "";
  560.                     $logicoVisita false;
  561.                     
  562.                     if (array_key_exists($reserva->getStatus(), $statusColorMap)) {
  563.                         $value $statusColorMap[$reserva->getStatus()];
  564.                         // Si el valor es una función, la ejecutamos para obtener el color.
  565.                         $color is_callable($value) ? $value($reservaSala) : $value;
  566.                         if ($reserva->getStatus() === 'Visit') {
  567.                             $logicoVisita true;
  568.                         }
  569.                     } else {
  570.                         $color $statusColorMap['default'];
  571.                     }
  572.                     if (!empty($reservaSala->getType()) and !($reservaSala->getType() == 'Visit')) {
  573.                         //Es un montaje o desmontaje
  574.                         $color "#a5b8a2";
  575.                         // Si es un montaje o desmontaje pero esta cancelado debe prevalecer el color de cancelado
  576.                         if ($reserva->getStatus() == 'Deleted') { $color "#ff0000"; }
  577.                     }
  578.                     if (($reservaSala->getIdLounge() > 21) and ($reservaSala->getIdLounge() < 30)){
  579.                         //Ajustamos el color a una sala de covarrubia
  580.                         switch ($color) {
  581.                             case '#ffaa00'$color "#b873bf"; break; //naranja (bloqueo) => morado
  582.                             case '#13ad27'$color "#017362"; break; //verde (Confirmed) => verde olivo
  583.                             case '#ff0000'$color "#ff0000"; break; //rojo
  584.                             case '#faafc3'$color "#faafc3"; break; //Rojo claro
  585.                             default: break; //no modificar el color
  586.                         }
  587.                     }
  588.                     if ($reservaSala->getIdLounge() > 29){
  589.                         //Ajustamos el color a una sala de bella view
  590.                         switch ($color) {
  591.                             case '#ffaa00'$color "#2691fc"; break; //naranja (bloqueo) => azul claro
  592.                             case '#13ad27'$color "#066191"; break; //verde (Confirmed) => azul oscuro
  593.                             case '#ff0000'$color "#ff0000"; break; //rojo
  594.                             case '#faafc3'$color "#faafc3"; break; //Rojo claro
  595.                             default: break; //no modificar el color
  596.                         }
  597.                     }
  598.                 }
  599.                 $pago1 "";
  600.                 $pago2 "";
  601.                 $ht "";
  602.                 if (!($reserva->getStatus() == 'Visit')) {
  603.                     $paymentsAll $em->getRepository(ReservationPaymentsClient::class)->findOneByReservationId($reserva->getId());
  604.                 } else {
  605.                     $paymentsAll null;
  606.                 }
  607.                 if (!empty($paymentsAll)) {
  608.                     $pago2 "<i class='icon-coin-euro' style='color: #000 !important;'></i>";      //Hay pagos parciales
  609.                 }
  610.                 if (!($reserva->getStatus() == 'Visit')) {
  611.                     $facturas $em->getRepository(ReservationInvoice::class)->findByReservationId($reserva->getId());
  612.                     $facturasCVR $em->getRepository(CvrReservationInvoice::class)->findByReservationId($reserva->getId());
  613.                     $facturasBLV $em->getRepository(BlvReservationInvoice::class)->findByReservationId($reserva->getId());
  614.                     foreach ($facturasCVR as $item) { array_push($facturas$item); }
  615.                     foreach ($facturasBLV as $item) { array_push($facturas$item); }
  616.                 }
  617.                 if (!empty($facturas)) {
  618.                     foreach ($facturas as $factura) {
  619.                         if ($factura->getMaster() == "master") {
  620.                             $pago1 "<i class='icon-thumbs-up3' style='color: #000 !important;'></i>";// Se ha pagado la totalidad
  621.                         }
  622.                         if ($factura->getMaster() != "master") {
  623.                             $pago2 "<i class='icon-coin-euro' style='color: #000 !important;'></i>";      //Hay pagos parciales
  624.                         }
  625.                     }
  626.                 }
  627.                 if ($reserva->getCateringName() == 'HIGO & TRIGO, S.L.') {
  628.                     $ht "<a style='color: #000 !important;'><strong>H&T</strong></a>";      // Es una reserva con servicio de Catering Higo & Trigo
  629.                 }
  630.                 // Pagos parciales y totales
  631.                 if (!$logicoVisita) {
  632.                     $datos[] = array(
  633.                         "title" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . ' ' $reservaSala->getLoungeName() . '<br>' $reserva->getTitle(),
  634.                         "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType(),
  635.                         "titleTwo" => $reservaSala->getLoungeName(),
  636.                         "titleThree" => '' '<br>' $reserva->getTitle(),
  637.                         "type" => $reservaSala->getType(),
  638.                         "id" => $reserva->getId(),
  639.                         "tooltip" => $tooltip,
  640.                         "start" => (new \DateTime($reservaSala->getDateStart()->format('Y-m-d') . ' ' sprintf('%02d'$reservaSala->getHourStart()) . ':' sprintf('%02d'$reservaSala->getMinStart()))),
  641.                         "end" => (new \DateTime($reservaSala->getDateEnd()->format('Y-m-d') . ' ' sprintf('%02d'$reservaSala->getHourEnd()) . ':' sprintf('%02d'$reservaSala->getMinEnd()))),
  642.                         "color" => $color,
  643.                         "loungeId" => $reservaSala->getIdLounge(),
  644.                         "url" => "/reservations-greenpatio/edit/" $reserva->getId(),
  645.                         "status" => $reserva->getStatus(),
  646.                     );
  647.                 } else {
  648.                     // Es una visita
  649.                     $datos[] = array(
  650.                         "title" => $reservaSala->getLoungeName(),
  651.                         "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' ' ' $reservaSala->getType() . '<br>',
  652.                         "titleTwo" => $reservaSala->getLoungeName(),
  653.                         "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  654.                         "type" => $reservaSala->getType(),
  655.                         "id" => $reservaSala->getId() . 'V',
  656.                         "tooltip" => $tooltip,
  657.                         "start" => (new \DateTime($reservaSala->getDateStart()->format('Y-m-d') . ' ' sprintf('%02d'$reservaSala->getHourStart()) . ':' sprintf('%02d'$reservaSala->getMinStart()))),
  658.                         "end" => (new \DateTime($reservaSala->getDateEnd()->format('Y-m-d') . ' ' sprintf('%02d'$reservaSala->getHourEnd()) . ':' sprintf('%02d'$reservaSala->getMinEnd()))),
  659.                         "color" => $color,
  660.                         "loungeId" => $reservaSala->getIdLounge(),
  661.                         "url" => '/reservations-greenpatio/addvisit',
  662.                         "status" => $reserva->getStatus(),
  663.                         "agentId" => $reservaSala->getAgentId(),
  664.                     );
  665.                 }
  666.             }
  667.         }
  668.         $newDatos = [];
  669.         // INICIO: Se unen las salas en una sola reserva por ID de reserva
  670.         foreach ($datos as $dato) {
  671.             // Inicializamos el arreglo para crear los indices
  672.             switch ($dato['color']){
  673.                 case '#a5b8a2':              //Montaje o Desmontaje
  674.                     if ($dato['type'] == 'Montaje'){
  675.                         $newDatos[$dato['id'].'M'] = null;
  676.                     } else {
  677.                         $newDatos[$dato['id'].'D'] = null;
  678.                     }
  679.                     break;
  680.                 default:                    //Dia de reserva o Visita (la visita ya viene con su indice #V )
  681.                     $newDatos[$dato['id']] = null;
  682.                     break;
  683.             }
  684.         }
  685.         foreach ($datos as $dato) {
  686.             switch ($dato['color']){
  687.                 //Montaje o Desmontaje
  688.                 case '#a5b8a2':
  689.                     if ($dato['type'] == "Montaje") {
  690.                         if (!empty($newDatos[$dato['id'] . 'M'])) {
  691.                             // El Montaje esta ocupando mas de 1 dia, se deben unir los dias de montaje si estamos tratando la misma sala (no se deben unir montajes de salas diferentes)
  692.                             if ($newDatos[$dato['id'] . 'M']['loungeId'] == $dato['loungeId']) {
  693.                                 if ($newDatos[$dato['id'] . 'M']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'M']['start'] = $dato['start']; }
  694.                                 if ($newDatos[$dato['id'] . 'M']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'M']['end'] = $dato['end']; }
  695.                             } else {
  696.                                 if (array_key_exists($dato['id'] . 'M'.$dato['loungeId'],$newDatos)){
  697.                                     if ($newDatos[$dato['id'] . 'M'.$dato['loungeId']]['start'] > $dato['start']) { $newDatos[$dato['id'] . 'M'.$dato['loungeId']]['start'] = $dato['start']; }
  698.                                     if ($newDatos[$dato['id'] . 'M'.$dato['loungeId']]['end'] < $dato['end']) { $newDatos[$dato['id'] . 'M'.$dato['loungeId']]['end'] = $dato['end']; }
  699.                                 } else {
  700.                                     $newDatos[$dato['id'] . 'M'.$dato['loungeId']] = $dato;
  701.                                 }
  702.                             }
  703.                         } else {
  704.                             $newDatos[$dato['id'] . 'M'] = $dato;
  705.                         }
  706.                     } else {
  707.                         if ($dato['type'] == "Desmontaje") {
  708.                             if (!empty($newDatos[$dato['id'] . 'D'])) {
  709.                                 // El Desmontaje esta ocupando mas de 1 dia, se deben unir los dias de desmontaje
  710.                                 if ($newDatos[$dato['id'] . 'D']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'D']['start'] = $dato['start']; }
  711.                                 if ($newDatos[$dato['id'] . 'D']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'D']['end'] = $dato['end']; }
  712.                             } else {
  713.                                 $newDatos[$dato['id'] . 'D'] = $dato;
  714.                             }
  715.                         }
  716.                     }
  717.                 break;
  718.                 //Visita Angie (id user 77)
  719.                 case '#22cbf5':
  720.                     if ($dato['type'] == "Visit") {
  721.                         $newDatos[$dato['start']->format('Ymd').'V77'.$dato['id']] = $dato;
  722.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V77'])) {
  723.                             // Hay varias visitas ese mismo dia para el agente
  724. //                            $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] . $dato['tooltip'];
  725.                         } else {
  726. //                            $newDatos[$dato['start']->format('Ymd').'V77'] = $dato;
  727.                         }
  728.                     }
  729.                 break;
  730.                 //Visita Gabriela (id user 82)
  731.                 case '#f5229a':
  732.                     if ($dato['type'] == "Visit") {
  733.                         $newDatos[$dato['start']->format('Ymd').'V82'.$dato['id']] = $dato;
  734.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V82'])) {
  735.                             // Hay varias visitas ese mismo dia para el agente
  736. //                            $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] . $dato['tooltip'];
  737.                         } else {
  738. //                            $newDatos[$dato['start']->format('Ymd').'V82'] = $dato;
  739.                         }
  740.                     }
  741.                 break;
  742.                 //Visita Cristina (id user 120)
  743.                 case '#157cc2':
  744.                     if ($dato['type'] == "Visit") {
  745.                         $newDatos[$dato['start']->format('Ymd').'V120'.$dato['id']] = $dato;
  746.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V120'])) {
  747.                             // Hay varias visitas ese mismo dia para el agente
  748. //                            $newDatos[$dato['start']->format('Ymd').'V120']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V120']['tooltip'] . $dato['tooltip'];
  749.                         } else {
  750. //                            $newDatos[$dato['start']->format('Ymd').'V120'] = $dato;
  751.                         }
  752.                     }
  753.                 break;
  754.                 //Visita Generica para agentes a Covarrubias
  755.                 case '#f0d800':
  756.                     if ($dato['type'] == "Visit") {
  757.                         $newDatos[$dato['start']->format('Ymd').'V0'.$dato['id']] = $dato;
  758.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V0'])) {
  759.                             // Hay varias visitas ese mismo dia para el agente
  760. //                            $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] . $dato['tooltip'];
  761.                         } else {
  762. //                            $newDatos[$dato['start']->format('Ymd').'V0'] = $dato;
  763.                         }
  764.                     }
  765.                     break;
  766.                 //Visita Generica para agentes a Bella View
  767.                 case '#990202':
  768.                     if ($dato['type'] == "Visit") {
  769.                         $newDatos[$dato['start']->format('Ymd').'V0'.$dato['id']] = $dato;
  770.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V0'])) {
  771.                             // Hay varias visitas ese mismo dia para el agente
  772. //                            $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] . $dato['tooltip'];
  773.                         } else {
  774. //                            $newDatos[$dato['start']->format('Ymd').'V0'] = $dato;
  775.                         }
  776.                     }
  777.                     break;
  778.                 //Reserva color naranja Bloqueo
  779.                 case '#ffaa00':
  780.                     if (empty($newDatos[$dato['id']])){
  781.                         $newDatos[$dato['id']] = $dato;
  782.                     } else {
  783.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  784.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  785.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  786.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  787.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  788.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  789.                             // No se encontro la cadena, debemos agregar
  790.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  791.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  792.                         }
  793.                     }
  794.                 break;
  795.                 //Reserva color morado Bloqueo (Covarrubias)
  796.                 case '#b873bf':
  797.                     if (empty($newDatos[$dato['id']])){
  798.                         $newDatos[$dato['id']] = $dato;
  799.                     } else {
  800.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  801.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  802.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  803.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  804.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  805.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  806.                             // No se encontro la cadena, debemos agregar
  807.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  808.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  809.                         }
  810.                     }
  811.                 break;
  812.                 //Reserva color Rojo claro Cotizado
  813.                 case '#faafc3':
  814.                     if (empty($newDatos[$dato['id']])){
  815.                         $newDatos[$dato['id']] = $dato;
  816.                     } else {
  817.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  818.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  819.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  820.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  821.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  822.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  823.                             // No se encontro la cadena, debemos agregar
  824.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  825.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  826.                         }
  827.                     }
  828.                 break;
  829.                 //Reserva color Rojo Reserva Cancelada
  830.                 case '#ff0000':
  831.                     //Las canceladas no se muestran en el calendario
  832.                 break;
  833.                 //Reserva color Verde Reserva Confirmada, Facturada, (se ha adelantado un pago parcial)
  834.                 case '#13ad27':
  835.                     if (empty($newDatos[$dato['id']])){
  836.                         $newDatos[$dato['id']] = $dato;
  837.                     } else {
  838.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  839.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  840.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  841.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  842.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  843.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  844.                             // No se encontro la cadena, debemos agregar
  845.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  846.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  847.                         }
  848.                     }
  849.                 break;
  850.                 //Reserva color Verde Reserva Confirmada, Facturada, (Covarrubias)
  851.                 case '#017362':
  852.                     if (empty($newDatos[$dato['id']])){
  853.                         $newDatos[$dato['id']] = $dato;
  854.                     } else {
  855.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  856.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  857.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  858.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  859.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  860.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  861.                             // No se encontro la cadena, debemos agregar
  862.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  863.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  864.                         }
  865.                     }
  866.                 break;
  867.                 //Reserva color Verde Reserva Confirmada, Facturada, (Bella View)
  868.                 case '#066191':
  869.                     if (empty($newDatos[$dato['id']])){
  870.                         $newDatos[$dato['id']] = $dato;
  871.                     } else {
  872.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  873.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  874.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  875.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  876.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  877.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  878.                             // No se encontro la cadena, debemos agregar
  879.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  880.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  881.                         }
  882.                     }
  883.                 break;
  884.                 //Se pondra color a negro para resaltar este cualquier caso que no haya sido considerado (status Pendiente)
  885.                 default:
  886.                     if (empty($newDatos[$dato['id']])){
  887.                         $newDatos[$dato['id']] = $dato;
  888.                     } else {
  889.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  890.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  891.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  892.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  893.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  894.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  895.                             // No se encontro la cadena, debemos agregar
  896.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  897.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  898.                         }
  899.                     }
  900.                     // Se pone en color negro para resaltar este caso que no esta entrando en ninguno de los casos anteriores
  901.                     $newDatos[$dato['id']]['color'] = '#000000';
  902.                     if ($dato['type'] == "Visit") {
  903.                         // Si no es una de los agentes regulares (Gaby, Angie, Cristina) se busca el color del usuario configurado en el perfil
  904.                         $elAgente $em->getRepository(User::class)->findOneById($dato['agentId']);
  905.                         $elAgenteColor = !empty($elAgente) ? $elAgente->getColor() : null;
  906.                         if (!empty($elAgenteColor)){ $newDatos[$dato['id']]['color'] = $elAgenteColor; }
  907.                     }
  908.                 break;
  909.             }
  910.         }
  911.         $datos0 = [];
  912.         foreach ($newDatos as $key => $item) {
  913.             if (!empty($item['id'])) {
  914.                 $datos0[$key] = array('title' => $item['title'],
  915.                     'titleOne' => $item['titleOne'],
  916.                     'titleTwo' => $item['titleTwo'],
  917.                     'titleThree' => $item['titleThree'],
  918.                     'type' => $item['type'],
  919.                     'id' => $item['id'],
  920.                     'tooltip' => $item['tooltip'],
  921.                     'start' => $item['start'],
  922.                     'end' => $item['end'],
  923.                     'color' => $item['color'],
  924.                     'loungeId' => $item['loungeId'],
  925.                     'url' => $item['url']
  926.                 );
  927.             }
  928.         }
  929.         $newDatos $datos0;
  930.         $datos = [];
  931.         foreach ($newDatos as $item) {
  932.             if ($item['color'] != '#ff0000') {
  933.                 // No se agregan al calendario los elementos eliminados o elementos vacios
  934.                 if (!empty($item)) {
  935.                     //INICIO: Verificamos por huecos dentro de la reserva
  936.                     if (empty($item['type'])) {
  937.                         // solo las reservas se van a verificar en este if
  938.                         if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el evento tiene mas de 2 dias, puede haber huecos
  939.                             $resSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($item['id']);
  940.                             $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  941.                             $arrayPeriod = [];
  942.                             foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  943.                             $logAllDiasEnReserva false;
  944.                             $logDiaEnReserva false;
  945.                             //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  946.                             foreach ($arrayPeriod as $day) {
  947.                                 foreach ($resSimples as $resSimple) {
  948.                                     if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  949.                                         $logDiaEnReserva true;
  950.                                         break;
  951.                                     }
  952.                                 }
  953.                                 if (!$logDiaEnReserva) {
  954.                                     //Un dia no se encontraba, hay un hueco
  955.                                     foreach ($resSimples as $resDayToAdd) {
  956.                                         if (empty($resDayToAdd->getType())) {       // Solo se deben agregar salsa los montajes y desmontajes aqui no van
  957.                                             $item['start'] = $resDayToAdd->getDateStart();
  958.                                             $item['end'] = $resDayToAdd->getDateEnd();
  959.                                             $br '<br>';
  960.                                             $br strpos($item['title'], $br);
  961.                                             $tempText substr($item['title'], $br 4);
  962.                                             $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  963.                                             $datos[] = $item;
  964.                                         }
  965.                                     }
  966.                                     break;
  967.                                 } else {
  968.                                     //Se debe evaluar el siguiente dia
  969.                                     $logDiaEnReserva false;
  970.                                     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
  971.                                         $logAllDiasEnReserva true;
  972.                                     }
  973.                                 }
  974.                             }
  975.                             if ($logAllDiasEnReserva) { $datos[] = $item; }
  976.                         } else {
  977.                             // El evento es de 1 o 2 dias, no hay posibilidad de hueco
  978.                             $datos[] = $item;
  979.                         }
  980.                     } else {
  981.                         //Es Visita Las visitas son las unicas entradas que no tienen hueco
  982.                         if ($item['type'] == 'Visit'){
  983.                             $datos[] = $item;
  984.                         } else {
  985.                             // es montaje o desmontaje, se va verificar por huecos
  986.                             if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el item tiene mas de 2 dias, puede haber huecos
  987.                                 $parameters = array(
  988.                                     'id' => $item['id'],
  989.                                     'type' => $item['type'],
  990.                                 );
  991.                                 $dql 'SELECT i
  992.                                         FROM GreenPatioBundle:ReservationLoungeSimple i
  993.                                         WHERE  i.idReservation = :id
  994.                                           and i.type = :type';
  995.                                 $query $em->createQuery($dql)->setParameters($parameters);
  996.                                 $resSimples $query->getResult();
  997.                                 $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  998.                                 $arrayPeriod = [];
  999.                                 foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  1000.                                 $logAllDiasEnReserva false;
  1001.                                 $logDiaEnReserva false;
  1002.                                 //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  1003.                                 foreach ($arrayPeriod as $day) {
  1004.                                     foreach ($resSimples as $resSimple) {
  1005.                                         if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  1006.                                             $logDiaEnReserva true;
  1007.                                             break;
  1008.                                         }
  1009.                                     }
  1010.                                     if (!$logDiaEnReserva) {
  1011.                                         //Un dia no se encontraba, hay un hueco
  1012.                                         foreach ($resSimples as $resDayToAdd) {
  1013.                                             if (!empty($resDayToAdd->getType())) {       // Solo se deben agregar montajes y desmontajes aqui
  1014.                                                 $item['start'] = $resDayToAdd->getDateStart();
  1015.                                                 $item['end'] = $resDayToAdd->getDateEnd();
  1016.                                                 $br '<br>';
  1017.                                                 $br strpos($item['title'], $br);
  1018.                                                 $tempText substr($item['title'], $br 4);
  1019.                                                 $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  1020.                                                 $datos[] = $item;
  1021.                                             }
  1022.                                         }
  1023.                                         break;
  1024.                                     } else {
  1025.                                         //Se debe evaluar el siguiente dia
  1026.                                         $logDiaEnReserva false;
  1027.                                         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
  1028.                                             $logAllDiasEnReserva true;
  1029.                                         }
  1030.                                     }
  1031.                                 }
  1032.                                 if ($logAllDiasEnReserva) { $datos[] = $item; }
  1033.                             } else {
  1034.                                 // El montaje o desmontaje es de 1 o 2 dias, no hay posibilidad de hueco
  1035.                                 $datos[] = $item;
  1036.                             }
  1037.                         }
  1038.                     }
  1039.                     //FIN: Verificamos por huecos dentro de la reserva
  1040.                 }
  1041.             }
  1042.         }
  1043.         $return = array( 'reservation' => $datos, );
  1044.         $response = new JsonResponse($return);
  1045.         return $response;
  1046.     }
  1047.     /**
  1048.      * @Route("/gp-cvr/calendarconfac", name="gp_cvr_calendar_con_fac")
  1049.      */
  1050.     public function calendarCvrGpConfFactReservationsAction(Request $requestAlertService $alertService) {
  1051.         $session = new Session();
  1052.         $token=$session->get('tokenGoogleCalendar');
  1053.         if (!is_null($token)) {
  1054.             $this->googleCalendar->setAccessToken($token);
  1055.             $connectGoogle "1";
  1056.         }else{
  1057.             $connectGoogle "0";
  1058.         }
  1059.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1060.         $user_id $user_logueado->getId();
  1061.         $wnotes = new WidgetNotes();
  1062.         $wnotes->setDateAt(new \DateTime("now"));
  1063.         $form $this->createWidgetNotesCreateForm($wnotes);
  1064.         $alertService->loadGpAlerts($user_logueado);
  1065.         return $this->render('MDS/GreenPatioBundle/reservations/calendar-gp-cvr-confac-reservations.html.twig',
  1066.             array(
  1067.                 'form' => $form->createView(),
  1068.                 'user'=> $user_id,
  1069.                 'connectGoogle' => $connectGoogle,
  1070.             )
  1071.         );
  1072.     }
  1073.     /**
  1074.      * @Route("/gp-cvr/eventsgpcvrconfac", name="get_reservations_gp_cvr_con_fac")
  1075.      */
  1076.     public function reservationGpCvrEventsConfFactAction(Request $request)
  1077.     {
  1078.         $em $this->getDoctrine()->getManager();
  1079.         // Buscamos las reservas desde 1 año atras en adelante para no traer exceso de datos
  1080.         $todayOneYearAgo = new DateTime('now -365 days');
  1081.         $parameters = array('dateStart' => $todayOneYearAgo,);
  1082.         $dql 'SELECT p
  1083.                 FROM GreenPatioBundle:ReservationLoungeSimple p                         
  1084.                 WHERE p.dateStart >= :dateStart  
  1085.                 ORDER BY p.dateStart ASC ';
  1086.         $query $em->createQuery($dql)->setParameters($parameters);
  1087.         $reservation $query->getResult();
  1088.         // Buscamos las visitas desde 1 semana atras en adelante para no traer exceso de datos (Tiempo confirmado por Gabriela Bracho)
  1089.         $todayOneWeekAgo = new DateTime('now -1 week');
  1090.         $parameters = array('dateStart' => $todayOneWeekAgo,);
  1091.         $dql 'SELECT p
  1092.                 FROM GreenPatioBundle:ReservationVisit p                         
  1093.                 WHERE p.dateStart >= :dateStart  
  1094.                 ORDER BY p.dateStart ASC ';
  1095.         $query $em->createQuery($dql)->setParameters($parameters);
  1096.         $visitas $query->getResult();
  1097.         $arrayFechaVisitas = [];
  1098.         foreach ($visitas as $item) {
  1099.             //Se agrupan las visitas por fechas
  1100.             $arrayFechaVisitas[$item->getDateStart()->format('Y-m-d').$item->getId()][] = $item;
  1101.         }
  1102.         $newArrayVisitas = [];
  1103.         //Se agrupan las visitas por agente
  1104.         foreach ($arrayFechaVisitas as $fecha) {
  1105.             foreach ($fecha as $item) {
  1106.                 //Se van concatenando los titulos de las visitas en una sola
  1107.                 $loungeNameTemp '';
  1108.                 $idAgentLounge = ($item->getIdLounge() == 0) ? $item->getAgentId() : '0';
  1109.                 if (!empty($newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge])) {
  1110. //                    $loungeNameTemp = $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' . $idAgentLounge]->getLoungeName();
  1111.                 }
  1112.                 $item->setLoungeName($loungeNameTemp $item->getDateStart()->format('H:i') . ' ' $item->getLoungeName() . '<br>');
  1113.                 $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge] = $item;
  1114.             }
  1115.         }
  1116.         $visitas $newArrayVisitas;
  1117.         $xArray = [];
  1118.         foreach ($arrayFechaVisitas as $elem) { foreach ($elem as $item) { $xArray[] = $item; } }
  1119.         foreach ($xArray as $item) { array_push($reservation$item); }
  1120.         $datos = [];
  1121.         $datosMontaje = [];
  1122.         $datosDesMontaje = [];
  1123.         if (!empty($reservation)) {
  1124.             foreach ($reservation as $reservaSala) {
  1125.                 if (!empty($reservaSala->getIdReservation())) {
  1126.                     $reserva $em->getRepository(Reservation::class)->findOneById($reservaSala->getIdReservation());
  1127.                     if ($reservaSala->getType() == 'Visit') { $reserva->setStatus('Visit'); }
  1128.                 } else {
  1129.                     // Estamos con una visita
  1130.                     $reserva = new Reservation();
  1131.                     $reserva->setStatus('Visit');
  1132.                     $reserva->setTitle($reservaSala->getLoungeName());
  1133.                 }
  1134.                 if ($reservaSala->getDateStart()->format('d') == $reservaSala->getDateEnd()->format('d')) {
  1135.                     $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();
  1136.                 } else {
  1137.                     $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();
  1138.                 }
  1139.                 $logicoVisita false;
  1140.                 if (!is_null($reserva->getStatus())) {
  1141.                     $statusColorMap = [
  1142.                         'Bloqueo' => function($reservaSala) {
  1143.                             $idLounge $reservaSala->getIdLounge();
  1144.                             if ($idLounge 29) {
  1145.                                 return "#2691fc"// Marrón (Bella View)
  1146.                             } elseif ($idLounge 21) {
  1147.                                 return "#b873bf"// Morado (Covarrubias)
  1148.                             } else {
  1149.                                 return "#ffaa00"// Naranja (Green Patio)
  1150.                             }
  1151.                         },
  1152.                         'Confirmed' => "#13ad27",
  1153.                         'Invoiced' => "#13ad27",
  1154.                         'Deleted' => "#ff0000",
  1155.                         'Cotizado' => "#faafc3",
  1156.                         'Reservado' => "#13ad27",
  1157.                         'Visit' => function($reservaSala) {
  1158.                             if ($reservaSala->getIdLounge() == 0) {
  1159.                                 return $agentColorMap[$reservaSala->getAgentId()] ?? "";
  1160.                             } else {
  1161.                                 if ($reservaSala->getIdLounge() == 1) {
  1162.                                     return '#f0d800';   //  Color Covarrubias
  1163.                                 } else {
  1164.                                     return '#066191';   //  Color Bella View
  1165.                                 }
  1166.                             }
  1167.                         },
  1168.                         'default' => "#066191",
  1169.                     ];
  1170.                     $color "";
  1171.                     $logicoVisita false;
  1172.                     if (array_key_exists($reserva->getStatus(), $statusColorMap)) {
  1173.                         $value $statusColorMap[$reserva->getStatus()];
  1174.                         // Si el valor es una función, la ejecutamos para obtener el color.
  1175.                         $color is_callable($value) ? $value($reservaSala) : $value;
  1176.                         if ($reserva->getStatus() === 'Visit') {
  1177.                             $logicoVisita true;
  1178.                         }
  1179.                     } else {
  1180.                         $color $statusColorMap['default'];
  1181.                     }
  1182.                     if (!empty($reservaSala->getType()) and !($reservaSala->getType() == 'Visit')) {
  1183.                         //Es un montaje o desmontaje
  1184.                         $color "#a5b8a2";
  1185.                         // Si es un montaje o desmontaje pero esta cancelado debe prevalecer el color de cancelado
  1186.                         if ($reserva->getStatus() == 'Deleted') { $color "#ff0000"; }
  1187.                     }
  1188.                     if (($reservaSala->getIdLounge() > 21) and ($reservaSala->getIdLounge() < 30)){
  1189.                         //Ajustamos el color a una sala de covarrubia
  1190.                         switch ($color) {
  1191.                             case '#ffaa00'$color "#b873bf"; break; //naranja (bloqueo) => morado
  1192.                             case '#13ad27'$color "#017362"; break; //verde (Confirmed) => verde olivo
  1193.                             case '#ff0000'$color "#ff0000"; break; //rojo
  1194.                             case '#faafc3'$color "#faafc3"; break; //Rojo claro
  1195.                             default: break; //no modificar el color
  1196.                         }
  1197.                     }
  1198.                     if ($reservaSala->getIdLounge() > 29){
  1199.                         //Ajustamos el color a una sala de bella view
  1200.                         switch ($color) {
  1201.                             case '#ffaa00'$color "#2691fc"; break; //naranja (bloqueo) => azul claro
  1202.                             case '#13ad27'$color "#066191"; break; //verde (Confirmed) => azul oscuro
  1203.                             case '#ff0000'$color "#ff0000"; break; //rojo
  1204.                             case '#faafc3'$color "#faafc3"; break; //Rojo claro
  1205.                             default: break; //no modificar el color
  1206.                         }
  1207.                     }
  1208.                 }
  1209.                 $pago1 "";
  1210.                 $pago2 "";
  1211.                 $ht "";
  1212.                 if (!($reserva->getStatus() == 'Visit')) {
  1213.                     $paymentsAll $em->getRepository(ReservationPaymentsClient::class)->findOneByReservationId($reserva->getId());
  1214.                 } else {
  1215.                     $paymentsAll null;
  1216.                 }
  1217.                 if (!empty($paymentsAll)) {
  1218.                     $pago2 "<i class='icon-coin-euro' style='color: #000 !important;'></i>";      //Hay pagos parciales
  1219.                 }
  1220.                 if (!($reserva->getStatus() == 'Visit')) {
  1221.                     $facturas $em->getRepository(ReservationInvoice::class)->findByReservationId($reserva->getId());
  1222.                     $facturasCVR $em->getRepository(CvrReservationInvoice::class)->findByReservationId($reserva->getId());
  1223.                     $facturasBLV $em->getRepository(BlvReservationInvoice::class)->findByReservationId($reserva->getId());
  1224.                     foreach ($facturasCVR as $item) { array_push($facturas$item); }
  1225.                     foreach ($facturasBLV as $item) { array_push($facturas$item); }
  1226.                 }
  1227.                 if (!empty($facturas)) {
  1228.                     foreach ($facturas as $factura) {
  1229.                         if ($factura->getMaster() == "master") {
  1230.                             $pago1 "<i class='icon-thumbs-up3' style='color: #000 !important;'></i>";// Se ha pagado la totalidad
  1231.                         }
  1232.                         if ($factura->getMaster() != "master") {
  1233.                             $pago2 "<i class='icon-coin-euro' style='color: #000 !important;'></i>";      //Hay pagos parciales
  1234.                         }
  1235.                     }
  1236.                 }
  1237.                 if ($reserva->getCateringName() == 'HIGO & TRIGO, S.L.') {
  1238.                     $ht "<a style='color: #000 !important;'><strong>H&T</strong></a>";      // Es una reserva con servicio de Catering Higo & Trigo
  1239.                 }
  1240.                 // Pagos parciales y totales
  1241.                 if (!empty($reserva)) {
  1242.                     if (!$logicoVisita) {
  1243.                         if (($reserva->getStatus() == 'Confirmed') or ($reserva->getStatus() == 'Invoiced')) {
  1244.                             $datos[] = array(
  1245.                                 "title" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . ' ' $reservaSala->getLoungeName() . '<br>' $reserva->getTitle(),
  1246.                                 "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType(),
  1247.                                 "titleTwo" => $reservaSala->getLoungeName(),
  1248.                                 "titleThree" => '' '<br>' $reserva->getTitle(),
  1249.                                 "type" => $reservaSala->getType(),
  1250.                                 "id" => $reserva->getId(),
  1251.                                 "tooltip" => $tooltip,
  1252.                                 "start" => $reservaSala->getDateStart(),
  1253.                                 "end" => $reservaSala->getDateEnd(),
  1254.                                 "color" => $color,
  1255.                                 "loungeId" => $reservaSala->getIdLounge(),
  1256.                                 "url" => "/reservations-greenpatio/edit/" $reserva->getId(),
  1257.                                 "status" => $reserva->getStatus(),
  1258.                             );
  1259.                         }
  1260.                     } else {
  1261.                         // Es una visita
  1262.                     }
  1263.                 } else {
  1264.                     $datos = [];
  1265.                 }
  1266.             }
  1267.         }
  1268.         $newDatos = [];
  1269.         // INICIO: Se unen las salas en una sola reserva por ID de reserva
  1270.         foreach ($datos as $dato) {
  1271.             // Inicializamos el arreglo para crear los indices
  1272.             switch ($dato['color']){
  1273.                 case '#a5b8a2':              //Montaje o Desmontaje
  1274.                     if ($dato['type'] == 'Montaje'){
  1275.                         $newDatos[$dato['id'].'M'] = null;
  1276.                     } else {
  1277.                         $newDatos[$dato['id'].'D'] = null;
  1278.                     }
  1279.                     break;
  1280.                 default:                    //Dia de reserva o Visita (la visita ya viene con su indice #V )
  1281.                     $newDatos[$dato['id']] = null;
  1282.                     break;
  1283.             }
  1284.         }
  1285.         foreach ($datos as $dato) {
  1286.             switch ($dato['color']){
  1287.                 //Montaje o Desmontaje
  1288.                 case '#a5b8a2':
  1289.                     if ($dato['type'] == "Montaje") {
  1290.                         if (!empty($newDatos[$dato['id'] . 'M'])) {
  1291.                             // El Montaje esta ocupando mas de 1 dia, se deben unir los dias de montaje si estamos tratando la misma sala (no se deben unir montajes de salas diferentes)
  1292.                             if ($newDatos[$dato['id'] . 'M']['loungeId'] == $dato['loungeId']) {
  1293.                                 if ($newDatos[$dato['id'] . 'M']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'M']['start'] = $dato['start']; }
  1294.                                 if ($newDatos[$dato['id'] . 'M']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'M']['end'] = $dato['end']; }
  1295.                             } else {
  1296.                                 if (array_key_exists($dato['id'] . 'M'.$dato['loungeId'],$newDatos)){
  1297.                                     if ($newDatos[$dato['id'] . 'M'.$dato['loungeId']]['start'] > $dato['start']) { $newDatos[$dato['id'] . 'M'.$dato['loungeId']]['start'] = $dato['start']; }
  1298.                                     if ($newDatos[$dato['id'] . 'M'.$dato['loungeId']]['end'] < $dato['end']) { $newDatos[$dato['id'] . 'M'.$dato['loungeId']]['end'] = $dato['end']; }
  1299.                                 } else {
  1300.                                     $newDatos[$dato['id'] . 'M'.$dato['loungeId']] = $dato;
  1301.                                 }
  1302.                             }
  1303.                         } else {
  1304.                             $newDatos[$dato['id'] . 'M'] = $dato;
  1305.                         }
  1306.                     } else {
  1307.                         if ($dato['type'] == "Desmontaje") {
  1308.                             if (!empty($newDatos[$dato['id'] . 'D'])) {
  1309.                                 // El Desmontaje esta ocupando mas de 1 dia, se deben unir los dias de desmontaje
  1310.                                 if ($newDatos[$dato['id'] . 'D']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'D']['start'] = $dato['start']; }
  1311.                                 if ($newDatos[$dato['id'] . 'D']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'D']['end'] = $dato['end']; }
  1312.                             } else {
  1313.                                 $newDatos[$dato['id'] . 'D'] = $dato;
  1314.                             }
  1315.                         }
  1316.                     }
  1317.                     break;
  1318.                 //Visita Angie (id user 77)
  1319.                 case '#22cbf5':
  1320.                     if ($dato['type'] == "Visit") {
  1321.                         $newDatos[$dato['start']->format('Ymd').'V77'.$dato['id']] = $dato;
  1322.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V77'])) {
  1323.                             // Hay varias visitas ese mismo dia para el agente
  1324. //                            $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] . $dato['tooltip'];
  1325.                         } else {
  1326. //                            $newDatos[$dato['start']->format('Ymd').'V77'] = $dato;
  1327.                         }
  1328.                     }
  1329.                     break;
  1330.                 //Visita Gabriela (id user 82)
  1331.                 case '#f5229a':
  1332.                     if ($dato['type'] == "Visit") {
  1333.                         $newDatos[$dato['start']->format('Ymd').'V82'.$dato['id']] = $dato;
  1334.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V82'])) {
  1335.                             // Hay varias visitas ese mismo dia para el agente
  1336. //                            $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] . $dato['tooltip'];
  1337.                         } else {
  1338. //                            $newDatos[$dato['start']->format('Ymd').'V82'] = $dato;
  1339.                         }
  1340.                     }
  1341.                     break;
  1342.                 //Visita Cristina (id user 120)
  1343.                 case '#157cc2':
  1344.                     if ($dato['type'] == "Visit") {
  1345.                         $newDatos[$dato['start']->format('Ymd').'V120'.$dato['id']] = $dato;
  1346.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V120'])) {
  1347.                             // Hay varias visitas ese mismo dia para el agente
  1348. //                            $newDatos[$dato['start']->format('Ymd').'V120']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V120']['tooltip'] . $dato['tooltip'];
  1349.                         } else {
  1350. //                            $newDatos[$dato['start']->format('Ymd').'V120'] = $dato;
  1351.                         }
  1352.                     }
  1353.                     break;
  1354.                 //Visita Generica para agentes a Covarrubias
  1355.                 case '#f0d800':
  1356.                     if ($dato['type'] == "Visit") {
  1357.                         $newDatos[$dato['start']->format('Ymd').'V0'.$dato['id']] = $dato;
  1358.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V0'])) {
  1359.                             // Hay varias visitas ese mismo dia para el agente
  1360. //                            $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] . $dato['tooltip'];
  1361.                         } else {
  1362. //                            $newDatos[$dato['start']->format('Ymd').'V0'] = $dato;
  1363.                         }
  1364.                     }
  1365.                     break;
  1366.                 //Visita Generica para agentes a Bella View
  1367.                 case '#990202':
  1368.                     if ($dato['type'] == "Visit") {
  1369.                         $newDatos[$dato['start']->format('Ymd').'V0'.$dato['id']] = $dato;
  1370.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V0'])) {
  1371.                             // Hay varias visitas ese mismo dia para el agente
  1372. //                            $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] . $dato['tooltip'];
  1373.                         } else {
  1374. //                            $newDatos[$dato['start']->format('Ymd').'V0'] = $dato;
  1375.                         }
  1376.                     }
  1377.                     break;
  1378.                 //Reserva color naranja Bloqueo
  1379.                 case '#ffaa00':
  1380.                     if (empty($newDatos[$dato['id']])){
  1381.                         $newDatos[$dato['id']] = $dato;
  1382.                     } else {
  1383.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1384.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  1385.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  1386.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1387.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1388.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1389.                             // No se encontro la cadena, debemos agregar
  1390.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  1391.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1392.                         }
  1393.                     }
  1394.                     break;
  1395.                 //Reserva color morado Bloqueo (Covarrubias)
  1396.                 case '#b873bf':
  1397.                     if (empty($newDatos[$dato['id']])){
  1398.                         $newDatos[$dato['id']] = $dato;
  1399.                     } else {
  1400.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1401.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  1402.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  1403.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1404.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1405.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1406.                             // No se encontro la cadena, debemos agregar
  1407.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  1408.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1409.                         }
  1410.                     }
  1411.                     break;
  1412.                 //Reserva color Rojo claro Cotizado
  1413.                 case '#faafc3':
  1414.                     if (empty($newDatos[$dato['id']])){
  1415.                         $newDatos[$dato['id']] = $dato;
  1416.                     } else {
  1417.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1418.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  1419.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  1420.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1421.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1422.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1423.                             // No se encontro la cadena, debemos agregar
  1424.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  1425.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1426.                         }
  1427.                     }
  1428.                     break;
  1429.                 //Reserva color Rojo Reserva Cancelada
  1430.                 case '#ff0000':
  1431.                     //Las canceladas no se muestran en el calendario
  1432.                     break;
  1433.                 //Reserva color Verde Reserva Confirmada, Facturada, (se ha adelantado un pago parcial)
  1434.                 case '#13ad27':
  1435.                     if (empty($newDatos[$dato['id']])){
  1436.                         $newDatos[$dato['id']] = $dato;
  1437.                     } else {
  1438.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1439.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  1440.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  1441.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1442.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1443.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1444.                             // No se encontro la cadena, debemos agregar
  1445.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  1446.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1447.                         }
  1448.                     }
  1449.                     break;
  1450.                 //Reserva color Verde Reserva Confirmada, Facturada, (Covarrubias)
  1451.                 case '#017362':
  1452.                     if (empty($newDatos[$dato['id']])){
  1453.                         $newDatos[$dato['id']] = $dato;
  1454.                     } else {
  1455.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1456.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  1457.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  1458.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1459.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1460.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1461.                             // No se encontro la cadena, debemos agregar
  1462.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  1463.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1464.                         }
  1465.                     }
  1466.                     break;
  1467.                 //Se pondra color a negro para resaltar este cualquier caso que no haya sido considerado (status Pendiente)
  1468.                 default:
  1469.                     if (empty($newDatos[$dato['id']])){
  1470.                         $newDatos[$dato['id']] = $dato;
  1471.                     } else {
  1472.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  1473.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) { $newDatos[$dato['id']]['start'] = $dato['start']; }
  1474.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) { $newDatos[$dato['id']]['end'] = $dato['end']; }
  1475.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  1476.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  1477.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  1478.                             // No se encontro la cadena, debemos agregar
  1479.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$dato['titleTwo'];
  1480.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  1481.                         }
  1482.                     }
  1483.                     // Se pone en color negro para resaltar este caso que no esta entrando en ninguno de los casos anteriores
  1484.                     $newDatos[$dato['id']]['color'] = '#000000';
  1485.                     if ($dato['type'] == "Visit") {
  1486.                         // Si no es una de los agentes regulares (Gaby, Angie, Cristina) se busca el color del usuario configurado en el perfil
  1487.                         $elAgente $em->getRepository(User::class)->findOneById($dato['agentId']);
  1488.                         $elAgenteColor = !empty($elAgente) ? $elAgente->getColor() : null;
  1489.                         if (!empty($elAgenteColor)){ $newDatos[$dato['id']]['color'] = $elAgenteColor; }
  1490.                     }
  1491.                     break;
  1492.             }
  1493.         }
  1494.         $datos0 = array();
  1495.         foreach ($newDatos as $key => $item) {
  1496.             if (!empty($item['id'])) {
  1497.                 $datos0[$key] = array('title' => $item['title'],
  1498.                     'titleOne' => $item['titleOne'],
  1499.                     'titleTwo' => $item['titleTwo'],
  1500.                     'titleThree' => $item['titleThree'],
  1501.                     'type' => $item['type'],
  1502.                     'id' => $item['id'],
  1503.                     'tooltip' => $item['tooltip'],
  1504.                     'start' => $item['start'],
  1505.                     'end' => $item['end'],
  1506.                     'color' => $item['color'],
  1507.                     'loungeId' => $item['loungeId'],
  1508.                     'url' => $item['url']
  1509.                 );
  1510.             }
  1511.         }
  1512.         $newDatos $datos0;
  1513.         $datos = array();
  1514.         foreach ($newDatos as $item) {
  1515.             if ($item['color'] != '#ff0000') {
  1516.                 // No se agregan al calendario los elementos eliminados o elementos vacios
  1517.                 if (!empty($item)) {
  1518.                     //INICIO: Verificamos por huecos dentro de la reserva
  1519.                     if (empty($item['type'])) {
  1520.                         // solo las reservas se van a verificar en este if
  1521.                         if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el evento tiene mas de 2 dias, puede haber huecos
  1522.                             $resSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($item['id']);
  1523.                             $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  1524.                             $arrayPeriod = array();
  1525.                             foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  1526.                             $logAllDiasEnReserva false;
  1527.                             $logDiaEnReserva false;
  1528.                             //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  1529.                             foreach ($arrayPeriod as $day) {
  1530.                                 foreach ($resSimples as $resSimple) {
  1531.                                     if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  1532.                                         $logDiaEnReserva true;
  1533.                                         break;
  1534.                                     }
  1535.                                 }
  1536.                                 if (!$logDiaEnReserva) {
  1537.                                     //Un dia no se encontraba, hay un hueco
  1538.                                     foreach ($resSimples as $resDayToAdd) {
  1539.                                         if (empty($resDayToAdd->getType())) {       // Solo se deben agregar salsa los montajes y desmontajes aqui no van
  1540.                                             $item['start'] = $resDayToAdd->getDateStart();
  1541.                                             $item['end'] = $resDayToAdd->getDateEnd();
  1542.                                             $br '<br>';
  1543.                                             $br strpos($item['title'], $br);
  1544.                                             $tempText substr($item['title'], $br 4);
  1545.                                             $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  1546.                                             $datos[] = $item;
  1547.                                         }
  1548.                                     }
  1549.                                     break;
  1550.                                 } else {
  1551.                                     //Se debe evaluar el siguiente dia
  1552.                                     $logDiaEnReserva false;
  1553.                                     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
  1554.                                         $logAllDiasEnReserva true;
  1555.                                     }
  1556.                                 }
  1557.                             }
  1558.                             if ($logAllDiasEnReserva) { $datos[] = $item; }
  1559.                         } else {
  1560.                             // El evento es de 1 o 2 dias, no hay posibilidad de hueco
  1561.                             $datos[] = $item;
  1562.                         }
  1563.                     } else {
  1564.                         //Es Visita Las visitas son las unicas entradas que no tienen hueco
  1565.                         if ($item['type'] == 'Visit'){
  1566.                             $datos[] = $item;
  1567.                         } else {
  1568.                             // es montaje o desmontaje, se va verificar por huecos
  1569.                             if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el item tiene mas de 2 dias, puede haber huecos
  1570.                                 $parameters = array(
  1571.                                     'id' => $item['id'],
  1572.                                     'type' => $item['type'],
  1573.                                 );
  1574.                                 $dql 'SELECT i
  1575.                                         FROM GreenPatioBundle:ReservationLoungeSimple i
  1576.                                         WHERE  i.idReservation = :id
  1577.                                           and i.type = :type';
  1578.                                 $query $em->createQuery($dql)->setParameters($parameters);
  1579.                                 $resSimples $query->getResult();
  1580.                                 $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  1581.                                 $arrayPeriod = array();
  1582.                                 foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  1583.                                 $logAllDiasEnReserva false;
  1584.                                 $logDiaEnReserva false;
  1585.                                 //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  1586.                                 foreach ($arrayPeriod as $day) {
  1587.                                     foreach ($resSimples as $resSimple) {
  1588.                                         if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  1589.                                             $logDiaEnReserva true;
  1590.                                             break;
  1591.                                         }
  1592.                                     }
  1593.                                     if (!$logDiaEnReserva) {
  1594.                                         //Un dia no se encontraba, hay un hueco
  1595.                                         foreach ($resSimples as $resDayToAdd) {
  1596.                                             if (!empty($resDayToAdd->getType())) {       // Solo se deben agregar montajes y desmontajes aqui
  1597.                                                 $item['start'] = $resDayToAdd->getDateStart();
  1598.                                                 $item['end'] = $resDayToAdd->getDateEnd();
  1599.                                                 $br '<br>';
  1600.                                                 $br strpos($item['title'], $br);
  1601.                                                 $tempText substr($item['title'], $br 4);
  1602.                                                 $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  1603.                                                 $datos[] = $item;
  1604.                                             }
  1605.                                         }
  1606.                                         break;
  1607.                                     } else {
  1608.                                         //Se debe evaluar el siguiente dia
  1609.                                         $logDiaEnReserva false;
  1610.                                         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
  1611.                                             $logAllDiasEnReserva true;
  1612.                                         }
  1613.                                     }
  1614.                                 }
  1615.                                 if ($logAllDiasEnReserva) { $datos[] = $item; }
  1616.                             } else {
  1617.                                 // El montaje o desmontaje es de 1 o 2 dias, no hay posibilidad de hueco
  1618.                                 $datos[] = $item;
  1619.                             }
  1620.                         }
  1621.                     }
  1622.                     //FIN: Verificamos por huecos dentro de la reserva
  1623.                 }
  1624.             }
  1625.         }
  1626.         $return = array( 'reservation' => $datos, );
  1627.         $response = new JsonResponse($return);
  1628.         return $response;
  1629.     }
  1630.     private function createWidgetNotesCreateForm(WidgetNotes $entity)
  1631.     {
  1632.         $form $this->createForm(WidgetNotesType::class, $entity, array(
  1633.             'action' => $this->generateUrl('widget_notes_calendar_cvr_create'),
  1634.             'method' => 'POST'
  1635.         ));
  1636.         return $form;
  1637.     }
  1638. };