src/Controller/higotrigo/CateringCalendarController.php line 192

Open in your IDE?
  1. <?php
  2. namespace App\Controller\higotrigo;
  3. use App\Entity\HtFile;
  4. use App\Entity\User;
  5. use App\Entity\WidgetNotes;
  6. use App\Form\WidgetNotesType;
  7. use App\MDS\GreenPatioBundle\Entity\Reservation;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\Session\Session;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Google_Client;
  16. use Google_Service_Calendar;
  17. use Psr\Log\LoggerInterface;
  18. use Google_Service_Calendar_Event;
  19. use Google_Service_Calendar_EventDateTime;
  20. use FOS\RestBundle\Controller\Annotations as Rest;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  22. use DateTime;
  23. use App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice;
  24. use App\MDS\GreenPatioBundle\Entity\ReservationInvoice;
  25. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
  26. use App\MDS\GreenPatioBundle\Entity\ReservationPaymentsClient;
  27. use DatePeriod;
  28. use DateInterval;
  29. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  30. class CateringCalendarController extends AbstractController
  31. {
  32.     /**
  33.      * @Route("/higotrigo/calendar", name="ht_calendar")
  34.      */
  35.     public function calendarCateringAction(Request $request) {
  36.         $session = new Session();
  37.         $token=$session->get('tokenGoogleCalendar');
  38.         if (!is_null($token)) {
  39.             $this->googleCalendar->setAccessToken($token);
  40.             $connectGoogle "1";
  41.         }else{
  42.             $connectGoogle "0";
  43.         }
  44.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  45.         $user_id $user_logueado->getId();
  46.         $wnotes = new WidgetNotes();
  47.         $wnotes->setDateAt(new \DateTime("now"));
  48.         $form $this->createWidgetNotesCreateForm($wnotes);
  49.         return $this->render('higotrigo/calendar-ht-caterings.html.twig',
  50.             array(
  51.                 'form' => $form->createView(),
  52.                 'user'=> $user_id,
  53.                 'connectGoogle' => $connectGoogle,
  54.             )
  55.         );
  56.     }
  57.     /**
  58.      * @Route("/widget/notes/calendarht/create/", name="widget_notes_calendar_ht_create")
  59.      */
  60.     public function addNotesAction(Request $requestLoggerInterface $logger)
  61.     {
  62.         $em $this->getDoctrine()->getManager();
  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.         return $this->redirectToRoute('ht_calendar');
  103.     }
  104.     /**
  105.      * @Route("/higotrigo/eventsht_OLD", name="get_caterings_ht_OLD")
  106.      */
  107.     public function htEventsOLDAction(EntityManagerInterface $em)
  108.     {
  109.         $todayOneYearAgo = new \DateTime('first day of January last year');
  110.         $parameters = array('dateStart' => $todayOneYearAgo, );
  111.         $dql 'SELECT p
  112.                 FROM App:HtFile p                         
  113.                 WHERE p.dateStart >= :dateStart AND p.dateEnd >= p.dateStart
  114.                 AND p.reservation IS NULL 
  115.                 ORDER BY p.dateStart ASC ';
  116.         $query $em->createQuery($dql)->setParameters($parameters);
  117.         $reservation $query->getResult();
  118.         $datos = array();
  119.         if (!empty($reservation)) {
  120.             foreach ($reservation as $reserva) {
  121.                 if ($reserva->getDateStart()->format('d') == $reserva->getDateEnd()->format('d')) {
  122.                     $tooltip $reserva->getTitle() . ' - Del'$reserva->getDateStart()->format('d/m') . ' desde ' $reserva->getDateStart()->format('H:i') . " a " $reserva->getDateEnd()->format('H:i');
  123.                 } else {
  124.                     $tooltip $reserva->getTitle() . ' - Del'$reserva->getDateStart()->format('d/m') . ' desde ' $reserva->getDateStart()->format('H:i') . " a " $reserva->getDateEnd()->format('d/m') . " a " $reserva->getDateEnd()->format('H:i');
  125.                 }
  126.                 $color "#c4771a";
  127.                 // Si el que crea la reserva es un agente de GP, se asigna el color #dd610b (naranja)
  128.                 $agent $reserva->getCreatedId();
  129.                 if ($agent->getTeam() == 17) {
  130. //                    $color = "#d9023d";
  131.                     $color "#ba0d0d";
  132.                 }
  133.                 // Iniciado o Cotizando
  134.                 if (($reserva->getStatus() == 'Iniciado') or ($reserva->getStatus() == 'Quoting')){ $color '#ed3939'; }
  135.                 // Cancelado
  136.                 if ($reserva->getStatus() == 'Cancel'){ $color '#000000'; }
  137.                 $datos[] = array(
  138.                     "title" => $reserva->getDateStart()->format('d/m/Y H:i') . ' ' '<br>' '<br>' $reserva->getTitle(),
  139.                     "titleOne" => $reserva->getDateStart()->format('H:i') . '<br>',
  140.                     "titleTwo" => $reserva->getDateEnd()->format('H:i') . '<br>',
  141.                     "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  142.                     "type" => '',
  143.                     "id" => $reserva->getId(),
  144.                     "tooltip" => $tooltip,
  145.                     "start" => $reserva->getDateStart(),
  146.                     "end" => $reserva->getDateEnd(),
  147.                     "color" => $color,
  148.                     "loungeId" => 1,
  149.                     "url" => "/higotrigo/ht/file/".$reserva->getId()."/edit",
  150.                     "status" => $reserva->getStatus(),
  151.                 );
  152.             }
  153.         }
  154.         $return = array( 
  155.             'reservation' => $datos,
  156.         );
  157.         $response = new JsonResponse($return);
  158.         return $response;
  159.     }
  160.     /**
  161.      * @Route("/higotrigo/eventsht", name="get_caterings_ht")
  162.      */
  163.     public function htEventsAction(UrlGeneratorInterface $urlGenerator)
  164.     {
  165.         $em $this->getDoctrine()->getManager();
  166.         // Buscamos las reservas desde 1 aƱo atras en adelante para no traer exceso de datos
  167.         $todayOneYearAgo = new DateTime('now -180 days');
  168.         $parameters = array('dateStart' => $todayOneYearAgo,);
  169.         $dql 'SELECT p
  170.                 FROM GreenPatioBundle:ReservationLoungeSimple p                         
  171.                 WHERE p.dateStart >= :dateStart  
  172.                 ORDER BY p.dateStart ASC ';
  173.         $query $em->createQuery($dql)->setParameters($parameters);
  174.         $reservation $query->getResult();
  175.         // Buscamos las visitas desde 1 semana atras en adelante para no traer exceso de datos (Tiempo confirmado por Gabriela Bracho)
  176.         $todayOneWeekAgo = new DateTime('now -1 week');
  177.         $parameters = array('dateStart' => $todayOneWeekAgo,);
  178.         $dql 'SELECT p
  179.                 FROM GreenPatioBundle:ReservationVisit p                         
  180.                 WHERE p.dateStart >= :dateStart  
  181.                 ORDER BY p.dateStart ASC ';
  182.         $query $em->createQuery($dql)->setParameters($parameters);
  183.         $visitas $query->getResult();
  184.         $arrayFechaVisitas = array();
  185.         foreach ($visitas as $item) {
  186.             //Se agrupan las visitas por fechas
  187.             $arrayFechaVisitas[$item->getDateStart()->format('Y-m-d')][] = $item;
  188.         }
  189.         $newArrayVisitas = array();
  190.         //Se agrupan las visitas por agente
  191.         foreach ($arrayFechaVisitas as $fecha) {
  192.             foreach ($fecha as $item) {
  193.                 //Se van concatenando los titulos de las visitas en una sola
  194.                 $loungeNameTemp '';
  195.                 $idAgentLounge = ($item->getIdLounge() == 0) ? $item->getAgentId() : '0';
  196.                 if (!empty($newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge])) {
  197.                     $loungeNameTemp $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge]->getLoungeName();
  198.                 }
  199.                 $item->setLoungeName($loungeNameTemp $item->getDateStart()->format('H:i') . ' ' $item->getLoungeName() . '<br>');
  200.                 $newArrayVisitas[$item->getDateStart()->format('Y-m-d') . '-' $idAgentLounge] = $item;
  201.             }
  202.         }
  203.         $visitas $newArrayVisitas;
  204.         foreach ($visitas as $item) { array_push($reservation$item); }
  205.         $datos = array();
  206.         if (!empty($reservation)) {
  207.             foreach ($reservation as $reservaSala) {
  208.                 if (!empty($reservaSala->getIdReservation())) {
  209.                     $reserva $em->getRepository(Reservation::class)->findOneById($reservaSala->getIdReservation());
  210.                     if ($reservaSala->getType() == 'Visit') {
  211.                         $reserva->setStatus('Visit');
  212.                     }
  213.                 } else {
  214.                     // Estamos con una visita
  215.                     $reserva = new Reservation();
  216.                     $reserva->setStatus('Visit');
  217.                     $reserva->setTitle($reservaSala->getLoungeName());
  218.                 }
  219.                 if ($reservaSala->getDateStart()->format('d') == $reservaSala->getDateEnd()->format('d')) {
  220.                     $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();
  221.                 } else {
  222.                     $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();
  223.                 }
  224.                 $logicoVisita false;
  225.                 if (!is_null($reserva->getStatus())) {
  226.                     $statusColorMap = [
  227.                         'Bloqueo' => function($reservaSala) { return ($reservaSala->getIdLounge() > 21) ? "#b873bf" "#ffaa00"; },
  228.                         'Confirmed' => "#13ad27",
  229.                         'Invoiced' => "#13ad27",
  230.                         'Deleted' => "#ff0000",
  231.                         'Cotizado' => "#faafc3",
  232.                         'Reservado' => "#13ad27",
  233.                         'Visit' => function($reservaSala) {
  234.                             if ($reservaSala->getIdLounge() == 0) {
  235.                                 $agentColorMap = [
  236.                                     77 => "#22cbf5",
  237.                                     82 => "#f5229a",
  238.                                     106 => "#157cc2",
  239.                                 ];
  240.                                 return $agentColorMap[$reservaSala->getAgentId()] ?? "";
  241.                             } else {
  242.                                 return '#f0d800';
  243.                             }
  244.                         },
  245.                         'default' => "",
  246.                     ];
  247.                     $color "";
  248.                     $logicoVisita false;
  249.                     if (array_key_exists($reserva->getStatus(), $statusColorMap)) {
  250.                         $value $statusColorMap[$reserva->getStatus()];
  251.                         // Si el valor es una función, la ejecutamos para obtener el color.
  252.                         $color is_callable($value) ? $value($reservaSala) : $value;
  253.                         if ($reserva->getStatus() === 'Visit') {
  254.                             $logicoVisita true;
  255.                         }
  256.                     } else {
  257.                         $color $statusColorMap['default'];
  258.                     }
  259.                     if (!empty($reservaSala->getType()) and !($reservaSala->getType() == 'Visit')) {
  260.                         //Es un montaje o desmontaje
  261.                         $color "#a5b8a2";
  262.                         // Si es un montaje o desmontaje pero esta cancelado debe prevalecer el color de cancelado
  263.                         if ($reserva->getStatus() == 'Deleted') { $color "#ff0000"; }
  264.                     }
  265.                     if (($reservaSala->getIdLounge() == 22) or  ($reservaSala->getIdLounge() == 23) or
  266.                         ($reservaSala->getIdLounge() == 24) or ($reservaSala->getIdLounge() == 25)){
  267.                         //Ajustamos el color a una sala de covarrubia
  268.                         switch ($color) {
  269.                             case '#ffaa00'$color "#b873bf"; break; //naranja (bloqueo) => morado
  270.                             case '#13ad27'$color "#017362"; break; //verde (Confirmed) => verde olivo
  271.                             case '#ff0000'$color "#ff0000"; break; //rojo
  272.                             case '#faafc3'$color "#faafc3"; break; //Rojo claro
  273.                             default: break; //no modificar el color
  274.                         }
  275.                     }
  276.                 }
  277.                 $ht "";
  278.                 if ($reserva->getCateringName() == 'HIGO & TRIGO, S.L.') {
  279.                     $ht "<a style='color: #000 !important;'><strong>H&T</strong></a>";      // Es una reserva con servicio de Catering Higo & Trigo
  280.                 }
  281.                 // Pagos parciales y totales
  282.                 $pago1 ""$pago2 ""// En HT no son relevantes los pagos de GP
  283.                 if (!empty($reserva)) {
  284.                     if (!$logicoVisita) {
  285.                         $urlReserva "#";
  286.                         if($reserva->getHtFile() != Null){
  287.                             $urlReserva $urlGenerator->generate('app_ht_file_edit', ['id' => $reserva->getHtFile()->getId()]);
  288.                         }
  289.                         $datos[] = array(
  290.                             "title" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . '<br>' $reservaSala->getLoungeName() . '<br>' '<br>' $reserva->getTitle(),
  291.                             "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' $pago2 $pago1 $ht ' ' $reservaSala->getType() . '<br>',
  292.                             "titleTwo" => $reservaSala->getLoungeName(),
  293.                             "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  294.                             "type" => $reservaSala->getType(),
  295.                             "id" => $reserva->getId(),
  296.                             "tooltip" => $tooltip,
  297.                             "start" => $reservaSala->getDateStart(),
  298.                             "end" => $reservaSala->getDateEnd(),
  299.                             "color" => $color,
  300.                             "loungeId" => $reservaSala->getIdLounge(),
  301.                             "url" => $urlReserva,
  302.                             "status" => $reserva->getStatus(),
  303.                         );
  304.                     } else {
  305.                         // Es una visita
  306.                         $datos[] = array(
  307.                             "title" => $reservaSala->getLoungeName(),
  308.                             "titleOne" => $reservaSala->getDateStart()->format('H:i') . ' ' ' ' $reservaSala->getType() . '<br>',
  309.                             "titleTwo" => $reservaSala->getLoungeName(),
  310.                             "titleThree" => '' '<br>' '<br>' $reserva->getTitle(),
  311.                             "type" => $reservaSala->getType(),
  312.                             "id" => $reservaSala->getId() . 'V',
  313.                             "tooltip" => $tooltip,
  314.                             "start" => $reservaSala->getDateStart(),
  315.                             "end" => $reservaSala->getDateEnd(),
  316.                             "color" => $color,
  317.                             "loungeId" => $reservaSala->getIdLounge(),
  318.                             "url" => '/reservations-greenpatio/addvisit',
  319.                             "status" => $reserva->getStatus(),
  320.                             "agentId" => $reservaSala->getAgentId(),
  321.                         );
  322.                     }
  323.                 } else {
  324.                     $datos = [];
  325.                 }
  326.             }
  327.         }
  328.         $newDatos = array();
  329.         // INICIO: Se unen las salas en una sola reserva por ID de reserva
  330.         foreach ($datos as $dato) {
  331.             // Inicializamos el arreglo para crear los indices
  332.             switch ($dato['color']){
  333.                 case '#a5b8a2':              //Montaje o Desmontaje
  334.                     if ($dato['type'] == 'Montaje'){
  335.                         $newDatos[$dato['id'].'M'] = null;
  336.                     } else {
  337.                         $newDatos[$dato['id'].'D'] = null;
  338.                     }
  339.                     break;
  340.                 default:                    //Dia de reserva o Visita (la visita ya viene con su indice #V )
  341.                     $newDatos[$dato['id']] = null;
  342.                     break;
  343.             }
  344.         }
  345.         foreach ($datos as $dato) {
  346.             switch ($dato['color']){
  347.                 //Montaje o Desmontaje
  348.                 case '#a5b8a2':
  349.                     if ($dato['type'] == "Montaje") {
  350.                         if (!empty($newDatos[$dato['id'] . 'M'])) {
  351.                             // El Montaje esta ocupando mas de 1 dia, se deben unir los dias de montaje
  352.                             if ($newDatos[$dato['id'] . 'M']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'M']['start'] = $dato['start']; }
  353.                             if ($newDatos[$dato['id'] . 'M']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'M']['end'] = $dato['end']; }
  354.                         } else {
  355.                             $newDatos[$dato['id'] . 'M'] = $dato;
  356.                         }
  357.                     } else {
  358.                         if ($dato['type'] == "Desmontaje") {
  359.                             if (!empty($newDatos[$dato['id'] . 'D'])) {
  360.                                 // El Desmontaje esta ocupando mas de 1 dia, se deben unir los dias de desmontaje
  361.                                 if ($newDatos[$dato['id'] . 'D']['start'] > $dato['start']) { $newDatos[$dato['id'] . 'D']['start'] = $dato['start']; }
  362.                                 if ($newDatos[$dato['id'] . 'D']['end'] < $dato['end']) { $newDatos[$dato['id'] . 'D']['end'] = $dato['end']; }
  363.                             } else {
  364.                                 $newDatos[$dato['id'] . 'D'] = $dato;
  365.                             }
  366.                         }
  367.                     }
  368.                     break;
  369.                 //Visita Angie (id user 77)
  370.                 case '#22cbf5':
  371.                     if ($dato['type'] == "Visit") {
  372.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V77'])) {
  373.                             // Hay varias visitas ese mismo dia para el agente
  374.                             $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V77']['tooltip'] . $dato['tooltip'];
  375.                         } else {
  376.                             $newDatos[$dato['start']->format('Ymd').'V77'] = $dato;
  377.                         }
  378.                     }
  379.                     break;
  380.                 //Visita Gabriela (id user 82)
  381.                 case '#f5229a':
  382.                     if ($dato['type'] == "Visit") {
  383.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V82'])) {
  384.                             // Hay varias visitas ese mismo dia para el agente
  385.                             $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V82']['tooltip'] . $dato['tooltip'];
  386.                         } else {
  387.                             $newDatos[$dato['start']->format('Ymd').'V82'] = $dato;
  388.                         }
  389.                     }
  390.                     break;
  391.                 //Visita MarĆ­a (id user 106)
  392.                 case '#157cc2':
  393.                     if ($dato['type'] == "Visit") {
  394.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V106'])) {
  395.                             // Hay varias visitas ese mismo dia para el agente
  396.                             $newDatos[$dato['start']->format('Ymd').'V106']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V106']['tooltip'] . $dato['tooltip'];
  397.                         } else {
  398.                             $newDatos[$dato['start']->format('Ymd').'V106'] = $dato;
  399.                         }
  400.                     }
  401.                     break;
  402.                 //Visita Generica para agentes a Covarrubias
  403.                 case '#f0d800':
  404.                     if ($dato['type'] == "Visit") {
  405.                         if (!empty($newDatos[$dato['start']->format('Ymd').'V0'])) {
  406.                             // Hay varias visitas ese mismo dia para el agente
  407.                             $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] = $newDatos[$dato['start']->format('Ymd').'V0']['tooltip'] . $dato['tooltip'];
  408.                         } else {
  409.                             $newDatos[$dato['start']->format('Ymd').'V0'] = $dato;
  410.                         }
  411.                     }
  412.                     break;
  413.                 //Reserva color naranja Bloqueo
  414.                 case '#ffaa00':
  415.                     if (empty($newDatos[$dato['id']])){
  416.                         $newDatos[$dato['id']] = $dato;
  417.                     } else {
  418.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  419.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  420.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  421.                         }
  422.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  423.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  424.                         }
  425.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  426.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  427.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  428.                             // No se encontro la cadena, debemos agregar
  429.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  430.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  431.                         }
  432.                     }
  433.                     break;
  434.                 //Reserva color morado Bloqueo (Covarrubias)
  435.                 case '#b873bf':
  436.                     if (empty($newDatos[$dato['id']])){
  437.                         $newDatos[$dato['id']] = $dato;
  438.                     } else {
  439.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  440.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  441.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  442.                         }
  443.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  444.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  445.                         }
  446.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  447.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  448.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  449.                             // No se encontro la cadena, debemos agregar
  450.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  451.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  452.                         }
  453.                     }
  454.                     break;
  455.                 //Reserva color Rojo claro Cotizado
  456.                 case '#faafc3':
  457.                     if (empty($newDatos[$dato['id']])){
  458.                         $newDatos[$dato['id']] = $dato;
  459.                     } else {
  460.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  461.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  462.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  463.                         }
  464.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  465.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  466.                         }
  467.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  468.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  469.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  470.                             // No se encontro la cadena, debemos agregar
  471.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  472.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  473.                         }
  474.                     }
  475.                     break;
  476.                 //Reserva color Rojo Reserva Cancelada
  477.                 // Revisar el caso de una reserva externa para el calendario y el caso de una reserva cancelada de GP pero sigue firme para HT
  478.                 case '#ff0000':
  479.                     //Las canceladas no se muestran en el calendario
  480.                     break;
  481.                 //Reserva color Verde Reserva Confirmada, Facturada, (se ha adelantado un pago parcial)
  482.                 case '#13ad27':
  483.                     if (empty($newDatos[$dato['id']])){
  484.                         $newDatos[$dato['id']] = $dato;
  485.                     } else {
  486.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  487.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  488.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  489.                         }
  490.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  491.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  492.                         }
  493.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  494.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  495.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  496.                             // No se encontro la cadena, debemos agregar
  497.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  498.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  499.                         }
  500.                     }
  501.                     break;
  502.                 //Reserva color Verde Reserva Confirmada, Facturada, (Covarrubias)
  503.                 case '#017362':
  504.                     if (empty($newDatos[$dato['id']])){
  505.                         $newDatos[$dato['id']] = $dato;
  506.                     } else {
  507.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  508.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  509.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  510.                         }
  511.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  512.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  513.                         }
  514.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  515.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  516.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  517.                             // No se encontro la cadena, debemos agregar
  518.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  519.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  520.                         }
  521.                     }
  522.                     break;
  523.                 //Se pondra color a negro para resaltar este cualquier caso que no haya sido considerado (status Pendiente)
  524.                 default:
  525.                     if (empty($newDatos[$dato['id']])){
  526.                         $newDatos[$dato['id']] = $dato;
  527.                     } else {
  528.                         // Se verifican la actualizacion de incio y fin, para tener el menor inicio y el mayor fin
  529.                         if ($newDatos[$dato['id']]['start'] > $dato['start']) {
  530.                             $newDatos[$dato['id']]['start'] = $dato['start'];
  531.                         }
  532.                         if ($newDatos[$dato['id']]['end'] < $dato['end']) {
  533.                             $newDatos[$dato['id']]['end'] = $dato['end'];
  534.                         }
  535.                         $newDatos[$dato['id']]['tooltip'] = $newDatos[$dato['id']]['tooltip'] . ' | ' $dato['tooltip'];
  536.                         // Verificamos si la sala ya ha sido previamente agregada a la lista de salas para no repetirla
  537.                         if (strpos($newDatos[$dato['id']]['title'], $dato['titleTwo']) === false) {
  538.                             // No se encontro la cadena, debemos agregar
  539.                             $newDatos[$dato['id']]['titleTwo'] = $newDatos[$dato['id']]['titleTwo'] . '<br>' $dato['titleTwo'];
  540.                             $newDatos[$dato['id']]['title'] = $newDatos[$dato['id']]['titleOne'] . $newDatos[$dato['id']]['titleTwo'] . $newDatos[$dato['id']]['titleThree'];
  541.                         }
  542.                     }
  543.                     // Se pone en color amarillo para resaltar este caso que no esta entrando en ninguno de los casos anteriores
  544.                     $newDatos[$dato['id']]['color'] = '#f0d800';
  545.                     break;
  546.             }
  547.         }
  548.         $datos0 = array();
  549.         foreach ($newDatos as $key => $item) {
  550.             if (!empty($item['id'])) {
  551.                 $datos0[$key] = array('title' => $item['title'],
  552.                     'titleOne' => $item['titleOne'],
  553.                     'titleTwo' => $item['titleTwo'],
  554.                     'titleThree' => $item['titleThree'],
  555.                     'type' => $item['type'],
  556.                     'id' => $item['id'],
  557.                     'tooltip' => $item['tooltip'],
  558.                     'start' => $item['start'],
  559.                     'end' => $item['end'],
  560.                     'color' => $item['color'],
  561.                     'loungeId' => $item['loungeId'],
  562.                     'url' => $item['url'],
  563.                     'status' => $item['status'],
  564.                 );
  565.             }
  566.         }
  567.         $newDatos $datos0;
  568.         $datos = array();
  569.         foreach ($newDatos as $item) {
  570.             if ($item['color'] != '#ff0000') {
  571.                 // No se agregan al calendario los elementos eliminados o elementos vacios
  572.                 if (!empty($item)) {
  573.                     //INICIO: Verificamos por huecos dentro de la reserva
  574.                     if (empty($item['type'])) {
  575.                         // solo las reservas se van a verificar en este if
  576.                         if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el evento tiene mas de 2 dias, puede haber huecos
  577.                             $resSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($item['id']);
  578.                             $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  579.                             $arrayPeriod = array();
  580.                             foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  581.                             $logAllDiasEnReserva false;
  582.                             $logDiaEnReserva false;
  583.                             //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  584.                             foreach ($arrayPeriod as $day) {
  585.                                 foreach ($resSimples as $resSimple) {
  586.                                     if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  587.                                         $logDiaEnReserva true;
  588.                                         break;
  589.                                     }
  590.                                 }
  591.                                 if (!$logDiaEnReserva) {
  592.                                     //Un dia no se encontraba, hay un hueco
  593.                                     foreach ($resSimples as $resDayToAdd) {
  594.                                         if (empty($resDayToAdd->getType())) {       // Solo se deben agregar salsa los montajes y desmontajes aqui no van
  595.                                             $item['start'] = $resDayToAdd->getDateStart();
  596.                                             $item['end'] = $resDayToAdd->getDateEnd();
  597.                                             $br '<br>';
  598.                                             $br strpos($item['title'], $br);
  599.                                             $tempText substr($item['title'], $br 4);
  600.                                             $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  601.                                             $datos[] = $item;
  602.                                         }
  603.                                     }
  604.                                     break;
  605.                                 } else {
  606.                                     //Se debe evaluar el siguiente dia
  607.                                     $logDiaEnReserva false;
  608.                                     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
  609.                                         $logAllDiasEnReserva true;
  610.                                     }
  611.                                 }
  612.                             }
  613.                             if ($logAllDiasEnReserva) { $datos[] = $item; }
  614.                         } else {
  615.                             // El evento es de 1 o 2 dias, no hay posibilidad de hueco
  616.                             $datos[] = $item;
  617.                         }
  618.                     } else {
  619.                         //Es Visita Las visitas son las unicas entradas que no tienen hueco
  620.                         if ($item['type'] == 'Visit'){
  621.                             $datos[] = $item;
  622.                         } else {
  623.                             // es montaje o desmontaje, se va verificar por huecos
  624.                             if ((date_diff($item['start'], $item['end'])->d) > 1) {    //el item tiene mas de 2 dias, puede haber huecos
  625.                                 $parameters = array(
  626.                                     'id' => $item['id'],
  627.                                     'type' => $item['type'],
  628.                                 );
  629.                                 $dql 'SELECT i
  630.                                         FROM GreenPatioBundle:ReservationLoungeSimple i
  631.                                         WHERE  i.idReservation = :id
  632.                                           and i.type = :type';
  633.                                 $query $em->createQuery($dql)->setParameters($parameters);
  634.                                 $resSimples $query->getResult();
  635.                                 $period = new DatePeriod$item['start'], new DateInterval('P1D'), $item['end'] );
  636.                                 $arrayPeriod = array();
  637.                                 foreach ($period as $key => $value) { $arrayPeriod[] = $value; }
  638.                                 $logAllDiasEnReserva false;
  639.                                 $logDiaEnReserva false;
  640.                                 //Verificamos que cada dia tenga su reserva de sala para que no haya hueco
  641.                                 foreach ($arrayPeriod as $day) {
  642.                                     foreach ($resSimples as $resSimple) {
  643.                                         if ($resSimple->getDateStart()->format('Y-m-d') == $day->format('Y-m-d')) {
  644.                                             $logDiaEnReserva true;
  645.                                             break;
  646.                                         }
  647.                                     }
  648.                                     if (!$logDiaEnReserva) {
  649.                                         //Un dia no se encontraba, hay un hueco
  650.                                         foreach ($resSimples as $resDayToAdd) {
  651.                                             if (!empty($resDayToAdd->getType())) {       // Solo se deben agregar montajes y desmontajes aqui
  652.                                                 $item['start'] = $resDayToAdd->getDateStart();
  653.                                                 $item['end'] = $resDayToAdd->getDateEnd();
  654.                                                 $br '<br>';
  655.                                                 $br strpos($item['title'], $br);
  656.                                                 $tempText substr($item['title'], $br 4);
  657.                                                 $item['title'] = $resDayToAdd->getDateStart()->format('H:i') . ' ' '<br>' $tempText;
  658.                                                 $datos[] = $item;
  659.                                             }
  660.                                         }
  661.                                         break;
  662.                                     } else {
  663.                                         //Se debe evaluar el siguiente dia
  664.                                         $logDiaEnReserva false;
  665.                                         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
  666.                                             $logAllDiasEnReserva true;
  667.                                         }
  668.                                     }
  669.                                 }
  670.                                 if ($logAllDiasEnReserva) { $datos[] = $item; }
  671.                             } else {
  672.                                 // El montaje o desmontaje es de 1 o 2 dias, no hay posibilidad de hueco
  673.                                 $datos[] = $item;
  674.                             }
  675.                         }
  676.                     }
  677.                     //FIN: Verificamos por huecos dentro de la reserva
  678.                 }
  679.             }
  680.         }
  681.         // Buscamos las pruebas de menu desde 6 meses atras
  682.         $todayHalfYearAgo = new DateTime('now -180 days');
  683.         $parameters = array('dateStart' => $todayHalfYearAgo,);
  684.         $dql 'SELECT p
  685.                 FROM App:HtVisit p                         
  686.                 WHERE p.dateStart >= :dateStart  
  687.                 ORDER BY p.dateStart ASC ';
  688.         $query $em->createQuery($dql)->setParameters($parameters);
  689.         $pmenu $query->getResult();
  690.         $arrayPmenu = array(); $color '#ccad11';
  691.         foreach ($pmenu as $item){
  692.             $agent = (!empty($item->getAgentId())) ? ($item->getAgentId())->getName() : 'Sin agente';
  693.             $pax = (!empty($item->getPax())) ? (' - '.$item->getPax() . ' PAX') : null;
  694.             $title =''$titleOne =''$titleTwo =''$titleThree =''$type =''$id =''$tooltip =''$start =''$end =''$loungeId =''$url ='';
  695.             if(!empty($item->getReservation())){
  696.                 $title = ($item->getDateStart())->format('H:i'). ' PRUEBA DE MENU ( '.$agent' )<br>' $item->getName(). $pax ' - ' . ($item->getReservation())->getTitle();
  697.                 $titleOne '$titleOne';
  698.                 $titleTwo '$titleTwo';
  699.                 $titleThree '$titleThree';
  700.                 $type 'Prueba Menu';
  701.                 $id $item->getId();
  702.                 $loungeId = (!empty(($item->getLounge()))) ? '<b> - '. ($item->getLounge())->getName() : null;
  703.                 $tooltip '<b>'. ($item->getReservation())->getTitle() .$loungeId;
  704.                 $start $item->getDateStart();
  705.                 $end $item->getDateEnd();
  706.                 $end->modify('+1 hour');
  707.                 $loungeId = ($item->getLounge())->getId();
  708.                 $url '/higotrigo/ht/file/'.($item->getReservation())->getId().'/edit';
  709.             } else {
  710.                 $title = ($item->getDateStart())->format('H:i'). ' PRUEBA DE MENU ( '.$agent' )<br>' $item->getName() . $pax;
  711.                 $titleOne '$titleOne';
  712.                 $titleTwo '$titleTwo';
  713.                 $titleThree '$titleThree';
  714.                 $type 'Prueba Menu';
  715.                 $id $item->getId();
  716.                 $loungeId = (!empty(($item->getLounge()))) ? '<b> '. ($item->getLounge())->getName() : null;
  717.                 $tooltip '<b>' $loungeId;
  718.                 $start $item->getDateStart();
  719.                 $end $item->getDateEnd();
  720.                 $end->modify('+1 hour');
  721.                 $loungeId = ($item->getLounge())->getId();
  722.                 $url '/#';
  723.             }
  724.             $arrayPmenu[] = array(
  725.                 'title' => $title,
  726.                 'titleOne' => $titleOne,
  727.                 'titleTwo' => $titleTwo,
  728.                 'titleThree' => $titleThree,
  729.                 'type' => $type,
  730.                 'id' => $id,
  731.                 'tooltip' => $tooltip,
  732.                 'start' => $start,
  733.                 'end' => $end,
  734.                 'color' => $color,
  735.                 'loungeId' => $loungeId,
  736.                 'url' => $url,
  737.             );
  738.         }
  739.         foreach ($arrayPmenu as $item){ array_push($datos$item); }
  740.         $return = array( 'reservation' => $datos, );
  741.         $response = new JsonResponse($return);
  742.         return $response;
  743.     }
  744.     private function createWidgetNotesCreateForm(WidgetNotes $entity)
  745.     {
  746.         $form $this->createForm(WidgetNotesType::class, $entity, array(
  747.             'action' => $this->generateUrl('widget_notes_calendar_ht_create'),
  748.             'method' => 'POST'
  749.         ));
  750.         return $form;
  751.     }
  752. };