src/MDS/VenuesBundle/Controller/ReservationsQuoteController.php line 86

Open in your IDE?
  1. <?php
  2. namespace App\MDS\VenuesBundle\Controller;
  3. use App\Entity\HtFile;
  4. use App\Entity\ReservationLoungeWebDescription;
  5. use App\Entity\SageArticle;
  6. use App\Entity\SageVatRates;
  7. use App\Entity\WidgetNotes;
  8. use App\Form\WidgetNotesType;
  9. use App\MDS\AvexpressBundle\Entity\AveFiles;
  10. use App\MDS\VenuesBundle\Entity\Reservation;
  11. use App\MDS\VenuesBundle\Entity\ReservationInvoiceItems;
  12. use App\MDS\VenuesBundle\Entity\ReservationLoungeSimple;
  13. use App\MDS\VenuesBundle\Entity\ReservationLoungeSimpleServiceLog;
  14. use App\MDS\VenuesBundle\Entity\ReservationService;
  15. use App\MDS\VenuesBundle\Entity\ReservationGpPrice;
  16. use App\MDS\VenuesBundle\Entity\ReservationLounge;
  17. use App\MDS\VenuesBundle\Entity\ReservationLoungeDetails;
  18. use App\MDS\VenuesBundle\Entity\ReservationLoungeProfile;
  19. use App\MDS\VenuesBundle\Entity\ReservationPeriod;
  20. use App\MDS\VenuesBundle\Form\ReservationGpPriceType;
  21. use App\MDS\VenuesBundle\Form\ReservationLoungeDetailsType;
  22. use App\MDS\VenuesBundle\Form\ReservationLoungeProfileType;
  23. use App\MDS\VenuesBundle\Form\ReservationPeriodType;
  24. use App\MDS\VenuesBundle\Form\ReservationType;
  25. use Doctrine\ORM\EntityManagerInterface;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use DateTime;
  30. use DatePeriod;
  31. use DateInterval;
  32. use Google_Client;
  33. use Google_Service_Calendar;
  34. use Symfony\Component\HttpFoundation\JsonResponse;
  35. use Symfony\Contracts\Translation\TranslatorInterface;
  36. use App\Service\AgendaService;
  37. use App\Service\VenueService;
  38. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  39. class ReservationsQuoteController extends AbstractController
  40. {
  41.     private Google_Client $googleCalendar;
  42.     private TranslatorInterface $translator;
  43.     private AgendaService $agendaService;
  44.     private SessionInterface $session;
  45.     private VenueService $venueService;
  46.     private \App\Service\ReservationService $reservationService;
  47.     private \App\Service\DocContractService $docContractService;
  48.     public function __construct(
  49.         TranslatorInterface $translator,
  50.         AgendaService $agendaService,
  51.         VenueService $venueService,
  52.         SessionInterface $session,
  53.         \App\Service\ReservationService $reservationService,
  54.         \App\Service\DocContractService $docContractService
  55.     ) {
  56.         $redirect_uri 'https://' $_SERVER['HTTP_HOST'] . '/calendar/token';
  57.         $googleCalendar = new Google_Client();
  58.         $googleCalendar->setApplicationName('Google Calendar API PHP Quickstart');
  59.         //campos a extraer de la base de datos User
  60.         $googleCalendar->setClientId('2790497987-57qc3vu4pr7vb0s8phpub2me58pe34lb.apps.googleusercontent.com');
  61.         $googleCalendar->setClientSecret('nj2C7unaTO68DRhyORsyipSj');
  62.         //fin campos user
  63. //        $api_key = "AIzaSyBR84cS1IU2BPvk5V3VnbqdkJESlv440Ac";
  64. //        $client->setDeveloperKey($api_key);
  65.         $googleCalendar->setRedirectUri($redirect_uri);
  66.         $googleCalendar->addScope(Google_Service_Calendar::CALENDAR);
  67.         $guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
  68.         $googleCalendar->setHttpClient($guzzleClient);
  69.         $this->googleCalendar $googleCalendar;
  70.         $this->translator $translator;
  71.         $this->agendaService $agendaService;
  72.         $this->venueService $venueService;
  73.         $this->session $session;
  74.         $this->reservationService $reservationService;
  75.         $this->docContractService $docContractService;
  76.     }
  77.     /**
  78.      * @Route("/createsimplelounge/{id}", name="reservations_venues_create_simple_lounge")
  79.      * Crea un Reservation Lounge Simple en la cotizacion
  80.      */
  81.     public function createSimpleLoungeAction($idEntityManagerInterface $emRequest $request)
  82.     {
  83.         $simpleLounge $request->request->all()['reservation_sala'] ?? [];
  84.         // Sala precargada
  85.         $loungeProfile $em->getRepository(ReservationLoungeDetails::class)
  86.             ->findOneById($simpleLounge['salaPrecargadas'] ?? null);
  87.         if (!$loungeProfile) {
  88.             $this->addFlash('mensajereservationerror''La sala seleccionada no existe.');
  89.             return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
  90.         }
  91.         $loungeId $loungeProfile->getId();
  92.         $loungeDetails $em->getRepository(ReservationLoungeDetails::class)->findOneById($loungeId);
  93.         // Nombre de sala, necesario para Sage
  94.         $loungeName '';
  95.         if ($loungeDetails && method_exists($loungeDetails'getName')) {
  96.             $loungeName = (string) $loungeDetails->getName();
  97.         } elseif (!empty($simpleLounge['loungeName'])) {
  98.             $loungeName = (string) $simpleLounge['loungeName'];
  99.         }
  100.         if ($loungeName === '') {
  101.             $this->addFlash('mensajereservationerror''No se pudo determinar el nombre de la sala.');
  102.             return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
  103.         }
  104.         // ¿Existe ya esta sala en la misma reserva y rank?
  105.         $previusLoungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneBy([
  106.             'idLounge' => $loungeId,
  107.             'idReservation' => $id,
  108.             'rankQuote' => $simpleLounge['idQuote'] ?? null
  109.         ]);
  110.         // Heredar idioma si existe alguna sala previa en la reserva
  111.         $anyLoungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneBy([
  112.             'idLounge' => $loungeId,
  113.             'idReservation' => $id
  114.         ]);
  115.         $idioma $anyLoungeSimple ? (int) $anyLoungeSimple->getLanguage() : 1;
  116.         // Descripciones web por sala/idioma con fallbacks
  117.         $loungeWebDescriptionRepo $em->getRepository(ReservationLoungeWebDescription::class);
  118.         $loungeWebDescription $loungeWebDescriptionRepo->findOneBy([
  119.             'lounge' => $loungeProfile,
  120.             'language' => $idioma
  121.         ]) ?? ($idioma !== $loungeWebDescriptionRepo->findOneBy([
  122.                 'lounge' => $loungeProfile,
  123.                 'language' => 1
  124.             ]) : null) ?? $loungeWebDescriptionRepo->findOneBy(['lounge' => $loungeProfile]);
  125.         // Summary recibido del formulario (opcional)
  126.         $loungeSummaryDescription is_array($simpleLounge) && array_key_exists('importantDescription'$simpleLounge)
  127.             ? (string) $simpleLounge['importantDescription']
  128.             : null;
  129.         if (empty($previusLoungeSimple)) {
  130.             // Sin anterior, tiramos de WebDescription si existe
  131.             $loungeImportantDescGeneralText $loungeWebDescription $loungeWebDescription->getImportantDescGeneralText() : '';
  132.             $loungeImportantDescSchedules $loungeWebDescription $loungeWebDescription->getImportantDescSchedules() : '';
  133.             $loungeImportantDescParking $loungeWebDescription $loungeWebDescription->getImportantDescParking() : '';
  134.             if (empty($loungeSummaryDescription)) {
  135.                 $loungeSummaryDescription $loungeWebDescription $loungeWebDescription->getImportantDescription() : '';
  136.             }
  137.         } else {
  138.             // Heredamos de la simple existente
  139.             $loungeSummaryDescription $previusLoungeSimple->getImportantDescription();
  140.             $loungeImportantDescGeneralText $previusLoungeSimple->getImportantDescGeneralText();
  141.             $loungeImportantDescSchedules $previusLoungeSimple->getImportantDescSchedules();
  142.             $loungeImportantDescParking $previusLoungeSimple->getImportantDescParking();
  143.         }
  144.         // Reserva para calcular sucoe e IVA
  145.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  146.         if (!$reservation) {
  147.             $this->addFlash('mensajereservationerror''No se encontró la reserva.');
  148.             return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
  149.         }
  150.         $sucoe = (bool) $reservation->isSucoe();
  151.         $sageVatRate $em->getRepository(SageVatRates::class)->findOneBy([
  152.             'sageCode' => $sucoe '00' '03'
  153.         ]);
  154.         // Artículo Sage por nombre de sala + tipo IVA
  155.         $sageArticle $em->getRepository(SageArticle::class)->findOneBy([
  156.             'vatType' => $sageVatRate,
  157.             'name' => $loungeName
  158.         ]);
  159.         // Solo salta el error si no se ha encontrado el artículo y está el modulo de Sage activo
  160.         if (!$sageArticle && $this->session->get('_config')['msage']) {
  161.             $this->addFlash('mensajereservationerror''No se ha encontrado el artículo de Sage para la sala: ' $loungeName);
  162.             return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
  163.         }
  164.         // Normalización horas desde POST
  165.         $hourMinStart = (string) ($simpleLounge['hourStart'] ?? '');
  166.         $hourMinEnd = (string) ($simpleLounge['hourEnd'] ?? '');
  167.         // Normalización horas desde POST usando el servicio
  168.         $startData $this->reservationService->formatTimeInput((string) ($simpleLounge['hourStart'] ?? ''));
  169.         $endData $this->reservationService->formatTimeInput((string) ($simpleLounge['hourEnd'] ?? ''));
  170.         $hourStart $startData['hour'];
  171.         $minStart $startData['min'];
  172.         $hourEnd $endData['hour'];
  173.         $minEnd $endData['min'];
  174.         $dateStart = new \DateTime(($simpleLounge['dateStart'] ?? date('Y-m-d')) . ' ' $startData['formatted']);
  175.         $dateEnd = new \DateTime(($simpleLounge['dateStart'] ?? date('Y-m-d')) . ' ' $endData['formatted']); // un solo día
  176.         $servicePrice = (float) ($simpleLounge['servicePrice'] ?? 0);
  177.         $idReservation = (int) $id;
  178.         // Usuario
  179.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  180.         $user_id $user_logueado $user_logueado->getId() : null;
  181.         $createdAt = new \DateTime('now');
  182.         $updatedAt = new \DateTime('now');
  183.         $pax = (int) ($simpleLounge['pax'] ?? 0);
  184.         // Rank de cotización
  185.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  186.         $reservationAll $qb->where('r.idReservation = :idReservation')
  187.             ->setParameter('idReservation'$id)
  188.             ->orderBy('r.rankQuote''ASC')
  189.             ->getQuery()
  190.             ->getResult();
  191.         $newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
  192.         if (!empty($simpleLounge['idQuote']) && is_numeric($simpleLounge['idQuote'])) {
  193.             $newRankId = (int) $simpleLounge['idQuote'];
  194.         }
  195.         // Tipo: Dia de evento (null), Montaje o Desmontaje
  196.         $typeXLounge = empty($simpleLounge['type']) ? null $simpleLounge['type'];
  197.         // Crear la entidad
  198.         $lounge = new ReservationLoungeSimple();
  199.         $lounge->setIdLounge($loungeId);
  200.         $lounge->setHourStart($hourStart);
  201.         $lounge->setMinStart($minStart);
  202.         $lounge->setHourEnd($hourEnd);
  203.         $lounge->setMinEnd($minEnd);
  204.         $lounge->setLoungeName($loungeName);
  205.         $lounge->setDateStart($dateStart);
  206.         $lounge->setDateEnd($dateEnd);
  207.         $lounge->setRankQuote($newRankId);
  208.         $lounge->setIdReservation($idReservation);
  209.         $lounge->setType($typeXLounge);
  210.         $lounge->setSageIva($sageVatRate);
  211.         $lounge->setOpIva(1);
  212.         $lounge->setCreatedAt($createdAt);
  213.         $lounge->setCreatedBy($user_id);
  214.         $lounge->setUpdatedAt($updatedAt);
  215.         $lounge->setUpdatedBy($user_id);
  216.         $lounge->setPax($pax);
  217.         $lounge->setImportantDescription($loungeSummaryDescription ?? '');
  218.         $lounge->setImportantDescGeneralText($loungeImportantDescGeneralText ?? '');
  219.         $lounge->setImportantDescSchedules($loungeImportantDescSchedules ?? '');
  220.         $lounge->setImportantDescParking($loungeImportantDescParking ?? '');
  221.         // Precio tarifario
  222.         $price $this->reservationService->getTariffPrice($dateStart$loungeId$servicePrice);
  223.         $lounge->setServicePrice($price);
  224.         // Vincular la sala al artículo
  225.         $lounge->setSageArticle($sageArticle);
  226.         try {
  227.             $em->persist($lounge);
  228.             $em->flush();
  229.             $event 'The Reservation has been updated.';
  230.             $successMessage $this->translator->trans($event);
  231.             $this->addFlash('mensajereservation'$successMessage);
  232.         } catch (\Exception $e) {
  233.             $event 'An error occurred: ' $e->getMessage();
  234.             $errorMessage $this->translator->trans($event);
  235.             $this->addFlash('mensajereservationerror'$errorMessage);
  236.         }
  237.         //Se llama al servicio para crear la entrada en la agenda y actualizar el Pax de la agenda
  238.         $loungeNameAgenda = empty($typeXLounge) ? $loungeName $loungeName ' ( ' $typeXLounge ' ) ';
  239.         $agenda $this->agendaService->createAgendaFromSource($idReservation'SALAS A UTILIZAR'nullnull$dateStart$dateEnd$loungeNameAgenda$lounge->getId(), 'ReservationLoungeSimple'$user_id);
  240.         $paxAge $this->agendaService->calculatePaxForReservation($idReservation);
  241.         $agenda $this->agendaService->updatePaxLine($idReservation$paxAge$user_id);
  242.         // Actualizar fechas de la reserva usando el servicio
  243.         if ($reservation) {
  244.             $this->reservationService->updateReservationDates($reservation);
  245.             //Se llama al servicio para crear la entrada en la agenda de las fechas
  246.             $this->agendaService->updateDatesLine($idReservation$user_id);
  247.         }
  248.         // Creamos la Snapshot de las salas y servicios del sistema (LOG)
  249.         $version $this->venueService->createSnapshot($reservation);
  250.         // Sincronizar contratos si está confirmado
  251.         if ($reservation->getStatus() === 'Confirmed') {
  252.             $this->docContractService->autoAssignContracts($reservation$user_logueado);
  253.         }
  254.         // Redirección para agregar servicio de limpieza
  255.         return $this->redirectToRoute('reservations_white_addservices_cleaning', [
  256.             'resid' => $id,
  257.             'loungesimpleid' => $lounge->getId(),
  258.         ]);
  259.     }
  260.     /**
  261.      * @Route("/api/get-price", name="get_reservations_price_to_view", methods={"GET"})
  262.      */
  263.     public function getPrice(Request $request)
  264.     {
  265.         $loungeId $request->query->get('sala');
  266.         $dateStart $request->query->get('date');
  267.         if (!$loungeId || !$dateStart) {
  268.             return new JsonResponse(['error' => 'Missing parameters'], 400);
  269.         }
  270.         try {
  271.             $dateStartObj = new \DateTime($dateStart);
  272.         } catch (\Exception $e) {
  273.             return new JsonResponse(['error' => 'Invalid date'], 400);
  274.         }
  275.         $price $this->reservationService->getTariffPrice($dateStartObj$loungeId0);
  276.         return new JsonResponse(['price' => $price]);
  277.     }
  278.     /**
  279.      * @Route("/createsimpleloungemondes/{id}", name="reservations_venues_create_simple_lounge_mondes")
  280.      * Se crea un dia de montaje o desmontaje
  281.      */
  282.     public function createSimpleLoungeMonDesAction($idEntityManagerInterface $emRequest $request)
  283.     {
  284.         $simpleLounge $request->request->get('reservation_sala_mondes');
  285.         $loungeId $simpleLounge['idLounge'];
  286.         $loungeDetails $em->getRepository(ReservationLoungeDetails::class)->findOneById($loungeId);
  287.         $previusLoungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idLounge' => $loungeId'idReservation' => $id'rankQuote' => $simpleLounge['idQuote']));
  288.         $loungeName $loungeDetails->getName();
  289.         $hourMinStart $simpleLounge['hourStart'];
  290.         $hourMinEnd $simpleLounge['hourEnd'];
  291.         // Buscamos la reserva que es para saber si es sucoe o no
  292.         $reservation $em->getRepository(Reservation::class)->findOneById($id);
  293.         $sucoe $reservation->isSucoe();
  294.         // Si no es sucoe, cogemos el IVA del 21% y si lo es, entonces el del 0%
  295.         if (!$sucoe) {
  296.             $sageVatRate $em->getRepository(SageVatRates::class)->findOneBy(['sageCode' => '03']);
  297.         } else {
  298.             $sageVatRate $em->getRepository(SageVatRates::class)->findOneBy(['sageCode' => '00']);
  299.         }
  300.         $sageArticle $em->getRepository(SageArticle::class)->findOneBy(['vatType' => $sageVatRate'name' => $loungeName]);
  301.         // Si no se ha encontrado el artículo de Sage.
  302.         if (empty($sageArticle)) {
  303.             $this->addFlash('mensajereservationerror''No se ha encontrado el artículo de Sage para la sala: ' $loungeName);
  304.             return $this->redirectToRoute('reservations_venues_edit', array(
  305.                 'id' => $id,
  306.             ));
  307.         }
  308.         if (empty($previusLoungeSimple)) {
  309.             $loungeSummaryDescription $loungeDetails->getImportantDescription();
  310.             $loungeImportantDescGeneralText $loungeDetails->getImportantDescGeneralText();
  311.             $loungeImportantDescSchedules $loungeDetails->getImportantDescSchedules();
  312.             $loungeImportantDescParking $loungeDetails->getImportantDescParking();
  313.         } else {
  314.             $loungeSummaryDescription $previusLoungeSimple->getImportantDescription();
  315.             $loungeImportantDescGeneralText $previusLoungeSimple->getImportantDescGeneralText();
  316.             $loungeImportantDescSchedules $previusLoungeSimple->getImportantDescSchedules();
  317.             $loungeImportantDescParking $previusLoungeSimple->getImportantDescParking();
  318.         }
  319.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  320.         $reservationAll $qb->where('r.idReservation = :idReservation')
  321.             ->setParameter('idReservation'$id)
  322.             ->orderBy('r.rankQuote''ASC')
  323.             ->getQuery()
  324.             ->getResult();
  325.         $newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
  326.         if (!empty($simpleLounge['idQuote'])) {
  327.             if (is_numeric($simpleLounge['idQuote'])) {
  328.                 $newRankId $simpleLounge['idQuote'];
  329.             }
  330.         }
  331.         // Normalización horas desde POST usando el servicio
  332.         $startData $this->reservationService->formatTimeInput((string) ($simpleLounge['hourStart'] ?? ''));
  333.         $endData $this->reservationService->formatTimeInput((string) ($simpleLounge['hourEnd'] ?? ''));
  334.         $hourStart $startData['hour'];
  335.         $minStart $startData['min'];
  336.         $hourEnd $endData['hour'];
  337.         $minEnd $endData['min'];
  338.         $hourMinStart $startData['formatted'];
  339.         $hourMinEnd $endData['formatted'];
  340.         $dateStart = new DateTime($simpleLounge['dateStart'] . ' ' $hourMinStart);
  341.         $dateEnd = new DateTime($simpleLounge['dateStart'] . ' ' $hourMinEnd);   // Se usa DateStart por que solo hay un dia en el formulario
  342.         $servicePrice = empty($simpleLounge['servicePrice']) ? $simpleLounge['servicePrice'];
  343.         $idReservation $id;
  344.         /* Obtengo usuario logueado */
  345.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  346.         $user_id $user_logueado->getId();
  347.         $createdAt = new DateTime('now');
  348.         $createdBy $user_id;
  349.         $updatedAt = new DateTime('now');
  350.         $updatedBy $user_id;
  351.         $lounge = new ReservationLoungeSimple();
  352.         if ($simpleLounge['type'] == 'Montaje') {
  353.             $lounge->setType('Montaje');
  354.         } else {
  355.             $lounge->setType('Desmontaje');
  356.         }
  357.         $pax 0;
  358.         $lounge->setIdLounge($loungeId);
  359.         $lounge->setHourStart($hourStart);
  360.         $lounge->setMinStart($minStart);
  361.         $lounge->setHourEnd($hourEnd);
  362.         $lounge->setMinEnd($minEnd);
  363.         $lounge->setLoungeName($loungeName);
  364.         $lounge->setDateStart($dateStart);
  365.         $lounge->setDateEnd($dateEnd);
  366.         $lounge->setRankQuote(1);
  367.         $lounge->setSageIva($sageArticle->getVatType());
  368.         $lounge->setOpIva(1);
  369.         $lounge->setIdReservation($idReservation);
  370.         $lounge->setCreatedAt($createdAt);
  371.         $lounge->setCreatedBy($createdBy);
  372.         $lounge->setUpdatedAt($updatedAt);
  373.         $lounge->setUpdatedBy($updatedBy);
  374.         $lounge->setPax($pax);
  375.         $lounge->setRankQuote($newRankId);
  376.         $lounge->setImportantDescription($loungeSummaryDescription);
  377.         $lounge->setImportantDescGeneralText($loungeImportantDescGeneralText);
  378.         $lounge->setImportantDescSchedules($loungeImportantDescSchedules);
  379.         $lounge->setImportantDescParking($loungeImportantDescParking);
  380.         $price 0// Se asume 0 según lógica de precioPorFecha original que era inalcanzable
  381.         $servicePrice = ($price == 0) ? $servicePrice $price;
  382.         $lounge->setServicePrice($servicePrice);
  383.         // Vincular la sala al artículo
  384.         $lounge->setSageArticle($sageArticle);
  385.         try {
  386.             $em->persist($lounge);
  387.             $em->flush();
  388.             $event 'The Reservation has been updated.';
  389.             $successMessage $this->translator->trans($event);
  390.             $this->addFlash('mensajereservation'$successMessage);
  391.         } catch (\Exception $e) {
  392.             $event 'An error occurred: ' $e->getMessage();
  393.             $errorMessage $this->translator->trans($event);
  394.             $this->addFlash('mensajereservationerror'$errorMessage);
  395.         }
  396.         $reservax $em->getRepository(Reservation::class)->findOneById($idReservation);
  397.         if ($reservax) {
  398.             $this->reservationService->updateReservationDates($reservax);
  399.             
  400.             // Sincronizar contratos si está confirmado
  401.             if ($reservax->getStatus() === 'Confirmed') {
  402.                 $this->docContractService->autoAssignContracts($reservax$user_logueado);
  403.             }
  404.         }
  405.         // FIN: Verificamos si es necesario actualizar las fechas de la reserva
  406.         return $this->redirectToRoute(
  407.             'reservations_venues_edit_simple',
  408.             array(
  409.                 'id' => $id,
  410.                 'token' => null,
  411.                 '_fragment' => 'btn_quotes'
  412.             )
  413.         );
  414.     }
  415.     /**
  416.      * @Route("/duplicateday/{id}/{dayduplicate}/{idRankQuote}", name="reservations_venues_duplicate_day")
  417.      * Duplica un elemento de la cotizacion para el dia siguiente
  418.      */
  419.     public function duplicateDayAction($id$dayduplicate$idRankQuoteEntityManagerInterface $emRequest $request)
  420.     {
  421.         $loungeSimples $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($id);
  422.         $reservax $em->getRepository(Reservation::class)->findOneById($id);
  423.         $vatRepo $em->getRepository(SageVatRates::class);
  424.         /* Usuario logueado */
  425.         $user $this->get('security.token_storage')->getToken()->getUser();
  426.         $user_id $user $user->getId() : null;
  427.         $createdAt = new \DateTime('now');
  428.         $updatedAt = new \DateTime('now');
  429.         $createdBy $user_id;
  430.         $updatedBy $user_id;
  431.         if (!empty($loungeSimples)) {
  432.             foreach ($loungeSimples as $item) {
  433.                 if (
  434.                     $item->getDateStart() &&
  435.                     $item->getDateStart()->format('d-m-Y') == $dayduplicate &&
  436.                     $item->getRankQuote() == $idRankQuote
  437.                 ) {
  438.                     // Se duplica y suma un día (sin mutar el original)
  439.                     $newLoungeSimple = new ReservationLoungeSimple();
  440.                     $newLoungeSimple->setDateStart((clone $item->getDateStart())->modify('+1 day'));
  441.                     $newLoungeSimple->setDateEnd((clone $item->getDateEnd())->modify('+1 day'));
  442.                     $newLoungeSimple->setHourStart($item->getHourStart());
  443.                     $newLoungeSimple->setHourEnd($item->getHourEnd());
  444.                     $newLoungeSimple->setMinStart($item->getMinStart());
  445.                     $newLoungeSimple->setMinEnd($item->getMinEnd());
  446.                     $newLoungeSimple->setIdLounge($item->getIdLounge());
  447.                     $newLoungeSimple->setIdReservation($item->getIdReservation());
  448.                     $newLoungeSimple->setLoungeName($item->getLoungeName());
  449.                     $newLoungeSimple->setPax($item->getPax());
  450.                     $newLoungeSimple->setServicePrice($item->getServicePrice());
  451.                     // IVA (string)
  452.                     $newLoungeSimple->setIva($item->getIva());
  453.                     // Relación SageVatRates (entidad)
  454.                     $vatEntity method_exists($item'getSageIva') ? $item->getSageIva() : null;
  455.                     if (!$vatEntity) {
  456.                         $rawRate $item->getIva();
  457.                         if ($rawRate !== null && $rawRate !== '') {
  458.                             $rate = (float) $rawRate;
  459.                             // Normaliza si en BD está como fracción (0.21)
  460.                             if ($rate 1) {
  461.                                 $rate $rate 100;
  462.                             }
  463.                             // Ajusta 'rate' si tu campo en SageVatRates tiene otro nombre
  464.                             $vatEntity $vatRepo->findOneBy(['rate' => $rate]);
  465.                         }
  466.                     }
  467.                     $newLoungeSimple->setSageIva($vatEntity);
  468.                     $newLoungeSimple->setOpIva($item->getOpIva());
  469.                     $newLoungeSimple->setType($item->getType());
  470.                     $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
  471.                     $newLoungeSimple->setImportantDescription($item->getImportantDescription());
  472.                     $newLoungeSimple->setImportantDescGeneralText($item->getImportantDescGeneralText());
  473.                     $newLoungeSimple->setImportantDescSchedules($item->getImportantDescSchedules());
  474.                     $newLoungeSimple->setImportantDescParking($item->getImportantDescParking());
  475.                     $newLoungeSimple->setRankQuote($idRankQuote);
  476.                     $newLoungeSimple->setCreatedAt($createdAt);
  477.                     $newLoungeSimple->setCreatedBy($createdBy);
  478.                     $newLoungeSimple->setUpdatedAt($updatedAt);
  479.                     $newLoungeSimple->setUpdatedBy($updatedBy);
  480.                     try {
  481.                         $em->persist($newLoungeSimple);
  482.                         $em->flush();
  483.                         $event 'The Item has been duplicated.';
  484.                         $successMessage $this->translator->trans($event);
  485.                         $this->addFlash('mensajereservation'$successMessage);
  486.                     } catch (\Exception $e) {
  487.                         $event 'An error occurred: ' $e->getMessage();
  488.                         $errorMessage $this->translator->trans($event);
  489.                         $this->addFlash('mensajereservationerror'$errorMessage);
  490.                     }
  491.                     // Actualiza fechas de la reserva si procede
  492.                     $boolReserva false;
  493.                     if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()) {
  494.                         $reservax->setDateStart($newLoungeSimple->getDateStart());
  495.                         $boolReserva true;
  496.                     }
  497.                     if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()) {
  498.                         $reservax->setDateEnd($newLoungeSimple->getDateEnd());
  499.                         $boolReserva true;
  500.                     }
  501.                     if ($boolReserva) {
  502.                         $em->persist($reservax);
  503.                         $em->flush();
  504.                     }
  505.                 }
  506.             }
  507.         } else {
  508.             // Registro antiguo: transformar a los nuevos y luego duplicar
  509.             $loungeOld $em->getRepository(ReservationLounge::class)->findByIdReservation($id);
  510.             foreach ($loungeOld as $item) {
  511.                 if ($item->getDateStart()->format('Y-m-d') == $item->getDateEnd()->format('Y-m-d')) {
  512.                     // Mismo día → simple
  513.                     $newLoungeSimple = new ReservationLoungeSimple();
  514.                     $newLoungeSimple->setDateStart(clone $item->getDateStart());
  515.                     $newLoungeSimple->setDateEnd(clone $item->getDateEnd());
  516.                     $newLoungeSimple->setHourStart($item->getHourStart());
  517.                     $newLoungeSimple->setHourEnd($item->getHourEnd());
  518.                     $newLoungeSimple->setMinStart($item->getMinStart());
  519.                     $newLoungeSimple->setMinEnd($item->getMinEnd());
  520.                     $newLoungeSimple->setIdLounge($item->getIdLounge());
  521.                     $newLoungeSimple->setIdReservation($item->getIdReservation());
  522.                     $newLoungeSimple->setLoungeName($item->getLoungeName());
  523.                     $newLoungeSimple->setPax($item->getPax());
  524.                     $newLoungeSimple->setServicePrice($item->getServicePrice());
  525.                     // IVA (string)
  526.                     $newLoungeSimple->setIva($item->getIva());
  527.                     // Resolver SageVatRates desde el string
  528.                     $rawRate $item->getIva();
  529.                     $vatEnt null;
  530.                     if ($rawRate !== null && $rawRate !== '') {
  531.                         $rate = (float) $rawRate;
  532.                         if ($rate 1) {
  533.                             $rate $rate 100;
  534.                         }
  535.                         $vatEnt $vatRepo->findOneBy(['rate' => $rate]);
  536.                     }
  537.                     $newLoungeSimple->setSageIva($vatEnt);
  538.                     $newLoungeSimple->setOpIva($item->getOpIva());
  539.                     $newLoungeSimple->setType($item->getType());
  540.                     $newLoungeSimple->setRankQuote($item->getRankQuote());
  541.                     $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
  542.                     $newLoungeSimple->setImportantDescription($item->getImportantDescription());
  543.                     $newLoungeSimple->setCreatedAt($createdAt);
  544.                     $newLoungeSimple->setCreatedBy($createdBy);
  545.                     $newLoungeSimple->setUpdatedAt($updatedAt);
  546.                     $newLoungeSimple->setUpdatedBy($updatedBy);
  547.                     try {
  548.                         $em->persist($newLoungeSimple);
  549.                         $em->flush();
  550.                         $event 'The Item has been duplicated.';
  551.                         $successMessage $this->translator->trans($event);
  552.                         $this->addFlash('mensajereservation'$successMessage);
  553.                     } catch (\Exception $e) {
  554.                         $event 'An error occurred: ' $e->getMessage();
  555.                         $errorMessage $this->translator->trans($event);
  556.                         $this->addFlash('mensajereservationerror'$errorMessage);
  557.                     }
  558.                     // Actualiza fechas de la reserva si procede
  559.                     $boolReserva false;
  560.                     if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()) {
  561.                         $reservax->setDateStart($newLoungeSimple->getDateStart());
  562.                         $boolReserva true;
  563.                     }
  564.                     if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()) {
  565.                         $reservax->setDateEnd($newLoungeSimple->getDateEnd());
  566.                         $boolReserva true;
  567.                     }
  568.                     if ($boolReserva) {
  569.                         $em->persist($reservax);
  570.                         $em->flush();
  571.                     }
  572.                 } else {
  573.                     // Varios días → trocear en simples
  574.                     $firstDay = new \DateTime($item->getDateStart()->format('Y-m-d'));
  575.                     $lastDay = new \DateTime($item->getDateEnd()->format('Y-m-d'));
  576.                     $numDays = ($lastDay->diff($firstDay))->days 1;
  577.                     $actualDay = clone $item->getDateStart();
  578.                     $actualStartDay = clone $item->getDateStart();
  579.                     $actualEndDay = clone $item->getDateEnd();
  580.                     for ($i 0$i $numDays$i++) {
  581.                         $newLoungeSimple = new ReservationLoungeSimple();
  582.                         if ($i === 0) {
  583.                             // Primer día
  584.                             $newLoungeSimple->setDateStart(clone $actualStartDay);
  585.                             $newLoungeSimple->setDateEnd(new \DateTime($actualStartDay->format('Y-m-d') . ' 23:59'));
  586.                             $newLoungeSimple->setHourStart($item->getHourStart());
  587.                             $newLoungeSimple->setHourEnd('23');
  588.                             $newLoungeSimple->setMinStart($item->getMinStart());
  589.                             $newLoungeSimple->setMinEnd('59');
  590.                         } elseif (($i 1) === $numDays) {
  591.                             // Último día
  592.                             $newLoungeSimple->setDateStart(new \DateTime($actualEndDay->format('Y-m-d') . ' 00:00'));
  593.                             $newLoungeSimple->setDateEnd(clone $actualEndDay);
  594.                             $newLoungeSimple->setHourStart('00');
  595.                             $newLoungeSimple->setHourEnd($item->getHourEnd());
  596.                             $newLoungeSimple->setMinStart('00');
  597.                             $newLoungeSimple->setMinEnd($item->getMinEnd());
  598.                         } else {
  599.                             // Día intermedio
  600.                             $newLoungeSimple->setDateStart(new \DateTime($actualDay->format('Y-m-d') . ' 00:00'));
  601.                             $newLoungeSimple->setDateEnd(new \DateTime($actualDay->format('Y-m-d') . ' 23:59'));
  602.                             $newLoungeSimple->setHourStart('00');
  603.                             $newLoungeSimple->setHourEnd('23');
  604.                             $newLoungeSimple->setMinStart('00');
  605.                             $newLoungeSimple->setMinEnd('59');
  606.                         }
  607.                         $newLoungeSimple->setIdLounge($item->getIdLounge());
  608.                         $newLoungeSimple->setIdReservation($item->getIdReservation());
  609.                         $newLoungeSimple->setLoungeName($item->getLoungeName());
  610.                         $newLoungeSimple->setPax($item->getPax());
  611.                         $newLoungeSimple->setServicePrice($item->getServicePrice());
  612.                         // IVA (string) + entidad
  613.                         $newLoungeSimple->setIva($item->getIva());
  614.                         $rawRate $item->getIva();
  615.                         $vatEnt null;
  616.                         if ($rawRate !== null && $rawRate !== '') {
  617.                             $rate = (float) $rawRate;
  618.                             if ($rate 1) {
  619.                                 $rate $rate 100;
  620.                             }
  621.                             $vatEnt $vatRepo->findOneBy(['rate' => $rate]);
  622.                         }
  623.                         $newLoungeSimple->setSageIva($vatEnt);
  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.                         // Avanza el día (sin perder la referencia)
  634.                         $actualDay = (clone $actualDay)->modify('+1 day');
  635.                         try {
  636.                             $em->persist($newLoungeSimple);
  637.                             $em->flush();
  638.                             $event 'The Item has been updated.';
  639.                             $successMessage $this->translator->trans($event);
  640.                             $this->addFlash('mensajereservation'$successMessage);
  641.                         } catch (\Exception $e) {
  642.                             $event 'An error occurred: ' $e->getMessage();
  643.                             $errorMessage $this->translator->trans($event);
  644.                             $this->addFlash('mensajereservationerror'$errorMessage);
  645.                         }
  646.                         // Actualiza fechas de la reserva si procede
  647.                         $boolReserva false;
  648.                         if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()) {
  649.                             $reservax->setDateStart($newLoungeSimple->getDateStart());
  650.                             $boolReserva true;
  651.                         }
  652.                         if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()) {
  653.                             $reservax->setDateEnd($newLoungeSimple->getDateEnd());
  654.                             $boolReserva true;
  655.                         }
  656.                         if ($boolReserva) {
  657.                             $em->persist($reservax);
  658.                             $em->flush();
  659.                         }
  660.                     }
  661.                 }
  662.                 // Re-llama al mismo controlador ahora con la nueva tabla poblada
  663.                 return $this->redirectToRoute('reservations_venues_duplicate_day', [
  664.                     'id' => $id,
  665.                     'dayduplicate' => $dayduplicate,
  666.                 ]);
  667.             }
  668.         }
  669.         //Se llama al servicio para crear la entrada en la agenda y actualizar el Pax de la agenda
  670.         $agenda $this->agendaService->createAgendaFromSource($newLoungeSimple->getIdReservation(), 'SALAS A UTILIZAR'nullnull$newLoungeSimple->getDateStart(), $newLoungeSimple->getDateEnd(), $newLoungeSimple->getLoungeName(), $newLoungeSimple->getId(), 'ReservationLoungeSimple'$updatedBy);
  671.         $reserva $em->getRepository(Reservation::class)->findOneById($newLoungeSimple->getIdReservation());
  672.         //Se llama al servicio para crear la entrada en la agenda de las fechas
  673.         $agenda $this->agendaService->updateDatesLine($reserva->getId(), $updatedBy);
  674.         // Creamos la Snapshot de las salas y servicios del sistema (LOG)
  675.         $version $this->venueService->createSnapshot($reservax);
  676.         /* Obtengo usuario logueado */
  677.         $user $this->get('security.token_storage')->getToken()->getUser();
  678.         // Sincronizar contratos si está confirmado
  679.         if ($reservax->getStatus() === 'Confirmed') {
  680.             $this->docContractService->autoAssignContracts($reservax$user);
  681.         }
  682.         // Redirige para agregar Servicio de limpieza
  683.         return $this->redirectToRoute('reservations_white_addservices_cleaning', [
  684.             'resid' => $id,
  685.             'loungesimpleid' => isset($newLoungeSimple) ? $newLoungeSimple->getId() : null,
  686.         ]);
  687.     }
  688.     /**
  689.      * @Route("/deleteitemsimple/{id}/{daydelete}", name="reservations_venues_delete_simple_lounge")
  690.      * Elimina un Reservation Simple Lounge de la cotizacion
  691.      */
  692.     public function deleteSimpleLoungeAction($id$daydeleteEntityManagerInterface $emRequest $request)
  693.     {
  694.         $loungeSimple $em->getRepository(ReservationLoungeSimple::class)->findOneById($id);
  695.         if (!empty($loungeSimple)) {
  696.             //Se llama al servicio para eliminar la entrada en la agenda
  697.             $agenda $this->agendaService->deleteAgendaBySource($loungeSimple->getId(), 'ReservationLoungeSimple');
  698.         }
  699.         $id $loungeSimple->getIdReservation();
  700.         $reserva $em->getRepository(Reservation::class)->findOneById($loungeSimple->getIdReservation());
  701.         try {
  702.             $em->remove($loungeSimple);
  703.             $em->flush();
  704.             $event 'The item has been deleted.';
  705.             $successMessage $this->translator->trans($event);
  706.             $this->addFlash('mensajereservation'$successMessage);
  707.         } catch (\Exception $e) {
  708.             $event 'An error occurred: ' $e->getMessage();
  709.             $errorMessage $this->translator->trans($event);
  710.             $this->addFlash('mensajereservationerror'$errorMessage);
  711.         }
  712.         /* Obtengo usuario logueado */
  713.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  714.         // Recalcular fechas de la reserva usando el servicio
  715.         if ($reserva) {
  716.             $this->reservationService->updateReservationDates($reserva);
  717.             
  718.             // Sincronizar contratos si está confirmado
  719.             if ($reserva->getStatus() === 'Confirmed') {
  720.                 $this->docContractService->autoAssignContracts($reserva$user_logueado);
  721.             }
  722.         }
  723.         $user_id $user_logueado->getId();
  724.         //Se llama al servicio para crear la entrada en la agenda de las fechas
  725.         $agenda $this->agendaService->updateDatesLine($reserva->getId(), $user_id);
  726.         //Se llama al servicio para actualizar Pax en la agenda
  727.         $paxAge $this->agendaService->calculatePaxForReservation($reserva->getId());
  728.         $agenda $this->agendaService->updatePaxLine($reserva->getId(), $paxAge$user_id);
  729.         // Se elimina el servicio de horas de limpieza de la sala
  730.         return $this->redirectToRoute(
  731.             'reservations_venues_delete_simple_lounge_cleaning',
  732.             array(
  733.                 'idRes' => $id,
  734.                 'idLng' => $loungeSimple->getIdLounge(),
  735.                 'dateInAt' => $loungeSimple->getDateStart()->format('Y-m-d\TH:i'),
  736.                 'dateOutAt' => $loungeSimple->getDateEnd()->format('Y-m-d\TH:i'),
  737.             )
  738.         );
  739.     }
  740.     /**
  741.      * @Route("/deletequote/{idRes}/{idQuote}", name="reservations_delete_quote")
  742.      * Eliminar una cotizancion
  743.      */
  744.     public function deleteQuoteAction($idRes$idQuoteEntityManagerInterface $emRequest $request)
  745.     {
  746.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  747.         $reservation $qb->where('r.rankQuote = :rankQuote')
  748.             ->andWhere('r.idReservation = :idReservation')
  749.             ->setParameter('idReservation'$idRes)
  750.             ->setParameter('rankQuote'$idQuote)
  751.             ->getQuery()
  752.             ->getResult();
  753.         foreach ($reservation as $item) {
  754.             try {
  755.                 if (!empty($item)) {
  756.                     //Se llama al servicio para eliminar la entrada en la agenda
  757.                     $agenda $this->agendaService->deleteAgendaBySource($item->getId(), 'ReservationLoungeSimple');
  758.                 }
  759.                 $em->remove($item);
  760.                 $em->flush();
  761.                 $event 'Se ha eliminado la cotización';
  762.                 $successMessage $this->translator->trans($event);
  763.                 $this->addFlash('mensajereservation'$successMessage);
  764.             } catch (\Exception $e) {
  765.                 $event 'An error occurred: ' $e->getMessage();
  766.                 $errorMessage $this->translator->trans($event);
  767.                 $this->addFlash('mensajereservationerror'$errorMessage);
  768.             }
  769.             //Se deben eliminar todas las horas de limpieza asociadas a las salas de la cotización
  770.             $loungeDetails $em->getRepository(ReservationLoungeDetails::class)->findOneById($item->getIdLounge());
  771.             $stringName 'HORAS ( ' $loungeDetails->getName() . ' )';
  772.             $serviceCatIdClean 21;
  773.             $dateInAt = new \DateTime($item->getDateStart()->format('Y-m-d\TH:i'));
  774.             $dateOutAt = new \DateTime($item->getDateEnd()->format('Y-m-d\TH:i'));
  775.             $qb $em->getRepository(ReservationService::class)->createQueryBuilder('rs');
  776.             $serviceClean $qb->where('rs.reservationId = :id')
  777.                 ->andWhere('rs.name = :name')
  778.                 ->andWhere('rs.dateInAt = :dateInAt')
  779.                 ->andWhere('rs.dateOutAt = :dateOutAt')
  780.                 ->andWhere('rs.serviceCatId = :serviceCatId')
  781.                 ->setParameter('id'$idRes)
  782.                 ->setParameter('name'$stringName)
  783.                 ->setParameter('dateInAt'$dateInAt)
  784.                 ->setParameter('dateOutAt'$dateOutAt)
  785.                 ->setParameter('serviceCatId'$serviceCatIdClean)
  786.                 ->getQuery()
  787.                 ->getResult();
  788.             if (!empty($serviceClean)) {
  789.                 // Se elimina el servicio de horas de limpieza de la sala
  790.                 $em->remove($serviceClean[0]);
  791.                 $em->flush();
  792.             }
  793.         }
  794.         /* Obtengo usuario logueado */
  795.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  796.         $user_id $user_logueado->getId();
  797.         //Se llama al servicio para actualizar Pax en la agenda
  798.         $paxAge $this->agendaService->calculatePaxForReservation($idRes);
  799.         $agenda $this->agendaService->updatePaxLine($idRes$paxAge$user_id);
  800.         //Se llama al servicio para actualizar Fechas en la agenda
  801.         $agenda $this->agendaService->updateDatesLine($idRes$user_id);
  802.         // Recalcular fechas de la reserva
  803.         $reservaEntity $em->getRepository(Reservation::class)->find($idRes);
  804.         if ($reservaEntity) {
  805.             $this->reservationService->updateReservationDates($reservaEntity);
  806.         }
  807.         return $this->redirectToRoute(
  808.             'reservations_venues_edit_simple',
  809.             array(
  810.                 'id' => $idRes,
  811.                 'token' => null,
  812.                 '_fragment' => 'btn_quotes'
  813.             )
  814.         );
  815.     }
  816.     /**
  817.      * @Route("/checkquote/{idRes}/{idQuote}", name="reservations_check_quote")
  818.      * Confirmación de que se ha aceptado la cotizancion, se eliminaran las otras cotizaciones del expediente
  819.      */
  820.     public function checkQuoteAction($idRes$idQuoteEntityManagerInterface $emRequest $request)
  821.     {
  822.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  823.         $reservation $qb->where('r.rankQuote <> :rankQuote')
  824.             ->andWhere('r.idReservation = :idReservation')
  825.             ->setParameter('idReservation'$idRes)
  826.             ->setParameter('rankQuote'$idQuote)
  827.             ->getQuery()
  828.             ->getResult();
  829.         foreach ($reservation as $item) {
  830.             try {
  831.                 if (!empty($item)) {
  832.                     //Se llama al servicio para eliminar la entrada en la agenda
  833.                     $agenda $this->agendaService->deleteAgendaBySource($item->getId(), 'ReservationLoungeSimple');
  834.                 }
  835.                 $em->remove($item);
  836.                 $em->flush();
  837.                 $event 'Se han eliminado las otras cotizaciones';
  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.         }
  846.         // Actualizar fechas de la reserva usando el servicio
  847.         $reservation $em->getRepository(Reservation::class)->findOneById($idRes);
  848.         $this->reservationService->updateReservationDates($reservation);
  849.         /* Obtengo usuario logueado */
  850.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  851.         $user_id $user_logueado->getId();
  852.         //Se llama al servicio para actualizar Pax en la agenda
  853.         $paxAge $this->agendaService->calculatePaxForReservation($idRes);
  854.         $agenda $this->agendaService->updatePaxLine($idRes$paxAge$user_id);
  855.         //Se llama al servicio para actualizar Fechas en la agenda
  856.         $agenda $this->agendaService->updateDatesLine($idRes$user_id);
  857.         return $this->redirectToRoute(
  858.             'reservations_venues_edit_simple',
  859.             array(
  860.                 'id' => $idRes,
  861.                 'token' => null,
  862.                 '_fragment' => 'btn_quotes'
  863.             )
  864.         );
  865.     }
  866.     /**
  867.      * @Route("/duplicatequote", name="reservations_duplicate_quote")
  868.      * Duplicar una cotizacion
  869.      */
  870.     public function duplicateQuoteAction(EntityManagerInterface $emRequest $request)
  871.     {
  872.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  873.         $user_id $user_logueado->getId();
  874.         $hoy = new \DateTime("now"NULL);
  875.         $reqDuplicateQuote $request->request->get('addquote');
  876.         $newLounge $em->getRepository(ReservationLoungeDetails::class)->findOneById($reqDuplicateQuote['salaPrecargadas']);
  877.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  878.         $reservationAll $qb->where('r.idReservation = :idReservation')
  879.             ->setParameter('idReservation'$reqDuplicateQuote['reservationId'])
  880.             ->orderBy('r.rankQuote''ASC')
  881.             ->getQuery()
  882.             ->getResult();
  883.         $newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
  884.         if (empty($reqDuplicateQuote['idQuote'])) {
  885.             $reqDuplicateQuote['idQuote'] = reset($reservationAll)->getRankQuote();
  886.         }   //Si no elige cotización se duplica la primera
  887.         $qb $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
  888.         $reservation $qb->where('r.rankQuote = :rankQuote')
  889.             ->andWhere('r.idReservation = :idReservation')
  890.             ->setParameter('idReservation'$reqDuplicateQuote['reservationId'])
  891.             ->setParameter('rankQuote'$reqDuplicateQuote['idQuote'])
  892.             ->getQuery()
  893.             ->getResult();
  894.         // Descripciones web por sala/idioma con fallbacks
  895.         $loungeProfile $newLounge;
  896.         // Heredar idioma si existe alguna sala previa en la reserva
  897.         $idioma = empty($reservationAll) ? 1$reservationAll[0]->getLanguage();
  898.         $loungeWebDescriptionRepo $em->getRepository(ReservationLoungeWebDescription::class);
  899.         $loungeWebDescription $loungeWebDescriptionRepo->findOneBy([
  900.                 'lounge' => $loungeProfile,
  901.                 'language' => $idioma
  902.             ]) ?? ($idioma !== $loungeWebDescriptionRepo->findOneBy([
  903.                 'lounge' => $loungeProfile,
  904.                 'language' => 1
  905.             ]) : null) ?? $loungeWebDescriptionRepo->findOneBy(['lounge' => $loungeProfile]);
  906.         $loungeImportantDescGeneralText $loungeWebDescription $loungeWebDescription->getImportantDescGeneralText() : '';
  907.         $loungeImportantDescSchedules $loungeWebDescription $loungeWebDescription->getImportantDescSchedules() : '';
  908.         $loungeImportantDescParking $loungeWebDescription $loungeWebDescription->getImportantDescParking() : '';
  909.         $loungeSummaryDescription $loungeWebDescription $loungeWebDescription->getImportantDescription() : '';
  910.         foreach ($reservation as $item) {
  911.             $newLoungeSimple = new ReservationLoungeSimple();
  912.             $newLoungeSimple->setDateStart($item->getDateStart());
  913.             $newLoungeSimple->setDateEnd($item->getDateEnd());
  914.             $newLoungeSimple->setIdReservation($reqDuplicateQuote['reservationId']);
  915.             $newLoungeSimple->setPax($item->getPax());
  916.             $newLoungeSimple->setType($item->getType());
  917.             $newLoungeSimple->setCreatedAt($hoy);
  918.             $newLoungeSimple->setCreatedBy($user_id);
  919.             $newLoungeSimple->setUpdatedAt($hoy);
  920.             $newLoungeSimple->setUpdatedBy($user_id);
  921.             $newLoungeSimple->setHourStart($item->getHourStart());
  922.             $newLoungeSimple->setMinStart($item->getMinStart());
  923.             $newLoungeSimple->setHourEnd($item->getHourEnd());
  924.             $newLoungeSimple->setMinEnd($item->getMinEnd());
  925.             $newLoungeSimple->setRankQuote($newRankId);
  926.             $newLoungeSimple->setIva($item->getIva());
  927.             $newLoungeSimple->setOpIva($item->getOpIva());
  928.             $newLoungeSimple->setIdLounge($newLounge->getId());
  929.             $newLoungeSimple->setLoungename($newLounge->getName());
  930.             //            $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
  931.             $newLoungeSimple->setImportantDescription($loungeSummaryDescription);
  932.             $newLoungeSimple->setImportantDescGeneralText($loungeImportantDescGeneralText);
  933.             $newLoungeSimple->setImportantDescSchedules($loungeImportantDescSchedules);
  934.             $newLoungeSimple->setImportantDescParking($loungeImportantDescParking);
  935.             $newLoungeSimple->setLanguage($item->getLanguage());
  936.             $newLoungeSimple->setSageArticle($item->getSageArticle());
  937.             $newLoungeSimple->setSentToSage($item->isSentToSage());
  938.             $newLoungeSimple->setSageIva($item->getSageIva());
  939.             if (!empty($reqDuplicateQuote['salaPrice'])) {
  940.                 $newLoungeSimple->setServicePrice($reqDuplicateQuote['salaPrice']);
  941.             } else {
  942.                 $newLoungeSimple->setServicePrice($item->getServicePrice());
  943.             }
  944.             try {
  945.                 $em->persist($newLoungeSimple);
  946.                 $em->flush();
  947.                 $event 'Se ha agregado la nueva cotización';
  948.                 $successMessage $this->translator->trans($event);
  949.                 $this->addFlash('mensajereservation'$successMessage);
  950.             } catch (\Exception $e) {
  951.                 $event 'An error occurred: ' $e->getMessage();
  952.                 $errorMessage $this->translator->trans($event);
  953.                 $this->addFlash('mensajereservationerror'$errorMessage);
  954.             }
  955.             //Se llama al servicio para crear la entrada en la agenda
  956.             $agenda $this->agendaService->createAgendaFromSource(
  957.                 $newLoungeSimple->getIdReservation(),
  958.                 'SALAS A UTILIZAR',
  959.                 null,
  960.                 null,
  961.                 $newLoungeSimple->getDateStart(),
  962.                 $newLoungeSimple->getDateEnd(),
  963.                 $newLoungeSimple->getLoungename(),
  964.                 $newLoungeSimple->getId(),
  965.                 'ReservationLoungeSimple',
  966.                 $newLoungeSimple->getUpdatedBy()
  967.             );
  968.             // Se debe agregar el servicio de limpieza por cada sala que se agregue
  969.             $resLoungeSimple $newLoungeSimple;
  970.             $service = new ReservationService();
  971.             $service->setReservationId($reqDuplicateQuote['reservationId']);
  972.             $service->setSupplierId(0);
  973.             $service->setDateInAt($resLoungeSimple->getDateStart());
  974.             $service->setDateOutAt($resLoungeSimple->getDateEnd());
  975.             /* Obtengo usuario logueado */
  976.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  977.             $user_id $user_logueado->getId();
  978.             $service->setCreatedId($user_id);
  979.             $service->setUpdatedId($user_id);
  980.             $service->setCreatedAt(new \DateTime("now"));
  981.             $service->setUpdatedAt(new \DateTime("now"));
  982.             $service->setServiceCatId('21');
  983.             $service->setServiceCatName('Limpieza');
  984.             $service->setContcolor('green-300');
  985.             $service->setName('HORAS ( ' $resLoungeSimple->getLoungeName() . ' )');
  986.             $service->setPrice('14');
  987.             $service->setCurrency('Euro');
  988.             $service->setUnits('8');
  989.             $service->setCommission('0');
  990.             $service->setPax('0');
  991.             $service->setOver('0');
  992.             $service->setIva('21');
  993.             $service->setOpIva('1');
  994.             $service->setOpCommission('1');
  995.             $service->setCommission('57.14');
  996.             $service->setViewInfo(0);
  997.             $service->setToinvoice(0);
  998.             $service->setServiceId(0);
  999. //            $em->persist($service);
  1000. //            $em->flush();
  1001.         }
  1002.         $reserva $em->getRepository(Reservation::class)->findOneById($reqDuplicateQuote['reservationId']);
  1003.         // Creamos la Snapshot de las salas y servicios del sistema (LOG)
  1004.         $version $this->venueService->createSnapshot($reserva);
  1005.         return $this->redirectToRoute(
  1006.             'reservations_venues_edit_simple',
  1007.             array(
  1008.                 'id' => $reqDuplicateQuote['reservationId'],
  1009.                 'token' => null,
  1010.                 '_fragment' => 'btn_quotes'
  1011.             )
  1012.         );
  1013.     }
  1014.     /**
  1015.      * @Route("/loghistoric/{id}", name="reservations_log_historic")
  1016.      * Log del historico de la cotizacion de la reserva id
  1017.      */
  1018.     public function logHistoricQuoteAction($idEntityManagerInterface $emRequest $request){
  1019.         $reservaLogs $em->getRepository(ReservationLoungeSimpleServiceLog::class)->findByReservaId($id);
  1020.         return $this->render(
  1021.             'MDS/VenuesBundle/reservations/list-reservations-log-historic.html.twig',
  1022.             array(
  1023.                 'id' => $id,
  1024.                 'reservaLogs' => $reservaLogs,
  1025.             )
  1026.         );
  1027.     }
  1028.     /**
  1029.      * @Route("/logrecover/{reservationId}/{versionId}", name="reservations_log_recover")
  1030.      * Recuperar desde Log de historico una versión de una reserva. Se eliminaran salas y servicios del expediente no facturados
  1031.      */
  1032.     public function logRecoverQuoteAction($reservationId$versionIdEntityManagerInterface $emRequest $request){
  1033.         $reservaLogs $em->getRepository(ReservationLoungeSimpleServiceLog::class)->findBy(array('reservaId' => $reservationId'version' => $versionId));
  1034.         $reservationsLounges $em->getRepository(ReservationLoungeSimple::class)->findBy(array('idReservation' => $reservationId));
  1035.         $reservationsLoungesInvoiced $em->getRepository(ReservationInvoiceItems::class)->findBy(array('reservationId' => $reservationId'itemType' => 'LOUNGE'));
  1036.         $reservationsServices $em->getRepository(ReservationService::class)->findBy(array('reservationId' => $reservationId));
  1037.         $reservationsServicesInvoiced $em->getRepository(ReservationInvoiceItems::class)->findBy(array('reservationId' => $reservationId'itemType' => 'SERVICE'));
  1038.         $sageIva $em->getRepository(SageVatRates::class)->findOneBySageCode('03');
  1039.         /* Obtengo usuario logueado */
  1040.         $user $this->get('security.token_storage')->getToken()->getUser();
  1041.         // 1. Obtener los IDs de los items que SÍ están facturados
  1042.         $invoicedLoungeIds = [];
  1043.         foreach ($reservationsLoungesInvoiced as $invoiceLounge) {
  1044.             $invoicedLoungeIds[] = $invoiceLounge->getLngControlId();
  1045.         }
  1046.         $invoicedServiceIds = [];
  1047.         foreach ($reservationsServicesInvoiced as $invoiceService) {
  1048.             $invoicedServiceIds[] = $invoiceService->getSrvControlId();
  1049.         }
  1050.         // 2. Eliminar los Lounges (Salas) que NO están facturados
  1051.         foreach ($reservationsLounges as $lounge) {
  1052.             if (!in_array($lounge->getId(), $invoicedLoungeIds)) {
  1053.                 $em->remove($lounge);
  1054.             }
  1055.         }
  1056.         // 2.1 Eliminar los Servicios que NO están facturados
  1057.         foreach ($reservationsServices as $service) {
  1058.             if (!in_array($service->getId(), $invoicedServiceIds)) {
  1059.                 $em->remove($service);
  1060.             }
  1061.         }
  1062.         // 3. Generar las nuevas entidades a partir del Log
  1063.         foreach ($reservaLogs as $log) {
  1064.             if ($log->getItemType() === 'lounge') {
  1065.                 $newLounge = new ReservationLoungeSimple();
  1066.                 $newLounge->setIdReservation($log->getReservaId());
  1067.                 $newLounge->setIdLounge($log->getIdLounge());
  1068.                 $newLounge->setLoungeName($log->getItemName());
  1069.                 $newLounge->setDateStart($log->getDateStart());
  1070.                 $newLounge->setDateEnd($log->getDateEnd());
  1071.                 $newLounge->setPax($log->getPax());
  1072.                 $newLounge->setRankQuote($log->getRankQuote());
  1073.                 $newLounge->setServicePrice((string)$log->getPrice());
  1074.                 $newLounge->setSageIva($sageIva);
  1075.                 $newLounge->setCreatedBy($log->getAgentId());
  1076.                 $newLounge->setUpdatedBy($log->getAgentId());
  1077.                 // Mapear el desglose de horas para la sala
  1078.                 if ($log->getDateStart()) {
  1079.                     $newLounge->setHourStart($log->getDateStart()->format('H'));
  1080.                     $newLounge->setMinStart($log->getDateStart()->format('i'));
  1081.                 }
  1082.                 if ($log->getDateEnd()) {
  1083.                     $newLounge->setHourEnd($log->getDateEnd()->format('H'));
  1084.                     $newLounge->setMinEnd($log->getDateEnd()->format('i'));
  1085.                 }
  1086.                 $loungeProfile $em->getRepository(ReservationLoungeDetails::class)->findOneById($log->getIdLounge());
  1087.                 $idioma 1;
  1088.                 // Descripciones web por sala/idioma con fallbacks
  1089.                 $loungeWebDescriptionRepo $em->getRepository(ReservationLoungeWebDescription::class);
  1090.                 $loungeWebDescription $loungeWebDescriptionRepo->findOneBy([
  1091.                         'lounge' => $loungeProfile,
  1092.                         'language' => $idioma
  1093.                     ]) ?? ($idioma !== $loungeWebDescriptionRepo->findOneBy([
  1094.                         'lounge' => $loungeProfile,
  1095.                         'language' => 1
  1096.                     ]) : null) ?? $loungeWebDescriptionRepo->findOneBy(['lounge' => $loungeProfile]);
  1097.                 $loungeSummaryDescription null;
  1098.                 $loungeImportantDescGeneralText $loungeWebDescription $loungeWebDescription->getImportantDescGeneralText() : '';
  1099.                 $loungeImportantDescSchedules $loungeWebDescription $loungeWebDescription->getImportantDescSchedules() : '';
  1100.                 $loungeImportantDescParking $loungeWebDescription $loungeWebDescription->getImportantDescParking() : '';
  1101.                 $loungeSummaryDescription $loungeWebDescription $loungeWebDescription->getImportantDescription() : '';
  1102.                 $newLounge->setImportantDescription($loungeSummaryDescription ?? '');
  1103.                 $newLounge->setImportantDescGeneralText($loungeImportantDescGeneralText ?? '');
  1104.                 $newLounge->setImportantDescSchedules($loungeImportantDescSchedules ?? '');
  1105.                 $newLounge->setImportantDescParking($loungeImportantDescParking ?? '');
  1106.                 $em->persist($newLounge);
  1107.             } elseif ($log->getItemType() === 'service') {
  1108.                 $newService = new ReservationService();
  1109.                 $newService->setReservationId($log->getReservaId());
  1110.                 $newService->setServiceId($log->getItemId());
  1111.                 $newService->setName($log->getItemName());
  1112.                 $newService->setPrice((string)$log->getPrice());
  1113.                 $newService->setPax((string)$log->getPax());
  1114.                 $newService->setDateInAt($log->getDateStart());
  1115.                 $newService->setDateOutAt($log->getDateEnd());
  1116.                 // Mapeo específico de servicios
  1117.                 $newService->setUnits($log->getUnits() ?? '1');
  1118.                 $newService->setOpCommission($log->getOpCommission());
  1119.                 $newService->setCommission($log->getCommission() ?? '0');
  1120.                 $newService->setOver($log->getPriceOver());
  1121.                 $newService->setToinvoice($log->getToinvoice());
  1122.                 $newService->setViewInfo($log->getViewInfo() ?? false);
  1123.                 $newService->setServiceCatId($log->getServiceCatId());
  1124.                 $newService->setServiceCatName($log->getServiceCatName());
  1125.                 $newService->setCreatedId($user->getId());
  1126.                 $newService->setUpdatedId($user->getId());
  1127.                 $newService->setSageIva($sageIva);
  1128.                 $newService->setIva(21);
  1129.                 if ($log->getDateStart()) {
  1130.                     $newService->setHour($log->getDateStart()->format('H:i'));
  1131.                 }
  1132.                 // VALORES POR DEFECTO REQUERIDOS
  1133.                 $newService->setSupplierId(0);
  1134.                 $newService->setContcolor('#000000');
  1135.                 $em->persist($newService);
  1136.             }
  1137.         }
  1138.         // 4. Ejecutar todas las eliminaciones e inserciones en la BBDD
  1139.         $em->flush();
  1140.         return $this->redirectToRoute(
  1141.             'reservations_venues_edit_simple',
  1142.             array(
  1143.                 'id' => $reservationId,
  1144.                 'token' => null,
  1145.                 '_fragment' => 'btn_quotes'
  1146.             )
  1147.         );
  1148.     }
  1149.     /**
  1150.      * @Route("/productfileavlist/{id}",  name="reservations_list_multiple_productfile_av")
  1151.      * Listar productos de Av para agregar en el servicio id
  1152.      */
  1153.     public function listMultipleProductAvAction$idRequest $request){
  1154.         $em $this->getDoctrine()->getManager();
  1155.         $parameters = [];
  1156.         $dql 'SELECT i
  1157.                 FROM AvexpressBundle:AveProduct i
  1158.                 ORDER BY i.name ASC';
  1159.         $query $em->createQuery($dql)->setParameters($parameters);
  1160.         $avs $query->getResult();
  1161.         $dql 'SELECT i
  1162.                 FROM AvexpressBundle:AvePackageTemplate i
  1163.                 ORDER BY i.name ASC';
  1164.         $query $em->createQuery($dql)->setParameters($parameters);
  1165.         $avsPack $query->getResult();
  1166.         $data_av = [];
  1167.         foreach ($avsPack as $item) {
  1168.             $productNames = [];
  1169.             $parameters = ['packId' => $item->getId()];
  1170.             $dql 'SELECT i
  1171.                 FROM AvexpressBundle:AvePackageTemplateItems i
  1172.                 WHERE i.packId = :packId
  1173.                 ORDER BY i.rankAvPack ASC';
  1174.             $query $em->createQuery($dql)->setParameters($parameters);
  1175.             $avsPackProducts $query->getResult();
  1176.             foreach ($avsPackProducts as $product) { $productNames[] = $product->getProductName(); }
  1177.             $packageName $item->getName();
  1178.             if (!empty($productNames)) { $packageName .= ' (' implode(', '$productNames) . ')'; }
  1179.             $data_av[] = array(
  1180.                 'id'    => $item->getId(),
  1181.                 'name'  => $packageName,
  1182.                 'type'  => 'Paquete',
  1183.                 'price' => $item->getPricePackage(),
  1184.             );
  1185.         }
  1186.         foreach($avs as $av){
  1187.             $data_av[] = array(
  1188.                 'id' => $av->getId(),
  1189.                 'name' => $av->getName(),
  1190.                 'type' => $av->getType(),
  1191.                 'price' => $av->getPrice(),
  1192.             );
  1193.         }
  1194.         $resService $em->getRepository(ReservationService::class)->findOneById($id);
  1195.         return $this->render('MDS/VenuesBundle/reservations/add-services-avs.html.twig',
  1196.             array(
  1197.                 'id' => $id,
  1198.                 'idRes' => empty($resService) ? $resService->getReservationId(),
  1199.                 'avs' => $data_av,
  1200.             ));
  1201.     }
  1202.     /**
  1203.      * @Route("/productfileavadd/{id}",  name="reservations_add_multiple_productfile_av")
  1204.      * Agregar productos de Av para agregar en el servicio id
  1205.      */
  1206.     public function addMultipleProductAvAction$idRequest $request){
  1207.         $em $this->getDoctrine()->getManager();
  1208.         $resService $em->getRepository(ReservationService::class)->findOneById($id);
  1209.         $prodSelected $request->request->get('details');
  1210.         $serviceName '';
  1211.         $servicePrice 0;
  1212.         foreach ($prodSelected as $item){
  1213.             if(empty($serviceName)){
  1214.                 $serviceName .= $item['name'];
  1215.             } else {
  1216.                 $serviceName .= ' + '$item['name'];
  1217.             }
  1218.             $servicePrice += $item['total_price'];
  1219.         }
  1220.         $resService->setName($serviceName);
  1221.         $resService->setPrice($servicePrice);
  1222.         $resService->setToInvoice(1);
  1223.         $resService->setOpIva(1);
  1224.         $resService->setIva(21);
  1225.         try {
  1226.             $em->persist($resService);
  1227.             $em->flush();
  1228.             $event 'The Reservation has been updated.';
  1229.             $successMessage $this->translator->trans($event);
  1230.             $this->addFlash('mensajereservation'$successMessage);
  1231.         } catch (\Exception $e) {
  1232.             $event 'An error occurred: ' $e->getMessage();
  1233.             $errorMessage $this->translator->trans($event);
  1234.             $this->addFlash('mensajereservationerror'$errorMessage);
  1235.         }
  1236.         return $this->redirectToRoute('reservations_venues_edit_simple', [
  1237.             'id' => $resService->getReservationId(),
  1238.             'token' => null,
  1239.             '_fragment' => 'btn_srv'
  1240.         ]);
  1241.     }
  1242.     /**
  1243.      * @Route("/reschedule/{reservationId}/{newDate}", name="reservations_reschedule", methods={"POST"})
  1244.      * Reprogramar todas las fechas del evento, incluido reservations, reservationLoungeSimple y reservationService
  1245.      */
  1246.     public function rescheduleQuoteAction($reservationId$newDateEntityManagerInterface $emRequest $request)
  1247.     {
  1248.         try {
  1249.             $reservation $em->getRepository(Reservation::class)->find($reservationId);
  1250.             if (!$reservation) {
  1251.                 return new JsonResponse(['status' => 'error''message' => 'Reserva no encontrada.'], 404);
  1252.             }
  1253.             $oldStartDate $reservation->getDateStart();
  1254.             if (!$oldStartDate) {
  1255.                 return new JsonResponse(['status' => 'error''message' => 'La reserva actual no tiene una fecha de inicio configurada.'], 400);
  1256.             }
  1257.             // Establecemos las horas a las 00:00:00 para calcular los días exactos sin afectar los husos horarios
  1258.             $oldStartMidnight = clone $oldStartDate;
  1259.             $oldStartMidnight->setTime(000);
  1260.             $newStartMidnight = new \DateTime($newDate);
  1261.             $newStartMidnight->setTime(000);
  1262.             // Calculamos la diferencia en días
  1263.             $interval $oldStartMidnight->diff($newStartMidnight);
  1264.             $daysDiff $interval->days;
  1265.             $invert $interval->invert// 1 si la fecha nueva es pasada, 0 si es futura
  1266.             if ($daysDiff === 0) {
  1267.                 return new JsonResponse(['status' => 'error''message' => 'La fecha seleccionada es igual a la actual.'], 400);
  1268.             }
  1269.             // Función anónima para aplicar la suma/resta de días a una fecha conservando su hora original
  1270.             $applyInterval = function(?\DateTime $date) use ($daysDiff$invert) {
  1271.                 if (!$date) return null;
  1272.                 $clonedDate = clone $date;
  1273.                 $intervalStr 'P' $daysDiff 'D'// P[N]D = Period N Days
  1274.                 if ($invert) {
  1275.                     $clonedDate->sub(new \DateInterval($intervalStr));
  1276.                 } else {
  1277.                     $clonedDate->add(new \DateInterval($intervalStr));
  1278.                 }
  1279.                 return $clonedDate;
  1280.             };
  1281.             // 1. Reprogramar la Reserva
  1282.             // Asignamos la nueva fecha (preservando la hora del inicio antiguo, si tuviera alguna)
  1283.             $reservation->setDateStart($applyInterval($reservation->getDateStart()));
  1284.             if ($reservation->getDateEnd()) {
  1285.                 $reservation->setDateEnd($applyInterval($reservation->getDateEnd()));
  1286.             }
  1287.             // 2. Reprogramar las Salas (ReservationLoungeSimple)
  1288.             $lounges $em->getRepository(ReservationLoungeSimple::class)->findBy(['idReservation' => $reservationId]);
  1289.             foreach ($lounges as $lounge) {
  1290.                 $lounge->setDateStart($applyInterval($lounge->getDateStart()));
  1291.                 $lounge->setDateEnd($applyInterval($lounge->getDateEnd()));
  1292.             }
  1293.             // 3. Reprogramar los Servicios (ReservationService)
  1294.             $services $em->getRepository(ReservationService::class)->findBy(['reservationId' => $reservationId]);
  1295.             foreach ($services as $service) {
  1296.                 $service->setDateInAt($applyInterval($service->getDateInAt()));
  1297.                 $service->setDateOutAt($applyInterval($service->getDateOutAt()));
  1298.             }
  1299.             $em->flush();
  1300.             // Creamos la Snapshot de las salas y servicios del sistema (LOG)
  1301.             $version $this->venueService->createSnapshot($reservation);
  1302.             return new JsonResponse([
  1303.                 'status' => 'success',
  1304.                 'message' => 'Las fechas del evento han sido reprogramadas correctamente.'
  1305.             ]);
  1306.         } catch (\Exception $e) {
  1307.             return new JsonResponse([
  1308.                 'status' => 'error',
  1309.                 'message' => 'Ocurrió un error en el servidor: ' $e->getMessage()
  1310.             ], 500);
  1311.         }
  1312.     }
  1313.     /**
  1314.      * @Route("/registerFormGpWeb/{token}", name="registerformgpweb", defaults={"token"=null})
  1315.      * Crear una reserva con la información que llega desde la web
  1316.      * Crear la sala segun los datos ingresados
  1317.      * Generar un modelo de correo electronico para enviar la propuesta de cotización al cliente
  1318.      */
  1319.     public function registerFormWebApiAction($tokenRequest $requestEntityManagerInterface $em)
  1320.     {
  1321.         // ==========================================
  1322.         // 0. VALIDACIONES DE USUARIO Y RESERVA
  1323.         // ==========================================
  1324.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1325.         if (!($user_logueado)){
  1326.             return $this->redirectToRoute('login');
  1327.         } else {
  1328.             $user_id $user_logueado->getId();
  1329.         }
  1330.         $reservaPrevia $em->getRepository(Reservation::class)->findOneByToken($token);
  1331.         if (!empty($reservaPrevia)){
  1332.             // Ya se ha creado la reserva previamente
  1333.             return $this->redirectToRoute('reservations_venues_edit_simple', array(
  1334.                 'id' => $reservaPrevia->getId(),
  1335.                 'token' => null,
  1336.                 '_fragment' => null
  1337.             ));
  1338.         }
  1339.         // ==========================================
  1340.         // 1. DESCIFRAR Y VALIDAR EL TOKEN
  1341.         // ==========================================
  1342.         if (empty($token)) {
  1343.             $this->addFlash('mensajereservationerror''No se ha proporcionado ningún token en la URL.');
  1344.             // Ajusta la ruta de retorno en caso de error
  1345.             return $this->redirectToRoute('reservations_greenpatio_index');
  1346.         }
  1347.         $base64Key 'x4BMAcZUEQLNWgLB4NRHprTyySUZtcs4F1FCn9EKwJ4=';
  1348.         $key base64_decode($base64Key);
  1349.         $parts explode('.'$token);
  1350.         if (count($parts) !== || $parts[0] !== 'v1') {
  1351.             $this->addFlash('mensajereservationerror''El formato del token no es válido.');
  1352.             return $this->redirectToRoute('reservations_greenpatio_index');
  1353.         }
  1354.         // Función auxiliar para decodificar Base64 URL-safe
  1355.         $base64UrlDecode = function($data) {
  1356.             $remainder strlen($data) % 4;
  1357.             if ($remainder) {
  1358.                 $data .= str_repeat('='$remainder);
  1359.             }
  1360.             return base64_decode(strtr($data'-_''+/'));
  1361.         };
  1362.         $iv         $base64UrlDecode($parts[1]);
  1363.         $tag        $base64UrlDecode($parts[2]);
  1364.         $ciphertext $base64UrlDecode($parts[3]);
  1365.         $aad        'greenpatio-register-v1';
  1366.         // Descifrar usando AES-256-GCM
  1367.         $decrypted openssl_decrypt(
  1368.             $ciphertext,
  1369.             'aes-256-gcm',
  1370.             $key,
  1371.             OPENSSL_RAW_DATA,
  1372.             $iv,
  1373.             $tag,
  1374.             $aad
  1375.         );
  1376.         if ($decrypted === false) {
  1377.             $this->addFlash('mensajereservationerror''No se pudo descifrar la información del token.');
  1378.             return $this->redirectToRoute('reservations_greenpatio_index');
  1379.         }
  1380.         $data json_decode($decryptedtrue);
  1381.         if (json_last_error() !== JSON_ERROR_NONE) {
  1382.             $this->addFlash('mensajereservationerror''El token no contiene datos válidos.');
  1383.             return $this->redirectToRoute('reservations_greenpatio_index');
  1384.         }
  1385.         // Opcional: Validar fecha de expiración si viene en el token
  1386.         if (isset($data['expiresAt']) && time() > $data['expiresAt']) {
  1387.             $this->addFlash('mensajereservationerror''El enlace de reserva ha expirado.');
  1388.             return $this->redirectToRoute('reservations_greenpatio_index');
  1389.         }
  1390.         // ==========================================
  1391.         // 2. EXTRAER LAS VARIABLES DEL TOKEN
  1392.         // ==========================================
  1393.         $yourName         $data['name'] ?? '';
  1394.         $yourPhone        $data['phone'] ?? '';
  1395.         $yourEmail        $data['email'] ?? '';
  1396.         $yourReferral     $data['referral'] ?? '';
  1397.         $eventDateString  $data['eventDate'] ?? 'now';
  1398.         $yourEventDate    \DateTime::createFromFormat('d/m/Y'trim($eventDateString));
  1399.         $yourAttendees    $data['attendees'] ?? null;
  1400.         $eventSpace       $data['eventSpace'] ?? '';
  1401.         $yourEventDetails $data['eventDetails'] ?? '';
  1402.         // ==========================================
  1403.         // 3. CREAMOS LA RESERVA
  1404.         // ==========================================
  1405.         $hoy = new \DateTime("now"NULL);
  1406.         $reserva = new Reservation();
  1407.         $reserva->setTitle('Reserva ingresada en la web para el día: '$yourEventDate->format('d/m/Y'));
  1408.         $reserva->setClient(null);
  1409.         $reserva->setCreatedAt($hoy);
  1410.         $reserva->setPriority(1);
  1411. //        $reserva->setDateStart(new \DateTime('2078-01-01'));
  1412.         $reserva->setDateStart($yourEventDate);
  1413. //        $reserva->setDateEnd(new \DateTime('2000-01-01'));
  1414.         $reserva->setDateEnd($yourEventDate);
  1415.         $reserva->setCreatedBy($user_id);
  1416.         $reserva->setSupplier(4765);        // Higo&Trigo
  1417.         $reserva->setStatus('Iniciado');
  1418.         $reserva->setUpdatedAt($hoy);
  1419.         $reserva->setUpdatedBy($user_id);
  1420.         $reserva->setDaysBlock(7);
  1421.         if (!empty($yourAttendees) and is_numeric($yourAttendees)){ $reserva->setPax($yourAttendees); } else { $reserva->setPax(null); }
  1422.         $reserva->setAccessKey(null);
  1423.         $reserva->setClientContact(null);
  1424.         $reserva->setContactUnregistered($yourEmail);       // Desde la web es requerido
  1425.         $reserva->setDays(null);
  1426.         $reserva->setContract(null);
  1427.         if (!empty($yourName)){ $reserva->setNameContactUnregistered($yourName); } else { $reserva->setNameContactUnregistered(null); }
  1428.         if (!empty($yourPhone)){ $reserva->setPhoneContactUnregistered($yourPhone); } else { $reserva->setPhoneContactUnregistered(null); }
  1429.         $reserva->setToken($token);
  1430.         $reserva->setComAvGp(null);
  1431.         $reserva->setComHtGp(null);
  1432.         $reserva->setInfoFormWeb($yourEmail .' || '$yourReferral .' || '$yourEventDate->format('d/m/Y') .' || '$yourName .' || '$yourPhone .' || '$yourAttendees .' || '$eventSpace);
  1433.         if (!empty($yourEventDetails)){ $reserva->setDescription($yourEventDetails); } else { $reserva->setDescription(null); }
  1434.         // --- Generamos la info del correo electronico y la agregamos a la descripción para que el agente copie y pegue
  1435.         $nombreArray explode(' 'trim($yourName));
  1436.         $primerNombre $nombreArray[0];
  1437.         // Definimos las URLs de los enlaces
  1438. //        $urlProposal = "https://cotizacion.greenpatio.es/index.php?token=" . $reserva->getToken();
  1439.         $urlProposal "https://develup.solutions/cotizacion/?token=" $reserva->getToken();
  1440.         $urlLegends "https://drive.google.com/file/d/1_zc43gcvyajig-VRJyNXfe-0E8bhhQGZ/view";
  1441.         $urlCatering "https://drive.google.com/drive/folders/1ihGR2yGWGgdtJeRsAI5LoUuEqkApAcXU";
  1442.         // Construimos el HTML en la variable $xMail
  1443.         $xMail = <<<HTML
  1444. <div style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #222222; line-height: 1.6;">
  1445.     <p style="margin: 0;">{$yourEmail}</p>
  1446.     <p style="margin: 0; margin-bottom: 20px;">PÁGINA WEB GREEN PATIO - Espacios</p>
  1447.     <p>Hola {$primerNombre}, ¡un placer de saludarte!</p>
  1448.     <p><em>A continuación te dejo el link con las opciones disponibles para la fecha solicitada:</em></p>
  1449.     
  1450.     <p style="padding-left: 40px; margin-bottom: 20px;">
  1451.         <strong><em style="color: #5b9e43; font-size: 16px;">CLICK AQUÍ --&gt;:</em></strong> 
  1452.         <a href="{$urlProposal}" style="color: #1155cc; font-size: 18px; text-decoration: underline;">PROPOSAL</a>
  1453.     </p>
  1454.     
  1455.     <p><strong style="text-decoration: underline;"><em>HACER CLICK para ver los <span style="color: #5b9e43;">"DOSSIERES"</span> de los espacios:</em></strong></p>
  1456.     <ul style="margin-top: 5px; margin-bottom: 20px;">
  1457.         <li><a href="{$urlLegends}" style="color: #1155cc; font-weight: bold; text-decoration: underline;">LEGENDS BY GREEN PATIO</a></li>
  1458.     </ul>
  1459.     
  1460.     <p><strong style="text-decoration: underline;"><em>PROVEEDORES EN EXCLUSIVA:</em></strong></p>
  1461.     <ul style="margin-top: 5px; margin-bottom: 20px;">
  1462.         <li><a href="{$urlCatering}" style="color: #1155cc; font-weight: bold; text-decoration: underline;">Catering Higo &amp; Trigo</a> - Te lo cotizamos desde Green Patio</li>
  1463.         <li><strong>AV EXPRESS</strong> - Te lo cotiza directamente: Salvador Guerrero: <a href="tel:620956367" style="color: #222222; text-decoration: none;">620956367</a> // <a href="mailto:salvador@avexpress.tv" style="color: #222222; text-decoration: none;">salvador@avexpress.tv</a></li>
  1464.     </ul>
  1465.     
  1466.     <p><strong><span style="color: #5b9e43; text-decoration: underline;">IMPORTANTE:</span></strong></p>
  1467.     <ul style="margin-top: 5px; margin-bottom: 25px;">
  1468.         <li>Todas nuestras condiciones, horarios, y demás información están en la parte de <strong><span style="color: #5b9e43;">"IMPORTANTE"</span></strong> en el link enviado (justo debajo del precio de cada sala).</li>
  1469.         <li>Dada la demanda de dicha fecha, en caso de desear bloqueo de la sala, será bloqueo en opción compartida, es decir: para el primer cliente que reserve en firme.</li>
  1470.     </ul>
  1471.     
  1472.     <p>Cualquier cosita no dudes en decirme,</p>
  1473.     <p>Quedo atenta y mil gracias nuevamente!</p>
  1474. </div>
  1475. HTML;
  1476.         $reserva->setMailToClient($xMail);
  1477.         try{
  1478.             $em->persist($reserva);
  1479.             $em->flush();
  1480.             $event 'The Reservation has been updated.';
  1481.             $successMessage $this->translator->trans($event);
  1482.             $this->addFlash('mensajereservation'$successMessage);
  1483.         } catch (\Exception $e){
  1484.             $event 'An error occurred: '.$e->getMessage();
  1485.             $errorMessage $this->translator->trans($event);
  1486.             $this->addFlash('mensajereservationerror'$errorMessage);
  1487.         }
  1488.         $id $reserva->getId();
  1489.         // Normalizamos el texto antes del switc para el caso del guión largo
  1490.         $eventSpace str_replace('–''-'$eventSpace);
  1491.         switch ($eventSpace) {
  1492.             case 'La Imprenta - Sala Plenaria'$simpleLounge 2; break;
  1493.             case 'La Imprenta - Invernadero'$simpleLounge 39; break;
  1494.             case 'La Imprenta - Escenario'$simpleLounge 40; break;
  1495.             case 'La Imprenta - Sala Cristal'$simpleLounge 13; break;
  1496.             case "La Imprenta - L'Atelier"$simpleLounge 14; break;
  1497.             case 'Covarrubias The One - Sala White'$simpleLounge 24; break;
  1498.             case 'Covarrubias The One - Sala Black'$simpleLounge 25; break;
  1499.             case 'Sala 25'$simpleLounge 19; break;
  1500.             case 'Lima Rooms'$simpleLounge 3; break;
  1501.             case 'Espacio Legends'$simpleLounge 42; break;
  1502.             default: $simpleLounge 0; break;
  1503.         }
  1504.         $loungeDetails $em->getRepository(ReservationLoungeDetails::class)->findOneById($simpleLounge);
  1505.         $loungeId $loungeDetails->getId();
  1506.         $previusLoungeSimple null;
  1507.         $anyLoungeSimple null;
  1508.         $idioma 1;
  1509.         if($anyLoungeSimple){
  1510.             $idioma $anyLoungeSimple->getLanguage();
  1511.         }
  1512.         $loungeWebDescription $em->getRepository(ReservationLoungeWebDescription::class)->findOneBy(array('lounge' => $simpleLounge'language' => $idioma));
  1513.         $loungeName $loungeDetails->getName();
  1514.         $loungeSummaryDescription null;
  1515.         if (empty($previusLoungeSimple)) {
  1516.             if (empty($loungeSummaryDescription)) { $loungeSummaryDescription = empty($loungeWebDescription) ? null $loungeWebDescription->getImportantDescription(); }
  1517.             $loungeImportantDescGeneralText = empty($loungeWebDescription) ? null $loungeWebDescription->getImportantDescGeneralText();
  1518.             $loungeImportantDescSchedules = empty($loungeWebDescription) ? null $loungeWebDescription->getImportantDescSchedules();
  1519.             $loungeImportantDescParking = empty($loungeWebDescription) ? null $loungeWebDescription->getImportantDescParking();
  1520.         }
  1521.         $iva 21;
  1522.         $newRankId 1;
  1523.         $hourStart '12'$minStart '00'$hourMinStart '12:00';
  1524.         $hourEnd '20'$minEnd '00'$hourMinEnd '20:00';
  1525.         $dateStart = clone $yourEventDate; [$hour$minute] = explode(':'$hourMinStart); $dateStart->setTime((int)$hour, (int)$minute);
  1526.         $dateEnd = clone $yourEventDate; [$hour$minute] = explode(':'$hourMinEnd); $dateEnd->setTime((int)$hour, (int)$minute);
  1527.         $servicePrice 0;
  1528.         $idReservation $id;
  1529.         $createdAt = new DateTime('now');
  1530.         $createdBy $user_id;
  1531.         $updatedAt = new DateTime('now');
  1532.         $updatedBy $user_id;
  1533.         $pax = empty($yourAttendees) ? $yourAttendees;
  1534.         $lounge = new ReservationLoungeSimple();
  1535.         $lounge->setIdLounge ($loungeId);
  1536.         $lounge->setHourStart ($hourStart);
  1537.         $lounge->setMinStart ($minStart);
  1538.         $lounge->setHourEnd ($hourEnd);
  1539.         $lounge->setMinEnd ($minEnd);
  1540.         $lounge->setLoungeName ($loungeName);
  1541.         $lounge->setDateStart ($dateStart);
  1542.         $lounge->setDateEnd ($dateEnd);
  1543.         $lounge->setRankQuote(1);
  1544.         $lounge->setIdReservation ($idReservation);
  1545.         $lounge->setIva($iva);
  1546.         $lounge->setOpIva(1);
  1547.         $lounge->setCreatedAt ($createdAt);
  1548.         $lounge->setCreatedBy ($createdBy);
  1549.         $lounge->setUpdatedAt ($updatedAt);
  1550.         $lounge->setUpdatedBy ($updatedBy);
  1551.         $lounge->setPax ($pax);
  1552.         $lounge->setRankQuote($newRankId);
  1553.         $sageVatRate $em->getRepository(SageVatRates::class)->findOneBy([ 'sageCode' => '03' ]);
  1554.         $lounge->setSageIva($sageVatRate);         // Iva de Sage al 21%
  1555.         $lounge->setImportantDescription($loungeSummaryDescription);
  1556.         $lounge->setImportantDescGeneralText($loungeImportantDescGeneralText);
  1557.         $lounge->setImportantDescSchedules($loungeImportantDescSchedules);
  1558.         $lounge->setImportantDescParking($loungeImportantDescParking);
  1559.         $price $this->precioTarifario($dateStart$loungeId$servicePrice);
  1560.         $lounge->setServicePrice($price);
  1561.         try{
  1562.             $em->persist($lounge);
  1563.             $em->flush();
  1564.             $event 'The Reservation has been updated.';
  1565.             $successMessage $this->translator->trans($event);
  1566.             $this->addFlash('mensajereservation'$successMessage);
  1567.         } catch (\Exception $e){
  1568.             $event 'An error occurred: '.$e->getMessage();
  1569.             $errorMessage $this->translator->trans($event);
  1570.             $this->addFlash('mensajereservationerror'$errorMessage);
  1571.         }
  1572.         // Agregar el servicio de limpieza
  1573.         $service = new ReservationService();
  1574.         $service->setReservationId($idReservation);
  1575.         $service->setSupplierId(0);
  1576.         $service->setDateInAt($lounge->getDateStart());
  1577.         $service->setDateOutAt($lounge->getDateEnd());
  1578.         $service->setCreatedId($user_id);
  1579.         $service->setUpdatedId($user_id);
  1580.         $service->setCreatedAt(new \DateTime("now"));
  1581.         $service->setUpdatedAt(new \DateTime("now"));
  1582.         $service->setServiceCatId('21');
  1583.         $service->setServiceCatName('Limpieza');
  1584.         $service->setContcolor('green-300');
  1585.         $service->setName('HORAS ( '.$lounge->getLoungeName().' )');
  1586.         $service->setPrice('14');
  1587.         $service->setCurrency('Euro');
  1588.         $service->setUnits('8');
  1589.         $service->setCommission('0');
  1590.         $service->setPax('0');
  1591.         $service->setOver('0');
  1592.         // Busco la reserva para saber si es sucoe o no
  1593.         // $sucoe = $reserva->isSucoe();
  1594.         // Sino es sucoe, cogemos el IVA del 21
  1595.         // if(! $sucoe) {
  1596.         //      $sageVatRate = $em->getRepository(SageVatRates::class)->findOneBy(['sageCode' => '03']);
  1597.         // } else {
  1598.         //      $sageVatRate = $em->getRepository(SageVatRates::class)->findOneBy(['sageCode' => '00']);
  1599.         // }
  1600.         $sageArticle null;
  1601.         // Si el módulo de Sage está activo, buscamos el artículo. Si no, lo dejamos en null y se mostrará un error en la vista.
  1602.         // if ($this->session->get('_config')['msage']) {
  1603.         //      $sageArticle = $em->getRepository(SageArticle::class)->findOneBy(['vatType' => $sageVatRate, 'name' => $service->getServiceCatName()]);
  1604.         //      Si no se ha encontrado el artículo de Sage.
  1605.         //      if (empty($sageArticle)) {
  1606.         //          $this->addFlash('mensajereservationerror', 'No se ha encontrado el artículo de Sage para el servicio: ' . $service->getServiceCatName() . '. No se ha podido crear el servicio para la sala.');
  1607.         //      }
  1608.         // }
  1609.         // $service->setSageIva($sageVatRate);
  1610.         $service->setOpIva('1');
  1611.         $service->setOpCommission('1');
  1612.         $service->setCommission('57.14');
  1613.         $service->setViewInfo(0);
  1614.         $service->setToinvoice(0);
  1615.         $service->setServiceId(0);
  1616.         // Vincular el artículo de Sage al servicio
  1617.         // $service->setSageArticle($sageArticle);
  1618.         $em->persist($service);
  1619.         $em->flush();
  1620.         // Sincronización con HT
  1621.         if (!empty($reserva)) {
  1622.             if (in_array($reserva->getStatus(), [null'''Confirmed''Invoiced''Iniciado''Cotizado''Bloqueo'])) {
  1623. //                if ($reserva->getCateringName() == 'HIGO & TRIGO, S.L.') {
  1624.                     $htFile $em->getRepository(HtFile::class)->findByReservation($reserva);
  1625.                     if (empty($htFile)) { return $this->redirectToRoute('sinc_gp_ht', array('id' => $id,)); }
  1626. //                }
  1627.             }
  1628.         }
  1629.         // Sincronización con AV
  1630.         if (!empty($reserva)) {
  1631.             if (in_array($reserva->getStatus(), [null'''Confirmed''Invoiced''Iniciado''Cotizado''Bloqueo'])) {
  1632.                 $aveFile $em->getRepository(AveFiles::class)->findByReservation($reserva);
  1633.                 if (empty($aveFile)) { return $this->redirectToRoute('sinc_gp_ave', array('id' => $id,)); }
  1634.             }
  1635.         }
  1636.         return $this->redirectToRoute('reservations_venues_edit_simple', array(
  1637.             'id' => $id,
  1638.             'token' => null,
  1639.             '_fragment' => 'btn_quotes'
  1640.         ));
  1641.     }
  1642.     private function precioPorFecha($date$loungeId)
  1643.     {
  1644.         return array('price' => 0, );
  1645.         $em $this->getDoctrine()->getManager();
  1646.         $price0 null;
  1647.         // Buscamos por año
  1648.         $parameters = array('dateYear' => $date->format('Y'), 'loungeId' => $loungeId'priceIsActive' => true, );
  1649.         $dql 'SELECT i
  1650.                 FROM VenuesBundle:ReservationLoungeProfile i
  1651.                 WHERE  ((i.year1 <= :dateYear and i.year2 >= :dateYear) ) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive';
  1652.         $query $em->createQuery($dql)->setParameters($parameters);
  1653.         $price1 $query->getResult();
  1654.         // Buscamos por año y mes
  1655.         $parameters = array('dateYear' => $date->format('Y'), 'month' => true'loungeId' => $loungeId'priceIsActive' => true, );
  1656.         switch ($date->format('m')) {
  1657.             case '01'//Enero
  1658.                 $dql 'SELECT i
  1659.                     FROM VenuesBundle:ReservationLoungeProfile i
  1660.                     WHERE (
  1661.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1662.                           AND (i.month1 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1663.                       ';
  1664.                 break;
  1665.             case '02'//Febrero
  1666.                 $dql 'SELECT i
  1667.                     FROM VenuesBundle:ReservationLoungeProfile i
  1668.                     WHERE (
  1669.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1670.                           AND (i.month2 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1671.                       ';
  1672.                 break;
  1673.             case '03'//Marzo
  1674.                 $dql 'SELECT i
  1675.                     FROM VenuesBundle:ReservationLoungeProfile i
  1676.                     WHERE (
  1677.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1678.                           AND (i.month3 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1679.                       ';
  1680.                 break;
  1681.             case '04'//Abril
  1682.                 $dql 'SELECT i
  1683.                     FROM VenuesBundle:ReservationLoungeProfile i
  1684.                     WHERE (
  1685.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1686.                           AND (i.month4 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1687.                       ';
  1688.                 break;
  1689.             case '05'//Mayo
  1690.                 $dql 'SELECT i
  1691.                     FROM VenuesBundle:ReservationLoungeProfile i
  1692.                     WHERE (
  1693.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1694.                           AND (i.month5 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1695.                       ';
  1696.                 break;
  1697.             case '06'//Junio
  1698.                 $dql 'SELECT i
  1699.                     FROM VenuesBundle:ReservationLoungeProfile i
  1700.                     WHERE (
  1701.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1702.                           AND (i.month6 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1703.                       ';
  1704.                 break;
  1705.             case '07'//Julio
  1706.                 $dql 'SELECT i
  1707.                     FROM VenuesBundle:ReservationLoungeProfile i
  1708.                     WHERE (
  1709.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1710.                           AND (i.month7 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1711.                       ';
  1712.                 break;
  1713.             case '08'//Agosto
  1714.                 $dql 'SELECT i
  1715.                     FROM VenuesBundle:ReservationLoungeProfile i
  1716.                     WHERE (
  1717.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1718.                           AND (i.month8 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1719.                       ';
  1720.                 break;
  1721.             case '09'//Septiembre
  1722.                 $dql 'SELECT i
  1723.                     FROM VenuesBundle:ReservationLoungeProfile i
  1724.                     WHERE (
  1725.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1726.                           AND (i.month9 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1727.                       ';
  1728.                 break;
  1729.             case '10'//Octubre
  1730.                 $dql 'SELECT i
  1731.                     FROM VenuesBundle:ReservationLoungeProfile i
  1732.                     WHERE (
  1733.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1734.                           AND (i.month10 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1735.                       ';
  1736.                 break;
  1737.             case '11'//Noviembre
  1738.                 $dql 'SELECT i
  1739.                     FROM VenuesBundle:ReservationLoungeProfile i
  1740.                     WHERE (
  1741.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1742.                           AND (i.month11 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1743.                       ';
  1744.                 break;
  1745.             case '12'//Diciembre
  1746.                 $dql 'SELECT i
  1747.                     FROM VenuesBundle:ReservationLoungeProfile i
  1748.                     WHERE (
  1749.                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1750.                           AND (i.month12 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1751.                       ';
  1752.                 break;
  1753.             default:
  1754.                 break;
  1755.         }
  1756.         $query $em->createQuery($dql)->setParameters($parameters);
  1757.         $price2 $query->getResult();
  1758.         // Buscamos por año, mes y dia de la semana
  1759.         $parameters = array('dateYear' => $date->format('Y'), 'month' => true'day' => true'loungeId' => $loungeId'priceIsActive' => true, );
  1760.         switch ($date->format('m')) {
  1761.             case '01'//Enero
  1762.                 switch ($date->format('l')) {
  1763.                     case 'Monday'//Lunes
  1764.                         $dql 'SELECT i
  1765.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1766.                                     WHERE (
  1767.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1768.                                           AND (i.month1 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1769.                                       ';
  1770.                         break;
  1771.                     case 'Tuesday'//Martes
  1772.                         $dql 'SELECT i
  1773.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1774.                                     WHERE (
  1775.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1776.                                           AND (i.month1 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1777.                                       ';
  1778.                         break;
  1779.                     case 'Wednesday'//Miercoles
  1780.                         $dql 'SELECT i
  1781.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1782.                                     WHERE (
  1783.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1784.                                           AND (i.month1 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1785.                                       ';
  1786.                         break;
  1787.                     case 'Thursday'//Jueves
  1788.                         $dql 'SELECT i
  1789.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1790.                                     WHERE (
  1791.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1792.                                           AND (i.month1 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1793.                                       ';
  1794.                         break;
  1795.                     case 'Friday'//Viernes
  1796.                         $dql 'SELECT i
  1797.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1798.                                     WHERE (
  1799.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1800.                                           AND (i.month1 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1801.                                       ';
  1802.                         break;
  1803.                     case 'Saturday'//Sabado
  1804.                         $dql 'SELECT i
  1805.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1806.                                     WHERE (
  1807.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1808.                                           AND (i.month1 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1809.                                       ';
  1810.                         break;
  1811.                     case 'Sunday'//Domingo
  1812.                         $dql 'SELECT i
  1813.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1814.                                     WHERE (
  1815.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1816.                                           AND (i.month1 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1817.                                       ';
  1818.                         break;
  1819.                     default:
  1820.                         break;
  1821.                 }
  1822.                 break;
  1823.             case '02'//Febrero
  1824.                 switch ($date->format('l')) {
  1825.                     case 'Monday'//Lunes
  1826.                         $dql 'SELECT i
  1827.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1828.                                     WHERE (
  1829.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1830.                                           AND (i.month2 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1831.                                       ';
  1832.                         break;
  1833.                     case 'Tuesday'//Martes
  1834.                         $dql 'SELECT i
  1835.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1836.                                     WHERE (
  1837.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1838.                                           AND (i.month2 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1839.                                       ';
  1840.                         break;
  1841.                     case 'Wednesday'//Miercoles
  1842.                         $dql 'SELECT i
  1843.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1844.                                     WHERE (
  1845.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1846.                                           AND (i.month2 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1847.                                       ';
  1848.                         break;
  1849.                     case 'Thursday'//Jueves
  1850.                         $dql 'SELECT i
  1851.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1852.                                     WHERE (
  1853.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1854.                                           AND (i.month2 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1855.                                       ';
  1856.                         break;
  1857.                     case 'Friday'//Viernes
  1858.                         $dql 'SELECT i
  1859.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1860.                                     WHERE (
  1861.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1862.                                           AND (i.month2 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1863.                                       ';
  1864.                         break;
  1865.                     case 'Saturday'//Sabado
  1866.                         $dql 'SELECT i
  1867.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1868.                                     WHERE (
  1869.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1870.                                           AND (i.month2 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1871.                                       ';
  1872.                         break;
  1873.                     case 'Sunday'//Domingo
  1874.                         $dql 'SELECT i
  1875.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1876.                                     WHERE (
  1877.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1878.                                           AND (i.month2 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1879.                                       ';
  1880.                         break;
  1881.                     default:
  1882.                         break;
  1883.                 }
  1884.                 break;
  1885.             case '03'//Marzo
  1886.                 switch ($date->format('l')) {
  1887.                     case 'Monday'//Lunes
  1888.                         $dql 'SELECT i
  1889.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1890.                                     WHERE (
  1891.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1892.                                           AND (i.month3 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1893.                                       ';
  1894.                         break;
  1895.                     case 'Tuesday'//Martes
  1896.                         $dql 'SELECT i
  1897.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1898.                                     WHERE (
  1899.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1900.                                           AND (i.month3 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1901.                                       ';
  1902.                         break;
  1903.                     case 'Wednesday'//Miercoles
  1904.                         $dql 'SELECT i
  1905.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1906.                                     WHERE (
  1907.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1908.                                           AND (i.month3 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1909.                                       ';
  1910.                         break;
  1911.                     case 'Thursday'//Jueves
  1912.                         $dql 'SELECT i
  1913.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1914.                                     WHERE (
  1915.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1916.                                           AND (i.month3 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1917.                                       ';
  1918.                         break;
  1919.                     case 'Friday'//Viernes
  1920.                         $dql 'SELECT i
  1921.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1922.                                     WHERE (
  1923.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1924.                                           AND (i.month3 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1925.                                       ';
  1926.                         break;
  1927.                     case 'Saturday'//Sabado
  1928.                         $dql 'SELECT i
  1929.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1930.                                     WHERE (
  1931.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1932.                                           AND (i.month3 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1933.                                       ';
  1934.                         break;
  1935.                     case 'Sunday'//Domingo
  1936.                         $dql 'SELECT i
  1937.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1938.                                     WHERE (
  1939.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1940.                                           AND (i.month3 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1941.                                       ';
  1942.                         break;
  1943.                     default:
  1944.                         break;
  1945.                 }
  1946.                 break;
  1947.             case '04'//Abril
  1948.                 switch ($date->format('l')) {
  1949.                     case 'Monday'//Lunes
  1950.                         $dql 'SELECT i
  1951.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1952.                                     WHERE (
  1953.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1954.                                           AND (i.month4 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1955.                                       ';
  1956.                         break;
  1957.                     case 'Tuesday'//Martes
  1958.                         $dql 'SELECT i
  1959.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1960.                                     WHERE (
  1961.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1962.                                           AND (i.month4 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1963.                                       ';
  1964.                         break;
  1965.                     case 'Wednesday'//Miercoles
  1966.                         $dql 'SELECT i
  1967.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1968.                                     WHERE (
  1969.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1970.                                           AND (i.month4 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1971.                                       ';
  1972.                         break;
  1973.                     case 'Thursday'//Jueves
  1974.                         $dql 'SELECT i
  1975.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1976.                                     WHERE (
  1977.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1978.                                           AND (i.month4 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1979.                                       ';
  1980.                         break;
  1981.                     case 'Friday'//Viernes
  1982.                         $dql 'SELECT i
  1983.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1984.                                     WHERE (
  1985.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1986.                                           AND (i.month4 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1987.                                       ';
  1988.                         break;
  1989.                     case 'Saturday'//Sabado
  1990.                         $dql 'SELECT i
  1991.                                     FROM VenuesBundle:ReservationLoungeProfile i
  1992.                                     WHERE (
  1993.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  1994.                                           AND (i.month4 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  1995.                                       ';
  1996.                         break;
  1997.                     case 'Sunday'//Domingo
  1998.                         $dql 'SELECT i
  1999.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2000.                                     WHERE (
  2001.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2002.                                           AND (i.month4 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2003.                                       ';
  2004.                         break;
  2005.                     default:
  2006.                         break;
  2007.                 }
  2008.                 break;
  2009.             case '05'//Mayo
  2010.                 switch ($date->format('l')) {
  2011.                     case 'Monday'//Lunes
  2012.                         $dql 'SELECT i
  2013.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2014.                                     WHERE (
  2015.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2016.                                           AND (i.month5 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2017.                                       ';
  2018.                         break;
  2019.                     case 'Tuesday'//Martes
  2020.                         $dql 'SELECT i
  2021.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2022.                                     WHERE (
  2023.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2024.                                           AND (i.month5 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2025.                                       ';
  2026.                         break;
  2027.                     case 'Wednesday'//Miercoles
  2028.                         $dql 'SELECT i
  2029.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2030.                                     WHERE (
  2031.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2032.                                           AND (i.month5 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2033.                                       ';
  2034.                         break;
  2035.                     case 'Thursday'//Jueves
  2036.                         $dql 'SELECT i
  2037.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2038.                                     WHERE (
  2039.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2040.                                           AND (i.month5 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2041.                                       ';
  2042.                         break;
  2043.                     case 'Friday'//Viernes
  2044.                         $dql 'SELECT i
  2045.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2046.                                     WHERE (
  2047.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2048.                                           AND (i.month5 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2049.                                       ';
  2050.                         break;
  2051.                     case 'Saturday'//Sabado
  2052.                         $dql 'SELECT i
  2053.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2054.                                     WHERE (
  2055.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2056.                                           AND (i.month5 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2057.                                       ';
  2058.                         break;
  2059.                     case 'Sunday'//Domingo
  2060.                         $dql 'SELECT i
  2061.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2062.                                     WHERE (
  2063.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2064.                                           AND (i.month5 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2065.                                       ';
  2066.                         break;
  2067.                     default:
  2068.                         break;
  2069.                 }
  2070.                 break;
  2071.             case '06'//Junio
  2072.                 switch ($date->format('l')) {
  2073.                     case 'Monday'//Lunes
  2074.                         $dql 'SELECT i
  2075.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2076.                                     WHERE (
  2077.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2078.                                           AND (i.month6 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2079.                                       ';
  2080.                         break;
  2081.                     case 'Tuesday'//Martes
  2082.                         $dql 'SELECT i
  2083.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2084.                                     WHERE (
  2085.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2086.                                           AND (i.month6 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2087.                                       ';
  2088.                         break;
  2089.                     case 'Wednesday'//Miercoles
  2090.                         $dql 'SELECT i
  2091.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2092.                                     WHERE (
  2093.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2094.                                           AND (i.month6 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2095.                                       ';
  2096.                         break;
  2097.                     case 'Thursday'//Jueves
  2098.                         $dql 'SELECT i
  2099.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2100.                                     WHERE (
  2101.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2102.                                           AND (i.month6 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2103.                                       ';
  2104.                         break;
  2105.                     case 'Friday'//Viernes
  2106.                         $dql 'SELECT i
  2107.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2108.                                     WHERE (
  2109.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2110.                                           AND (i.month6 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2111.                                       ';
  2112.                         break;
  2113.                     case 'Saturday'//Sabado
  2114.                         $dql 'SELECT i
  2115.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2116.                                     WHERE (
  2117.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2118.                                           AND (i.month6 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2119.                                       ';
  2120.                         break;
  2121.                     case 'Sunday'//Domingo
  2122.                         $dql 'SELECT i
  2123.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2124.                                     WHERE (
  2125.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2126.                                           AND (i.month6 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2127.                                       ';
  2128.                         break;
  2129.                     default:
  2130.                         break;
  2131.                 }
  2132.                 break;
  2133.             case '07'//Julio
  2134.                 switch ($date->format('l')) {
  2135.                     case 'Monday'//Lunes
  2136.                         $dql 'SELECT i
  2137.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2138.                                     WHERE (
  2139.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2140.                                           AND (i.month7 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2141.                                       ';
  2142.                         break;
  2143.                     case 'Tuesday'//Martes
  2144.                         $dql 'SELECT i
  2145.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2146.                                     WHERE (
  2147.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2148.                                           AND (i.month7 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2149.                                       ';
  2150.                         break;
  2151.                     case 'Wednesday'//Miercoles
  2152.                         $dql 'SELECT i
  2153.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2154.                                     WHERE (
  2155.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2156.                                           AND (i.month7 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2157.                                       ';
  2158.                         break;
  2159.                     case 'Thursday'//Jueves
  2160.                         $dql 'SELECT i
  2161.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2162.                                     WHERE (
  2163.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2164.                                           AND (i.month7 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2165.                                       ';
  2166.                         break;
  2167.                     case 'Friday'//Viernes
  2168.                         $dql 'SELECT i
  2169.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2170.                                     WHERE (
  2171.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2172.                                           AND (i.month7 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2173.                                       ';
  2174.                         break;
  2175.                     case 'Saturday'//Sabado
  2176.                         $dql 'SELECT i
  2177.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2178.                                     WHERE (
  2179.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2180.                                           AND (i.month7 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2181.                                       ';
  2182.                         break;
  2183.                     case 'Sunday'//Domingo
  2184.                         $dql 'SELECT i
  2185.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2186.                                     WHERE (
  2187.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2188.                                           AND (i.month7 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2189.                                       ';
  2190.                         break;
  2191.                     default:
  2192.                         break;
  2193.                 }
  2194.                 break;
  2195.             case '08'//Agosto
  2196.                 switch ($date->format('l')) {
  2197.                     case 'Monday'//Lunes
  2198.                         $dql 'SELECT i
  2199.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2200.                                     WHERE (
  2201.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2202.                                           AND (i.month8 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2203.                                       ';
  2204.                         break;
  2205.                     case 'Tuesday'//Martes
  2206.                         $dql 'SELECT i
  2207.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2208.                                     WHERE (
  2209.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2210.                                           AND (i.month8 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2211.                                       ';
  2212.                         break;
  2213.                     case 'Wednesday'//Miercoles
  2214.                         $dql 'SELECT i
  2215.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2216.                                     WHERE (
  2217.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2218.                                           AND (i.month8 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2219.                                       ';
  2220.                         break;
  2221.                     case 'Thursday'//Jueves
  2222.                         $dql 'SELECT i
  2223.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2224.                                     WHERE (
  2225.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2226.                                           AND (i.month8 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2227.                                       ';
  2228.                         break;
  2229.                     case 'Friday'//Viernes
  2230.                         $dql 'SELECT i
  2231.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2232.                                     WHERE (
  2233.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2234.                                           AND (i.month8 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2235.                                       ';
  2236.                         break;
  2237.                     case 'Saturday'//Sabado
  2238.                         $dql 'SELECT i
  2239.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2240.                                     WHERE (
  2241.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2242.                                           AND (i.month8 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2243.                                       ';
  2244.                         break;
  2245.                     case 'Sunday'//Domingo
  2246.                         $dql 'SELECT i
  2247.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2248.                                     WHERE (
  2249.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2250.                                           AND (i.month8 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2251.                                       ';
  2252.                         break;
  2253.                     default:
  2254.                         break;
  2255.                 }
  2256.                 break;
  2257.             case '09'//Septiembre
  2258.                 switch ($date->format('l')) {
  2259.                     case 'Monday'//Lunes
  2260.                         $dql 'SELECT i
  2261.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2262.                                     WHERE (
  2263.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2264.                                           AND (i.month9 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2265.                                       ';
  2266.                         break;
  2267.                     case 'Tuesday'//Martes
  2268.                         $dql 'SELECT i
  2269.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2270.                                     WHERE (
  2271.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2272.                                           AND (i.month9 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2273.                                       ';
  2274.                         break;
  2275.                     case 'Wednesday'//Miercoles
  2276.                         $dql 'SELECT i
  2277.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2278.                                     WHERE (
  2279.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2280.                                           AND (i.month9 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2281.                                       ';
  2282.                         break;
  2283.                     case 'Thursday'//Jueves
  2284.                         $dql 'SELECT i
  2285.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2286.                                     WHERE (
  2287.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2288.                                           AND (i.month9 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2289.                                       ';
  2290.                         break;
  2291.                     case 'Friday'//Viernes
  2292.                         $dql 'SELECT i
  2293.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2294.                                     WHERE (
  2295.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2296.                                           AND (i.month9 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2297.                                       ';
  2298.                         break;
  2299.                     case 'Saturday'//Sabado
  2300.                         $dql 'SELECT i
  2301.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2302.                                     WHERE (
  2303.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2304.                                           AND (i.month9 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2305.                                       ';
  2306.                         break;
  2307.                     case 'Sunday'//Domingo
  2308.                         $dql 'SELECT i
  2309.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2310.                                     WHERE (
  2311.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2312.                                           AND (i.month9 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2313.                                       ';
  2314.                         break;
  2315.                     default:
  2316.                         break;
  2317.                 }
  2318.                 break;
  2319.             case '10'//Octubre
  2320.                 switch ($date->format('l')) {
  2321.                     case 'Monday'//Lunes
  2322.                         $dql 'SELECT i
  2323.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2324.                                     WHERE (
  2325.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2326.                                           AND (i.month10 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2327.                                       ';
  2328.                         break;
  2329.                     case 'Tuesday'//Martes
  2330.                         $dql 'SELECT i
  2331.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2332.                                     WHERE (
  2333.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2334.                                           AND (i.month10 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2335.                                       ';
  2336.                         break;
  2337.                     case 'Wednesday'//Miercoles
  2338.                         $dql 'SELECT i
  2339.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2340.                                     WHERE (
  2341.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2342.                                           AND (i.month10 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2343.                                       ';
  2344.                         break;
  2345.                     case 'Thursday'//Jueves
  2346.                         $dql 'SELECT i
  2347.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2348.                                     WHERE (
  2349.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2350.                                           AND (i.month10 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2351.                                       ';
  2352.                         break;
  2353.                     case 'Friday'//Viernes
  2354.                         $dql 'SELECT i
  2355.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2356.                                     WHERE (
  2357.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2358.                                           AND (i.month10 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2359.                                       ';
  2360.                         break;
  2361.                     case 'Saturday'//Sabado
  2362.                         $dql 'SELECT i
  2363.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2364.                                     WHERE (
  2365.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2366.                                           AND (i.month10 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2367.                                       ';
  2368.                         break;
  2369.                     case 'Sunday'//Domingo
  2370.                         $dql 'SELECT i
  2371.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2372.                                     WHERE (
  2373.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2374.                                           AND (i.month10 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2375.                                       ';
  2376.                         break;
  2377.                     default:
  2378.                         break;
  2379.                 }
  2380.                 break;
  2381.             case '11'//Noviembre
  2382.                 switch ($date->format('l')) {
  2383.                     case 'Monday'//Lunes
  2384.                         $dql 'SELECT i
  2385.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2386.                                     WHERE (
  2387.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2388.                                           AND (i.month11 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2389.                                       ';
  2390.                         break;
  2391.                     case 'Tuesday'//Martes
  2392.                         $dql 'SELECT i
  2393.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2394.                                     WHERE (
  2395.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2396.                                           AND (i.month11 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2397.                                       ';
  2398.                         break;
  2399.                     case 'Wednesday'//Miercoles
  2400.                         $dql 'SELECT i
  2401.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2402.                                     WHERE (
  2403.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2404.                                           AND (i.month11 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2405.                                       ';
  2406.                         break;
  2407.                     case 'Thursday'//Jueves
  2408.                         $dql 'SELECT i
  2409.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2410.                                     WHERE (
  2411.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2412.                                           AND (i.month11 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2413.                                       ';
  2414.                         break;
  2415.                     case 'Friday'//Viernes
  2416.                         $dql 'SELECT i
  2417.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2418.                                     WHERE (
  2419.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2420.                                           AND (i.month11 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2421.                                       ';
  2422.                         break;
  2423.                     case 'Saturday'//Sabado
  2424.                         $dql 'SELECT i
  2425.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2426.                                     WHERE (
  2427.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2428.                                           AND (i.month11 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2429.                                       ';
  2430.                         break;
  2431.                     case 'Sunday'//Domingo
  2432.                         $dql 'SELECT i
  2433.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2434.                                     WHERE (
  2435.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2436.                                           AND (i.month11 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2437.                                       ';
  2438.                         break;
  2439.                     default:
  2440.                         break;
  2441.                 }
  2442.                 break;
  2443.             case '12'//Diciembre
  2444.                 switch ($date->format('l')) {
  2445.                     case 'Monday'//Lunes
  2446.                         $dql 'SELECT i
  2447.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2448.                                     WHERE (
  2449.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2450.                                           AND (i.month12 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2451.                                       ';
  2452.                         break;
  2453.                     case 'Tuesday'//Martes
  2454.                         $dql 'SELECT i
  2455.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2456.                                     WHERE (
  2457.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2458.                                           AND (i.month12 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2459.                                       ';
  2460.                         break;
  2461.                     case 'Wednesday'//Miercoles
  2462.                         $dql 'SELECT i
  2463.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2464.                                     WHERE (
  2465.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2466.                                           AND (i.month12 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2467.                                       ';
  2468.                         break;
  2469.                     case 'Thursday'//Jueves
  2470.                         $dql 'SELECT i
  2471.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2472.                                     WHERE (
  2473.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2474.                                           AND (i.month12 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2475.                                       ';
  2476.                         break;
  2477.                     case 'Friday'//Viernes
  2478.                         $dql 'SELECT i
  2479.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2480.                                     WHERE (
  2481.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2482.                                           AND (i.month12 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2483.                                       ';
  2484.                         break;
  2485.                     case 'Saturday'//Sabado
  2486.                         $dql 'SELECT i
  2487.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2488.                                     WHERE (
  2489.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2490.                                           AND (i.month12 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2491.                                       ';
  2492.                         break;
  2493.                     case 'Sunday'//Domingo
  2494.                         $dql 'SELECT i
  2495.                                     FROM VenuesBundle:ReservationLoungeProfile i
  2496.                                     WHERE (
  2497.                                     ((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
  2498.                                           AND (i.month12 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
  2499.                                       ';
  2500.                         break;
  2501.                     default:
  2502.                         break;
  2503.                 }
  2504.                 break;
  2505.             default:
  2506.                 break;
  2507.         }
  2508.         $query $em->createQuery($dql)->setParameters($parameters);
  2509.         $price3 $query->getResult();
  2510.         foreach ($price3 as $item) {
  2511.             if (empty($price0)) {
  2512.                 $price0 $item;
  2513.             } else {
  2514.                 //Si los precios coinciden en fechas se tomara el que se haya cargado mas reciente en el sistema
  2515.                 if ($item->getCreatedAt() > $price0->getCreatedAt()) {
  2516.                     $price0 $item;
  2517.                 }
  2518.             }
  2519.         }
  2520.         if (empty($price0)) {
  2521.             $price 0;
  2522.         } else {
  2523.             $price $price0->getPrice();
  2524.         }
  2525.         return array('price' => $price, );
  2526.     }
  2527.     /*
  2528.      * Se busca el precio a Sugerir
  2529.      * $dateStart Fecha
  2530.      * $loungeId Id de  la sala
  2531.      * $servicePrice Preciointroducido por elusuario
  2532.      * */
  2533.     private function precioTarifario($dateStart$loungeId$servicePrice)
  2534.     {
  2535.         $em $this->getDoctrine()->getManager();
  2536.         $dateToFind = clone $dateStart;
  2537.         $dateToFind->setTime(000);
  2538.         $parameters = array(
  2539.             'loungeId' => $loungeId,
  2540.             'typePrice' => 'DIARIA',
  2541.             'dateToFind' => $dateToFind,
  2542.         );
  2543.         $dql 'SELECT p
  2544.                 FROM VenuesBundle:ReservationLoungeProfile p
  2545.                 WHERE p.typePrice = :typePrice AND p.dateStart = :dateToFind AND p.loungeId = :loungeId
  2546.                 ORDER BY p.levelPrice DESC';
  2547.         $query $em->createQuery($dql)->setParameters($parameters);
  2548.         $loungesPeriodsDaily $query->getResult();
  2549.         $priceTarifa = empty($loungesPeriodsDaily) ? $loungesPeriodsDaily[0]->getPrice();
  2550.         $price = ($servicePrice == 0) ? $priceTarifa $servicePrice;
  2551.         return $price;
  2552.     }
  2553. }