<?php
namespace App\MDS\VenuesBundle\Controller;
use App\Entity\ReservationLoungeWebDescription;
use App\Entity\SageArticle;
use App\Entity\SageVatRates;
use App\Entity\WidgetNotes;
use App\Form\WidgetNotesType;
use App\MDS\VenuesBundle\Entity\Reservation;
use App\MDS\VenuesBundle\Entity\ReservationLoungeSimple;
use App\MDS\VenuesBundle\Entity\ReservationLoungeSimpleServiceLog;
use App\MDS\VenuesBundle\Entity\ReservationService;
use App\MDS\VenuesBundle\Entity\ReservationGpPrice;
use App\MDS\VenuesBundle\Entity\ReservationLounge;
use App\MDS\VenuesBundle\Entity\ReservationLoungeDetails;
use App\MDS\VenuesBundle\Entity\ReservationLoungeProfile;
use App\MDS\VenuesBundle\Entity\ReservationPeriod;
use App\MDS\VenuesBundle\Form\ReservationGpPriceType;
use App\MDS\VenuesBundle\Form\ReservationLoungeDetailsType;
use App\MDS\VenuesBundle\Form\ReservationLoungeProfileType;
use App\MDS\VenuesBundle\Form\ReservationPeriodType;
use App\MDS\VenuesBundle\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\Component\HttpFoundation\JsonResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service\AgendaService;
use App\Service\VenueService;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class ReservationsQuoteController extends AbstractController
{
private Google_Client $googleCalendar;
private TranslatorInterface $translator;
private AgendaService $agendaService;
private SessionInterface $session;
private VenueService $venueService;
private \App\Service\ReservationService $reservationService;
private \App\Service\DocContractService $docContractService;
public function __construct(
TranslatorInterface $translator,
AgendaService $agendaService,
VenueService $venueService,
SessionInterface $session,
\App\Service\ReservationService $reservationService,
\App\Service\DocContractService $docContractService
) {
$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;
$this->agendaService = $agendaService;
$this->venueService = $venueService;
$this->session = $session;
$this->reservationService = $reservationService;
$this->docContractService = $docContractService;
}
/**
* @Route("/createsimplelounge/{id}", name="reservations_venues_create_simple_lounge")
* Crea un Reservation Lounge Simple en la cotizacion
*/
public function createSimpleLoungeAction($id, EntityManagerInterface $em, Request $request)
{
$simpleLounge = $request->request->all()['reservation_sala'] ?? [];
// Sala precargada
$loungeProfile = $em->getRepository(ReservationLoungeDetails::class)
->findOneById($simpleLounge['salaPrecargadas'] ?? null);
if (!$loungeProfile) {
$this->addFlash('mensajereservationerror', 'La sala seleccionada no existe.');
return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
}
$loungeId = $loungeProfile->getId();
$loungeDetails = $em->getRepository(ReservationLoungeDetails::class)->findOneById($loungeId);
// Nombre de sala, necesario para Sage
$loungeName = '';
if ($loungeDetails && method_exists($loungeDetails, 'getName')) {
$loungeName = (string) $loungeDetails->getName();
} elseif (!empty($simpleLounge['loungeName'])) {
$loungeName = (string) $simpleLounge['loungeName'];
}
if ($loungeName === '') {
$this->addFlash('mensajereservationerror', 'No se pudo determinar el nombre de la sala.');
return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
}
// ¿Existe ya esta sala en la misma reserva y rank?
$previusLoungeSimple = $em->getRepository(ReservationLoungeSimple::class)->findOneBy([
'idLounge' => $loungeId,
'idReservation' => $id,
'rankQuote' => $simpleLounge['idQuote'] ?? null
]);
// Heredar idioma si existe alguna sala previa en la reserva
$anyLoungeSimple = $em->getRepository(ReservationLoungeSimple::class)->findOneBy([
'idLounge' => $loungeId,
'idReservation' => $id
]);
$idioma = $anyLoungeSimple ? (int) $anyLoungeSimple->getLanguage() : 1;
// Descripciones web por sala/idioma con fallbacks
$loungeWebDescriptionRepo = $em->getRepository(ReservationLoungeWebDescription::class);
$loungeWebDescription = $loungeWebDescriptionRepo->findOneBy([
'lounge' => $loungeProfile,
'language' => $idioma
]) ?? ($idioma !== 1 ? $loungeWebDescriptionRepo->findOneBy([
'lounge' => $loungeProfile,
'language' => 1
]) : null) ?? $loungeWebDescriptionRepo->findOneBy(['lounge' => $loungeProfile]);
// Summary recibido del formulario (opcional)
$loungeSummaryDescription = is_array($simpleLounge) && array_key_exists('importantDescription', $simpleLounge)
? (string) $simpleLounge['importantDescription']
: null;
if (empty($previusLoungeSimple)) {
// Sin anterior, tiramos de WebDescription si existe
$loungeImportantDescGeneralText = $loungeWebDescription ? $loungeWebDescription->getImportantDescGeneralText() : '';
$loungeImportantDescSchedules = $loungeWebDescription ? $loungeWebDescription->getImportantDescSchedules() : '';
$loungeImportantDescParking = $loungeWebDescription ? $loungeWebDescription->getImportantDescParking() : '';
if (empty($loungeSummaryDescription)) {
$loungeSummaryDescription = $loungeWebDescription ? $loungeWebDescription->getImportantDescription() : '';
}
} else {
// Heredamos de la simple existente
$loungeSummaryDescription = $previusLoungeSimple->getImportantDescription();
$loungeImportantDescGeneralText = $previusLoungeSimple->getImportantDescGeneralText();
$loungeImportantDescSchedules = $previusLoungeSimple->getImportantDescSchedules();
$loungeImportantDescParking = $previusLoungeSimple->getImportantDescParking();
}
// Reserva para calcular sucoe e IVA
$reservation = $em->getRepository(Reservation::class)->findOneById($id);
if (!$reservation) {
$this->addFlash('mensajereservationerror', 'No se encontró la reserva.');
return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
}
$sucoe = (bool) $reservation->isSucoe();
$sageVatRate = $em->getRepository(SageVatRates::class)->findOneBy([
'sageCode' => $sucoe ? '00' : '03'
]);
// Artículo Sage por nombre de sala + tipo IVA
$sageArticle = $em->getRepository(SageArticle::class)->findOneBy([
'vatType' => $sageVatRate,
'name' => $loungeName
]);
// Solo salta el error si no se ha encontrado el artículo y está el modulo de Sage activo
if (!$sageArticle && $this->session->get('_config')['msage']) {
$this->addFlash('mensajereservationerror', 'No se ha encontrado el artículo de Sage para la sala: ' . $loungeName);
return $this->redirectToRoute('reservations_venues_edit', ['id' => $id]);
}
// Normalización horas desde POST
$hourMinStart = (string) ($simpleLounge['hourStart'] ?? '');
$hourMinEnd = (string) ($simpleLounge['hourEnd'] ?? '');
// Normalización horas desde POST usando el servicio
$startData = $this->reservationService->formatTimeInput((string) ($simpleLounge['hourStart'] ?? ''));
$endData = $this->reservationService->formatTimeInput((string) ($simpleLounge['hourEnd'] ?? ''));
$hourStart = $startData['hour'];
$minStart = $startData['min'];
$hourEnd = $endData['hour'];
$minEnd = $endData['min'];
$dateStart = new \DateTime(($simpleLounge['dateStart'] ?? date('Y-m-d')) . ' ' . $startData['formatted']);
$dateEnd = new \DateTime(($simpleLounge['dateStart'] ?? date('Y-m-d')) . ' ' . $endData['formatted']); // un solo día
$servicePrice = (float) ($simpleLounge['servicePrice'] ?? 0);
$idReservation = (int) $id;
// Usuario
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado ? $user_logueado->getId() : null;
$createdAt = new \DateTime('now');
$updatedAt = new \DateTime('now');
$pax = (int) ($simpleLounge['pax'] ?? 0);
// Rank de cotización
$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']) && is_numeric($simpleLounge['idQuote'])) {
$newRankId = (int) $simpleLounge['idQuote'];
}
// Tipo: Dia de evento (null), Montaje o Desmontaje
$typeXLounge = empty($simpleLounge['type']) ? null : $simpleLounge['type'];
// Crear la entidad
$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($newRankId);
$lounge->setIdReservation($idReservation);
$lounge->setType($typeXLounge);
$lounge->setSageIva($sageVatRate);
$lounge->setOpIva(1);
$lounge->setCreatedAt($createdAt);
$lounge->setCreatedBy($user_id);
$lounge->setUpdatedAt($updatedAt);
$lounge->setUpdatedBy($user_id);
$lounge->setPax($pax);
$lounge->setImportantDescription($loungeSummaryDescription ?? '');
$lounge->setImportantDescGeneralText($loungeImportantDescGeneralText ?? '');
$lounge->setImportantDescSchedules($loungeImportantDescSchedules ?? '');
$lounge->setImportantDescParking($loungeImportantDescParking ?? '');
// Precio tarifario
$price = $this->reservationService->getTariffPrice($dateStart, $loungeId, $servicePrice);
$lounge->setServicePrice($price);
// Vincular la sala al artículo
$lounge->setSageArticle($sageArticle);
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);
}
//Se llama al servicio para crear la entrada en la agenda y actualizar el Pax de la agenda
$loungeNameAgenda = empty($typeXLounge) ? $loungeName : $loungeName . ' ( ' . $typeXLounge . ' ) ';
$agenda = $this->agendaService->createAgendaFromSource($idReservation, 'SALAS A UTILIZAR', null, null, $dateStart, $dateEnd, $loungeNameAgenda, $lounge->getId(), 'ReservationLoungeSimple', $user_id);
$paxAge = $this->agendaService->calculatePaxForReservation($idReservation);
$agenda = $this->agendaService->updatePaxLine($idReservation, $paxAge, $user_id);
// Actualizar fechas de la reserva usando el servicio
if ($reservation) {
$this->reservationService->updateReservationDates($reservation);
//Se llama al servicio para crear la entrada en la agenda de las fechas
$this->agendaService->updateDatesLine($idReservation, $user_id);
}
// Creamos la Snapshot de las salas y servicios del sistema (LOG)
$version = $this->venueService->createSnapshot($reservation);
// Sincronizar contratos si está confirmado
if ($reservation->getStatus() === 'Confirmed') {
$this->docContractService->autoAssignContracts($reservation, $user_logueado);
}
// Redirección para agregar servicio de limpieza
return $this->redirectToRoute('reservations_white_addservices_cleaning', [
'resid' => $id,
'loungesimpleid' => $lounge->getId(),
]);
}
/**
* @Route("/api/get-price", name="get_reservations_price_to_view", methods={"GET"})
*/
public function getPrice(Request $request)
{
$loungeId = $request->query->get('sala');
$dateStart = $request->query->get('date');
if (!$loungeId || !$dateStart) {
return new JsonResponse(['error' => 'Missing parameters'], 400);
}
try {
$dateStartObj = new \DateTime($dateStart);
} catch (\Exception $e) {
return new JsonResponse(['error' => 'Invalid date'], 400);
}
$price = $this->reservationService->getTariffPrice($dateStartObj, $loungeId, 0);
return new JsonResponse(['price' => $price]);
}
/**
* @Route("/createsimpleloungemondes/{id}", name="reservations_venues_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'];
// Buscamos la reserva que es para saber si es sucoe o no
$reservation = $em->getRepository(Reservation::class)->findOneById($id);
$sucoe = $reservation->isSucoe();
// Si no es sucoe, cogemos el IVA del 21% y si lo es, entonces el del 0%
if (!$sucoe) {
$sageVatRate = $em->getRepository(SageVatRates::class)->findOneBy(['sageCode' => '03']);
} else {
$sageVatRate = $em->getRepository(SageVatRates::class)->findOneBy(['sageCode' => '00']);
}
$sageArticle = $em->getRepository(SageArticle::class)->findOneBy(['vatType' => $sageVatRate, 'name' => $loungeName]);
// Si no se ha encontrado el artículo de Sage.
if (empty($sageArticle)) {
$this->addFlash('mensajereservationerror', 'No se ha encontrado el artículo de Sage para la sala: ' . $loungeName);
return $this->redirectToRoute('reservations_venues_edit', array(
'id' => $id,
));
}
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'];
}
}
// Normalización horas desde POST usando el servicio
$startData = $this->reservationService->formatTimeInput((string) ($simpleLounge['hourStart'] ?? ''));
$endData = $this->reservationService->formatTimeInput((string) ($simpleLounge['hourEnd'] ?? ''));
$hourStart = $startData['hour'];
$minStart = $startData['min'];
$hourEnd = $endData['hour'];
$minEnd = $endData['min'];
$hourMinStart = $startData['formatted'];
$hourMinEnd = $endData['formatted'];
$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 = 0;
$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->setSageIva($sageArticle->getVatType());
$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 = 0; // Se asume 0 según lógica de precioPorFecha original que era inalcanzable
$servicePrice = ($price == 0) ? $servicePrice : $price;
$lounge->setServicePrice($servicePrice);
// Vincular la sala al artículo
$lounge->setSageArticle($sageArticle);
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);
if ($reservax) {
$this->reservationService->updateReservationDates($reservax);
// Sincronizar contratos si está confirmado
if ($reservax->getStatus() === 'Confirmed') {
$this->docContractService->autoAssignContracts($reservax, $user_logueado);
}
}
// FIN: Verificamos si es necesario actualizar las fechas de la reserva
return $this->redirectToRoute(
'reservations_venues_edit_simple',
array(
'id' => $id,
'token' => null,
'_fragment' => 'btn_quotes'
)
);
}
/**
* @Route("/duplicateday/{id}/{dayduplicate}/{idRankQuote}", name="reservations_venues_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);
$vatRepo = $em->getRepository(SageVatRates::class);
/* Usuario logueado */
$user = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user ? $user->getId() : null;
$createdAt = new \DateTime('now');
$updatedAt = new \DateTime('now');
$createdBy = $user_id;
$updatedBy = $user_id;
if (!empty($loungeSimples)) {
foreach ($loungeSimples as $item) {
if (
$item->getDateStart() &&
$item->getDateStart()->format('d-m-Y') == $dayduplicate &&
$item->getRankQuote() == $idRankQuote
) {
// Se duplica y suma un día (sin mutar el original)
$newLoungeSimple = new ReservationLoungeSimple();
$newLoungeSimple->setDateStart((clone $item->getDateStart())->modify('+1 day'));
$newLoungeSimple->setDateEnd((clone $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());
// IVA (string)
$newLoungeSimple->setIva($item->getIva());
// Relación SageVatRates (entidad)
$vatEntity = method_exists($item, 'getSageIva') ? $item->getSageIva() : null;
if (!$vatEntity) {
$rawRate = $item->getIva();
if ($rawRate !== null && $rawRate !== '') {
$rate = (float) $rawRate;
// Normaliza si en BD está como fracción (0.21)
if ($rate > 1) {
$rate = $rate / 100;
}
// Ajusta 'rate' si tu campo en SageVatRates tiene otro nombre
$vatEntity = $vatRepo->findOneBy(['rate' => $rate]);
}
}
$newLoungeSimple->setSageIva($vatEntity);
$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);
}
// Actualiza fechas de la reserva si procede
$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();
}
}
}
} else {
// Registro antiguo: transformar a los nuevos y luego duplicar
$loungeOld = $em->getRepository(ReservationLounge::class)->findByIdReservation($id);
foreach ($loungeOld as $item) {
if ($item->getDateStart()->format('Y-m-d') == $item->getDateEnd()->format('Y-m-d')) {
// Mismo día → simple
$newLoungeSimple = new ReservationLoungeSimple();
$newLoungeSimple->setDateStart(clone $item->getDateStart());
$newLoungeSimple->setDateEnd(clone $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());
// IVA (string)
$newLoungeSimple->setIva($item->getIva());
// Resolver SageVatRates desde el string
$rawRate = $item->getIva();
$vatEnt = null;
if ($rawRate !== null && $rawRate !== '') {
$rate = (float) $rawRate;
if ($rate > 1) {
$rate = $rate / 100;
}
$vatEnt = $vatRepo->findOneBy(['rate' => $rate]);
}
$newLoungeSimple->setSageIva($vatEnt);
$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);
}
// Actualiza fechas de la reserva si procede
$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();
}
} else {
// Varios días → trocear en simples
$firstDay = new \DateTime($item->getDateStart()->format('Y-m-d'));
$lastDay = new \DateTime($item->getDateEnd()->format('Y-m-d'));
$numDays = ($lastDay->diff($firstDay))->days + 1;
$actualDay = clone $item->getDateStart();
$actualStartDay = clone $item->getDateStart();
$actualEndDay = clone $item->getDateEnd();
for ($i = 0; $i < $numDays; $i++) {
$newLoungeSimple = new ReservationLoungeSimple();
if ($i === 0) {
// Primer día
$newLoungeSimple->setDateStart(clone $actualStartDay);
$newLoungeSimple->setDateEnd(new \DateTime($actualStartDay->format('Y-m-d') . ' 23:59'));
$newLoungeSimple->setHourStart($item->getHourStart());
$newLoungeSimple->setHourEnd('23');
$newLoungeSimple->setMinStart($item->getMinStart());
$newLoungeSimple->setMinEnd('59');
} elseif (($i + 1) === $numDays) {
// Último día
$newLoungeSimple->setDateStart(new \DateTime($actualEndDay->format('Y-m-d') . ' 00:00'));
$newLoungeSimple->setDateEnd(clone $actualEndDay);
$newLoungeSimple->setHourStart('00');
$newLoungeSimple->setHourEnd($item->getHourEnd());
$newLoungeSimple->setMinStart('00');
$newLoungeSimple->setMinEnd($item->getMinEnd());
} else {
// Día intermedio
$newLoungeSimple->setDateStart(new \DateTime($actualDay->format('Y-m-d') . ' 00:00'));
$newLoungeSimple->setDateEnd(new \DateTime($actualDay->format('Y-m-d') . ' 23:59'));
$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());
// IVA (string) + entidad
$newLoungeSimple->setIva($item->getIva());
$rawRate = $item->getIva();
$vatEnt = null;
if ($rawRate !== null && $rawRate !== '') {
$rate = (float) $rawRate;
if ($rate > 1) {
$rate = $rate / 100;
}
$vatEnt = $vatRepo->findOneBy(['rate' => $rate]);
}
$newLoungeSimple->setSageIva($vatEnt);
$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);
// Avanza el día (sin perder la referencia)
$actualDay = (clone $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);
}
// Actualiza fechas de la reserva si procede
$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();
}
}
}
// Re-llama al mismo controlador ahora con la nueva tabla poblada
return $this->redirectToRoute('reservations_venues_duplicate_day', [
'id' => $id,
'dayduplicate' => $dayduplicate,
]);
}
}
//Se llama al servicio para crear la entrada en la agenda y actualizar el Pax de la agenda
$agenda = $this->agendaService->createAgendaFromSource($newLoungeSimple->getIdReservation(), 'SALAS A UTILIZAR', null, null, $newLoungeSimple->getDateStart(), $newLoungeSimple->getDateEnd(), $newLoungeSimple->getLoungeName(), $newLoungeSimple->getId(), 'ReservationLoungeSimple', $updatedBy);
$reserva = $em->getRepository(Reservation::class)->findOneById($newLoungeSimple->getIdReservation());
//Se llama al servicio para crear la entrada en la agenda de las fechas
$agenda = $this->agendaService->updateDatesLine($reserva->getId(), $updatedBy);
// Creamos la Snapshot de las salas y servicios del sistema (LOG)
$version = $this->venueService->createSnapshot($reservax);
/* Obtengo usuario logueado */
$user = $this->get('security.token_storage')->getToken()->getUser();
// Sincronizar contratos si está confirmado
if ($reservax->getStatus() === 'Confirmed') {
$this->docContractService->autoAssignContracts($reservax, $user);
}
// Redirige para agregar Servicio de limpieza
return $this->redirectToRoute('reservations_white_addservices_cleaning', [
'resid' => $id,
'loungesimpleid' => isset($newLoungeSimple) ? $newLoungeSimple->getId() : null,
]);
}
/**
* @Route("/deleteitemsimple/{id}/{daydelete}", name="reservations_venues_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);
if (!empty($loungeSimple)) {
//Se llama al servicio para eliminar la entrada en la agenda
$agenda = $this->agendaService->deleteAgendaBySource($loungeSimple->getId(), 'ReservationLoungeSimple');
}
$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);
}
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Recalcular fechas de la reserva usando el servicio
if ($reserva) {
$this->reservationService->updateReservationDates($reserva);
// Sincronizar contratos si está confirmado
if ($reserva->getStatus() === 'Confirmed') {
$this->docContractService->autoAssignContracts($reserva, $user_logueado);
}
}
$user_id = $user_logueado->getId();
//Se llama al servicio para crear la entrada en la agenda de las fechas
$agenda = $this->agendaService->updateDatesLine($reserva->getId(), $user_id);
//Se llama al servicio para actualizar Pax en la agenda
$paxAge = $this->agendaService->calculatePaxForReservation($reserva->getId());
$agenda = $this->agendaService->updatePaxLine($reserva->getId(), $paxAge, $user_id);
// Se elimina el servicio de horas de limpieza de la sala
return $this->redirectToRoute(
'reservations_venues_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 {
if (!empty($item)) {
//Se llama al servicio para eliminar la entrada en la agenda
$agenda = $this->agendaService->deleteAgendaBySource($item->getId(), 'ReservationLoungeSimple');
}
$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();
}
}
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
//Se llama al servicio para actualizar Pax en la agenda
$paxAge = $this->agendaService->calculatePaxForReservation($idRes);
$agenda = $this->agendaService->updatePaxLine($idRes, $paxAge, $user_id);
//Se llama al servicio para actualizar Fechas en la agenda
$agenda = $this->agendaService->updateDatesLine($idRes, $user_id);
// Recalcular fechas de la reserva
$reservaEntity = $em->getRepository(Reservation::class)->find($idRes);
if ($reservaEntity) {
$this->reservationService->updateReservationDates($reservaEntity);
}
return $this->redirectToRoute(
'reservations_venues_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 {
if (!empty($item)) {
//Se llama al servicio para eliminar la entrada en la agenda
$agenda = $this->agendaService->deleteAgendaBySource($item->getId(), 'ReservationLoungeSimple');
}
$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);
}
}
// Actualizar fechas de la reserva usando el servicio
$reservation = $em->getRepository(Reservation::class)->findOneById($idRes);
$this->reservationService->updateReservationDates($reservation);
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
//Se llama al servicio para actualizar Pax en la agenda
$paxAge = $this->agendaService->calculatePaxForReservation($idRes);
$agenda = $this->agendaService->updatePaxLine($idRes, $paxAge, $user_id);
//Se llama al servicio para actualizar Fechas en la agenda
$agenda = $this->agendaService->updateDatesLine($idRes, $user_id);
return $this->redirectToRoute(
'reservations_venues_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();
// Descripciones web por sala/idioma con fallbacks
$loungeProfile = $newLounge;
// Heredar idioma si existe alguna sala previa en la reserva
$idioma = empty($reservationAll) ? 1: $reservationAll[0]->getLanguage();
$loungeWebDescriptionRepo = $em->getRepository(ReservationLoungeWebDescription::class);
$loungeWebDescription = $loungeWebDescriptionRepo->findOneBy([
'lounge' => $loungeProfile,
'language' => $idioma
]) ?? ($idioma !== 1 ? $loungeWebDescriptionRepo->findOneBy([
'lounge' => $loungeProfile,
'language' => 1
]) : null) ?? $loungeWebDescriptionRepo->findOneBy(['lounge' => $loungeProfile]);
$loungeImportantDescGeneralText = $loungeWebDescription ? $loungeWebDescription->getImportantDescGeneralText() : '';
$loungeImportantDescSchedules = $loungeWebDescription ? $loungeWebDescription->getImportantDescSchedules() : '';
$loungeImportantDescParking = $loungeWebDescription ? $loungeWebDescription->getImportantDescParking() : '';
$loungeSummaryDescription = $loungeWebDescription ? $loungeWebDescription->getImportantDescription() : '';
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($loungeSummaryDescription);
$newLoungeSimple->setImportantDescGeneralText($loungeImportantDescGeneralText);
$newLoungeSimple->setImportantDescSchedules($loungeImportantDescSchedules);
$newLoungeSimple->setImportantDescParking($loungeImportantDescParking);
$newLoungeSimple->setLanguage($item->getLanguage());
$newLoungeSimple->setSageArticle($item->getSageArticle());
$newLoungeSimple->setSentToSage($item->isSentToSage());
$newLoungeSimple->setSageIva($item->getSageIva());
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 llama al servicio para crear la entrada en la agenda
$agenda = $this->agendaService->createAgendaFromSource(
$newLoungeSimple->getIdReservation(),
'SALAS A UTILIZAR',
null,
null,
$newLoungeSimple->getDateStart(),
$newLoungeSimple->getDateEnd(),
$newLoungeSimple->getLoungename(),
$newLoungeSimple->getId(),
'ReservationLoungeSimple',
$newLoungeSimple->getUpdatedBy()
);
// 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->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();
}
$reserva = $em->getRepository(Reservation::class)->findOneById($reqDuplicateQuote['reservationId']);
// Creamos la Snapshot de las salas y servicios del sistema (LOG)
$version = $this->venueService->createSnapshot($reserva);
return $this->redirectToRoute(
'reservations_venues_edit_simple',
array(
'id' => $reqDuplicateQuote['reservationId'],
'token' => null,
'_fragment' => 'btn_quotes'
)
);
}
/**
* @Route("/loghistoric/{id}", name="reservations_log_historic")
* Log del historico de la cotizacion de la reserva id
*/
public function logHistoricQuoteAction($id, EntityManagerInterface $em, Request $request){
$reservaLogs = $em->getRepository(ReservationLoungeSimpleServiceLog::class)->findByReservaId($id);
return $this->render(
'MDS/VenuesBundle/reservations/list-reservations-log-historic.html.twig',
array(
'id' => $id,
'reservaLogs' => $reservaLogs,
)
);
}
/**
* @Route("/productfileavlist/{id}", name="reservations_list_multiple_productfile_av")
* Listar productos de Av para agregar en el servicio id
*/
public function listMultipleProductAvAction( $id, Request $request){
$em = $this->getDoctrine()->getManager();
$parameters = [];
$dql = 'SELECT i
FROM AvexpressBundle:AveProduct i
ORDER BY i.name ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$avs = $query->getResult();
$data_av = [];
$data_av[] = array( 'id' => -6, 'name' => 'Paquete de técnicos 8h + 1 (Técnico video y sonido, dietas no incluidas)', 'type' => 'Paquete', 'price' => '600');
$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');
$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');
$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');
$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');
$data_av[] = array( 'id' => -1, 'name' => 'Paquete de Sala Art Legends (Proyectores de sala inmersiva bajo cotización)', 'type' => 'Paquete', 'price' => '1000');
foreach($avs as $av){
$data_av[] = array(
'id' => $av->getId(),
'name' => $av->getName(),
'type' => $av->getType(),
'price' => $av->getPrice(),
);
}
$resService = $em->getRepository(ReservationService::class)->findOneById($id);
return $this->render('MDS/VenuesBundle/reservations/add-services-avs.html.twig',
array(
'id' => $id,
'idRes' => empty($resService) ? 0 : $resService->getReservationId(),
'avs' => $data_av,
));
}
/**
* @Route("/productfileavadd/{id}", name="reservations_add_multiple_productfile_av")
* Agregar productos de Av para agregar en el servicio id
*/
public function addMultipleProductAvAction( $id, Request $request){
$em = $this->getDoctrine()->getManager();
$resService = $em->getRepository(ReservationService::class)->findOneById($id);
$prodSelected = $request->request->get('details');
$serviceName = '';
$servicePrice = 0;
foreach ($prodSelected as $item){
if(empty($serviceName)){
$serviceName .= $item['name'];
} else {
$serviceName .= ' + '. $item['name'];
}
$servicePrice += $item['total_price'];
}
$resService->setName($serviceName);
$resService->setPrice($servicePrice);
$resService->setToInvoice(1);
$resService->setOpIva(1);
$resService->setIva(21);
try {
$em->persist($resService);
$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);
}
return $this->redirectToRoute('reservations_venues_edit_simple', [
'id' => $resService->getReservationId(),
'token' => null,
'_fragment' => 'btn_srv'
]);
}
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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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 VenuesBundle: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, );
}
/*
* Se busca el precio a Sugerir
* $dateStart Fecha
* $loungeId Id de la sala
* $servicePrice Preciointroducido por elusuario
* */
private function precioTarifario($dateStart, $loungeId, $servicePrice)
{
$em = $this->getDoctrine()->getManager();
$dateToFind = clone $dateStart;
$dateToFind->setTime(0, 0, 0);
$parameters = array(
'loungeId' => $loungeId,
'typePrice' => 'DIARIA',
'dateToFind' => $dateToFind,
);
$dql = 'SELECT p
FROM VenuesBundle: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;
return $price;
}
}