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

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