src/MDS/GreenPatioBundle/Controller/ReservationsQuoteController.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\MDS\GreenPatioBundle\Controller;
  3. use App\Entity\ReservationLoungeWebDescription;
  4. use App\Entity\WidgetNotes;
  5. use App\Form\WidgetNotesType;
  6. use App\MDS\AvexpressBundle\Entity\AveFiles;
  7. use App\MDS\GreenPatioBundle\Entity\Reservation;
  8. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
  9. use App\MDS\GreenPatioBundle\Entity\ReservationService;
  10. use App\MDS\GreenPatioBundle\Entity\ReservationGpPrice;
  11. use App\MDS\GreenPatioBundle\Entity\ReservationLounge;
  12. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeDetails;
  13. use App\MDS\GreenPatioBundle\Entity\ReservationLoungeProfile;
  14. use App\MDS\GreenPatioBundle\Entity\ReservationPeriod;
  15. use App\MDS\GreenPatioBundle\Form\ReservationGpPriceType;
  16. use App\MDS\GreenPatioBundle\Form\ReservationLoungeDetailsType;
  17. use App\MDS\GreenPatioBundle\Form\ReservationLoungeProfileType;
  18. use App\MDS\GreenPatioBundle\Form\ReservationPeriodType;
  19. use App\MDS\GreenPatioBundle\Form\ReservationType;
  20. use App\Service\SincGpHtAvService;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use DateTime;
  26. use DatePeriod;
  27. use DateInterval;
  28. use Google_Client;
  29. use Google_Service_Calendar;
  30. use Symfony\Contracts\Translation\TranslatorInterface;
  31. use Symfony\Component\HttpFoundation\JsonResponse;
  32. class ReservationsQuoteController extends AbstractController
  33. {
  34.     public function __construct(TranslatorInterface $translator,  SincGpHtAvService $sincGpHtAvService)
  35.     {
  36.         $redirect_uri 'https://' $_SERVER['HTTP_HOST']. '/calendar/token';
  37.         $googleCalendar = new Google_Client();
  38.         $googleCalendar->setApplicationName('Google Calendar API PHP Quickstart');
  39.         //campos a extraer de la base de datos User
  40.         $googleCalendar->setClientId('2790497987-57qc3vu4pr7vb0s8phpub2me58pe34lb.apps.googleusercontent.com');
  41.         $googleCalendar->setClientSecret('nj2C7unaTO68DRhyORsyipSj');
  42.         //fin campos user
  43. //        $api_key = "AIzaSyBR84cS1IU2BPvk5V3VnbqdkJESlv440Ac";
  44. //        $client->setDeveloperKey($api_key);
  45.         $googleCalendar->setRedirectUri($redirect_uri);
  46.         $googleCalendar->addScope(Google_Service_Calendar::CALENDAR);
  47.         $guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
  48.         $googleCalendar->setHttpClient($guzzleClient);
  49.         $this->googleCalendar $googleCalendar;
  50.         $this->translator $translator;
  51.         $this->sincGpHtAvService $sincGpHtAvService;
  52.     }
  53.     private $sincGpHtAvService;
  54.     /**
  55.      * @Route("/createsimplelounge/{id}", name="reservations_greenpatio_create_simple_lounge")
  56.      * Crea un Reservation Lounge Simple en la cotizacion
  57.      */
  58.     public function createSimpleLoungeAction($idEntityManagerInterface $emRequest $request)
  59.     {
  60.         $simpleLounge $request->request->get('reservation_sala');
  61.         $loungeProfile $em->getRepository(ReservationLoungeDetails::class)->findOneById($simpleLounge['salaPrecargadas']);
  62.         $loungeId $loungeProfile->getId();
  63.         $loungeDetails $em->getRepository(ReservationLoungeDetails::class)->findOneById($loungeId);
  64.         $previusLoungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idLounge' => $loungeId'idReservation' => $id'rankQuote' => $simpleLounge['idQuote']));
  65.         //Buscamos si hay ya alguna sala en la reserva
  66.         $anyLoungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idLounge' => $loungeId'idReservation' => $id));
  67.         $idioma 1;
  68.         if($anyLoungeSimple){
  69.             $idioma $anyLoungeSimple->getLanguage();
  70.         }
  71.         $loungeWebDescription $em->getRepository(ReservationLoungeWebDescription::class)->findOneBy(array('lounge' => $loungeProfile'language' => $idioma));
  72.         $loungeName $loungeDetails->getName();
  73.         $hourMinStart $simpleLounge['hourStart'];
  74.         $hourMinEnd $simpleLounge['hourEnd'];
  75.         $loungeSummaryDescription array_key_exists('importantDescription'$simpleLounge) ? $simpleLounge['importantDescription'] : null;
  76.         if (empty($previusLoungeSimple)) {
  77.             if (empty($loungeSummaryDescription)) { $loungeSummaryDescription $loungeWebDescription->getImportantDescription(); }
  78.             $loungeImportantDescGeneralText $loungeWebDescription->getImportantDescGeneralText();
  79.             $loungeImportantDescSchedules $loungeWebDescription->getImportantDescSchedules();
  80.             $loungeImportantDescParking $loungeWebDescription->getImportantDescParking();
  81.         } else {
  82.             $loungeSummaryDescription $previusLoungeSimple->getImportantDescription();
  83.             $loungeImportantDescGeneralText $previusLoungeSimple->getImportantDescGeneralText();
  84.             $loungeImportantDescSchedules $previusLoungeSimple->getImportantDescSchedules();
  85.             $loungeImportantDescParking $previusLoungeSimple->getImportantDescParking();
  86.         }
  87.         
  88.         $iva 21;
  89.         if (array_key_exists('iva'$simpleLounge)) {
  90.             if (empty($simpleLounge['iva']) && !is_numeric($simpleLounge['iva'])) {
  91.                 $iva 21;
  92.             } else {
  93.                 $iva $simpleLounge['iva'];
  94.             }
  95.         }
  96.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  97.         $reservationAll $qb->where('r.idReservation = :idReservation')
  98.             ->setParameter('idReservation'$id)
  99.             ->orderBy('r.rankQuote''ASC')
  100.             ->getQuery()
  101.             ->getResult();
  102.         $newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
  103.         if (!empty($simpleLounge['idQuote'])){ if (is_numeric($simpleLounge['idQuote'])){ $newRankId $simpleLounge['idQuote']; } }
  104.         // Autocompletacion HH:mm en Start
  105.         switch (strlen($hourMinStart)) {
  106.             case 0:
  107.                 // Vacio
  108.                 $hourStart '00'$minStart '00'$hourMinStart '00:00';
  109.                 break;
  110.             case 1:
  111.                 // H  -> 0H:00
  112.                 if (is_numeric($hourMinStart)){
  113.                     $hourStart '0'.$hourMinStart$minStart '00'$hourMinStart $hourStart.':'.$minStart;
  114.                 } else {
  115.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  116.                 }
  117.                 break;
  118.             case 2:
  119.                 // HH  -> HH:00
  120.                 if (is_numeric($hourMinStart)){
  121.                     $hourStart $hourMinStart$minStart '00'$hourMinStart $hourStart.':'.$minStart;
  122.                 } else {
  123.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  124.                 }
  125.                 break;
  126.             case 3:
  127.                 // Hmm  -> 0H:mm
  128.                 if (is_numeric($hourMinStart)){
  129.                     $hourStart '0'.substr($hourMinStart,0,1); $minStart substr($hourMinStart,1,2); $hourMinStart $hourStart.':'.$minStart;
  130.                 } else {
  131.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  132.                 }
  133.                 break;
  134.             case 4:
  135.                 // HHmm  -> HH:mm
  136.                 if (is_numeric($hourMinStart)){
  137.                     $hourStart substr($hourMinStart,0,2); $minStart substr($hourMinStart,2,2); $hourMinStart $hourStart.':'.$minStart;
  138.                 } else {
  139.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  140.                 }
  141.                 break;
  142.             case 5:
  143.                 // HH:mm
  144.                 if (is_numeric(substr($hourMinStart,0,2)) and (substr($hourMinStart,2,1)==':') and is_numeric(substr($hourMinStart,0,2))){
  145.                     $hourStart substr($hourMinStart,0,2); $minStart substr($hourMinStart,3,2); $hourMinStart $hourStart.':'.$minStart;
  146.                 } else {
  147.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  148.                 }
  149.                 break;
  150.             default:
  151.                 // XXXXyyy
  152.                 $hourStart '00'$minStart '00'$hourMinStart '00:00';
  153.                 break;
  154.         }
  155.         // Autocompletacion HH:mm en End
  156.         switch (strlen($hourMinEnd)) {
  157.             case 0:
  158.                 // Vacio
  159.                 $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  160.                 break;
  161.             case 1:
  162.                 // H  -> 0H:00
  163.                 if (is_numeric($hourMinEnd)){
  164.                     $hourEnd '0'.$hourMinEnd$minEnd '00'$hourMinEnd $hourEnd.':'.$minEnd;
  165.                 } else {
  166.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  167.                 }
  168.                 break;
  169.             case 2:
  170.                 // HH  -> HH:00
  171.                 if (is_numeric($hourMinEnd)){
  172.                     $hourEnd $hourMinEnd$minEnd '00'$hourMinEnd $hourEnd.':'.$minEnd;
  173.                 } else {
  174.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  175.                 }
  176.                 break;
  177.             case 3:
  178.                 // Hmm  -> 0H:mm
  179.                 if (is_numeric($hourMinEnd)){
  180.                     $hourEnd '0'.substr($hourMinEnd,0,1); $minEnd substr($hourMinEnd,1,2); $hourMinEnd $hourEnd.':'.$minEnd;
  181.                 } else {
  182.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  183.                 }
  184.                 break;
  185.             case 4:
  186.                 // HHmm  -> HH:mm
  187.                 if (is_numeric($hourMinEnd)){
  188.                     $hourEnd substr($hourMinEnd,0,2); $minEnd substr($hourMinEnd,2,2); $hourMinEnd $hourEnd.':'.$minEnd;
  189.                 } else {
  190.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  191.                 }
  192.                 break;
  193.             case 5:
  194.                 // HH:mm
  195.                 if (is_numeric(substr($hourMinEnd,0,2)) and (substr($hourMinEnd,2,1)==':') and is_numeric(substr($hourMinEnd,0,2))){
  196.                     $hourEnd substr($hourMinEnd,0,2); $minEnd substr($hourMinEnd,3,2); $hourMinEnd $hourEnd.':'.$minEnd;
  197.                 } else {
  198.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  199.                 }
  200.                 break;
  201.             default:
  202.                 // XXXXyyy
  203.                 $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  204.                 break;
  205.         }
  206.         $dateStart = new DateTime($simpleLounge['dateStart'] . ' '$hourMinStart);
  207.         $dateEnd = new DateTime($simpleLounge['dateStart'] . ' '$hourMinEnd);   // Se usa DateStart por que solo hay un dia en el formulario
  208.         $idService 0;
  209.         $serviceName '';
  210.         $servicePrice = (empty($simpleLounge['servicePrice'])) ? :$simpleLounge['servicePrice'];
  211.         $idReservation $id;
  212.         /* Obtengo usuario logueado */
  213.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  214.         $user_id $user_logueado->getId();
  215.         $createdAt = new DateTime('now');
  216.         $createdBy $user_id;
  217.         $updatedAt = new DateTime('now');
  218.         $updatedBy $user_id;
  219.         $pax $simpleLounge['pax']; if (empty($pax)){$pax 0;}
  220.         $lounge = new ReservationLoungeSimple();
  221.         $lounge->setIdLounge ($loungeId);
  222.         $lounge->setHourStart ($hourStart);
  223.         $lounge->setMinStart ($minStart);
  224.         $lounge->setHourEnd ($hourEnd);
  225.         $lounge->setMinEnd ($minEnd);
  226.         $lounge->setLoungeName ($loungeName);
  227.         $lounge->setDateStart ($dateStart);
  228.         $lounge->setDateEnd ($dateEnd);
  229.         $lounge->setRankQuote(1);
  230.         $lounge->setIdReservation ($idReservation);
  231.         $lounge->setIva($iva);
  232.         $lounge->setOpIva(1);
  233.         $lounge->setCreatedAt ($createdAt);
  234.         $lounge->setCreatedBy ($createdBy);
  235.         $lounge->setUpdatedAt ($updatedAt);
  236.         $lounge->setUpdatedBy ($updatedBy);
  237.         $lounge->setPax ($pax);
  238.         $lounge->setRankQuote($newRankId);
  239.         $lounge->setImportantDescription($loungeSummaryDescription);
  240.         $lounge->setImportantDescGeneralText($loungeImportantDescGeneralText);
  241.         $lounge->setImportantDescSchedules($loungeImportantDescSchedules);
  242.         $lounge->setImportantDescParking($loungeImportantDescParking);
  243.         $price $this->precioTarifario($dateStart$loungeId$servicePrice);
  244.         $lounge->setServicePrice($price);
  245.         try{
  246.             $em->persist($lounge);
  247.             $em->flush();
  248.             $event 'The Reservation has been updated.';
  249.             $successMessage $this->translator->trans($event);
  250.             $this->addFlash('mensajereservation'$successMessage);
  251.         } catch (\Exception $e){
  252.             $event 'An error occurred: '.$e->getMessage();
  253.             $errorMessage $this->translator->trans($event);
  254.             $this->addFlash('mensajereservationerror'$errorMessage);
  255.         }
  256.         // INICIO: Actualizacion de fecha de inicio y fin del evento, a partir de la info de la sala
  257.         $boolSincGpAv false;
  258.         $reserva $em->getRepository(Reservation::class)->findOneById($idReservation);
  259.         if ($reserva->getDateStart() > $dateStart){ $reserva->setDateStart($dateStart); $boolSincGpAv true; }
  260.         if ($reserva->getDateStart()->format('Y') == '2078' ){ $reserva->setDateStart($dateStart); $boolSincGpAv true; }
  261.         if ($reserva->getDateEnd() < $dateEnd){ $reserva->setDateEnd($dateEnd); $boolSincGpAv true; }
  262.         if ($reserva->getDateEnd()->format('Y') == '2000' ){ $reserva->setDateEnd($dateEnd); $boolSincGpAv true; }
  263.         try{
  264.             $em->persist($reserva);
  265.             $em->flush();
  266.             $event '';
  267.             $successMessage $this->translator->trans($event);
  268.             $this->addFlash('mensajereservation'$successMessage);
  269.         } catch (\Exception $e){}
  270.         // Sincronización global de todos los campos
  271.         if ($boolSincGpAv){
  272.             $data $this->sincGpHtAvService->sincGlobalGpHtAv($id);
  273.         }
  274.         // Sincronización con Av Express
  275.         if ($boolSincGpAv) {
  276.             $AveFile $em->getRepository(AveFiles::class)->findByReservation($reserva);
  277.             if (($reserva->getStatus() == 'Confirmed') or ($reserva->getStatus() == 'Cotizado') or ($reserva->getStatus() == 'Invoiced') or ($reserva->getStatus() == 'Bloqueo')) {
  278.                 if (empty($AveFile)) {
  279.                     // Si no se ha creado aun el expediente de Av Express debemos crearlo
  280.                     return $this->redirectToRoute('sinc_gp_ave', array('id' => $id,));
  281.                 }
  282.             }
  283.         }
  284.         // FIN: Actualizacion de fecha de inicio y fin del evento, a partir de la info de la sala
  285.         // Se debe redirigir para agregar el Servicio de limpieza
  286.         return $this->redirectToRoute('reservations_white_addservices_cleaning',
  287.             array(
  288.                 'resid' => $id,
  289.                 'loungesimpleid' => $lounge->getId(),
  290.             ));
  291.     }
  292.     /**
  293.      * @Route("/api/get-price", name="get_reservations_price_to_view", methods={"GET"})
  294.      */
  295.     public function getPrice(Request $request)
  296.     {
  297.         $loungeId $request->query->get('sala');
  298.         $dateStart $request->query->get('date');
  299.         if (!$loungeId || !$dateStart) {
  300.             return new JsonResponse(['error' => 'Missing parameters'], 400);
  301.         }
  302.         try {
  303.             $dateStartObj = new \DateTime($dateStart);
  304.         } catch (\Exception $e) {
  305.             return new JsonResponse(['error' => 'Invalid date'], 400);
  306.         }
  307.         $price $this->precioTarifario($dateStartObj$loungeId0);
  308.         return new JsonResponse(['price' => $price]);
  309.     }
  310.     /**
  311.      * @Route("/createsimpleloungemondes/{id}", name="reservations_greenpatio_create_simple_lounge_mondes")
  312.      * Se crea un dia de montaje o desmontaje
  313.      */
  314.     public function createSimpleLoungeMonDesAction($idEntityManagerInterface $emRequest $request)
  315.     {
  316.         $simpleLounge $request->request->get('reservation_sala_mondes');
  317.         $loungeId $simpleLounge['idLounge'];
  318.         $loungeDetails $em->getRepository(ReservationLoungeDetails::class)->findOneById($loungeId);
  319.         $previusLoungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idLounge' => $loungeId'idReservation' => $id'rankQuote' => $simpleLounge['idQuote']));
  320.         $loungeName $loungeDetails->getName();
  321.         $hourMinStart $simpleLounge['hourStart'];
  322.         $hourMinEnd $simpleLounge['hourEnd'];
  323.         $ivaNew = empty($simpleLounge['iva']) ? 21 $simpleLounge['iva'];
  324.         if (empty($previusLoungeSimple)) {
  325.             $loungeSummaryDescription $loungeDetails->getImportantDescription();
  326.             $loungeImportantDescGeneralText $loungeDetails->getImportantDescGeneralText();
  327.             $loungeImportantDescSchedules $loungeDetails->getImportantDescSchedules();
  328.             $loungeImportantDescParking $loungeDetails->getImportantDescParking();
  329.         } else {
  330.             $loungeSummaryDescription $previusLoungeSimple->getImportantDescription();
  331.             $loungeImportantDescGeneralText $previusLoungeSimple->getImportantDescGeneralText();
  332.             $loungeImportantDescSchedules $previusLoungeSimple->getImportantDescSchedules();
  333.             $loungeImportantDescParking $previusLoungeSimple->getImportantDescParking();
  334.         }
  335.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  336.         $reservationAll $qb->where('r.idReservation = :idReservation')
  337.             ->setParameter('idReservation'$id)
  338.             ->orderBy('r.rankQuote''ASC')
  339.             ->getQuery()
  340.             ->getResult();
  341.         $newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
  342.         if (!empty($simpleLounge['idQuote'])){ if (is_numeric($simpleLounge['idQuote'])){ $newRankId $simpleLounge['idQuote']; } }
  343.         // Autocompletacion HH:mm en Start
  344.         switch (strlen($hourMinStart)) {
  345.             case 0:
  346.                 // Vacio
  347.                 $hourStart '00'$minStart '00'$hourMinStart '00:00';
  348.                 break;
  349.             case 1:
  350.                 // H  -> 0H:00
  351.                 if (is_numeric($hourMinStart)){
  352.                     $hourStart '0'.$hourMinStart$minStart '00'$hourMinStart $hourStart.':'.$minStart;
  353.                 } else {
  354.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  355.                 }
  356.                 break;
  357.             case 2:
  358.                 // HH  -> HH:00
  359.                 if (is_numeric($hourMinStart)){
  360.                     $hourStart $hourMinStart$minStart '00'$hourMinStart $hourStart.':'.$minStart;
  361.                 } else {
  362.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  363.                 }
  364.                 break;
  365.             case 3:
  366.                 // Hmm  -> 0H:mm
  367.                 if (is_numeric($hourMinStart)){
  368.                     $hourStart '0'.substr($hourMinStart,0,1); $minStart substr($hourMinStart,1,2); $hourMinStart $hourStart.':'.$minStart;
  369.                 } else {
  370.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  371.                 }
  372.                 break;
  373.             case 4:
  374.                 // HHmm  -> HH:mm
  375.                 if (is_numeric($hourMinStart)){
  376.                     $hourStart substr($hourMinStart,0,2); $minStart substr($hourMinStart,2,2); $hourMinStart $hourStart.':'.$minStart;
  377.                 } else {
  378.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  379.                 }
  380.                 break;
  381.             case 5:
  382.                 // HH:mm
  383.                 if (is_numeric(substr($hourMinStart,0,2)) and (substr($hourMinStart,2,1)==':') and is_numeric(substr($hourMinStart,0,2))){
  384.                     $hourStart substr($hourMinStart,0,2); $minStart substr($hourMinStart,3,2); $hourMinStart $hourStart.':'.$minStart;
  385.                 } else {
  386.                     $hourStart '00'$minStart '00'$hourMinStart '00:00';
  387.                 }
  388.                 break;
  389.             default:
  390.                 // XXXXyyy
  391.                 $hourStart '00'$minStart '00'$hourMinStart '00:00';
  392.                 break;
  393.         }
  394.         // Autocompletacion HH:mm en End
  395.         switch (strlen($hourMinEnd)) {
  396.             case 0:
  397.                 // Vacio
  398.                 $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  399.                 break;
  400.             case 1:
  401.                 // H  -> 0H:00
  402.                 if (is_numeric($hourMinEnd)){
  403.                     $hourEnd '0'.$hourMinEnd$minEnd '00'$hourMinEnd $hourEnd.':'.$minEnd;
  404.                 } else {
  405.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  406.                 }
  407.                 break;
  408.             case 2:
  409.                 // HH  -> HH:00
  410.                 if (is_numeric($hourMinEnd)){
  411.                     $hourEnd $hourMinEnd$minEnd '00'$hourMinEnd $hourEnd.':'.$minEnd;
  412.                 } else {
  413.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  414.                 }
  415.                 break;
  416.             case 3:
  417.                 // Hmm  -> 0H:mm
  418.                 if (is_numeric($hourMinEnd)){
  419.                     $hourEnd '0'.substr($hourMinEnd,0,1); $minEnd substr($hourMinEnd,1,2); $hourMinEnd $hourEnd.':'.$minEnd;
  420.                 } else {
  421.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  422.                 }
  423.                 break;
  424.             case 4:
  425.                 // HHmm  -> HH:mm
  426.                 if (is_numeric($hourMinEnd)){
  427.                     $hourEnd substr($hourMinEnd,0,2); $minEnd substr($hourMinEnd,2,2); $hourMinEnd $hourEnd.':'.$minEnd;
  428.                 } else {
  429.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  430.                 }
  431.                 break;
  432.             case 5:
  433.                 // HH:mm
  434.                 if (is_numeric(substr($hourMinEnd,0,2)) and (substr($hourMinEnd,2,1)==':') and is_numeric(substr($hourMinEnd,0,2))){
  435.                     $hourEnd substr($hourMinEnd,0,2); $minEnd substr($hourMinEnd,3,2); $hourMinEnd $hourEnd.':'.$minEnd;
  436.                 } else {
  437.                     $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  438.                 }
  439.                 break;
  440.             default:
  441.                 // XXXXyyy
  442.                 $hourEnd '00'$minEnd '00'$hourMinEnd '00:00';
  443.                 break;
  444.         }
  445.         $dateStart = new DateTime($simpleLounge['dateStart'] . ' '$hourMinStart);
  446.         $dateEnd = new DateTime($simpleLounge['dateStart'] . ' '$hourMinEnd);   // Se usa DateStart por que solo hay un dia en el formulario
  447.         $servicePrice = empty($simpleLounge['servicePrice']) ? :$simpleLounge['servicePrice'];
  448.         $idReservation $id;
  449.         /* Obtengo usuario logueado */
  450.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  451.         $user_id $user_logueado->getId();
  452.         $createdAt = new DateTime('now');
  453.         $createdBy $user_id;
  454.         $updatedAt = new DateTime('now');
  455.         $updatedBy $user_id;
  456.         $lounge = new ReservationLoungeSimple();
  457.         if ($simpleLounge['type'] == 'Montaje'){ $lounge->setType ('Montaje'); } else {  $lounge->setType ('Desmontaje'); }
  458.         $pax null;
  459.         $lounge->setIdLounge ($loungeId);
  460.         $lounge->setHourStart ($hourStart);
  461.         $lounge->setMinStart ($minStart);
  462.         $lounge->setHourEnd ($hourEnd);
  463.         $lounge->setMinEnd ($minEnd);
  464.         $lounge->setLoungeName ($loungeName);
  465.         $lounge->setDateStart ($dateStart);
  466.         $lounge->setDateEnd ($dateEnd);
  467.         $lounge->setRankQuote(1);
  468.         $lounge->setIva($ivaNew);
  469.         $lounge->setOpIva(1);
  470.         $lounge->setIdReservation ($idReservation);
  471.         $lounge->setCreatedAt ($createdAt);
  472.         $lounge->setCreatedBy ($createdBy);
  473.         $lounge->setUpdatedAt ($updatedAt);
  474.         $lounge->setUpdatedBy ($updatedBy);
  475.         $lounge->setPax ($pax);
  476.         $lounge->setRankQuote($newRankId);
  477.         $lounge->setImportantDescription($loungeSummaryDescription);
  478.         $lounge->setImportantDescGeneralText($loungeImportantDescGeneralText);
  479.         $lounge->setImportantDescSchedules($loungeImportantDescSchedules);
  480.         $lounge->setImportantDescParking($loungeImportantDescParking);
  481.         $price $this->precioPorFecha($dateStart$loungeId);
  482.         $servicePrice = ($price['price'] == 0) ? $servicePrice $price;
  483.         $lounge->setServicePrice($servicePrice);
  484.         try{
  485.             $em->persist($lounge);
  486.             $em->flush();
  487.             $event 'The Reservation has been updated.';
  488.             $successMessage $this->translator->trans($event);
  489.             $this->addFlash('mensajereservation'$successMessage);
  490.         } catch (\Exception $e){
  491.             $event 'An error occurred: '.$e->getMessage();
  492.             $errorMessage $this->translator->trans($event);
  493.             $this->addFlash('mensajereservationerror'$errorMessage);
  494.         }
  495.         $reservax $em->getRepository(Reservation::class)->findOneById($idReservation);
  496.         // INICIO: Verificamos si es necesario actualizar las fechas de la reserva
  497.         $boolReserva false;
  498.         if ($lounge->getDateStart() < $reservax->getDateStart()){
  499.             $reservax->setDateStart($lounge->getDateStart());
  500.             $boolReserva true;
  501.         }
  502.         if ($reservax->getDateEnd() < $lounge->getDateEnd()){
  503.             $reservax->setDateEnd($lounge->getDateEnd());
  504.             $boolReserva true;
  505.         }
  506.         if ($boolReserva){
  507.             $em->persist($reservax);
  508.             $em->flush();
  509.             // Sincronización global de todos los campos
  510.             $data $this->sincGpHtAvService->sincGlobalGpHtAv($id);
  511.         }
  512.         $boolSincGpAv $boolReserva;
  513.         // Sincronización con Av Express
  514.         if ($boolSincGpAv) {
  515.             $AveFile $em->getRepository(AveFiles::class)->findByReservation($reservax);
  516.             if (($reservax->getStatus() == 'Confirmed') or ($reservax->getStatus() == 'Cotizado') or ($reservax->getStatus() == 'Invoiced') or ($reservax->getStatus() == 'Bloqueo')) {
  517.                 if (empty($AveFile)) {
  518.                     // Si no se ha creado aun el expediente de Av Express debemos crearlo
  519.                     return $this->redirectToRoute('sinc_gp_ave', array('id' => $id,));
  520.                 }
  521.             }
  522.         }
  523.         // FIN: Verificamos si es necesario actualizar las fechas de la reserva
  524.         return $this->redirectToRoute('reservations_greenpatio_edit_simple',
  525.             array(
  526.                 'id' => $id,
  527.                 'token' => null,
  528.                 '_fragment' => 'btn_quotes'
  529.             ));
  530.     }
  531.     /**
  532.      * @Route("/duplicateday/{id}/{dayduplicate}/{idRankQuote}", name="reservations_greenpatio_duplicate_day")
  533.      * Duplica un elemento de la cotizacion para el dia siguiente
  534.      */
  535.     public function duplicateDayAction($id$dayduplicate$idRankQuoteEntityManagerInterface $emRequest $request)
  536.     {
  537.         $loungeSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($id);
  538.         $reservax $em->getRepository(Reservation::class)->findOneById($id);
  539.         /* Obtengo usuario logueado */
  540.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  541.         $user_id $user_logueado->getId();
  542.         $createdAt = new DateTime('now');
  543.         $createdBy $user_id;
  544.         $updatedAt = new DateTime('now');
  545.         $updatedBy $user_id;
  546.         if (!empty($loungeSimples)){
  547.             foreach ($loungeSimples as $item){
  548.                 if (($item->getDateStart()->format('d-m-Y') == $dayduplicate) and ($item->getRankQuote() == $idRankQuote)){
  549.                     // Se duplica y suma un dia
  550.                     $newLoungeSimple = new ReservationLoungeSimple();
  551.                     $newLoungeSimple->setDateStart($item->getDateStart()->modify('+1 day'));
  552.                     $newLoungeSimple->setDateEnd($item->getDateEnd()->modify('+1 day'));
  553.                     $newLoungeSimple->setHourStart($item->getHourStart());
  554.                     $newLoungeSimple->setHourEnd($item->getHourEnd());
  555.                     $newLoungeSimple->setMinStart($item->getMinStart());
  556.                     $newLoungeSimple->setMinEnd($item->getMinEnd());
  557.                     $newLoungeSimple->setIdLounge($item->getIdLounge());
  558.                     $newLoungeSimple->setIdReservation($item->getIdReservation());
  559.                     $newLoungeSimple->setLoungeName($item->getLoungeName());
  560.                     $newLoungeSimple->setPax($item->getPax());
  561.                     $newLoungeSimple->setServicePrice($item->getServicePrice());
  562.                     $newLoungeSimple->setIva($item->getIva());
  563.                     $newLoungeSimple->setOpIva($item->getOpIva());
  564.                     $newLoungeSimple->setType($item->getType());
  565.                     $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
  566.                     $newLoungeSimple->setImportantDescription($item->getImportantDescription());
  567.                     $newLoungeSimple->setImportantDescGeneralText($item->getImportantDescGeneralText());
  568.                     $newLoungeSimple->setImportantDescSchedules($item->getImportantDescSchedules());
  569.                     $newLoungeSimple->setImportantDescParking($item->getImportantDescParking());
  570.                     $newLoungeSimple->setRankQuote($idRankQuote);
  571.                     $newLoungeSimple->setCreatedAt($createdAt);
  572.                     $newLoungeSimple->setCreatedBy($createdBy);
  573.                     $newLoungeSimple->setUpdatedAt($updatedAt);
  574.                     $newLoungeSimple->setUpdatedBy($updatedBy);
  575.                     try{
  576.                         $em->persist($newLoungeSimple);
  577.                         $em->flush();
  578.                         $event 'The Item has been duplicated.';
  579.                         $successMessage $this->translator->trans($event);
  580.                         $this->addFlash('mensajereservation'$successMessage);
  581.                     } catch (\Exception $e){
  582.                         $event 'An error occurred: '.$e->getMessage();
  583.                         $errorMessage $this->translator->trans($event);
  584.                         $this->addFlash('mensajereservationerror'$errorMessage);
  585.                     }
  586.                     // INICIO: Verificamos si es necesario actualizar las fechas de la reserva
  587.                     $boolReserva false;
  588.                     if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()){
  589.                         $reservax->setDateStart($newLoungeSimple->getDateStart());
  590.                         $boolReserva true;
  591.                     }
  592.                     if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()){
  593.                         $reservax->setDateEnd($newLoungeSimple->getDateEnd());
  594.                         $boolReserva true;
  595.                     }
  596.                     if ($boolReserva){
  597.                         $em->persist($reservax);
  598.                         $em->flush();
  599.                         // Sincronización global de todos los campos
  600.                         $data $this->sincGpHtAvService->sincGlobalGpHtAv($id);
  601.                     }
  602.                     // FIN: Verificamos si es necesario actualizar las fechas de la reserva
  603.                 }
  604.             }
  605.         } else {
  606.             // registro antiguo, se pasara a los nuevos registros y luego duplicara
  607.             $loungeOld $em->getRepository(ReservationLounge::class)->findByIdReservation($id);
  608.             foreach ($loungeOld as $item){
  609.                 if ($item->getDateStart()->format('Y-m-d') == $item->getDateEnd()->format('Y-m-d')){
  610.                     // Es el mismo dia, se crea un registro simple
  611.                     $newLoungeSimple = new ReservationLoungeSimple();
  612.                     $newLoungeSimple->setDateStart($item->getDateStart());
  613.                     $newLoungeSimple->setDateEnd($item->getDateEnd());
  614.                     $newLoungeSimple->setHourStart($item->getHourStart());
  615.                     $newLoungeSimple->setHourEnd($item->getHourEnd());
  616.                     $newLoungeSimple->setMinStart($item->getMinStart());
  617.                     $newLoungeSimple->setMinEnd($item->getMinEnd());
  618.                     $newLoungeSimple->setIdLounge($item->getIdLounge());
  619.                     $newLoungeSimple->setIdReservation($item->getIdReservation());
  620.                     $newLoungeSimple->setLoungeName($item->getLoungeName());
  621.                     $newLoungeSimple->setPax($item->getPax());
  622.                     $newLoungeSimple->setServicePrice($item->getServicePrice());
  623.                     $newLoungeSimple->setIva($item->getIva());
  624.                     $newLoungeSimple->setOpIva($item->getOpIva());
  625.                     $newLoungeSimple->setType($item->getType());
  626.                     $newLoungeSimple->setRankQuote($item->getRankQuote());
  627.                     $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
  628.                     $newLoungeSimple->setImportantDescription($item->getImportantDescription());
  629.                     $newLoungeSimple->setCreatedAt($createdAt);
  630.                     $newLoungeSimple->setCreatedBy($createdBy);
  631.                     $newLoungeSimple->setUpdatedAt($updatedAt);
  632.                     $newLoungeSimple->setUpdatedBy($updatedBy);
  633.                     try{
  634.                         $em->persist($newLoungeSimple);
  635.                         $em->flush();
  636.                         $event 'The Item has been duplicated.';
  637.                         $successMessage $this->translator->trans($event);
  638.                         $this->addFlash('mensajereservation'$successMessage);
  639.                     } catch (\Exception $e){
  640.                         $event 'An error occurred: '.$e->getMessage();
  641.                         $errorMessage $this->translator->trans($event);
  642.                         $this->addFlash('mensajereservationerror'$errorMessage);
  643.                     }
  644.                     // INICIO: Verificamos si es necesario actualizar las fechas de la reserva
  645.                     $boolReserva false;
  646.                     if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()){
  647.                         $reservax->setDateStart($newLoungeSimple->getDateStart());
  648.                         $boolReserva true;
  649.                     }
  650.                     if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()){
  651.                         $reservax->setDateEnd($newLoungeSimple->getDateEnd());
  652.                         $boolReserva true;
  653.                     }
  654.                     if ($boolReserva){
  655.                         $em->persist($reservax);
  656.                         $em->flush();
  657.                     }
  658.                     // FIN: Verificamos si es necesario actualizar las fechas de la reserva
  659.                 } else {
  660.                     // Registro con varios dias, se calcula el numero de dias y se crean ese numero de registros nuevos
  661.                     $firstDay $item->getDateStart();
  662.                     $firstDay = new DateTime($firstDay->format('Y-m-d'));
  663.                     $lastDay $item->getDateEnd();
  664.                     $lastDay = new DateTime($lastDay->format('Y-m-d'));
  665.                     $numDays = ((($lastDay)->diff($firstDay))->days) +1;
  666.                     $actualDay $item->getDateStart();
  667.                     $actualStartDay $item->getDateStart();
  668.                     $actualEndDay $item->getDateEnd();
  669.                     for ($i=0$i<sizeof($numDays); $i++){
  670.                         // Se crea un registro por cada dia
  671.                         $newLoungeSimple = new ReservationLoungeSimple();
  672.                         if ($i == 0){
  673.                             // Primer dia
  674.                             $newLoungeSimple->setDateStart($actualStartDay);
  675.                             $actualStartDayEnd = new DateTime($actualStartDay->format('Y-m-d').' 23:59');
  676.                             $newLoungeSimple->setDateEnd($actualStartDayEnd);
  677.                             $newLoungeSimple->setHourStart($item->getHourStart());
  678.                             $newLoungeSimple->setHourEnd('23');
  679.                             $newLoungeSimple->setMinStart($item->getMinStart());
  680.                             $newLoungeSimple->setMinEnd('59');
  681.                         } else {
  682.                             if (($i 1) == sizeof($numDays)){
  683.                                 // Ultimo dia
  684.                                 $actualEndDayStart = new DateTime($actualEndDay->format('Y-m-d').' 00:00');
  685.                                 $newLoungeSimple->setDateStart($actualEndDayStart);
  686.                                 $newLoungeSimple->setDateEnd($actualEndDay);
  687.                                 $newLoungeSimple->setHourStart('00');
  688.                                 $newLoungeSimple->setHourEnd($item->getHourEnd());
  689.                                 $newLoungeSimple->setMinStart('00');
  690.                                 $newLoungeSimple->setMinEnd($item->getMinEnd());
  691.                             } else {
  692.                                 // Dia intermedio
  693.                                 $actualMidDayStart = new DateTime($actualDay->format('Y-m-d').' 00:00');
  694.                                 $actualMidDayEnd = new DateTime($actualDay->format('Y-m-d').' 23:59');
  695.                                 $newLoungeSimple->setDateStart($actualMidDayStart);
  696.                                 $newLoungeSimple->setDateEnd($actualMidDayEnd);
  697.                                 $newLoungeSimple->setHourStart('00');
  698.                                 $newLoungeSimple->setHourEnd('23');
  699.                                 $newLoungeSimple->setMinStart('00');
  700.                                 $newLoungeSimple->setMinEnd('59');
  701.                             }
  702.                         }
  703.                         $newLoungeSimple->setIdLounge($item->getIdLounge());
  704.                         $newLoungeSimple->setIdReservation($item->getIdReservation());
  705.                         $newLoungeSimple->setLoungeName($item->getLoungeName());
  706.                         $newLoungeSimple->setPax($item->getPax());
  707.                         $newLoungeSimple->setServicePrice($item->getServicePrice());
  708.                         $newLoungeSimple->setIva($item->getIva());
  709.                         $newLoungeSimple->setOpIva($item->getOpIva());
  710.                         $newLoungeSimple->setType($item->getType());
  711.                         $newLoungeSimple->setRankQuote($item->getRankQuote());
  712.                         $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
  713.                         $newLoungeSimple->setImportantDescription($item->getImportantDescription());
  714.                         $newLoungeSimple->setCreatedAt($createdAt);
  715.                         $newLoungeSimple->setCreatedBy($createdBy);
  716.                         $newLoungeSimple->setUpdatedAt($updatedAt);
  717.                         $newLoungeSimple->setUpdatedBy($updatedBy);
  718.                         $actualDay $actualDay->modify('+1 day');
  719.                         try{
  720.                             $em->persist($newLoungeSimple);
  721.                             $em->flush();
  722.                             $event 'The Item has been updated.';
  723.                             $successMessage $this->translator->trans($event);
  724.                             $this->addFlash('mensajereservation'$successMessage);
  725.                         } catch (\Exception $e){
  726.                             $event 'An error occurred: '.$e->getMessage();
  727.                             $errorMessage $this->translator->trans($event);
  728.                             $this->addFlash('mensajereservationerror'$errorMessage);
  729.                         }
  730.                         // INICIO: Verificamos si es necesario actualizar las fechas de la reserva
  731.                         $boolReserva false;
  732.                         if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()){
  733.                             $reservax->setDateStart($newLoungeSimple->getDateStart());
  734.                             $boolReserva true;
  735.                         }
  736.                         if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()){
  737.                             $reservax->setDateEnd($newLoungeSimple->getDateEnd());
  738.                             $boolReserva true;
  739.                         }
  740.                         if ($boolReserva){
  741.                             $em->persist($reservax);
  742.                             $em->flush();
  743.                         }
  744.                         // FIN: Verificamos si es necesario actualizar las fechas de la reserva
  745.                     }
  746.                 }
  747.             }
  748.             // Se vuelve a llamar a este mismo controlador ahora con los registros en la nueva tabla
  749.             return $this->redirectToRoute('reservations_greenpatio_duplicate_day', array( 'id' => $id'dayduplicate' => $dayduplicate, ));
  750.         }
  751.         // Se debe redirigir para agregar el Servicio de limpieza
  752.         return $this->redirectToRoute('reservations_white_addservices_cleaning',
  753.             array(
  754.                 'resid' => $id,
  755.                 'loungesimpleid' => $newLoungeSimple->getId(),
  756.             ));
  757.     }
  758.     /**
  759.      * @Route("/deleteitemsimple/{id}/{daydelete}", name="reservations_greenpatio_delete_simple_lounge")
  760.      * Elimina un Reservation Simple Lounge de la cotizacion
  761.      */
  762.     public function deleteSimpleLoungeAction($id$daydeleteEntityManagerInterface $emRequest $request)
  763.     {
  764.         $loungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneById($id);
  765.         $id $loungeSimple->getIdReservation();
  766.         $reserva $em->getRepository(Reservation::class)->findOneById($loungeSimple->getIdReservation());
  767.         try{
  768.             $em->remove($loungeSimple);
  769.             $em->flush();
  770.             $event 'The item has been deleted.';
  771.             $successMessage $this->translator->trans($event);
  772.             $this->addFlash('mensajereservation'$successMessage);
  773.         } catch (\Exception $e){
  774.             $event 'An error occurred: '.$e->getMessage();
  775.             $errorMessage $this->translator->trans($event);
  776.             $this->addFlash('mensajereservationerror'$errorMessage);
  777.         }
  778.         // Si se elimina el primer dia o el ultimo, se debe modificar las fechas de la reserva
  779.         if(($reserva->getDateStart()->format('Ymd') == $loungeSimple->getDateStart()->format('Ymd')) or ($reserva->getDateEnd()->format('Ymd') == $loungeSimple->getDateEnd()->format('Ymd'))){
  780.             $allLoungeSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($reserva->getId());
  781.             if (!empty($allLoungeSimples)){
  782.                 $reserva->setDateStart(new DateTime('2078-01-01'));
  783.                 $reserva->setDateEnd(new DateTime('2000-01-01'));
  784.                 foreach ($allLoungeSimples as $newLoungeSimple){
  785.                     // INICIO: Verificamos si es necesario actualizar las fechas de la reserva
  786.                     $boolReserva false;
  787.                     if ($newLoungeSimple->getDateStart() < $reserva->getDateStart()){
  788.                         $reserva->setDateStart($newLoungeSimple->getDateStart());
  789.                         $boolReserva true;
  790.                     }
  791.                     if ($reserva->getDateEnd() < $newLoungeSimple->getDateEnd()){
  792.                         $reserva->setDateEnd($newLoungeSimple->getDateEnd());
  793.                         $boolReserva true;
  794.                     }
  795.                     if ($boolReserva){
  796.                         $em->persist($reserva);
  797.                         $em->flush();
  798.                     }
  799.                     // FIN: Verificamos si es necesario actualizar las fechas de la reserva
  800.                 }
  801.             } else {
  802.                 // Se elimino la ultima sala y la reserva queda vacia
  803.                 $reserva->setDateStart(new DateTime('2078-01-01'));
  804.                 $reserva->setDateEnd(new DateTime('2000-01-01'));
  805.                 $em->persist($reserva);
  806.                 $em->flush();
  807.             }
  808.             // Sincronización global de todos los campos
  809.             $data $this->sincGpHtAvService->sincGlobalGpHtAv($reserva->getId());
  810.         }
  811.         // Se elimina el servicio de horas de limpieza de la sala
  812.         return $this->redirectToRoute('reservations_greenpatio_delete_simple_lounge_cleaning',
  813.             array(
  814.                 'idRes' => $id,
  815.                 'idLng' => $loungeSimple->getIdLounge(),
  816.                 'dateInAt' => $loungeSimple->getDateStart()->format('Y-m-d\TH:i'),
  817.                 'dateOutAt' => $loungeSimple->getDateEnd()->format('Y-m-d\TH:i'),
  818.             ));
  819.     }
  820.     /**
  821.      * @Route("/deletequote/{idRes}/{idQuote}", name="reservations_delete_quote")
  822.      * Eliminar una cotizancion
  823.      */
  824.     public function deleteQuoteAction$idRes$idQuoteEntityManagerInterface $emRequest $request)
  825.     {
  826.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  827.         $reservation $qb->where('r.rankQuote = :rankQuote')
  828.             ->andWhere('r.idReservation = :idReservation')
  829.             ->setParameter('idReservation'$idRes)
  830.             ->setParameter('rankQuote'$idQuote)
  831.             ->getQuery()
  832.             ->getResult();
  833.         foreach ($reservation as $item){
  834.             try{
  835.                 $em->remove($item);
  836.                 $em->flush();
  837.                 $event 'Se ha eliminado la cotización';
  838.                 $successMessage $this->translator->trans($event);
  839.                 $this->addFlash('mensajereservation'$successMessage);
  840.             } catch (\Exception $e){
  841.                 $event 'An error occurred: '.$e->getMessage();
  842.                 $errorMessage $this->translator->trans($event);
  843.                 $this->addFlash('mensajereservationerror'$errorMessage);
  844.             }
  845.             //Se deben eliminar todas las horas de limpieza asociadas a las salas de la cotización
  846.             $loungeDetails $em->getRepository(ReservationLoungeDetails::class)->findOneById($item->getIdLounge());
  847.             $stringName 'HORAS ( '.$loungeDetails->getName().' )';
  848.             $serviceCatIdClean 21;
  849.             $dateInAt = new \DateTime($item->getDateStart()->format('Y-m-d\TH:i'));
  850.             $dateOutAt = new \DateTime($item->getDateEnd()->format('Y-m-d\TH:i'));
  851.             $qb $em->getRepository(ReservationService::class)->createQueryBuilder('rs');
  852.             $serviceClean $qb->where('rs.reservationId = :id')
  853.                 ->andWhere('rs.name = :name')
  854.                 ->andWhere('rs.dateInAt = :dateInAt')
  855.                 ->andWhere('rs.dateOutAt = :dateOutAt')
  856.                 ->andWhere('rs.serviceCatId = :serviceCatId')
  857.                 ->setParameter('id'$idRes)
  858.                 ->setParameter('name'$stringName)
  859.                 ->setParameter('dateInAt'$dateInAt)
  860.                 ->setParameter('dateOutAt'$dateOutAt)
  861.                 ->setParameter('serviceCatId'$serviceCatIdClean)
  862.                 ->getQuery()
  863.                 ->getResult();
  864.             if (!empty($serviceClean)) {
  865.                 // Se elimina el servicio de horas de limpieza de la sala
  866.                 $em->remove($serviceClean[0]);
  867.                 $em->flush();
  868.             }
  869.         }
  870.         // Recalculo de fechas del expediente
  871.         $data $this->recalculoFechas($idRes);
  872.         // Sincronización global de todos los campos
  873.         $data $this->sincGpHtAvService->sincGlobalGpHtAv($idRes);
  874.         return $this->redirectToRoute('reservations_greenpatio_edit_simple',
  875.             array(
  876.                 'id' => $idRes,
  877.                 'token' => null,
  878.                 '_fragment' => 'btn_quotes'
  879.             ));
  880.     }
  881.     /**
  882.      * @Route("/checkquote/{idRes}/{idQuote}", name="reservations_check_quote")
  883.      * Confirmación de que se ha aceptado la cotizancion, se eliminaran las otras cotizaciones del expediente
  884.      */
  885.     public function checkQuoteAction$idRes$idQuoteEntityManagerInterface $emRequest $request)
  886.     {
  887.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  888.         $reservation $qb->where('r.rankQuote <> :rankQuote')
  889.             ->andWhere('r.idReservation = :idReservation')
  890.             ->setParameter('idReservation'$idRes)
  891.             ->setParameter('rankQuote'$idQuote)
  892.             ->getQuery()
  893.             ->getResult();
  894.         foreach ($reservation as $item){
  895.             try{
  896.                 $em->remove($item);
  897.                 $em->flush();
  898.                 $event 'Se han eliminado las otras cotizaciones';
  899.                 $successMessage $this->translator->trans($event);
  900.                 $this->addFlash('mensajereservation'$successMessage);
  901.             } catch (\Exception $e){
  902.                 $event 'An error occurred: '.$e->getMessage();
  903.                 $errorMessage $this->translator->trans($event);
  904.                 $this->addFlash('mensajereservationerror'$errorMessage);
  905.             }
  906.         }
  907.         return $this->redirectToRoute('reservations_greenpatio_edit_simple',
  908.             array(
  909.                 'id' => $idRes,
  910.                 'token' => null,
  911.                 '_fragment' => 'btn_quotes'
  912.             ));
  913.     }
  914.     /**
  915.      * @Route("/duplicatequote", name="reservations_duplicate_quote")
  916.      * Duplicar una cotizacion
  917.      */
  918.     public function duplicateQuoteActionEntityManagerInterface $emRequest $request) {
  919.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  920.         $user_id $user_logueado->getId();
  921.         $hoy = new \DateTime("now"NULL);
  922.         $reqDuplicateQuote $request->request->get('addquote');
  923.         $newLounge $em->getRepository(ReservationLoungeDetails::class)->findOneById($reqDuplicateQuote['salaPrecargadas']);
  924.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  925.         $reservationAll $qb->where('r.idReservation = :idReservation')
  926.             ->setParameter('idReservation'$reqDuplicateQuote['reservationId'])
  927.             ->orderBy('r.rankQuote''ASC')
  928.             ->getQuery()
  929.             ->getResult();
  930.         $newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
  931.         if (empty($reqDuplicateQuote['idQuote'])) { $reqDuplicateQuote['idQuote'] = reset($reservationAll)->getRankQuote(); }   //Si no elige cotización se duplica la primera
  932.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  933.         $reservation $qb->where('r.rankQuote = :rankQuote')
  934.             ->andWhere('r.idReservation = :idReservation')
  935.             ->setParameter('idReservation'$reqDuplicateQuote['reservationId'])
  936.             ->setParameter('rankQuote'$reqDuplicateQuote['idQuote'])
  937.             ->getQuery()
  938.             ->getResult();
  939.         $loungeWebDetail $em->getRepository(ReservationLoungeWebDescription::class)->findOneBy(array('lounge' => $newLounge->getId(), 'language' => 1));
  940.         $loungeWebDetail = empty($loungeWebDetail) ? $newLounge $loungeWebDetail;
  941.         foreach ($reservation as $item){
  942.             $newLoungeSimple = new ReservationLoungeSimple();
  943.             $newLoungeSimple->setDateStart($item->getDateStart());
  944.             $newLoungeSimple->setDateEnd($item->getDateEnd());
  945.             $newLoungeSimple->setIdReservation($reqDuplicateQuote['reservationId']);
  946.             $newLoungeSimple->setPax($item->getPax());
  947.             $newLoungeSimple->setType($item->getType());
  948.             $newLoungeSimple->setCreatedAt($hoy);
  949.             $newLoungeSimple->setCreatedBy($user_id);
  950.             $newLoungeSimple->setUpdatedAt($hoy);
  951.             $newLoungeSimple->setUpdatedBy($user_id);
  952.             $newLoungeSimple->setHourStart($item->getHourStart());
  953.             $newLoungeSimple->setMinStart($item->getMinStart());
  954.             $newLoungeSimple->setHourEnd($item->getHourEnd());
  955.             $newLoungeSimple->setMinEnd($item->getMinEnd());
  956.             $newLoungeSimple->setRankQuote($newRankId);
  957.             $newLoungeSimple->setIva($item->getIva());
  958.             $newLoungeSimple->setOpIva($item->getOpIva());
  959.             $newLoungeSimple->setIdLounge($newLounge->getId());
  960.             $newLoungeSimple->setLoungename($newLounge->getName());
  961. //            $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
  962.             $newLoungeSimple->setImportantDescription($loungeWebDetail->getImportantDescription());
  963.             $newLoungeSimple->setImportantDescGeneralText($loungeWebDetail->getImportantDescGeneralText());
  964.             $newLoungeSimple->setImportantDescSchedules($loungeWebDetail->getImportantDescSchedules());
  965.             $newLoungeSimple->setImportantDescParking($loungeWebDetail->getImportantDescParking());
  966.             if (!empty($reqDuplicateQuote['salaPrice'])){ $newLoungeSimple->setServicePrice($reqDuplicateQuote['salaPrice']); }  else { $newLoungeSimple->setServicePrice($item->getServicePrice());}
  967.             try{
  968.                 $em->persist($newLoungeSimple);
  969.                 $em->flush();
  970.                 $event 'Se ha agregado la nueva cotización';
  971.                 $successMessage $this->translator->trans($event);
  972.                 $this->addFlash('mensajereservation'$successMessage);
  973.             } catch (\Exception $e){
  974.                 $event 'An error occurred: '.$e->getMessage();
  975.                 $errorMessage $this->translator->trans($event);
  976.                 $this->addFlash('mensajereservationerror'$errorMessage);
  977.             }
  978.             // Rafa indica que se debe quitar esta asignación, mas adelante eliminaremos el codigo, despues de que prueben el sistema sin esta funcionalidad
  979.             if (false) {
  980.                 // Se debe agregar el servicio de limpieza por cada sala que se agregue
  981.                 $resLoungeSimple $newLoungeSimple;
  982.                 $service = new ReservationService();
  983.                 $service->setReservationId($reqDuplicateQuote['reservationId']);
  984.                 $service->setSupplierId(0);
  985.                 $service->setDateInAt($resLoungeSimple->getDateStart());
  986.                 $service->setDateOutAt($resLoungeSimple->getDateEnd());
  987.                 /* Obtengo usuario logueado */
  988.                 $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  989.                 $user_id $user_logueado->getId();
  990.                 $service->setCreatedId($user_id);
  991.                 $service->setUpdatedId($user_id);
  992.                 $service->setCreatedAt(new \DateTime("now"));
  993.                 $service->setUpdatedAt(new \DateTime("now"));
  994.                 $service->setServiceCatId('21');
  995.                 $service->setServiceCatName('Limpieza');
  996.                 $service->setContcolor('green-300');
  997.                 $service->setName('HORAS ( ' $resLoungeSimple->getLoungeName() . ' )');
  998.                 $service->setPrice('14');
  999.                 $service->setCurrency('Euro');
  1000.                 $service->setUnits('8');
  1001.                 $service->setCommission('0');
  1002.                 $service->setIva('0');
  1003.                 $service->setPax('0');
  1004.                 $service->setOver('0');
  1005.                 $service->setIva('21');
  1006.                 $service->setOpIva('1');
  1007.                 $service->setOpCommission('1');
  1008.                 $service->setCommission('57.14');
  1009.                 $service->setViewInfo(0);
  1010.                 $service->setToinvoice(0);
  1011.                 $service->setServiceId(0);
  1012.                 $em->persist($service);
  1013.                 $em->flush();
  1014.             }
  1015.         }
  1016.         return $this->redirectToRoute('reservations_greenpatio_edit_simple',
  1017.             array(
  1018.                 'id' => $reqDuplicateQuote['reservationId'],
  1019.                 'token' => null,
  1020.                 '_fragment' => 'btn_quotes'
  1021.             ));
  1022.     }
  1023.     private function precioPorFecha($date$loungeId){
  1024.         return array( 'price' => 0, );
  1025.         $em $this->getDoctrine()->getManager();
  1026.         $price0 null;
  1027.         // Buscamos por año
  1028.         $parameters = array( 'dateYear' => $date->format('Y'), 'loungeId' => $loungeId'priceIsActive' => true, );
  1029.         $dql 'SELECT i
  1030.                 FROM GreenPatioBundle:ReservationLoungeProfile i
  1031.                 WHERE  ((i.year1 <= :dateYear and i.year2 >= :dateYear) ) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive';
  1032.         $query $em->createQuery($dql)->setParameters($parameters);
  1033.         $price1 $query->getResult();
  1034.         // Buscamos por año y mes
  1035.         $parameters = array( 'dateYear' => $date->format('Y'), 'month' => true'loungeId' => $loungeId'priceIsActive' => true, );
  1036.         switch ($date->format('m')) {
  1037.             case '01'//Enero
  1038.                 $dql 'SELECT i
  1039.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1040.                     WHERE (
  1041.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1042.                           AND (i.month1 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1043.                       ';
  1044.                 break;
  1045.             case '02'//Febrero
  1046.                 $dql 'SELECT i
  1047.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1048.                     WHERE (
  1049.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1050.                           AND (i.month2 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1051.                       ';
  1052.                 break;
  1053.             case '03'//Marzo
  1054.                 $dql 'SELECT i
  1055.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1056.                     WHERE (
  1057.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1058.                           AND (i.month3 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1059.                       ';
  1060.                 break;
  1061.             case '04'//Abril
  1062.                 $dql 'SELECT i
  1063.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1064.                     WHERE (
  1065.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1066.                           AND (i.month4 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1067.                       ';
  1068.                 break;
  1069.             case '05'//Mayo
  1070.                 $dql 'SELECT i
  1071.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1072.                     WHERE (
  1073.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1074.                           AND (i.month5 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1075.                       ';
  1076.                 break;
  1077.             case '06'//Junio
  1078.                 $dql 'SELECT i
  1079.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1080.                     WHERE (
  1081.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1082.                           AND (i.month6 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1083.                       ';
  1084.                 break;
  1085.             case '07'//Julio
  1086.                 $dql 'SELECT i
  1087.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1088.                     WHERE (
  1089.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1090.                           AND (i.month7 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1091.                       ';
  1092.                 break;
  1093.             case '08'//Agosto
  1094.                 $dql 'SELECT i
  1095.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1096.                     WHERE (
  1097.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1098.                           AND (i.month8 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1099.                       ';
  1100.                 break;
  1101.             case '09'//Septiembre
  1102.                 $dql 'SELECT i
  1103.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1104.                     WHERE (
  1105.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1106.                           AND (i.month9 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1107.                       ';
  1108.                 break;
  1109.             case '10'//Octubre
  1110.                 $dql 'SELECT i
  1111.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1112.                     WHERE (
  1113.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1114.                           AND (i.month10 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1115.                       ';
  1116.                 break;
  1117.             case '11'//Noviembre
  1118.                 $dql 'SELECT i
  1119.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1120.                     WHERE (
  1121.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1122.                           AND (i.month11 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1123.                       ';
  1124.                 break;
  1125.             case '12'//Diciembre
  1126.                 $dql 'SELECT i
  1127.                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1128.                     WHERE (
  1129.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1130.                           AND (i.month12 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1131.                       ';
  1132.                 break;
  1133.             default:
  1134.                 break;
  1135.         }
  1136.         $query $em->createQuery($dql)->setParameters($parameters);
  1137.         $price2 $query->getResult();
  1138.         // Buscamos por año, mes y dia de la semana
  1139.         $parameters = array( 'dateYear' => $date->format('Y'), 'month' => true'day' => true'loungeId' => $loungeId'priceIsActive' => true, );
  1140.         switch ($date->format('m')) {
  1141.             case '01'//Enero
  1142.                 switch ($date->format('l')) {
  1143.                     case 'Monday'//Lunes
  1144.                         $dql 'SELECT i
  1145.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1146.                                     WHERE (
  1147.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1148.                                           AND (i.month1 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1149.                                       ';
  1150.                         break;
  1151.                     case 'Tuesday'//Martes
  1152.                         $dql 'SELECT i
  1153.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1154.                                     WHERE (
  1155.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1156.                                           AND (i.month1 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1157.                                       ';
  1158.                         break;
  1159.                     case 'Wednesday'//Miercoles
  1160.                         $dql 'SELECT i
  1161.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1162.                                     WHERE (
  1163.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1164.                                           AND (i.month1 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1165.                                       ';
  1166.                         break;
  1167.                     case 'Thursday'//Jueves
  1168.                         $dql 'SELECT i
  1169.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1170.                                     WHERE (
  1171.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1172.                                           AND (i.month1 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1173.                                       ';
  1174.                         break;
  1175.                     case 'Friday'//Viernes
  1176.                         $dql 'SELECT i
  1177.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1178.                                     WHERE (
  1179.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1180.                                           AND (i.month1 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1181.                                       ';
  1182.                         break;
  1183.                     case 'Saturday'//Sabado
  1184.                         $dql 'SELECT i
  1185.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1186.                                     WHERE (
  1187.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1188.                                           AND (i.month1 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1189.                                       ';
  1190.                         break;
  1191.                     case 'Sunday'//Domingo
  1192.                         $dql 'SELECT i
  1193.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1194.                                     WHERE (
  1195.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1196.                                           AND (i.month1 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1197.                                       ';
  1198.                         break;
  1199.                     default: break;
  1200.                 }
  1201.                 break;
  1202.             case '02'//Febrero
  1203.                 switch ($date->format('l')) {
  1204.                     case 'Monday'//Lunes
  1205.                         $dql 'SELECT i
  1206.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1207.                                     WHERE (
  1208.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1209.                                           AND (i.month2 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1210.                                       ';
  1211.                         break;
  1212.                     case 'Tuesday'//Martes
  1213.                         $dql 'SELECT i
  1214.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1215.                                     WHERE (
  1216.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1217.                                           AND (i.month2 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1218.                                       ';
  1219.                         break;
  1220.                     case 'Wednesday'//Miercoles
  1221.                         $dql 'SELECT i
  1222.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1223.                                     WHERE (
  1224.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1225.                                           AND (i.month2 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1226.                                       ';
  1227.                         break;
  1228.                     case 'Thursday'//Jueves
  1229.                         $dql 'SELECT i
  1230.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1231.                                     WHERE (
  1232.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1233.                                           AND (i.month2 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1234.                                       ';
  1235.                         break;
  1236.                     case 'Friday'//Viernes
  1237.                         $dql 'SELECT i
  1238.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1239.                                     WHERE (
  1240.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1241.                                           AND (i.month2 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1242.                                       ';
  1243.                         break;
  1244.                     case 'Saturday'//Sabado
  1245.                         $dql 'SELECT i
  1246.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1247.                                     WHERE (
  1248.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1249.                                           AND (i.month2 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1250.                                       ';
  1251.                         break;
  1252.                     case 'Sunday'//Domingo
  1253.                         $dql 'SELECT i
  1254.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1255.                                     WHERE (
  1256.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1257.                                           AND (i.month2 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1258.                                       ';
  1259.                         break;
  1260.                     default: break;
  1261.                 }
  1262.                 break;
  1263.             case '03'//Marzo
  1264.                 switch ($date->format('l')) {
  1265.                     case 'Monday'//Lunes
  1266.                         $dql 'SELECT i
  1267.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1268.                                     WHERE (
  1269.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1270.                                           AND (i.month3 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1271.                                       ';
  1272.                         break;
  1273.                     case 'Tuesday'//Martes
  1274.                         $dql 'SELECT i
  1275.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1276.                                     WHERE (
  1277.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1278.                                           AND (i.month3 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1279.                                       ';
  1280.                         break;
  1281.                     case 'Wednesday'//Miercoles
  1282.                         $dql 'SELECT i
  1283.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1284.                                     WHERE (
  1285.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1286.                                           AND (i.month3 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1287.                                       ';
  1288.                         break;
  1289.                     case 'Thursday'//Jueves
  1290.                         $dql 'SELECT i
  1291.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1292.                                     WHERE (
  1293.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1294.                                           AND (i.month3 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1295.                                       ';
  1296.                         break;
  1297.                     case 'Friday'//Viernes
  1298.                         $dql 'SELECT i
  1299.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1300.                                     WHERE (
  1301.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1302.                                           AND (i.month3 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1303.                                       ';
  1304.                         break;
  1305.                     case 'Saturday'//Sabado
  1306.                         $dql 'SELECT i
  1307.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1308.                                     WHERE (
  1309.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1310.                                           AND (i.month3 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1311.                                       ';
  1312.                         break;
  1313.                     case 'Sunday'//Domingo
  1314.                         $dql 'SELECT i
  1315.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1316.                                     WHERE (
  1317.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1318.                                           AND (i.month3 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1319.                                       ';
  1320.                         break;
  1321.                     default: break;
  1322.                 }
  1323.                 break;
  1324.             case '04'//Abril
  1325.                 switch ($date->format('l')) {
  1326.                     case 'Monday'//Lunes
  1327.                         $dql 'SELECT i
  1328.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1329.                                     WHERE (
  1330.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1331.                                           AND (i.month4 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1332.                                       ';
  1333.                         break;
  1334.                     case 'Tuesday'//Martes
  1335.                         $dql 'SELECT i
  1336.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1337.                                     WHERE (
  1338.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1339.                                           AND (i.month4 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1340.                                       ';
  1341.                         break;
  1342.                     case 'Wednesday'//Miercoles
  1343.                         $dql 'SELECT i
  1344.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1345.                                     WHERE (
  1346.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1347.                                           AND (i.month4 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1348.                                       ';
  1349.                         break;
  1350.                     case 'Thursday'//Jueves
  1351.                         $dql 'SELECT i
  1352.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1353.                                     WHERE (
  1354.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1355.                                           AND (i.month4 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1356.                                       ';
  1357.                         break;
  1358.                     case 'Friday'//Viernes
  1359.                         $dql 'SELECT i
  1360.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1361.                                     WHERE (
  1362.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1363.                                           AND (i.month4 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1364.                                       ';
  1365.                         break;
  1366.                     case 'Saturday'//Sabado
  1367.                         $dql 'SELECT i
  1368.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1369.                                     WHERE (
  1370.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1371.                                           AND (i.month4 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1372.                                       ';
  1373.                         break;
  1374.                     case 'Sunday'//Domingo
  1375.                         $dql 'SELECT i
  1376.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1377.                                     WHERE (
  1378.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1379.                                           AND (i.month4 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1380.                                       ';
  1381.                         break;
  1382.                     default: break;
  1383.                 }
  1384.                 break;
  1385.             case '05'//Mayo
  1386.                 switch ($date->format('l')) {
  1387.                     case 'Monday'//Lunes
  1388.                         $dql 'SELECT i
  1389.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1390.                                     WHERE (
  1391.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1392.                                           AND (i.month5 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1393.                                       ';
  1394.                         break;
  1395.                     case 'Tuesday'//Martes
  1396.                         $dql 'SELECT i
  1397.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1398.                                     WHERE (
  1399.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1400.                                           AND (i.month5 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1401.                                       ';
  1402.                         break;
  1403.                     case 'Wednesday'//Miercoles
  1404.                         $dql 'SELECT i
  1405.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1406.                                     WHERE (
  1407.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1408.                                           AND (i.month5 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1409.                                       ';
  1410.                         break;
  1411.                     case 'Thursday'//Jueves
  1412.                         $dql 'SELECT i
  1413.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1414.                                     WHERE (
  1415.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1416.                                           AND (i.month5 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1417.                                       ';
  1418.                         break;
  1419.                     case 'Friday'//Viernes
  1420.                         $dql 'SELECT i
  1421.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1422.                                     WHERE (
  1423.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1424.                                           AND (i.month5 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1425.                                       ';
  1426.                         break;
  1427.                     case 'Saturday'//Sabado
  1428.                         $dql 'SELECT i
  1429.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1430.                                     WHERE (
  1431.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1432.                                           AND (i.month5 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1433.                                       ';
  1434.                         break;
  1435.                     case 'Sunday'//Domingo
  1436.                         $dql 'SELECT i
  1437.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1438.                                     WHERE (
  1439.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1440.                                           AND (i.month5 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1441.                                       ';
  1442.                         break;
  1443.                     default: break;
  1444.                 }
  1445.                 break;
  1446.             case '06'//Junio
  1447.                 switch ($date->format('l')) {
  1448.                     case 'Monday'//Lunes
  1449.                         $dql 'SELECT i
  1450.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1451.                                     WHERE (
  1452.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1453.                                           AND (i.month6 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1454.                                       ';
  1455.                         break;
  1456.                     case 'Tuesday'//Martes
  1457.                         $dql 'SELECT i
  1458.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1459.                                     WHERE (
  1460.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1461.                                           AND (i.month6 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1462.                                       ';
  1463.                         break;
  1464.                     case 'Wednesday'//Miercoles
  1465.                         $dql 'SELECT i
  1466.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1467.                                     WHERE (
  1468.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1469.                                           AND (i.month6 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1470.                                       ';
  1471.                         break;
  1472.                     case 'Thursday'//Jueves
  1473.                         $dql 'SELECT i
  1474.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1475.                                     WHERE (
  1476.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1477.                                           AND (i.month6 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1478.                                       ';
  1479.                         break;
  1480.                     case 'Friday'//Viernes
  1481.                         $dql 'SELECT i
  1482.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1483.                                     WHERE (
  1484.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1485.                                           AND (i.month6 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1486.                                       ';
  1487.                         break;
  1488.                     case 'Saturday'//Sabado
  1489.                         $dql 'SELECT i
  1490.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1491.                                     WHERE (
  1492.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1493.                                           AND (i.month6 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1494.                                       ';
  1495.                         break;
  1496.                     case 'Sunday'//Domingo
  1497.                         $dql 'SELECT i
  1498.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1499.                                     WHERE (
  1500.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1501.                                           AND (i.month6 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1502.                                       ';
  1503.                         break;
  1504.                     default: break;
  1505.                 }
  1506.                 break;
  1507.             case '07'//Julio
  1508.                 switch ($date->format('l')) {
  1509.                     case 'Monday'//Lunes
  1510.                         $dql 'SELECT i
  1511.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1512.                                     WHERE (
  1513.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1514.                                           AND (i.month7 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1515.                                       ';
  1516.                         break;
  1517.                     case 'Tuesday'//Martes
  1518.                         $dql 'SELECT i
  1519.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1520.                                     WHERE (
  1521.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1522.                                           AND (i.month7 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1523.                                       ';
  1524.                         break;
  1525.                     case 'Wednesday'//Miercoles
  1526.                         $dql 'SELECT i
  1527.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1528.                                     WHERE (
  1529.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1530.                                           AND (i.month7 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1531.                                       ';
  1532.                         break;
  1533.                     case 'Thursday'//Jueves
  1534.                         $dql 'SELECT i
  1535.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1536.                                     WHERE (
  1537.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1538.                                           AND (i.month7 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1539.                                       ';
  1540.                         break;
  1541.                     case 'Friday'//Viernes
  1542.                         $dql 'SELECT i
  1543.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1544.                                     WHERE (
  1545.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1546.                                           AND (i.month7 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1547.                                       ';
  1548.                         break;
  1549.                     case 'Saturday'//Sabado
  1550.                         $dql 'SELECT i
  1551.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1552.                                     WHERE (
  1553.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1554.                                           AND (i.month7 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1555.                                       ';
  1556.                         break;
  1557.                     case 'Sunday'//Domingo
  1558.                         $dql 'SELECT i
  1559.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1560.                                     WHERE (
  1561.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1562.                                           AND (i.month7 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1563.                                       ';
  1564.                         break;
  1565.                     default: break;
  1566.                 }
  1567.                 break;
  1568.             case '08'//Agosto
  1569.                 switch ($date->format('l')) {
  1570.                     case 'Monday'//Lunes
  1571.                         $dql 'SELECT i
  1572.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1573.                                     WHERE (
  1574.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1575.                                           AND (i.month8 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1576.                                       ';
  1577.                         break;
  1578.                     case 'Tuesday'//Martes
  1579.                         $dql 'SELECT i
  1580.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1581.                                     WHERE (
  1582.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1583.                                           AND (i.month8 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1584.                                       ';
  1585.                         break;
  1586.                     case 'Wednesday'//Miercoles
  1587.                         $dql 'SELECT i
  1588.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1589.                                     WHERE (
  1590.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1591.                                           AND (i.month8 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1592.                                       ';
  1593.                         break;
  1594.                     case 'Thursday'//Jueves
  1595.                         $dql 'SELECT i
  1596.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1597.                                     WHERE (
  1598.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1599.                                           AND (i.month8 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1600.                                       ';
  1601.                         break;
  1602.                     case 'Friday'//Viernes
  1603.                         $dql 'SELECT i
  1604.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1605.                                     WHERE (
  1606.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1607.                                           AND (i.month8 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1608.                                       ';
  1609.                         break;
  1610.                     case 'Saturday'//Sabado
  1611.                         $dql 'SELECT i
  1612.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1613.                                     WHERE (
  1614.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1615.                                           AND (i.month8 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1616.                                       ';
  1617.                         break;
  1618.                     case 'Sunday'//Domingo
  1619.                         $dql 'SELECT i
  1620.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1621.                                     WHERE (
  1622.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1623.                                           AND (i.month8 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1624.                                       ';
  1625.                         break;
  1626.                     default: break;
  1627.                 }
  1628.                 break;
  1629.             case '09'//Septiembre
  1630.                 switch ($date->format('l')) {
  1631.                     case 'Monday'//Lunes
  1632.                         $dql 'SELECT i
  1633.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1634.                                     WHERE (
  1635.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1636.                                           AND (i.month9 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1637.                                       ';
  1638.                         break;
  1639.                     case 'Tuesday'//Martes
  1640.                         $dql 'SELECT i
  1641.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1642.                                     WHERE (
  1643.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1644.                                           AND (i.month9 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1645.                                       ';
  1646.                         break;
  1647.                     case 'Wednesday'//Miercoles
  1648.                         $dql 'SELECT i
  1649.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1650.                                     WHERE (
  1651.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1652.                                           AND (i.month9 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1653.                                       ';
  1654.                         break;
  1655.                     case 'Thursday'//Jueves
  1656.                         $dql 'SELECT i
  1657.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1658.                                     WHERE (
  1659.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1660.                                           AND (i.month9 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1661.                                       ';
  1662.                         break;
  1663.                     case 'Friday'//Viernes
  1664.                         $dql 'SELECT i
  1665.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1666.                                     WHERE (
  1667.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1668.                                           AND (i.month9 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1669.                                       ';
  1670.                         break;
  1671.                     case 'Saturday'//Sabado
  1672.                         $dql 'SELECT i
  1673.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1674.                                     WHERE (
  1675.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1676.                                           AND (i.month9 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1677.                                       ';
  1678.                         break;
  1679.                     case 'Sunday'//Domingo
  1680.                         $dql 'SELECT i
  1681.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1682.                                     WHERE (
  1683.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1684.                                           AND (i.month9 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1685.                                       ';
  1686.                         break;
  1687.                     default: break;
  1688.                 }
  1689.                 break;
  1690.             case '10'//Octubre
  1691.                 switch ($date->format('l')) {
  1692.                     case 'Monday'//Lunes
  1693.                         $dql 'SELECT i
  1694.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1695.                                     WHERE (
  1696.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1697.                                           AND (i.month10 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1698.                                       ';
  1699.                         break;
  1700.                     case 'Tuesday'//Martes
  1701.                         $dql 'SELECT i
  1702.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1703.                                     WHERE (
  1704.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1705.                                           AND (i.month10 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1706.                                       ';
  1707.                         break;
  1708.                     case 'Wednesday'//Miercoles
  1709.                         $dql 'SELECT i
  1710.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1711.                                     WHERE (
  1712.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1713.                                           AND (i.month10 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1714.                                       ';
  1715.                         break;
  1716.                     case 'Thursday'//Jueves
  1717.                         $dql 'SELECT i
  1718.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1719.                                     WHERE (
  1720.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1721.                                           AND (i.month10 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1722.                                       ';
  1723.                         break;
  1724.                     case 'Friday'//Viernes
  1725.                         $dql 'SELECT i
  1726.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1727.                                     WHERE (
  1728.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1729.                                           AND (i.month10 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1730.                                       ';
  1731.                         break;
  1732.                     case 'Saturday'//Sabado
  1733.                         $dql 'SELECT i
  1734.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1735.                                     WHERE (
  1736.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1737.                                           AND (i.month10 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1738.                                       ';
  1739.                         break;
  1740.                     case 'Sunday'//Domingo
  1741.                         $dql 'SELECT i
  1742.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1743.                                     WHERE (
  1744.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1745.                                           AND (i.month10 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1746.                                       ';
  1747.                         break;
  1748.                     default: break;
  1749.                 }
  1750.                 break;
  1751.             case '11'//Noviembre
  1752.                 switch ($date->format('l')) {
  1753.                     case 'Monday'//Lunes
  1754.                         $dql 'SELECT i
  1755.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1756.                                     WHERE (
  1757.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1758.                                           AND (i.month11 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1759.                                       ';
  1760.                         break;
  1761.                     case 'Tuesday'//Martes
  1762.                         $dql 'SELECT i
  1763.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1764.                                     WHERE (
  1765.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1766.                                           AND (i.month11 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1767.                                       ';
  1768.                         break;
  1769.                     case 'Wednesday'//Miercoles
  1770.                         $dql 'SELECT i
  1771.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1772.                                     WHERE (
  1773.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1774.                                           AND (i.month11 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1775.                                       ';
  1776.                         break;
  1777.                     case 'Thursday'//Jueves
  1778.                         $dql 'SELECT i
  1779.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1780.                                     WHERE (
  1781.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1782.                                           AND (i.month11 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1783.                                       ';
  1784.                         break;
  1785.                     case 'Friday'//Viernes
  1786.                         $dql 'SELECT i
  1787.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1788.                                     WHERE (
  1789.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1790.                                           AND (i.month11 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1791.                                       ';
  1792.                         break;
  1793.                     case 'Saturday'//Sabado
  1794.                         $dql 'SELECT i
  1795.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1796.                                     WHERE (
  1797.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1798.                                           AND (i.month11 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1799.                                       ';
  1800.                         break;
  1801.                     case 'Sunday'//Domingo
  1802.                         $dql 'SELECT i
  1803.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1804.                                     WHERE (
  1805.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1806.                                           AND (i.month11 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1807.                                       ';
  1808.                         break;
  1809.                     default: break;
  1810.                 }
  1811.                 break;
  1812.             case '12'//Diciembre
  1813.                 switch ($date->format('l')) {
  1814.                     case 'Monday'//Lunes
  1815.                         $dql 'SELECT i
  1816.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1817.                                     WHERE (
  1818.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1819.                                           AND (i.month12 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1820.                                       ';
  1821.                         break;
  1822.                     case 'Tuesday'//Martes
  1823.                         $dql 'SELECT i
  1824.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1825.                                     WHERE (
  1826.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1827.                                           AND (i.month12 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1828.                                       ';
  1829.                         break;
  1830.                     case 'Wednesday'//Miercoles
  1831.                         $dql 'SELECT i
  1832.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1833.                                     WHERE (
  1834.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1835.                                           AND (i.month12 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1836.                                       ';
  1837.                         break;
  1838.                     case 'Thursday'//Jueves
  1839.                         $dql 'SELECT i
  1840.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1841.                                     WHERE (
  1842.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1843.                                           AND (i.month12 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1844.                                       ';
  1845.                         break;
  1846.                     case 'Friday'//Viernes
  1847.                         $dql 'SELECT i
  1848.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1849.                                     WHERE (
  1850.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1851.                                           AND (i.month12 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1852.                                       ';
  1853.                         break;
  1854.                     case 'Saturday'//Sabado
  1855.                         $dql 'SELECT i
  1856.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1857.                                     WHERE (
  1858.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1859.                                           AND (i.month12 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1860.                                       ';
  1861.                         break;
  1862.                     case 'Sunday'//Domingo
  1863.                         $dql 'SELECT i
  1864.                                     FROM GreenPatioBundle:ReservationLoungeProfile i
  1865.                                     WHERE (
  1866.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1867.                                           AND (i.month12 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1868.                                       ';
  1869.                         break;
  1870.                     default: break;
  1871.                 }
  1872.                 break;
  1873.             default:
  1874.                 break;
  1875.         }
  1876.         $query $em->createQuery($dql)->setParameters($parameters);
  1877.         $price3 $query->getResult();
  1878.         foreach ($price3 as $item){
  1879.             if (empty($price0)){
  1880.                 $price0 $item;
  1881.             } else {
  1882.                 //Si los precios coinciden en fechas se tomara el que se haya cargado mas reciente en el sistema
  1883.                 if ($item->getCreatedAt() > $price0->getCreatedAt()){ $price0 $item; }
  1884.             }
  1885.         }
  1886.         if(empty($price0)){ $price 0; } else { $price $price0->getPrice(); }
  1887.         return array( 'price' => $price, );
  1888.     }
  1889.     private function precioTarifario($dateStart$loungeId$servicePrice){
  1890.         /*
  1891.          * Se busca el precio a Sugerir
  1892.          * $dateStart Fecha
  1893.          * $loungeId Id de  la sala
  1894.          * $servicePrice Preciointroducido por elusuario
  1895.          * */
  1896.         $em $this->getDoctrine()->getManager();
  1897.         $dateToFind = clone $dateStart;
  1898.         $dateToFind->setTime(000);
  1899.         $parameters = array(
  1900.             'loungeId' => $loungeId,
  1901.             'typePrice' => 'DIARIA',
  1902.             'dateToFind' => $dateToFind,
  1903.         );
  1904.         $dql 'SELECT p
  1905.                 FROM GreenPatioBundle:ReservationLoungeProfile p
  1906.                 WHERE p.typePrice = :typePrice AND p.dateStart = :dateToFind AND p.loungeId = :loungeId
  1907.                 ORDER BY p.levelPrice DESC';
  1908.         $query $em->createQuery($dql)->setParameters($parameters);
  1909.         $loungesPeriodsDaily $query->getResult();
  1910.         $priceTarifa = empty($loungesPeriodsDaily) ? $loungesPeriodsDaily[0]->getPrice();
  1911.         $price = ($servicePrice == 0) ? $priceTarifa $servicePrice;
  1912.         return $price;
  1913.     }
  1914.     private function recalculoFechas($id){
  1915.         /*
  1916.          * Se busca recalculan las fechas de incio y fin de la reserva
  1917.          * $id es el identificador de la reserva
  1918.          * */
  1919.         $em $this->getDoctrine()->getManager();
  1920.         $reserva $em->getRepository(Reservation::class)->findOneById($id);
  1921.         $allLoungeSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($id);
  1922.         $dateStart = new DateTime('2078-01-01');
  1923.         $dateEnd = new DateTime('2000-01-01');
  1924.         if (!empty($allLoungeSimples)){
  1925.             foreach ($allLoungeSimples as $loungeSimple){
  1926.                 $dateStart = ($loungeSimple->getDateStart() < $dateStart) ? $loungeSimple->getDateStart() : $dateStart;
  1927.                 $dateEnd = ($loungeSimple->getDateEnd() > $dateEnd) ? $loungeSimple->getDateStart() : $dateEnd;
  1928.             }
  1929.         }
  1930.         $reserva->setDateStart($dateStart);
  1931.         $reserva->setDateEnd($dateEnd);
  1932.         try{
  1933.             $em->persist($reserva);
  1934.             $em->flush();
  1935.             $event 'The Reservation has been updated.';
  1936.             $successMessage $this->translator->trans($event);
  1937.             $this->addFlash('mensajereservation'$successMessage);
  1938.         } catch (\Exception $e){
  1939.             $event 'An error occurred: '.$e->getMessage();
  1940.             $errorMessage $this->translator->trans($event);
  1941.             $this->addFlash('mensajereservationerror'$errorMessage);
  1942.         }
  1943.         return true;
  1944.     }
  1945. }