<?php
namespace App\MDS\GreenPatioBundle\Controller;
use App\Entity\ReservationLoungeWebDescription;
use App\Entity\WidgetNotes;
use App\Form\WidgetNotesType;
use App\MDS\AvexpressBundle\Entity\AveFiles;
use App\MDS\GreenPatioBundle\Entity\Reservation;
use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
use App\MDS\GreenPatioBundle\Entity\ReservationService;
use App\MDS\GreenPatioBundle\Entity\ReservationGpPrice;
use App\MDS\GreenPatioBundle\Entity\ReservationLounge;
use App\MDS\GreenPatioBundle\Entity\ReservationLoungeDetails;
use App\MDS\GreenPatioBundle\Entity\ReservationLoungeProfile;
use App\MDS\GreenPatioBundle\Entity\ReservationPeriod;
use App\MDS\GreenPatioBundle\Form\ReservationGpPriceType;
use App\MDS\GreenPatioBundle\Form\ReservationLoungeDetailsType;
use App\MDS\GreenPatioBundle\Form\ReservationLoungeProfileType;
use App\MDS\GreenPatioBundle\Form\ReservationPeriodType;
use App\MDS\GreenPatioBundle\Form\ReservationType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use DateTime;
use DatePeriod;
use DateInterval;
use Google_Client;
use Google_Service_Calendar;
use Symfony\Contracts\Translation\TranslatorInterface;
class ReservationsQuoteController extends AbstractController
{
public function __construct(TranslatorInterface $translator)
{
$redirect_uri = 'https://' . $_SERVER['HTTP_HOST']. '/calendar/token';
$googleCalendar = new Google_Client();
$googleCalendar->setApplicationName('Google Calendar API PHP Quickstart');
//campos a extraer de la base de datos User
$googleCalendar->setClientId('2790497987-57qc3vu4pr7vb0s8phpub2me58pe34lb.apps.googleusercontent.com');
$googleCalendar->setClientSecret('nj2C7unaTO68DRhyORsyipSj');
//fin campos user
// $api_key = "AIzaSyBR84cS1IU2BPvk5V3VnbqdkJESlv440Ac";
// $client->setDeveloperKey($api_key);
$googleCalendar->setRedirectUri($redirect_uri);
$googleCalendar->addScope(Google_Service_Calendar::CALENDAR);
$guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
$googleCalendar->setHttpClient($guzzleClient);
$this->googleCalendar = $googleCalendar;
$this->translator = $translator;
}
/**
* @Route("/createsimplelounge/{id}", name="reservations_greenpatio_create_simple_lounge")
* Crea un Reservation Lounge Simple en la cotizacion
*/
public function createSimpleLoungeAction($id, EntityManagerInterface $em, Request $request)
{
$simpleLounge = $request->request->get('reservation_sala');
$loungeProfile = $em->getRepository(ReservationLoungeDetails::class)->findOneById($simpleLounge['salaPrecargadas']);
$loungeId = $loungeProfile->getId();
$loungeDetails = $em->getRepository(ReservationLoungeDetails::class)->findOneById($loungeId);
$previusLoungeSimple = $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idLounge' => $loungeId, 'idReservation' => $id, 'rankQuote' => $simpleLounge['idQuote']));
//Buscamos si hay ya alguna sala en la reserva
$anyLoungeSimple = $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idLounge' => $loungeId, 'idReservation' => $id));
$idioma = 1;
if($anyLoungeSimple){
$idioma = $anyLoungeSimple->getLanguage();
}
$loungeWebDescription = $em->getRepository(ReservationLoungeWebDescription::class)->findOneBy(array('lounge' => $loungeProfile, 'language' => $idioma));
$loungeName = $loungeDetails->getName();
$hourMinStart = $simpleLounge['hourStart'];
$hourMinEnd = $simpleLounge['hourEnd'];
$loungeSummaryDescription = array_key_exists('importantDescription', $simpleLounge) ? $simpleLounge['importantDescription'] : null;
if (empty($previusLoungeSimple)) {
if (empty($loungeSummaryDescription)) { $loungeSummaryDescription = $loungeWebDescription->getImportantDescription(); }
$loungeImportantDescGeneralText = $loungeWebDescription->getImportantDescGeneralText();
$loungeImportantDescSchedules = $loungeWebDescription->getImportantDescSchedules();
$loungeImportantDescParking = $loungeWebDescription->getImportantDescParking();
} else {
$loungeSummaryDescription = $previusLoungeSimple->getImportantDescription();
$loungeImportantDescGeneralText = $previusLoungeSimple->getImportantDescGeneralText();
$loungeImportantDescSchedules = $previusLoungeSimple->getImportantDescSchedules();
$loungeImportantDescParking = $previusLoungeSimple->getImportantDescParking();
}
$iva = 21;
if (array_key_exists('iva', $simpleLounge)) {
if (empty($simpleLounge['iva']) && !is_numeric($simpleLounge['iva'])) {
$iva = 21;
} else {
$iva = $simpleLounge['iva'];
}
}
$qb = $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
$reservationAll = $qb->where('r.idReservation = :idReservation')
->setParameter('idReservation', $id)
->orderBy('r.rankQuote', 'ASC')
->getQuery()
->getResult();
$newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
if (!empty($simpleLounge['idQuote'])){ if (is_numeric($simpleLounge['idQuote'])){ $newRankId = $simpleLounge['idQuote']; } }
// Autocompletacion HH:mm en Start
switch (strlen($hourMinStart)) {
case 0:
// Vacio
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
break;
case 1:
// H -> 0H:00
if (is_numeric($hourMinStart)){
$hourStart = '0'.$hourMinStart; $minStart = '00'; $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 2:
// HH -> HH:00
if (is_numeric($hourMinStart)){
$hourStart = $hourMinStart; $minStart = '00'; $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 3:
// Hmm -> 0H:mm
if (is_numeric($hourMinStart)){
$hourStart = '0'.substr($hourMinStart,0,1); $minStart = substr($hourMinStart,1,2); $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 4:
// HHmm -> HH:mm
if (is_numeric($hourMinStart)){
$hourStart = substr($hourMinStart,0,2); $minStart = substr($hourMinStart,2,2); $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 5:
// HH:mm
if (is_numeric(substr($hourMinStart,0,2)) and (substr($hourMinStart,2,1)==':') and is_numeric(substr($hourMinStart,0,2))){
$hourStart = substr($hourMinStart,0,2); $minStart = substr($hourMinStart,3,2); $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
default:
// XXXXyyy
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
break;
}
// Autocompletacion HH:mm en End
switch (strlen($hourMinEnd)) {
case 0:
// Vacio
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
break;
case 1:
// H -> 0H:00
if (is_numeric($hourMinEnd)){
$hourEnd = '0'.$hourMinEnd; $minEnd = '00'; $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 2:
// HH -> HH:00
if (is_numeric($hourMinEnd)){
$hourEnd = $hourMinEnd; $minEnd = '00'; $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 3:
// Hmm -> 0H:mm
if (is_numeric($hourMinEnd)){
$hourEnd = '0'.substr($hourMinEnd,0,1); $minEnd = substr($hourMinEnd,1,2); $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 4:
// HHmm -> HH:mm
if (is_numeric($hourMinEnd)){
$hourEnd = substr($hourMinEnd,0,2); $minEnd = substr($hourMinEnd,2,2); $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 5:
// HH:mm
if (is_numeric(substr($hourMinEnd,0,2)) and (substr($hourMinEnd,2,1)==':') and is_numeric(substr($hourMinEnd,0,2))){
$hourEnd = substr($hourMinEnd,0,2); $minEnd = substr($hourMinEnd,3,2); $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
default:
// XXXXyyy
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
break;
}
$dateStart = new DateTime($simpleLounge['dateStart'] . ' '. $hourMinStart);
$dateEnd = new DateTime($simpleLounge['dateStart'] . ' '. $hourMinEnd); // Se usa DateStart por que solo hay un dia en el formulario
$idService = 0;
$serviceName = '';
$servicePrice = (empty($simpleLounge['servicePrice'])) ? 0 :$simpleLounge['servicePrice'];
$idReservation = $id;
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$createdAt = new DateTime('now');
$createdBy = $user_id;
$updatedAt = new DateTime('now');
$updatedBy = $user_id;
$pax = $simpleLounge['pax']; if (empty($pax)){$pax = 0;}
$lounge = new ReservationLoungeSimple();
$lounge->setIdLounge ($loungeId);
$lounge->setHourStart ($hourStart);
$lounge->setMinStart ($minStart);
$lounge->setHourEnd ($hourEnd);
$lounge->setMinEnd ($minEnd);
$lounge->setLoungeName ($loungeName);
$lounge->setDateStart ($dateStart);
$lounge->setDateEnd ($dateEnd);
$lounge->setRankQuote(1);
$lounge->setIdReservation ($idReservation);
$lounge->setIva($iva);
$lounge->setOpIva(1);
$lounge->setCreatedAt ($createdAt);
$lounge->setCreatedBy ($createdBy);
$lounge->setUpdatedAt ($updatedAt);
$lounge->setUpdatedBy ($updatedBy);
$lounge->setPax ($pax);
$lounge->setRankQuote($newRankId);
$lounge->setImportantDescription($loungeSummaryDescription);
$lounge->setImportantDescGeneralText($loungeImportantDescGeneralText);
$lounge->setImportantDescSchedules($loungeImportantDescSchedules);
$lounge->setImportantDescParking($loungeImportantDescParking);
// PRECIO POR TARIFA
$dateToFind = clone $dateStart;
$dateToFind->setTime(0, 0, 0);
$parameters = array(
'loungeId' => $loungeId,
'typePrice' => 'DIARIA',
'dateToFind' => $dateToFind,
);
$dql = 'SELECT p
FROM GreenPatioBundle:ReservationLoungeProfile p
WHERE p.typePrice = :typePrice AND p.dateStart = :dateToFind AND p.loungeId = :loungeId
ORDER BY p.levelPrice DESC';
$query = $em->createQuery($dql)->setParameters($parameters);
$loungesPeriodsDaily = $query->getResult();
$priceTarifa = empty($loungesPeriodsDaily) ? 0 : $loungesPeriodsDaily[0]->getPrice();
$price = ($servicePrice == 0) ? $priceTarifa : $servicePrice;
$lounge->setServicePrice($price);
try{
$em->persist($lounge);
$em->flush();
$event = 'The Reservation has been updated.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
// INICIO: Actualizacion de fecha de inicio y fin del evento, a partir de la info de la sala
$boolSincGpAv = false;
$reserva = $em->getRepository(Reservation::class)->findOneById($idReservation);
if ($reserva->getDateStart() > $dateStart){ $reserva->setDateStart($dateStart); $boolSincGpAv = true; }
if ($reserva->getDateStart()->format('Y') == '2078' ){ $reserva->setDateStart($dateStart); $boolSincGpAv = true; }
if ($reserva->getDateEnd() < $dateEnd){ $reserva->setDateEnd($dateEnd); $boolSincGpAv = true; }
if ($reserva->getDateEnd()->format('Y') == '2000' ){ $reserva->setDateEnd($dateEnd); $boolSincGpAv = true; }
try{
$em->persist($reserva);
$em->flush();
$event = '';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){}
// Sincronización con Av Express
if ($boolSincGpAv) {
$AveFile = $em->getRepository(AveFiles::class)->findByReservation($reserva);
if (($reserva->getStatus() == 'Confirmed') or ($reserva->getStatus() == 'Cotizado') or ($reserva->getStatus() == 'Invoiced') or ($reserva->getStatus() == 'Bloqueo')) {
if (empty($AveFile)) {
// Si no se ha creado aun el expediente de Av Express debemos crearlo
return $this->redirectToRoute('sinc_gp_ave', array('id' => $id,));
}
}
}
// FIN: Actualizacion de fecha de inicio y fin del evento, a partir de la info de la sala
// Se debe redirigir para agregar el Servicio de limpieza
return $this->redirectToRoute('reservations_white_addservices_cleaning',
array(
'resid' => $id,
'loungesimpleid' => $lounge->getId(),
));
}
/**
* @Route("/createsimpleloungemondes/{id}", name="reservations_greenpatio_create_simple_lounge_mondes")
* Se crea un dia de montaje o desmontaje
*/
public function createSimpleLoungeMonDesAction($id, EntityManagerInterface $em, Request $request)
{
$simpleLounge = $request->request->get('reservation_sala_mondes');
$loungeId = $simpleLounge['idLounge'];
$loungeDetails = $em->getRepository(ReservationLoungeDetails::class)->findOneById($loungeId);
$previusLoungeSimple = $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idLounge' => $loungeId, 'idReservation' => $id, 'rankQuote' => $simpleLounge['idQuote']));
$loungeName = $loungeDetails->getName();
$hourMinStart = $simpleLounge['hourStart'];
$hourMinEnd = $simpleLounge['hourEnd'];
$ivaNew = empty($simpleLounge['iva']) ? 21 : $simpleLounge['iva'];
if (empty($previusLoungeSimple)) {
$loungeSummaryDescription = $loungeDetails->getImportantDescription();
$loungeImportantDescGeneralText = $loungeDetails->getImportantDescGeneralText();
$loungeImportantDescSchedules = $loungeDetails->getImportantDescSchedules();
$loungeImportantDescParking = $loungeDetails->getImportantDescParking();
} else {
$loungeSummaryDescription = $previusLoungeSimple->getImportantDescription();
$loungeImportantDescGeneralText = $previusLoungeSimple->getImportantDescGeneralText();
$loungeImportantDescSchedules = $previusLoungeSimple->getImportantDescSchedules();
$loungeImportantDescParking = $previusLoungeSimple->getImportantDescParking();
}
$qb = $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
$reservationAll = $qb->where('r.idReservation = :idReservation')
->setParameter('idReservation', $id)
->orderBy('r.rankQuote', 'ASC')
->getQuery()
->getResult();
$newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
if (!empty($simpleLounge['idQuote'])){ if (is_numeric($simpleLounge['idQuote'])){ $newRankId = $simpleLounge['idQuote']; } }
// Autocompletacion HH:mm en Start
switch (strlen($hourMinStart)) {
case 0:
// Vacio
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
break;
case 1:
// H -> 0H:00
if (is_numeric($hourMinStart)){
$hourStart = '0'.$hourMinStart; $minStart = '00'; $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 2:
// HH -> HH:00
if (is_numeric($hourMinStart)){
$hourStart = $hourMinStart; $minStart = '00'; $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 3:
// Hmm -> 0H:mm
if (is_numeric($hourMinStart)){
$hourStart = '0'.substr($hourMinStart,0,1); $minStart = substr($hourMinStart,1,2); $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 4:
// HHmm -> HH:mm
if (is_numeric($hourMinStart)){
$hourStart = substr($hourMinStart,0,2); $minStart = substr($hourMinStart,2,2); $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
case 5:
// HH:mm
if (is_numeric(substr($hourMinStart,0,2)) and (substr($hourMinStart,2,1)==':') and is_numeric(substr($hourMinStart,0,2))){
$hourStart = substr($hourMinStart,0,2); $minStart = substr($hourMinStart,3,2); $hourMinStart = $hourStart.':'.$minStart;
} else {
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
}
break;
default:
// XXXXyyy
$hourStart = '00'; $minStart = '00'; $hourMinStart = '00:00';
break;
}
// Autocompletacion HH:mm en End
switch (strlen($hourMinEnd)) {
case 0:
// Vacio
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
break;
case 1:
// H -> 0H:00
if (is_numeric($hourMinEnd)){
$hourEnd = '0'.$hourMinEnd; $minEnd = '00'; $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 2:
// HH -> HH:00
if (is_numeric($hourMinEnd)){
$hourEnd = $hourMinEnd; $minEnd = '00'; $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 3:
// Hmm -> 0H:mm
if (is_numeric($hourMinEnd)){
$hourEnd = '0'.substr($hourMinEnd,0,1); $minEnd = substr($hourMinEnd,1,2); $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 4:
// HHmm -> HH:mm
if (is_numeric($hourMinEnd)){
$hourEnd = substr($hourMinEnd,0,2); $minEnd = substr($hourMinEnd,2,2); $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
case 5:
// HH:mm
if (is_numeric(substr($hourMinEnd,0,2)) and (substr($hourMinEnd,2,1)==':') and is_numeric(substr($hourMinEnd,0,2))){
$hourEnd = substr($hourMinEnd,0,2); $minEnd = substr($hourMinEnd,3,2); $hourMinEnd = $hourEnd.':'.$minEnd;
} else {
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
}
break;
default:
// XXXXyyy
$hourEnd = '00'; $minEnd = '00'; $hourMinEnd = '00:00';
break;
}
$dateStart = new DateTime($simpleLounge['dateStart'] . ' '. $hourMinStart);
$dateEnd = new DateTime($simpleLounge['dateStart'] . ' '. $hourMinEnd); // Se usa DateStart por que solo hay un dia en el formulario
$servicePrice = empty($simpleLounge['servicePrice']) ? 0 :$simpleLounge['servicePrice'];
$idReservation = $id;
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$createdAt = new DateTime('now');
$createdBy = $user_id;
$updatedAt = new DateTime('now');
$updatedBy = $user_id;
$lounge = new ReservationLoungeSimple();
if ($simpleLounge['type'] == 'Montaje'){ $lounge->setType ('Montaje'); } else { $lounge->setType ('Desmontaje'); }
$pax = null;
$lounge->setIdLounge ($loungeId);
$lounge->setHourStart ($hourStart);
$lounge->setMinStart ($minStart);
$lounge->setHourEnd ($hourEnd);
$lounge->setMinEnd ($minEnd);
$lounge->setLoungeName ($loungeName);
$lounge->setDateStart ($dateStart);
$lounge->setDateEnd ($dateEnd);
$lounge->setRankQuote(1);
$lounge->setIva($ivaNew);
$lounge->setOpIva(1);
$lounge->setIdReservation ($idReservation);
$lounge->setCreatedAt ($createdAt);
$lounge->setCreatedBy ($createdBy);
$lounge->setUpdatedAt ($updatedAt);
$lounge->setUpdatedBy ($updatedBy);
$lounge->setPax ($pax);
$lounge->setRankQuote($newRankId);
$lounge->setImportantDescription($loungeSummaryDescription);
$lounge->setImportantDescGeneralText($loungeImportantDescGeneralText);
$lounge->setImportantDescSchedules($loungeImportantDescSchedules);
$lounge->setImportantDescParking($loungeImportantDescParking);
$price = $this->precioPorFecha($dateStart, $loungeId);
$servicePrice = ($price['price'] == 0) ? $servicePrice : $price;
$lounge->setServicePrice($servicePrice);
try{
$em->persist($lounge);
$em->flush();
$event = 'The Reservation has been updated.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
$reservax = $em->getRepository(Reservation::class)->findOneById($idReservation);
// INICIO: Verificamos si es necesario actualizar las fechas de la reserva
$boolReserva = false;
if ($lounge->getDateStart() < $reservax->getDateStart()){
$reservax->setDateStart($lounge->getDateStart());
$boolReserva = true;
}
if ($reservax->getDateEnd() < $lounge->getDateEnd()){
$reservax->setDateEnd($lounge->getDateEnd());
$boolReserva = true;
}
if ($boolReserva){
$em->persist($reservax);
$em->flush();
}
$boolSincGpAv = $boolReserva;
// Sincronización con Av Express
if ($boolSincGpAv) {
$AveFile = $em->getRepository(AveFiles::class)->findByReservation($reservax);
if (($reservax->getStatus() == 'Confirmed') or ($reservax->getStatus() == 'Cotizado') or ($reservax->getStatus() == 'Invoiced') or ($reservax->getStatus() == 'Bloqueo')) {
if (empty($AveFile)) {
// Si no se ha creado aun el expediente de Av Express debemos crearlo
return $this->redirectToRoute('sinc_gp_ave', array('id' => $id,));
}
}
}
// FIN: Verificamos si es necesario actualizar las fechas de la reserva
return $this->redirectToRoute('reservations_greenpatio_edit_simple',
array(
'id' => $id,
'token' => null,
'_fragment' => 'btn_quotes'
));
}
/**
* @Route("/duplicateday/{id}/{dayduplicate}/{idRankQuote}", name="reservations_greenpatio_duplicate_day")
* Duplica un elemento de la cotizacion para el dia siguiente
*/
public function duplicateDayAction($id, $dayduplicate, $idRankQuote, EntityManagerInterface $em, Request $request)
{
$loungeSimples = $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($id);
$reservax = $em->getRepository(Reservation::class)->findOneById($id);
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$createdAt = new DateTime('now');
$createdBy = $user_id;
$updatedAt = new DateTime('now');
$updatedBy = $user_id;
if (!empty($loungeSimples)){
foreach ($loungeSimples as $item){
if (($item->getDateStart()->format('d-m-Y') == $dayduplicate) and ($item->getRankQuote() == $idRankQuote)){
// Se duplica y suma un dia
$newLoungeSimple = new ReservationLoungeSimple();
$newLoungeSimple->setDateStart($item->getDateStart()->modify('+1 day'));
$newLoungeSimple->setDateEnd($item->getDateEnd()->modify('+1 day'));
$newLoungeSimple->setHourStart($item->getHourStart());
$newLoungeSimple->setHourEnd($item->getHourEnd());
$newLoungeSimple->setMinStart($item->getMinStart());
$newLoungeSimple->setMinEnd($item->getMinEnd());
$newLoungeSimple->setIdLounge($item->getIdLounge());
$newLoungeSimple->setIdReservation($item->getIdReservation());
$newLoungeSimple->setLoungeName($item->getLoungeName());
$newLoungeSimple->setPax($item->getPax());
$newLoungeSimple->setServicePrice($item->getServicePrice());
$newLoungeSimple->setIva($item->getIva());
$newLoungeSimple->setOpIva($item->getOpIva());
$newLoungeSimple->setType($item->getType());
$newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
$newLoungeSimple->setImportantDescription($item->getImportantDescription());
$newLoungeSimple->setImportantDescGeneralText($item->getImportantDescGeneralText());
$newLoungeSimple->setImportantDescSchedules($item->getImportantDescSchedules());
$newLoungeSimple->setImportantDescParking($item->getImportantDescParking());
$newLoungeSimple->setRankQuote($idRankQuote);
$newLoungeSimple->setCreatedAt($createdAt);
$newLoungeSimple->setCreatedBy($createdBy);
$newLoungeSimple->setUpdatedAt($updatedAt);
$newLoungeSimple->setUpdatedBy($updatedBy);
try{
$em->persist($newLoungeSimple);
$em->flush();
$event = 'The Item has been duplicated.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
// INICIO: Verificamos si es necesario actualizar las fechas de la reserva
$boolReserva = false;
if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()){
$reservax->setDateStart($newLoungeSimple->getDateStart());
$boolReserva = true;
}
if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()){
$reservax->setDateEnd($newLoungeSimple->getDateEnd());
$boolReserva = true;
}
if ($boolReserva){
$em->persist($reservax);
$em->flush();
}
// FIN: Verificamos si es necesario actualizar las fechas de la reserva
}
}
} else {
// registro antiguo, se pasara a los nuevos registros y luego duplicara
$loungeOld = $em->getRepository(ReservationLounge::class)->findByIdReservation($id);
foreach ($loungeOld as $item){
if ($item->getDateStart()->format('Y-m-d') == $item->getDateEnd()->format('Y-m-d')){
// Es el mismo dia, se crea un registro simple
$newLoungeSimple = new ReservationLoungeSimple();
$newLoungeSimple->setDateStart($item->getDateStart());
$newLoungeSimple->setDateEnd($item->getDateEnd());
$newLoungeSimple->setHourStart($item->getHourStart());
$newLoungeSimple->setHourEnd($item->getHourEnd());
$newLoungeSimple->setMinStart($item->getMinStart());
$newLoungeSimple->setMinEnd($item->getMinEnd());
$newLoungeSimple->setIdLounge($item->getIdLounge());
$newLoungeSimple->setIdReservation($item->getIdReservation());
$newLoungeSimple->setLoungeName($item->getLoungeName());
$newLoungeSimple->setPax($item->getPax());
$newLoungeSimple->setServicePrice($item->getServicePrice());
$newLoungeSimple->setIva($item->getIva());
$newLoungeSimple->setOpIva($item->getOpIva());
$newLoungeSimple->setType($item->getType());
$newLoungeSimple->setRankQuote($item->getRankQuote());
$newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
$newLoungeSimple->setImportantDescription($item->getImportantDescription());
$newLoungeSimple->setCreatedAt($createdAt);
$newLoungeSimple->setCreatedBy($createdBy);
$newLoungeSimple->setUpdatedAt($updatedAt);
$newLoungeSimple->setUpdatedBy($updatedBy);
try{
$em->persist($newLoungeSimple);
$em->flush();
$event = 'The Item has been duplicated.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
// INICIO: Verificamos si es necesario actualizar las fechas de la reserva
$boolReserva = false;
if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()){
$reservax->setDateStart($newLoungeSimple->getDateStart());
$boolReserva = true;
}
if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()){
$reservax->setDateEnd($newLoungeSimple->getDateEnd());
$boolReserva = true;
}
if ($boolReserva){
$em->persist($reservax);
$em->flush();
}
// FIN: Verificamos si es necesario actualizar las fechas de la reserva
} else {
// Registro con varios dias, se calcula el numero de dias y se crean ese numero de registros nuevos
$firstDay = $item->getDateStart();
$firstDay = new DateTime($firstDay->format('Y-m-d'));
$lastDay = $item->getDateEnd();
$lastDay = new DateTime($lastDay->format('Y-m-d'));
$numDays = ((($lastDay)->diff($firstDay))->days) +1;
$actualDay = $item->getDateStart();
$actualStartDay = $item->getDateStart();
$actualEndDay = $item->getDateEnd();
for ($i=0; $i<sizeof($numDays); $i++){
// Se crea un registro por cada dia
$newLoungeSimple = new ReservationLoungeSimple();
if ($i == 0){
// Primer dia
$newLoungeSimple->setDateStart($actualStartDay);
$actualStartDayEnd = new DateTime($actualStartDay->format('Y-m-d').' 23:59');
$newLoungeSimple->setDateEnd($actualStartDayEnd);
$newLoungeSimple->setHourStart($item->getHourStart());
$newLoungeSimple->setHourEnd('23');
$newLoungeSimple->setMinStart($item->getMinStart());
$newLoungeSimple->setMinEnd('59');
} else {
if (($i + 1) == sizeof($numDays)){
// Ultimo dia
$actualEndDayStart = new DateTime($actualEndDay->format('Y-m-d').' 00:00');
$newLoungeSimple->setDateStart($actualEndDayStart);
$newLoungeSimple->setDateEnd($actualEndDay);
$newLoungeSimple->setHourStart('00');
$newLoungeSimple->setHourEnd($item->getHourEnd());
$newLoungeSimple->setMinStart('00');
$newLoungeSimple->setMinEnd($item->getMinEnd());
} else {
// Dia intermedio
$actualMidDayStart = new DateTime($actualDay->format('Y-m-d').' 00:00');
$actualMidDayEnd = new DateTime($actualDay->format('Y-m-d').' 23:59');
$newLoungeSimple->setDateStart($actualMidDayStart);
$newLoungeSimple->setDateEnd($actualMidDayEnd);
$newLoungeSimple->setHourStart('00');
$newLoungeSimple->setHourEnd('23');
$newLoungeSimple->setMinStart('00');
$newLoungeSimple->setMinEnd('59');
}
}
$newLoungeSimple->setIdLounge($item->getIdLounge());
$newLoungeSimple->setIdReservation($item->getIdReservation());
$newLoungeSimple->setLoungeName($item->getLoungeName());
$newLoungeSimple->setPax($item->getPax());
$newLoungeSimple->setServicePrice($item->getServicePrice());
$newLoungeSimple->setIva($item->getIva());
$newLoungeSimple->setOpIva($item->getOpIva());
$newLoungeSimple->setType($item->getType());
$newLoungeSimple->setRankQuote($item->getRankQuote());
$newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
$newLoungeSimple->setImportantDescription($item->getImportantDescription());
$newLoungeSimple->setCreatedAt($createdAt);
$newLoungeSimple->setCreatedBy($createdBy);
$newLoungeSimple->setUpdatedAt($updatedAt);
$newLoungeSimple->setUpdatedBy($updatedBy);
$actualDay = $actualDay->modify('+1 day');
try{
$em->persist($newLoungeSimple);
$em->flush();
$event = 'The Item has been updated.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
// INICIO: Verificamos si es necesario actualizar las fechas de la reserva
$boolReserva = false;
if ($newLoungeSimple->getDateStart() < $reservax->getDateStart()){
$reservax->setDateStart($newLoungeSimple->getDateStart());
$boolReserva = true;
}
if ($reservax->getDateEnd() < $newLoungeSimple->getDateEnd()){
$reservax->setDateEnd($newLoungeSimple->getDateEnd());
$boolReserva = true;
}
if ($boolReserva){
$em->persist($reservax);
$em->flush();
}
// FIN: Verificamos si es necesario actualizar las fechas de la reserva
}
}
}
// Se vuelve a llamar a este mismo controlador ahora con los registros en la nueva tabla
return $this->redirectToRoute('reservations_greenpatio_duplicate_day', array( 'id' => $id, 'dayduplicate' => $dayduplicate, ));
}
// Se debe redirigir para agregar el Servicio de limpieza
return $this->redirectToRoute('reservations_white_addservices_cleaning',
array(
'resid' => $id,
'loungesimpleid' => $newLoungeSimple->getId(),
));
}
/**
* @Route("/deleteitemsimple/{id}/{daydelete}", name="reservations_greenpatio_delete_simple_lounge")
* Elimina un Reservation Simple Lounge de la cotizacion
*/
public function deleteSimpleLoungeAction($id, $daydelete, EntityManagerInterface $em, Request $request)
{
$loungeSimple = $em->getRepository(ReservationLoungeSimple::class)->findOneById($id);
$id = $loungeSimple->getIdReservation();
$reserva = $em->getRepository(Reservation::class)->findOneById($loungeSimple->getIdReservation());
try{
$em->remove($loungeSimple);
$em->flush();
$event = 'The item has been deleted.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
// Si se elimina el primer dia o el ultimo, se debe modificar las fechas de la reserva
if(($reserva->getDateStart()->format('Ymd') == $loungeSimple->getDateStart()->format('Ymd')) or ($reserva->getDateEnd()->format('Ymd') == $loungeSimple->getDateEnd()->format('Ymd'))){
$allLoungeSimples = $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($reserva->getId());
if (!empty($allLoungeSimples)){
$reserva->setDateStart(new DateTime('2999-01-01'));
$reserva->setDateEnd(new DateTime('2000-01-01'));
foreach ($allLoungeSimples as $newLoungeSimple){
// INICIO: Verificamos si es necesario actualizar las fechas de la reserva
$boolReserva = false;
if ($newLoungeSimple->getDateStart() < $reserva->getDateStart()){
$reserva->setDateStart($newLoungeSimple->getDateStart());
$boolReserva = true;
}
if ($reserva->getDateEnd() < $newLoungeSimple->getDateEnd()){
$reserva->setDateEnd($newLoungeSimple->getDateEnd());
$boolReserva = true;
}
if ($boolReserva){
$em->persist($reserva);
$em->flush();
}
// FIN: Verificamos si es necesario actualizar las fechas de la reserva
}
} else {
// Se elimino la ultima sala y la reserva queda vacia
$reserva->setDateStart(new DateTime('2999-01-01'));
$reserva->setDateEnd(new DateTime('2000-01-01'));
$em->persist($reserva);
$em->flush();
}
}
// Se elimina el servicio de horas de limpieza de la sala
return $this->redirectToRoute('reservations_greenpatio_delete_simple_lounge_cleaning',
array(
'idRes' => $id,
'idLng' => $loungeSimple->getIdLounge(),
'dateInAt' => $loungeSimple->getDateStart()->format('Y-m-d\TH:i'),
'dateOutAt' => $loungeSimple->getDateEnd()->format('Y-m-d\TH:i'),
));
}
/**
* @Route("/deletequote/{idRes}/{idQuote}", name="reservations_delete_quote")
* Eliminar una cotizancion
*/
public function deleteQuoteAction( $idRes, $idQuote, EntityManagerInterface $em, Request $request)
{
$qb = $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
$reservation = $qb->where('r.rankQuote = :rankQuote')
->andWhere('r.idReservation = :idReservation')
->setParameter('idReservation', $idRes)
->setParameter('rankQuote', $idQuote)
->getQuery()
->getResult();
foreach ($reservation as $item){
try{
$em->remove($item);
$em->flush();
$event = 'Se ha eliminado la cotización';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
//Se deben eliminar todas las horas de limpieza asociadas a las salas de la cotización
$loungeDetails = $em->getRepository(ReservationLoungeDetails::class)->findOneById($item->getIdLounge());
$stringName = 'HORAS ( '.$loungeDetails->getName().' )';
$serviceCatIdClean = 21;
$dateInAt = new \DateTime($item->getDateStart()->format('Y-m-d\TH:i'));
$dateOutAt = new \DateTime($item->getDateEnd()->format('Y-m-d\TH:i'));
$qb = $em->getRepository(ReservationService::class)->createQueryBuilder('rs');
$serviceClean = $qb->where('rs.reservationId = :id')
->andWhere('rs.name = :name')
->andWhere('rs.dateInAt = :dateInAt')
->andWhere('rs.dateOutAt = :dateOutAt')
->andWhere('rs.serviceCatId = :serviceCatId')
->setParameter('id', $idRes)
->setParameter('name', $stringName)
->setParameter('dateInAt', $dateInAt)
->setParameter('dateOutAt', $dateOutAt)
->setParameter('serviceCatId', $serviceCatIdClean)
->getQuery()
->getResult();
if (!empty($serviceClean)) {
// Se elimina el servicio de horas de limpieza de la sala
$em->remove($serviceClean[0]);
$em->flush();
}
}
return $this->redirectToRoute('reservations_greenpatio_edit_simple',
array(
'id' => $idRes,
'token' => null,
'_fragment' => 'btn_quotes'
));
}
/**
* @Route("/checkquote/{idRes}/{idQuote}", name="reservations_check_quote")
* Confirmación de que se ha aceptado la cotizancion, se eliminaran las otras cotizaciones del expediente
*/
public function checkQuoteAction( $idRes, $idQuote, EntityManagerInterface $em, Request $request)
{
$qb = $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
$reservation = $qb->where('r.rankQuote <> :rankQuote')
->andWhere('r.idReservation = :idReservation')
->setParameter('idReservation', $idRes)
->setParameter('rankQuote', $idQuote)
->getQuery()
->getResult();
foreach ($reservation as $item){
try{
$em->remove($item);
$em->flush();
$event = 'Se han eliminado las otras cotizaciones';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
}
return $this->redirectToRoute('reservations_greenpatio_edit_simple',
array(
'id' => $idRes,
'token' => null,
'_fragment' => 'btn_quotes'
));
}
/**
* @Route("/duplicatequote", name="reservations_duplicate_quote")
* Duplicar una cotizacion
*/
public function duplicateQuoteAction( EntityManagerInterface $em, Request $request) {
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$hoy = new \DateTime("now", NULL);
$reqDuplicateQuote = $request->request->get('addquote');
$newLounge = $em->getRepository(ReservationLoungeDetails::class)->findOneById($reqDuplicateQuote['salaPrecargadas']);
$qb = $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
$reservationAll = $qb->where('r.idReservation = :idReservation')
->setParameter('idReservation', $reqDuplicateQuote['reservationId'])
->orderBy('r.rankQuote', 'ASC')
->getQuery()
->getResult();
$newRankId = (!empty($reservationAll)) ? (end($reservationAll)->getRankQuote() + 1) : 1;
if (empty($reqDuplicateQuote['idQuote'])) { $reqDuplicateQuote['idQuote'] = reset($reservationAll)->getRankQuote(); } //Si no elige cotización se duplica la primera
$qb = $em->getRepository(ReservationLoungeSimple::class)->createQueryBuilder('r');
$reservation = $qb->where('r.rankQuote = :rankQuote')
->andWhere('r.idReservation = :idReservation')
->setParameter('idReservation', $reqDuplicateQuote['reservationId'])
->setParameter('rankQuote', $reqDuplicateQuote['idQuote'])
->getQuery()
->getResult();
foreach ($reservation as $item){
$newLoungeSimple = new ReservationLoungeSimple();
$newLoungeSimple->setDateStart($item->getDateStart());
$newLoungeSimple->setDateEnd($item->getDateEnd());
$newLoungeSimple->setIdReservation($reqDuplicateQuote['reservationId']);
$newLoungeSimple->setPax($item->getPax());
$newLoungeSimple->setType($item->getType());
$newLoungeSimple->setCreatedAt($hoy);
$newLoungeSimple->setCreatedBy($user_id);
$newLoungeSimple->setUpdatedAt($hoy);
$newLoungeSimple->setUpdatedBy($user_id);
$newLoungeSimple->setHourStart($item->getHourStart());
$newLoungeSimple->setMinStart($item->getMinStart());
$newLoungeSimple->setHourEnd($item->getHourEnd());
$newLoungeSimple->setMinEnd($item->getMinEnd());
$newLoungeSimple->setRankQuote($newRankId);
$newLoungeSimple->setIva($item->getIva());
$newLoungeSimple->setOpIva($item->getOpIva());
$newLoungeSimple->setIdLounge($newLounge->getId());
$newLoungeSimple->setLoungename($newLounge->getName());
// $newLoungeSimple->setLoungeDescription($item->getLoungeDescription());
$newLoungeSimple->setImportantDescription($newLounge->getImportantDescription());
$newLoungeSimple->setImportantDescGeneralText($newLounge->getImportantDescGeneralText());
$newLoungeSimple->setImportantDescSchedules($newLounge->getImportantDescSchedules());
$newLoungeSimple->setImportantDescParking($newLounge->getImportantDescParking());
if (!empty($reqDuplicateQuote['salaPrice'])){ $newLoungeSimple->setServicePrice($reqDuplicateQuote['salaPrice']); } else { $newLoungeSimple->setServicePrice($item->getServicePrice());}
try{
$em->persist($newLoungeSimple);
$em->flush();
$event = 'Se ha agregado la nueva cotización';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajereservation', $successMessage);
} catch (\Exception $e){
$event = 'An error occurred: '.$e->getMessage();
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajereservationerror', $errorMessage);
}
// Se debe agregar el servicio de limpieza por cada sala que se agregue
$resLoungeSimple = $newLoungeSimple;
$service= new ReservationService();
$service->setReservationId($reqDuplicateQuote['reservationId']);
$service->setSupplierId(0);
$service->setDateInAt($resLoungeSimple->getDateStart());
$service->setDateOutAt($resLoungeSimple->getDateEnd());
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$service->setCreatedId($user_id);
$service->setUpdatedId($user_id);
$service->setCreatedAt(new \DateTime("now"));
$service->setUpdatedAt(new \DateTime("now"));
$service->setServiceCatId('21');
$service->setServiceCatName('Limpieza');
$service->setContcolor('green-300');
$service->setName('HORAS ( '.$resLoungeSimple->getLoungeName().' )');
$service->setPrice('14');
$service->setCurrency('Euro');
$service->setUnits('8');
$service->setCommission('0');
$service->setIva('0');
$service->setPax('0');
$service->setOver('0');
$service->setIva('21');
$service->setOpIva('1');
$service->setOpCommission('1');
$service->setCommission('57.14');
$service->setViewInfo(0);
$service->setToinvoice(0);
$service->setServiceId(0);
$em->persist($service);
$em->flush();
}
return $this->redirectToRoute('reservations_greenpatio_edit_simple',
array(
'id' => $reqDuplicateQuote['reservationId'],
'token' => null,
'_fragment' => 'btn_quotes'
));
}
private function precioPorFecha($date, $loungeId){
return array( 'price' => 0, );
$em = $this->getDoctrine()->getManager();
$price0 = null;
// Buscamos por año
$parameters = array( 'dateYear' => $date->format('Y'), 'loungeId' => $loungeId, 'priceIsActive' => true, );
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE ((i.year1 <= :dateYear and i.year2 >= :dateYear) ) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive';
$query = $em->createQuery($dql)->setParameters($parameters);
$price1 = $query->getResult();
// Buscamos por año y mes
$parameters = array( 'dateYear' => $date->format('Y'), 'month' => true, 'loungeId' => $loungeId, 'priceIsActive' => true, );
switch ($date->format('m')) {
case '01': //Enero
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '02': //Febrero
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '03': //Marzo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '04': //Abril
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '05': //Mayo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '06': //Junio
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '07': //Julio
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '08': //Agosto
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '09': //Septiembre
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '10': //Octubre
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '11': //Noviembre
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case '12': //Diciembre
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default:
break;
}
$query = $em->createQuery($dql)->setParameters($parameters);
$price2 = $query->getResult();
// Buscamos por año, mes y dia de la semana
$parameters = array( 'dateYear' => $date->format('Y'), 'month' => true, 'day' => true, 'loungeId' => $loungeId, 'priceIsActive' => true, );
switch ($date->format('m')) {
case '01': //Enero
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month1 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '02': //Febrero
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month2 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '03': //Marzo
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month3 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '04': //Abril
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month4 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '05': //Mayo
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month5 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '06': //Junio
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month6 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '07': //Julio
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month7 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '08': //Agosto
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month8 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '09': //Septiembre
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month9 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '10': //Octubre
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month10 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '11': //Noviembre
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month11 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
case '12': //Diciembre
switch ($date->format('l')) {
case 'Monday': //Lunes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month) AND (i.day1 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Tuesday': //Martes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month) AND (i.day2 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Wednesday': //Miercoles
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month) AND (i.day3 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Thursday': //Jueves
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month) AND (i.day4 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Friday': //Viernes
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month) AND (i.day5 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Saturday': //Sabado
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month) AND (i.day6 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
case 'Sunday': //Domingo
$dql = 'SELECT i
FROM GreenPatioBundle:ReservationLoungeProfile i
WHERE (
((i.year1 <= :dateYear and i.year2 >= :dateYear) or (i.year1 = :dateYear) or (i.year2 = :dateYear))
AND (i.month12 = :month) AND (i.day7 = :day)) and i.loungeId = :loungeId and i.priceIsActive = :priceIsActive
';
break;
default: break;
}
break;
default:
break;
}
$query = $em->createQuery($dql)->setParameters($parameters);
$price3 = $query->getResult();
foreach ($price3 as $item){
if (empty($price0)){
$price0 = $item;
} else {
//Si los precios coinciden en fechas se tomara el que se haya cargado mas reciente en el sistema
if ($item->getCreatedAt() > $price0->getCreatedAt()){ $price0 = $item; }
}
}
if(empty($price0)){ $price = 0; } else { $price = $price0->getPrice(); }
return array( 'price' => $price, );
}
}