<?php
namespace App\MDS\GreenPatioBundle\Controller;
use App\Entity\Client;
use App\Entity\Configuration;
use App\Entity\SettingsCompany;
use App\Entity\User;
use App\MDS\GreenPatioBundle\Entity\Reservation;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems;
use App\MDS\GreenPatioBundle\Entity\ReservationLoungeDetails;
use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
use App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceItems;
use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceItems;
use Google\Service\MigrationCenterAPI\DateTime;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManagerInterface;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
class ReservationsListingsController extends AbstractController
{
/**
* @Route("/liststatistics/", name="reservations_greenpatio_list_statistics")
*/
public function listStatisticsReservationAction(EntityManagerInterface $em, Request $request)
{
$clients = $em->getRepository(Client::class)->findAll();
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics.html.twig',
array(
'data' => null,
'clients' => $clients,
'clientId' => 0,
'salas' => $salas,
'consulta' => null,
'dateStartReq' => null,
'dateEndReq' => null,
));
}
/**
* @Route("/responseliststatistics/", name="reservations_greenpatio_response_list_statistics")
*/
public function responseListStatisticsReservationAction(EntityManagerInterface $em, Request $request)
{
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
$dateRequest = $request->request->get('forecast');
$clientId = $request->request->get('client');
$boolStatus = $request->request->get('boolStatus');
$selectedSalasNames = $request->request->get('selected_salas');
$arraySalasId = empty($request->request->get('tags')) ? null : $request->request->get('tags')['tags2'];
$dateStartReq = $dateRequest['date_start'];
$dateEndReq = $dateRequest['date_end'];
$data = [];
$data = $this->baseForecast($dateStartReq,$dateEndReq, $boolStatus, $clientId, $arraySalasId);
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
$clients = $em->getRepository(Client::class)->findAll();
$consulta = 'Del '. (new \DateTime($dateStartReq))->format('d/m/Y').' al '.(new \DateTime($dateEndReq))->format('d/m/Y').',';
if (!empty($boolStatus['Blocked']) and
!empty($boolStatus['Confirmed']) and
!empty($boolStatus['Quoted']) and
!empty($boolStatus['Invoiced']) and
!empty($boolStatus['Cancel'])
){
$consulta.=' todos los expedientes,';
} else {
$consulta.=' los expedientes';
if (!empty($boolStatus['Blocked'])) { $consulta .= ' Bloqueados,'; }
if (!empty($boolStatus['Confirmed'])) { $consulta .= ' Confirmados,'; }
if (!empty($boolStatus['Quoted'])) { $consulta .= ' Cotizados,'; }
if (!empty($boolStatus['Invoiced'])) { $consulta .= ' Facturados,'; }
if (!empty($boolStatus['Cancel'])) { $consulta .= ' Cancelados,'; }
}
if(empty($selectedSalasNames)) { $consulta.= ' de todas las salas.'; } else { $consulta.= ' en '.$selectedSalasNames.'.'; }
$boolBlocked = !empty($boolStatus['Blocked']) ? true : false ;
$boolConfirmed = !empty($boolStatus['Confirmed']) ? true : false;
$boolQuoted = !empty($boolStatus['Quoted']) ? true : false;
$boolInvoiced = !empty($boolStatus['Invoiced']) ? true : false;
$boolCancel = !empty($boolStatus['Cancel']) ? true : false;
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics.html.twig',
array(
'data' => $data['reservations'],
'clients' => $clients,
'salas' => $salas,
'consulta' => $consulta,
'company' => $company,
'clientId' => $clientId,
'dateStartReq' => $dateStartReq,
'dateEndReq' => $dateEndReq,
'boolBlocked' => $boolBlocked,
'boolConfirmed' => $boolConfirmed,
'boolQuoted' => $boolQuoted,
'boolInvoiced' => $boolInvoiced,
'boolCancel' => $boolCancel,
'selectedSalasNames' => $selectedSalasNames,
'arraySalasId' => empty($arraySalasId) ? null : implode(",", $arraySalasId),
'netoForeCast' => $data['netoForeCast'],
'vatForeCast' => $data['vatForeCast'],
'totalForeCast' => $data['totalForeCast'],
));
}
/**
* @Route("/createforecastprint/{dateStartReq}/{dateEndReq}", name="reservations_greenpatio_createforecastprint")
* Se genera una prevision de ventas con los datos recibidos en una pantalla para imprimir
*/
public function printForecastAction($dateStartReq, $dateEndReq, Request $request)
{
$em = $this->getDoctrine()->getManager();
$clientId = '';
$boolStatus = array(
'Confirmed' => 'on',
'Quoted' => 'on',
'Blocked' => 'on',
'Invoiced' => 'on',
);
$arraySalasId = empty($request->request->get('tags')) ? null : $request->request->get('tags')['tags2'];
$data = array();
$data = $this->baseForecast($dateStartReq,$dateEndReq, $boolStatus, $clientId, $arraySalasId);
$months = array(
'01' => 'Enero',
'02' => 'Febrero',
'03' => 'Marzo',
'04' => 'Abril',
'05' => 'Mayo',
'06' => 'Junio',
'07' => 'Julio',
'08' => 'Agosto',
'09' => 'Septiembre',
'10' => 'Octubre',
'11' => 'Noviembre',
'12' => 'Diciembre',
);
$hoy = new \DateTime("now", NULL);
$yearActual = $hoy->format('Y');
$monthActual = $hoy->format('m');
$years = array();
$yearActual++;
for ($i = 2019; $i < $yearActual; $i++){
array_unshift($years,$i); // Se genera el arreglo [2021,2020,2019] - En el 2019 es el inicio de las reservas
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
return $this->render('MDS/GreenPatioBundle/reservations/list-forecast-print.html.twig',
array(
'company' => $company,
'months' => $months,
'monthActual' => $monthActual,
'years' => $years,
'yearActual' => $yearActual,
'dateStartReq' => $dateStartReq,
'dateEndReq' => $dateEndReq,
'data' => $data['reservations'],
'netoForeCast' => $data['netoForeCast'],
'vatForeCast' => $data['vatForeCast'],
'totalForeCast' => $data['totalForeCast'],
)
);
}
/**
* @Route("/xlsstatistics/", name="excel_statistics")
* Estadisticas de Green Patio en xls
*/
public function excelStatisticsAction(EntityManagerInterface $em, Request $request)
{
$dateStartReq = $request->request->get('xls')['dateStartReq'];
$dateEndReq = $request->request->get('xls')['dateEndReq'];
$clientId = $request->request->get('xls')['clientId'];
$boolStatus = array();
if (!empty($request->request->get('xls')['boolBlocked'])){ $boolStatus['Blocked'] = 'on'; }
if (!empty($request->request->get('xls')['boolConfirmed'])){ $boolStatus['Confirmed'] = 'on'; }
if (!empty($request->request->get('xls')['boolQuoted'])){ $boolStatus['Quoted'] = 'on'; }
if (!empty($request->request->get('xls')['boolInvoiced'])){ $boolStatus['Invoiced'] = 'on'; }
if (!empty($request->request->get('xls')['boolCancel'])){ $boolStatus['Cancel'] = 'on'; }
$selectedSalasNames = $request->request->get('xls')['selectedSalasNames'];
$arraySalasId = !empty($request->request->get('xls')['arraySalasId']) ? explode(",", $request->request->get('xls')['arraySalasId']) : null ;
$data = array();
$data = $this->baseForecast($dateStartReq,$dateEndReq, $boolStatus, $clientId, $arraySalasId);
$consulta = 'del '. (new \DateTime($dateStartReq))->format('d/m/Y').' al '.(new \DateTime($dateEndReq))->format('d/m/Y').',';
if (!empty($boolStatus['Blocked']) and
!empty($boolStatus['Confirmed']) and
!empty($boolStatus['Quoted']) and
!empty($boolStatus['Invoiced']) and
!empty($boolStatus['Cancel'])
){
$consulta.=' todos los expedientes,';
} else {
$consulta.=' los expedientes';
if (!empty($boolStatus['Blocked'])) { $consulta .= ' Bloqueados,'; }
if (!empty($boolStatus['Confirmed'])) { $consulta .= ' Confirmados,'; }
if (!empty($boolStatus['Quoted'])) { $consulta .= ' Cotizados,'; }
if (!empty($boolStatus['Invoiced'])) { $consulta .= ' Facturados,'; }
if (!empty($boolStatus['Cancel'])) { $consulta .= ' Cancelados,'; }
}
if(empty($selectedSalasNames)) { $consulta.= ' de todas las salas.'; } else { $consulta.= ' en '.$selectedSalasNames.'.'; }
// Solicita el servicio de excel
$phpExcelObject = new Spreadsheet();
$phpExcelObject->getProperties()->setCreator("Grupo Green Patio")
->setLastModifiedBy("Grupo Green Patio")
->setTitle("Grupo Green Patio")
->setSubject("Grupo Green Patio")
->setDescription("Grupo Green Patio, generado usando clases de PHP")
->setKeywords("office 2005 openxml php")
->setCategory("Archivo de estadisticas");
$fill = new Fill();
$numberFormat = new NumberFormat();
$alignment = new Alignment();
$i = 6;
$indiceInicial = 7;
$indiceFinal = 7;
$activesheet = $phpExcelObject->getActiveSheet();
$drawingobject = new Drawing();
$drawingobject->setName('Image name');
$drawingobject->setDescription('Image description');
$drawingobject->setPath(getcwd() . '/assets/images/logo/logo_green_patio.png');
$drawingobject->setHeight(60);
$drawingobject->setOffsetY(20);
$drawingobject->setCoordinates('Q1');
$drawingobject->setWorksheet($activesheet);
$phpExcelObject
->getActiveSheet()
->getStyle('B3:O3')
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('C3', 'EstadÃsticas ' . $consulta);
$phpExcelObject
->getActiveSheet()
->getStyle('B' . $i . ':R' . $i)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('d1d1cf');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B' . $i, 'Fecha')
->setCellValue('D' . $i, 'Nombre')
->setCellValue('H' . $i, 'Expediente')
->setCellValue('J' . $i, 'Cliente')
->setCellValue('N' . $i, 'Venta Neta')
->setCellValue('P' . $i, 'Iva')
->setCellValue('R' . $i, 'Total');
$phpExcelObject->getActiveSheet()->getStyle('N' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('P' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('R' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
foreach ($data['reservations'] as $item) {
$phpExcelObject
->getActiveSheet()
->getStyle('N' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$phpExcelObject
->getActiveSheet()
->getStyle('P' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$phpExcelObject
->getActiveSheet()
->getStyle('R' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B' . ($i + 1), $item['dateStart']->format('d/m/Y'))
->setCellValue('D' . ($i + 1), $item['title'])
->setCellValue('H' . ($i + 1), $item['reservationId'])
->setCellValue('J' . ($i + 1), $item['clientName'])
->setCellValue('N' . ($i + 1), $item['neto'])
->setCellValue('P' . ($i + 1), $item['vat'])
->setCellValue('R' . ($i + 1), $item['total']);
$i++;
$indiceFinal++;
}
$indiceFinal--;
$phpExcelObject
->getActiveSheet()
->getStyle('L' . ($indiceFinal + 3) . ':' . 'R' . ($indiceFinal + 3))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject
->getActiveSheet()
->getStyle('N' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('N')
->setAutoSize(true);
$phpExcelObject
->getActiveSheet()
->getStyle('P' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('P')
->setAutoSize(true);
$phpExcelObject
->getActiveSheet()
->getStyle('R' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('R')
->setAutoSize(true);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('N' . ($indiceFinal + 3), 'Neto')
->setCellValue('P' . ($indiceFinal + 3), 'Iva')
->setCellValue('R' . ($indiceFinal + 3), 'Total');
$phpExcelObject->getActiveSheet()->getStyle('N' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('P' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('R' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('N' . ($indiceFinal + 4), '=SUM(' . 'N' . $indiceInicial . ' : N' . $indiceFinal . ')')
->setCellValue('P' . ($indiceFinal + 4), '=SUM(' . 'P' . $indiceInicial . ' : P' . $indiceFinal . ')')
->setCellValue('R' . ($indiceFinal + 4), '=SUM(' . 'R' . $indiceInicial . ' : R' . $indiceFinal . ')');
$phpExcelObject->getActiveSheet()->setTitle('EstadÃsticas');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Creamos pagina de Datos en bruto para Esteban Rincon
// Add new sheet
$objWorkSheet = $phpExcelObject->createSheet(1); //Setting index when creating
$phpExcelObject->setActiveSheetIndex(1);
$phpExcelObject->getActiveSheet()->setTitle('Datos en bruto');
$x = 1;
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . $x, 'Fecha')
->setCellValue('B' . $x, 'Nombre')
->setCellValue('C' . $x, 'Expediente')
->setCellValue('D' . $x, 'Cliente')
->setCellValue('E' . $x, 'Venta Neta')
->setCellValue('F' . $x, 'Iva')
->setCellValue('G' . $x, 'Total');
foreach ($data['reservations'] as $item) {
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . ($x + 1), $item['dateStart']->format('d/m/Y'))
->setCellValue('B' . ($x + 1), $item['title'])
->setCellValue('C' . ($x + 1), $item['reservationId'])
->setCellValue('D' . ($x + 1), $item['clientName'])
->setCellValue('E' . ($x + 1), $item['neto'])
->setCellValue('F' . ($x + 1), $item['vat'])
->setCellValue('G' . ($x + 1), $item['total']);
$x++;
}
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = new Xlsx($phpExcelObject);
// Envia la respuesta del controlador
$response = new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
}
);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'Grupo_Green_Patio' . '.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
$tot = $indiceFinal + 7;
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('L' . ($tot + 2), 'Grupo Green Patio')
->setCellValue('L' . ($tot + 3), 'comercial@greenpatio.es')
->setCellValue('L' . ($tot + 4), '+34 669 01 88 34');
$phpExcelObject
->getActiveSheet()
->getStyle('k' . ($tot + 2) . ':' . 'O' . ($tot + 4))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject->getActiveSheet()->setTitle('EstadÃsticas');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = new Xlsx($phpExcelObject);
// Envia la respuesta del controlador
$response = new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
}
);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'Green Patio - Estadisticas' . '.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
return $response;
}
/**
* @Route("/liststatisticsproducts/", name="reservations_greenpatio_list_statistics_products")
* Estadisticas por Porductos (Salas y Servicios)
*/
public function listStatisticsReservationProductsAction(EntityManagerInterface $em, Request $request)
{
$clients = $em->getRepository(Client::class)->findAll();
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-products.html.twig',
array(
'data' => null,
'clients' => $clients,
'clientId' => 0,
'salas' => $salas,
'consulta' => null,
'dateStartReq' => null,
'dateEndReq' => null,
));
}
/**
* @Route("/responseliststatisticsproducts/", name="reservations_greenpatio_response_list_statistics_products")
* Respuesta de la consulta de productos
*/
public function responseListStatisticsReservationProductsAction(EntityManagerInterface $em, Request $request)
{
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
$dateRequest = $request->request->get('forecast');
$clientId = $request->request->get('client');
$boolStatus = $request->request->get('boolStatus');
$selectedSalasNames = $request->request->get('selected_salas');
$arraySalasId = empty($request->request->get('tags')) ? null : $request->request->get('tags')['tags2'];
$dateStartReq = $dateRequest['date_start'];
$dateEndReq = $dateRequest['date_end'];
$data = array();
$data = $this->baseForecast($dateStartReq,$dateEndReq, $boolStatus, $clientId, $arraySalasId);
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
$clients = $em->getRepository(Client::class)->findAll();
$consulta = 'Del '. (new \DateTime($dateStartReq))->format('d/m/Y').' al '.(new \DateTime($dateEndReq))->format('d/m/Y').',';
if (!empty($boolStatus['Blocked']) and
!empty($boolStatus['Confirmed']) and
!empty($boolStatus['Quoted']) and
!empty($boolStatus['Invoiced']) and
!empty($boolStatus['Cancel'])
){
$consulta.=' todos los expedientes,';
} else {
$consulta.=' los expedientes';
if (!empty($boolStatus['Blocked'])) { $consulta .= ' Bloqueados,'; }
if (!empty($boolStatus['Confirmed'])) { $consulta .= ' Confirmados,'; }
if (!empty($boolStatus['Quoted'])) { $consulta .= ' Cotizados,'; }
if (!empty($boolStatus['Invoiced'])) { $consulta .= ' Facturados,'; }
if (!empty($boolStatus['Cancel'])) { $consulta .= ' Cancelados,'; }
}
if(empty($selectedSalasNames)) { $consulta.= ' de todas las salas.'; } else { $consulta.= ' en '.$selectedSalasNames.'.'; }
$boolBlocked = !empty($boolStatus['Blocked']) ? true : false ;
$boolConfirmed = !empty($boolStatus['Confirmed']) ? true : false;
$boolQuoted = !empty($boolStatus['Quoted']) ? true : false;
$boolInvoiced = !empty($boolStatus['Invoiced']) ? true : false;
$boolCancel = !empty($boolStatus['Cancel']) ? true : false;
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-products.html.twig',
array(
'data' => $data['reservations'],
'clients' => $clients,
'salas' => $salas,
'consulta' => $consulta,
'company' => $company,
'clientId' => $clientId,
'dateStartReq' => $dateStartReq,
'dateEndReq' => $dateEndReq,
'boolBlocked' => $boolBlocked,
'boolConfirmed' => $boolConfirmed,
'boolQuoted' => $boolQuoted,
'boolInvoiced' => $boolInvoiced,
'boolCancel' => $boolCancel,
'selectedSalasNames' => $selectedSalasNames,
'arraySalasId' => empty($arraySalasId) ? null : implode(",", $arraySalasId),
'netoForeCast' => $data['netoForeCast'],
'vatForeCast' => $data['vatForeCast'],
'totalForeCast' => $data['totalForeCast'],
));
}
/**
* @Route("/xlsstatisticsproducts/", name="excel_statistics_products")
* Estadisticas de Productos de Green Patio en xls
*/
public function excelStatisticsProductsAction(EntityManagerInterface $em, Request $request)
{
$dateStartReq = $request->request->get('xls')['dateStartReq'];
$dateEndReq = $request->request->get('xls')['dateEndReq'];
$clientId = $request->request->get('xls')['clientId'];
$boolStatus = array();
if (!empty($request->request->get('xls')['boolBlocked'])){ $boolStatus['Blocked'] = 'on'; }
if (!empty($request->request->get('xls')['boolConfirmed'])){ $boolStatus['Confirmed'] = 'on'; }
if (!empty($request->request->get('xls')['boolQuoted'])){ $boolStatus['Quoted'] = 'on'; }
if (!empty($request->request->get('xls')['boolInvoiced'])){ $boolStatus['Invoiced'] = 'on'; }
if (!empty($request->request->get('xls')['boolCancel'])){ $boolStatus['Cancel'] = 'on'; }
$selectedSalasNames = $request->request->get('xls')['selectedSalasNames'];
$arraySalasId = !empty($request->request->get('xls')['arraySalasId']) ? explode(",", $request->request->get('xls')['arraySalasId']) : null ;
$data = array();
$data = $this->baseForecast($dateStartReq,$dateEndReq, $boolStatus, $clientId, $arraySalasId);
$consulta = 'del '. (new \DateTime($dateStartReq))->format('d/m/Y').' al '.(new \DateTime($dateEndReq))->format('d/m/Y').',';
if (!empty($boolStatus['Blocked']) and
!empty($boolStatus['Confirmed']) and
!empty($boolStatus['Quoted']) and
!empty($boolStatus['Invoiced']) and
!empty($boolStatus['Cancel'])
){
$consulta.=' todos los expedientes,';
} else {
$consulta.=' los expedientes';
if (!empty($boolStatus['Blocked'])) { $consulta .= ' Bloqueados,'; }
if (!empty($boolStatus['Confirmed'])) { $consulta .= ' Confirmados,'; }
if (!empty($boolStatus['Quoted'])) { $consulta .= ' Cotizados,'; }
if (!empty($boolStatus['Invoiced'])) { $consulta .= ' Facturados,'; }
if (!empty($boolStatus['Cancel'])) { $consulta .= ' Cancelados,'; }
}
if(empty($selectedSalasNames)) { $consulta.= ' de todas las salas.'; } else { $consulta.= ' en '.$selectedSalasNames.'.'; }
// Solicita el servicio de excel
$phpExcelObject = new Spreadsheet();
$phpExcelObject->getProperties()->setCreator("Grupo Green Patio")
->setLastModifiedBy("Grupo Green Patio")
->setTitle("Grupo Green Patio")
->setSubject("Grupo Green Patio")
->setDescription("Grupo Green Patio, generado usando clases de PHP")
->setKeywords("office 2005 openxml php")
->setCategory("Archivo de estadisticas");
$fill = new Fill();
$numberFormat = new NumberFormat();
$alignment = new Alignment();
$i = 6;
$indiceInicial = 7;
$indiceFinal = 7;
$activesheet = $phpExcelObject->getActiveSheet();
$drawingobject = new Drawing();
$drawingobject->setName('Image name');
$drawingobject->setDescription('Image description');
$drawingobject->setPath(getcwd() . '/assets/images/logo/logo_green_patio.png');
$drawingobject->setHeight(60);
$drawingobject->setOffsetY(20);
$drawingobject->setCoordinates('Q1');
$drawingobject->setWorksheet($activesheet);
$phpExcelObject
->getActiveSheet()
->getStyle('B3:O3')
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('C3', 'EstadÃsticas ' . $consulta);
$phpExcelObject
->getActiveSheet()
->getStyle('B' . $i . ':R' . $i)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('d1d1cf');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B' . $i, 'Fecha')
->setCellValue('D' . $i, 'Nombre')
->setCellValue('G' . $i, 'Expediente')
->setCellValue('I' . $i, 'Cliente')
->setCellValue('L' . $i, 'Productos')
->setCellValue('N' . $i, 'Venta Neta')
->setCellValue('P' . $i, 'Iva')
->setCellValue('R' . $i, 'Total');
$phpExcelObject->getActiveSheet()->getStyle('N' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('P' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('R' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
foreach ($data['reservations'] as $item) {
$phpExcelObject
->getActiveSheet()
->getStyle('N' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$phpExcelObject
->getActiveSheet()
->getStyle('P' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$phpExcelObject
->getActiveSheet()
->getStyle('R' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$txtProducto = '';
$loungesData = $item['arrayLoungesData'][$item['reservationId']] ?? [];
foreach ($loungesData as $elem) {
$txtProducto.= $elem['loungeName']. ' - '. $elem['category'].' - ('. number_format((float)$elem['servicePrice'], 2, ',', '.'). ' € )'."\r\n";
}
$servicesData = $item['arrayServicesData'][$item['reservationId']] ?? [];
foreach ($servicesData as $elem) {
$txtProducto.= $elem['name']. ' - '. $elem['category'].' - ('. number_format((float)$elem['price'], 2, ',', '.'). ' € )'."\r\n";
}
$txtProducto = rtrim($txtProducto, "\r\n");
$phpExcelObject->getActiveSheet()->getStyle('L' . ($i + 1))->getAlignment()->setWrapText(true);
$phpExcelObject->getActiveSheet()->getColumnDimension('L')->setAutoSize(true);
$phpExcelObject->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(-1);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B' . ($i + 1), $item['dateStart']->format('d/m/Y'))
->setCellValue('D' . ($i + 1), $item['title'])
->setCellValue('G' . ($i + 1), $item['reservationId'])
->setCellValue('I' . ($i + 1), $item['clientName'])
->setCellValue('L' . ($i + 1), $txtProducto )
->setCellValue('N' . ($i + 1), $item['neto'])
->setCellValue('P' . ($i + 1), $item['vat'])
->setCellValue('R' . ($i + 1), $item['total']);
$i++;
$indiceFinal++;
}
$indiceFinal--;
$phpExcelObject
->getActiveSheet()
->getStyle('L' . ($indiceFinal + 3) . ':' . 'R' . ($indiceFinal + 3))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject
->getActiveSheet()
->getStyle('N' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('N')
->setAutoSize(true);
$phpExcelObject
->getActiveSheet()
->getStyle('P' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('P')
->setAutoSize(true);
$phpExcelObject
->getActiveSheet()
->getStyle('R' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('R')
->setAutoSize(true);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('N' . ($indiceFinal + 3), 'Neto')
->setCellValue('P' . ($indiceFinal + 3), 'Iva')
->setCellValue('R' . ($indiceFinal + 3), 'Total');
$phpExcelObject->getActiveSheet()->getStyle('N' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('P' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('R' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('N' . ($indiceFinal + 4), '=SUM(' . 'N' . $indiceInicial . ' : N' . $indiceFinal . ')')
->setCellValue('P' . ($indiceFinal + 4), '=SUM(' . 'P' . $indiceInicial . ' : P' . $indiceFinal . ')')
->setCellValue('R' . ($indiceFinal + 4), '=SUM(' . 'R' . $indiceInicial . ' : R' . $indiceFinal . ')');
$phpExcelObject->getActiveSheet()->setTitle('EstadÃsticas');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Creamos pagina de Datos en bruto para Esteban Rincon
// Add new sheet
$objWorkSheet = $phpExcelObject->createSheet(1); //Setting index when creating
$phpExcelObject->setActiveSheetIndex(1);
$phpExcelObject->getActiveSheet()->setTitle('Datos en bruto');
$x = 1;
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . $x, 'Fecha')
->setCellValue('B' . $x, 'Nombre')
->setCellValue('C' . $x, 'Expediente')
->setCellValue('D' . $x, 'Cliente')
->setCellValue('E' . $x, 'Productos')
->setCellValue('F' . $x, 'Categoria')
->setCellValue('G' . $x, 'Ubicacion')
->setCellValue('H' . $x, 'Venta Producto')
->setCellValue('I' . $x, 'Venta Neta')
->setCellValue('J' . $x, 'Iva')
->setCellValue('K' . $x, 'Total');
foreach ($data['reservations'] as $item) {
$phpExcelObject
->getActiveSheet()
->getStyle('H' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('K' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('I' . ($x + 1), $item['neto'])
->setCellValue('J' . ($x + 1), $item['vat'])
->setCellValue('K' . ($x + 1), $item['total']);
$location = '';
$loungesData = $item['arrayLoungesData'][$item['reservationId']] ?? [];
foreach ($loungesData as $elem) {
$phpExcelObject
->getActiveSheet()
->getStyle('H' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . ($x + 1), $item['dateStart']->format('d/m/Y'))
->setCellValue('B' . ($x + 1), $item['title'])
->setCellValue('C' . ($x + 1), $item['reservationId'])
->setCellValue('D' . ($x + 1), $item['clientName'])
->setCellValue('E' . ($x + 1), $elem['loungeName'])
->setCellValue('F' . ($x + 1), $elem['category'])
->setCellValue('G' . ($x + 1), $elem['location'])
->setCellValue('H' . ($x + 1), (float)$elem['servicePrice'])
;
$location = $elem['location'];
$x++;
}
$servicesData = $item['arrayServicesData'][$item['reservationId']] ?? [];
foreach ($servicesData as $elem) {
$phpExcelObject
->getActiveSheet()
->getStyle('H' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . ($x + 1), $item['dateStart']->format('d/m/Y'))
->setCellValue('B' . ($x + 1), $item['title'])
->setCellValue('C' . ($x + 1), $item['reservationId'])
->setCellValue('D' . ($x + 1), $item['clientName'])
->setCellValue('E' . ($x + 1), $elem['name'])
->setCellValue('F' . ($x + 1), $elem['category'])
->setCellValue('G' . ($x + 1), $location)
->setCellValue('H' . ($x + 1), (float)$elem['price'])
;
$x++;
}
}
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = new Xlsx($phpExcelObject);
// Envia la respuesta del controlador
$response = new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
}
);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'Grupo_Green_Patio' . '.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
$tot = $indiceFinal + 7;
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('L' . ($tot + 2), 'Grupo Green Patio')
->setCellValue('L' . ($tot + 3), 'comercial@greenpatio.es')
->setCellValue('L' . ($tot + 4), '+34 669 01 88 34');
$phpExcelObject
->getActiveSheet()
->getStyle('k' . ($tot + 2) . ':' . 'O' . ($tot + 4))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject->getActiveSheet()->setTitle('EstadÃsticas');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = new Xlsx($phpExcelObject);
// Envia la respuesta del controlador
$response = new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
}
);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'Green Patio - Estadisticas' . '.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
return $response;
}
/**
* @Route("/liststatisticsclient/", name="reservations_greenpatio_list_statistics_client")
* Estadisticas por las ventas de los clientes
*/
public function listStatisticsClientReservationAction(EntityManagerInterface $em, Request $request)
{
$clients = $em->getRepository(Client::class)->findAll();
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-client.html.twig',
array(
'data' => null,
'clients' => $clients,
'clientId' => 0,
'salas' => $salas,
'consulta' => null,
'dateStartReq' => null,
'dateEndReq' => null,
));
}
/**
* @Route("/responseliststatisticsclient/", name="reservations_greenpatio_response_list_statistics_client")
* Respuesta de las estadisticas de clientes
*/
public function responseListStatisticsReservationClientAction(EntityManagerInterface $em, Request $request)
{
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
$dateRequest = $request->request->get('forecast');
$clientId = $request->request->get('client');
// $boolStatus = $request->request->get('boolStatus');
$boolStatus = array('Invoiced' => 'on' );
$dateStartReq = $dateRequest['date_start'];
$dateEndReq = $dateRequest['date_end'];
$clients = $em->getRepository(Client::class)->findAll();
$consulta = 'Del '. (new \DateTime($dateStartReq))->format('d/m/Y').' al '.(new \DateTime($dateEndReq))->format('d/m/Y').' de todos los expedientes facturados';
$data = $this->baseForecastClient($dateStartReq,$dateEndReq, $boolStatus, $clientId);
$boolBlocked = !empty($boolStatus['Blocked']) ? true : false ;
$boolConfirmed = !empty($boolStatus['Confirmed']) ? true : false;
$boolQuoted = !empty($boolStatus['Quoted']) ? true : false;
$boolInvoiced = !empty($boolStatus['Invoiced']) ? true : false;
$boolCancel = !empty($boolStatus['Cancel']) ? true : false;
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-client.html.twig',
array(
'data' => $data['reservationsClients'],
'clients' => $clients,
'salas' => $salas,
'consulta' => $consulta,
'clientId' => $clientId,
'dateStartReq' => $dateStartReq,
'dateEndReq' => $dateEndReq,
'boolBlocked' => $boolBlocked,
'boolConfirmed' => $boolConfirmed,
'boolQuoted' => $boolQuoted,
'boolInvoiced' => $boolInvoiced,
'boolCancel' => $boolCancel,
'netoForeCast' => $data['netoForeCast'],
'vatForeCast' => $data['vatForeCast'],
'totalForeCast' => $data['totalForeCast'],
));
}
/**
* @Route("/xlsliststatisticsclient/", name="excel_list_statistics_client")
* Respuesta de las estadisticas de clientes
*/
public function excelListStatisticsReservationClientAction(EntityManagerInterface $em, Request $request)
{
$dateRequest = $request->request->get('xls');
$clientId = $dateRequest['clientId'];
// $boolStatus = $request->request->get('boolStatus');
$boolStatus = array('Invoiced' => 'on' );
$dateStartReq = $dateRequest['dateStartReq'];
$dateEndReq = $dateRequest['dateEndReq'];
$consulta = 'Del '. (new \DateTime($dateStartReq))->format('d/m/Y').' al '.(new \DateTime($dateEndReq))->format('d/m/Y').',';
$data = $this->baseForecastClient($dateStartReq,$dateEndReq, $boolStatus, $clientId);
// Solicita el servicio de excel
$phpExcelObject = new Spreadsheet();
$phpExcelObject->getProperties()->setCreator("Grupo Green Patio")
->setLastModifiedBy("Grupo Green Patio")
->setTitle("Grupo Green Patio")
->setSubject("Grupo Green Patio")
->setDescription("Grupo Green Patio, generado usando clases de PHP")
->setKeywords("office 2005 openxml php")
->setCategory("Archivo de estadisticas");
$fill = new Fill();
$numberFormat = new NumberFormat();
$alignment = new Alignment();
$i = 6;
$indiceInicial = 7;
$indiceFinal = 7;
$activesheet = $phpExcelObject->getActiveSheet();
$drawingobject = new Drawing();
$drawingobject->setName('Image name');
$drawingobject->setDescription('Image description');
$drawingobject->setPath(getcwd() . '/assets/images/logo/logo_green_patio.png');
$drawingobject->setHeight(60);
$drawingobject->setOffsetY(20);
$drawingobject->setCoordinates('Q1');
$drawingobject->setWorksheet($activesheet);
$phpExcelObject
->getActiveSheet()
->getStyle('B3:O3')
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('C3', 'EstadÃsticas ' . $consulta);
$phpExcelObject
->getActiveSheet()
->getStyle('B' . $i . ':R' . $i)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('d1d1cf');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B' . $i, 'No. de Orden')
->setCellValue('D' . $i, 'Cliente')
->setCellValue('G' . $i, 'Neto (€)')
->setCellValue('I' . $i, 'Total Eventos (€)')
->setCellValue('L' . $i, 'Facturación (%)')
->setCellValue('N' . $i, 'Beneficio (€)')
->setCellValue('P' . $i, 'Eventos')
->setCellValue('R' . $i, 'Rentabilidad (%)');
$phpExcelObject->getActiveSheet()->getStyle('N' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('P' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('R' . $i)
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$indice = 1;
foreach ($data['reservationsClients'] as $item) {
$phpExcelObject
->getActiveSheet()
->getStyle('L' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$phpExcelObject
->getActiveSheet()
->getStyle('N' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
$phpExcelObject
->getActiveSheet()
->getStyle('R' . ($i + 1))
->getNumberFormat()
->setFormatCode('#,##0.00');
// $txtProducto = '';
// $loungesData = $item['arrayLoungesData'][$item['reservationId']] ?? [];
// foreach ($loungesData as $elem) {
// $txtProducto.= $elem['loungeName']. ' - '. $elem['category'].' - ('. number_format((float)$elem['servicePrice'], 2, ',', '.'). ' € )'."\r\n";
// }
//
// $servicesData = $item['arrayServicesData'][$item['reservationId']] ?? [];
// foreach ($servicesData as $elem) {
// $txtProducto.= $elem['name']. ' - '. $elem['category'].' - ('. number_format((float)$elem['price'], 2, ',', '.'). ' € )'."\r\n";
// }
// $txtProducto = rtrim($txtProducto, "\r\n");
$phpExcelObject->getActiveSheet()->getStyle('L' . ($i + 1))->getAlignment()->setWrapText(true);
$phpExcelObject->getActiveSheet()->getColumnDimension('L')->setAutoSize(true);
$phpExcelObject->getActiveSheet()->getRowDimension($i + 1)->setRowHeight(-1);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B' . ($i + 1), $indice)
->setCellValue('D' . ($i + 1), $item['reservas'][0]['clientName'])
->setCellValue('G' . ($i + 1), $item['netoTotalCliente'])
->setCellValue('I' . ($i + 1), $item['totalCliente'])
->setCellValue('L' . ($i + 1), $item['percFacturaTotalClienteContraFacturaTotalEventos'] )
->setCellValue('N' . ($i + 1), $item['beneficioCliente'])
->setCellValue('P' . ($i + 1), $item['numeroEventosCliente'])
->setCellValue('R' . ($i + 1), $item['rentabilidadPercBenefit']);
$i++;
$indice++;
$indiceFinal++;
}
$indiceFinal--;
$phpExcelObject
->getActiveSheet()
->getStyle('E' . ($indiceFinal + 3) . ':' . 'R' . ($indiceFinal + 3))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject
->getActiveSheet()
->getStyle('N' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('N')
->setAutoSize(true);
$phpExcelObject
->getActiveSheet()
->getStyle('G' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('P')
->setAutoSize(true);
$phpExcelObject
->getActiveSheet()
->getStyle('R' . ($indiceFinal + 4))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getColumnDimension('R')
->setAutoSize(true);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('G' . ($indiceFinal + 3), 'Neto')
->setCellValue('I' . ($indiceFinal + 3), 'Total Eventos')
->setCellValue('N' . ($indiceFinal + 3), 'Beneficio')
->setCellValue('P' . ($indiceFinal + 3), 'Eventos')
// ->setCellValue('R' . ($indiceFinal + 3), 'Total')
;
$phpExcelObject->getActiveSheet()->getStyle('N' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('P' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->getActiveSheet()->getStyle('R' . ($indiceFinal + 3))
->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('G' . ($indiceFinal + 4), '=SUM(' . 'G' . $indiceInicial . ' : G' . $indiceFinal . ')')
->setCellValue('I' . ($indiceFinal + 4), '=SUM(' . 'I' . $indiceInicial . ' : I' . $indiceFinal . ')')
->setCellValue('N' . ($indiceFinal + 4), '=SUM(' . 'N' . $indiceInicial . ' : N' . $indiceFinal . ')')
->setCellValue('P' . ($indiceFinal + 4), '=SUM(' . 'P' . $indiceInicial . ' : P' . $indiceFinal . ')')
// ->setCellValue('R' . ($indiceFinal + 4), '=SUM(' . 'R' . $indiceInicial . ' : R' . $indiceFinal . ')')
;
$phpExcelObject->getActiveSheet()->setTitle('EstadÃsticas');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Creamos pagina de Datos en bruto para Esteban Rincon
// Add new sheet
$objWorkSheet = $phpExcelObject->createSheet(1); //Setting index when creating
$phpExcelObject->setActiveSheetIndex(1);
$phpExcelObject->getActiveSheet()->setTitle('Datos en bruto');
$x = 1;
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . $x, 'Fecha')
->setCellValue('B' . $x, 'Nombre')
->setCellValue('C' . $x, 'Expediente')
->setCellValue('D' . $x, 'Cliente')
->setCellValue('E' . $x, 'Productos')
->setCellValue('F' . $x, 'Categoria')
->setCellValue('G' . $x, 'Ubicacion')
->setCellValue('H' . $x, 'Venta Producto')
->setCellValue('I' . $x, 'Venta Neta')
->setCellValue('J' . $x, 'Iva')
->setCellValue('K' . $x, 'Total');
if (false) {
foreach ($data['reservations'] as $item) {
$phpExcelObject
->getActiveSheet()
->getStyle('H' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('K' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('I' . ($x + 1), $item['neto'])
->setCellValue('J' . ($x + 1), $item['vat'])
->setCellValue('K' . ($x + 1), $item['total']);
$location = '';
$loungesData = $item['arrayLoungesData'][$item['reservationId']] ?? [];
foreach ($loungesData as $elem) {
$phpExcelObject
->getActiveSheet()
->getStyle('H' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . ($x + 1), $item['dateStart']->format('d/m/Y'))
->setCellValue('B' . ($x + 1), $item['title'])
->setCellValue('C' . ($x + 1), $item['reservationId'])
->setCellValue('D' . ($x + 1), $item['clientName'])
->setCellValue('E' . ($x + 1), $elem['loungeName'])
->setCellValue('F' . ($x + 1), $elem['category'])
->setCellValue('G' . ($x + 1), $elem['location'])
->setCellValue('H' . ($x + 1), (float)$elem['servicePrice']);
$location = $elem['location'];
$x++;
}
$servicesData = $item['arrayServicesData'][$item['reservationId']] ?? [];
foreach ($servicesData as $elem) {
$phpExcelObject
->getActiveSheet()
->getStyle('H' . ($x + 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . ($x + 1), $item['dateStart']->format('d/m/Y'))
->setCellValue('B' . ($x + 1), $item['title'])
->setCellValue('C' . ($x + 1), $item['reservationId'])
->setCellValue('D' . ($x + 1), $item['clientName'])
->setCellValue('E' . ($x + 1), $elem['name'])
->setCellValue('F' . ($x + 1), $elem['category'])
->setCellValue('G' . ($x + 1), $location)
->setCellValue('H' . ($x + 1), (float)$elem['price']);
$x++;
}
}
}
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = new Xlsx($phpExcelObject);
// Envia la respuesta del controlador
$response = new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
}
);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'Grupo_Green_Patio' . '.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
$tot = $indiceFinal + 7;
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('L' . ($tot + 2), 'Grupo Green Patio')
->setCellValue('L' . ($tot + 3), 'comercial@greenpatio.es')
->setCellValue('L' . ($tot + 4), '+34 669 01 88 34');
$phpExcelObject
->getActiveSheet()
->getStyle('k' . ($tot + 2) . ':' . 'O' . ($tot + 4))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9ba67c');
$phpExcelObject->getActiveSheet()->setTitle('EstadÃsticas');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = new Xlsx($phpExcelObject);
// Envia la respuesta del controlador
$response = new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
}
);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'Green Patio - Estadisticas' . '.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
return $response;
}
/**
* @Route("/liststatquoting", name="reservations_greenpatio_list_stats_quoting")
* Estadisticas de expedientes inicializados en un periodo de tiempo
*/
public function listStatisticsQuotingReservationAction(EntityManagerInterface $em, Request $request)
{
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-quoting.html.twig',
array(
'data' => null,
'dateStartReq' => null,
'dateEndReq' => null,
'numberTotRes' => null,
'numberIniciado' => null,
'numberBloqueado' => null,
'numberConfirmado' => null,
'numberCotizado' => null,
'numberCancelado' => null,
'numberFacturado' => null,
'percIniciado' => null,
'percBloqueado' => null,
'percConfirmado' => null,
'percCotizado' => null,
'percCancelado' => null,
'percFacturado' => null,
'dataDonut' => null,
'legend' => null,
));
}
/**
* @Route("/responseliststatquoting", name="reservations_greenpatio_response_list_stats_quoting")
* Respuesta de estadisticas de expedientes inicializados en un periodo de tiempo y sus cambios de estados
*/
public function responseListStatisticsQuotingReservationAction(EntityManagerInterface $em, Request $request)
{
$dateRequest = $request->request->get('forecast');
$dateStartReq = $dateRequest['date_start'];
$dateStartReq .= ' 00:00:00';
$dateEndReq = $dateRequest['date_end'];
$dateEndReq .= ' 23:59:59';
$parameters = array( 'start' => $dateStartReq, 'end'=> $dateEndReq, );
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.createdAt BETWEEN :start AND :end
ORDER BY p.createdAt ASC
";
$query = $em->createQuery($dql)->setParameters($parameters);
$reservations = $query->getResult();
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE (p.dateStart BETWEEN :start AND :end)
AND (p.updatedAt BETWEEN :start AND :end)
AND (p.createdAt < :start OR p.createdAt > :end)
ORDER BY p.createdAt ASC
";
$query = $em->createQuery($dql)->setParameters($parameters);
$reservationsGanadas = $query->getResult();
$numberTotRes = sizeof($reservations);
$data = []; $numberIniciado = $numberBloqueado = $numberConfirmado = $numberCotizado = $numberCancelado = $numberFacturado = $numberGanado = $numberGanConf = $numberGanFac = 0;
if(!empty($reservations)){
foreach ($reservations as $item){
$client = (empty($item->getClient())) ?
(empty($item->getNameContactUnregistered()) ? 'No se asigno un cliente, ni se especifico un cliente no registrado': $item->getNameContactUnregistered()) :
(empty($em->getRepository(Client::class)->findOneById($item->getClient())) ? 'No se pudo encontrar el cliente en la base de datos' : ($em->getRepository(Client::class)->findOneById($item->getClient()))->getName());
$agentId = $item->getCreatedBy();
$agent = $em->getRepository(User::class)->findOneById($agentId);
$agent = empty($agent) ? 'No se encontro al agente' : ($agent->getName() . ' '. $agent->getLastName());
$resStatus = null;
switch ($item->getStatus()){
case 'Iniciado': $numberIniciado++; $resStatus = 'Iniciado'; break;
case 'Bloqueo': $numberBloqueado++; $resStatus = 'Bloqueado'; break;
case 'Confirmed': $numberConfirmado++; $resStatus = 'Confirmado'; break;
case 'Cotizado': $numberCotizado++; $resStatus = 'Cotizado'; break;
case 'Deleted': $numberCancelado++; $resStatus = 'Cancelado'; break;
case 'Invoiced': $numberFacturado++; $resStatus = 'Facturado'; break;
default: break;
}
$data[]= array(
'dateReference' => $item->getCreatedAt(),
'reservationId' => $item->getId(),
'title' => $item->getTitle(),
'clientName' => $client,
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'status' => $resStatus,
'createdAt' => $item->getCreatedAt(),
'createdBy' => $agentId,
'agentFullName' => $agent,
);
}
}
if(!empty($reservationsGanadas)){
foreach ($reservationsGanadas as $item){
if (($item->getStatus() == 'Confirmed') or ($item->getStatus() == 'Invoiced')) {
$client = (empty($item->getClient())) ?
(empty($item->getNameContactUnregistered()) ? 'No se asigno un cliente, ni se especifico un cliente no registrado' : $item->getNameContactUnregistered()) :
(empty($em->getRepository(Client::class)->findOneById($item->getClient())) ? 'No se pudo encontrar el cliente en la base de datos' : ($em->getRepository(Client::class)->findOneById($item->getClient()))->getName());
$agentId = $item->getCreatedBy();
$agent = $em->getRepository(User::class)->findOneById($agentId);
$agent = empty($agent) ? 'No se encontro al agente' : ($agent->getName() . ' ' . $agent->getLastName());
$resStatus = null;
switch ($item->getStatus()) {
case 'Iniciado': break;
case 'Bloqueo': break;
case 'Confirmed':
$numberConfirmado++;
$numberGanado++;
$numberGanConf++;
$numberTotRes++;
$resStatus = 'Confirmado ( Ganado )';
break;
case 'Cotizado': break;
case 'Deleted': break;
case 'Invoiced':
$numberFacturado++;
$numberGanado++;
$numberGanFac++;
$numberTotRes++;
$resStatus = 'Facturado ( Ganado )';
break;
default:
break;
}
$data[] = array(
'dateReference' => $item->getCreatedAt(),
'reservationId' => $item->getId(),
'title' => $item->getTitle(),
'clientName' => $client,
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'status' => $resStatus,
'createdAt' => $item->getCreatedAt(),
'createdBy' => $agentId,
'agentFullName' => $agent,
);
}
}
}
if ($numberTotRes == 0){
$percIniciado = 0;
$percBloqueado = 0;
$percConfirmado = 0;
$percCotizado = 0;
$percCancelado = 0;
$percFacturado = 0;
} else {
$percIniciado = ($numberIniciado * 100) / $numberTotRes;
$percBloqueado = ($numberBloqueado * 100) / $numberTotRes;
$percConfirmado = ($numberConfirmado * 100) / $numberTotRes;
$percCotizado = ($numberCotizado * 100) / $numberTotRes;
$percCancelado = ($numberCancelado * 100) / $numberTotRes;
$percFacturado = ($numberFacturado * 100) / $numberTotRes;
}
$numberSumConBloFac = ($numberBloqueado + $numberConfirmado + $numberFacturado);
$perSumConBloFac = ($percBloqueado + $percConfirmado + $percFacturado);
$dataDonut = $legend = [];
$dataDonut = [
['name' => 'Iniciado', 'value' => $numberIniciado],
['name' => 'Bloqueado', 'value' => $numberBloqueado],
['name' => 'Confirmado', 'value' => $numberConfirmado],
['name' => 'Cotizado', 'value' => $numberCotizado],
['name' => 'Cancelado', 'value' => $numberCancelado],
['name' => 'Facturado', 'value' => $numberFacturado]
];
$legend = ['Iniciado', 'Bloqueado', 'Confirmado', 'Cotizado', 'Cancelado', 'Facturado'];
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-quoting.html.twig',
array(
'data' => $data,
'dateStartReq' => $dateStartReq,
'dateEndReq' => $dateEndReq,
'numberTotRes' => $numberTotRes,
'numberIniciado' => $numberIniciado,
'numberBloqueado' => $numberBloqueado,
'numberConfirmado' => $numberConfirmado,
'numberCotizado' => $numberCotizado,
'numberCancelado' => $numberCancelado,
'numberFacturado' => $numberFacturado,
'numberGanado' => $numberGanado,
'numberGanConf' => $numberGanConf,
'numberGanFac' => $numberGanFac,
'percIniciado' => $percIniciado,
'percBloqueado' => $percBloqueado,
'percConfirmado' => $percConfirmado,
'percCotizado' => $percCotizado,
'percCancelado' => $percCancelado,
'percFacturado' => $percFacturado,
'numberSumConBloFac' => $numberSumConBloFac,
'perSumConBloFac' => $perSumConBloFac,
'dataDonut' => $dataDonut,
'legend' => $legend,
));
}
/**
* @Route("/liststattarif", name="reservations_greenpatio_list_stats_tarif")
* Estadisticas de expedientes y el tarifario en un periodo de tiempo
*/
public function listStatisticsTarifReservationAction(EntityManagerInterface $em, Request $request)
{
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-tarif.html.twig',
array(
'data' => null,
'dateStartReq' => null,
'dateEndReq' => null,
'numberTotRes' => null,
'numberIniciado' => null,
'numberBloqueado' => null,
'numberConfirmado' => null,
'numberCotizado' => null,
'numberCancelado' => null,
'numberFacturado' => null,
'percIniciado' => null,
'percBloqueado' => null,
'percConfirmado' => null,
'percCotizado' => null,
'percCancelado' => null,
'percFacturado' => null,
'dataDonut' => null,
'legend' => null,
));
}
/**
* @Route("/responseliststattarif", name="reservations_greenpatio_response_list_stats_tarif")
* Respuesta de estadisticas de tarifarios
*/
public function responseListStatisticsTarifReservationAction(EntityManagerInterface $em, Request $request)
{
$dateRequest = $request->request->get('forecast');
$dateStartReq = $dateRequest['date_start'];
$dateStartReq .= ' 00:00:00';
$dateEndReq = $dateRequest['date_end'];
$dateEndReq .= ' 23:59:59';
$parameters = array( 'start' => $dateStartReq, 'end'=> $dateEndReq, 'stat'=>['Confirmed','Invoiced'] );
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND p.status in (:stat)
ORDER BY p.dateStart ASC
";
$query = $em->createQuery($dql)->setParameters($parameters);
$reservations = $query->getResult();
$numberTotRes = sizeof($reservations);
$data = []; $numberConfirmado = $numberFacturado = 0; $stat = '';
if(!empty($reservations)){
foreach ($reservations as $item){
$agent = $em->getRepository(User::class)->findOneById($item->getCreatedBy());
$agent = empty($agent) ? 'No se encontro el nombre del agente' : $agent->getName().' '.$agent->getLastName();
$client = $em->getRepository(Client::class)->findOneById($item->getClient());
$client = empty($client) ? 'No se encontro el nombre del cliente' : $client->getName();
if ($item->getStatus() == 'Confirmed'){ $numberConfirmado++; $stat = 'Confirmado'; } else { $numberFacturado++; $stat = 'Facturado'; }
$data[$item->getId()]= array(
'dateReference' => $item->getDateStart(),
'reservationId' => $item->getId(),
'title' => $item->getTitle(),
'clientName' => $client,
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'status' => $stat,
'createdAt' => $item->getCreatedAt(),
'createdBy' => $item->getCreatedBy(),
'agentFullName' => $agent,
'lounges' => [],
);
$reservaTionsLounges = $em->getRepository(ReservationLoungeSimple::class)->findByIdReservation($item->getId());
foreach ($reservaTionsLounges as $elem){
// PRECIO POR TARIFA
$dateToFind = clone $elem->getDateStart();
$dateToFind->setTime(0, 0, 0);
$parameters = array(
'loungeId' => $elem->getIdLounge(),
'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)) ? $loungesPeriodsDaily[0]->getPrice() : null;
if (!empty($elem->getType())){ $priceTarifa = null; } // por el momento no se han cargado tarifas para montajes ni desmontajes
$priceLounge = $elem->getServicePrice();
if (($priceTarifa != 0) and !empty($priceTarifa)) {
$variacion = (($priceLounge - $priceTarifa) / $priceTarifa) * 100;
$variacionTipo = ($priceLounge > $priceTarifa) ? 'Positiva' : (($priceLounge == $priceTarifa) ? 'Neutral' : 'Negativa');
} else {
// Si es cero la tarifa o nula, la variacion sera el precio
$variacion = $priceLounge;
$variacionTipo = 'No se pudo determinar la tarifa';
}
$typeLounge = empty($elem->getType()) ? null : $elem->getType().' - ';
$data[$item->getId()]['lounges'][$elem->getId()] = array(
'idLounge'=>$elem->getIdLounge(),
'loungeName'=>$elem->getLoungeName(),
'loungeType'=>$typeLounge,
'loungeDate'=>$elem->getDateStart(),
'loungePrice'=>$elem->getServicePrice(),
'loungeTarifa'=>$priceTarifa,
'variacion'=>$variacion,
'variacionTipo'=>$variacionTipo,
);
}
}
}
$dataDonut = $legend = [];
$dataDonut = [
['name' => 'Confirmado', 'value' => $numberConfirmado],
['name' => 'Facturado', 'value' => $numberFacturado]
];
$legend = ['Confirmado', 'Facturado'];
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-tarif.html.twig',
array(
'data' => $data,
'dateStartReq' => $dateStartReq,
'dateEndReq' => $dateEndReq,
'numberTotRes' => $numberTotRes,
'numberConfirmado' => $numberConfirmado,
'numberFacturado' => $numberFacturado,
'dataDonut' => $dataDonut,
'legend' => $legend,
));
}
/**
* @Route("/liststatisticsfromweb/", name="reservations_greenpatio_list_statistics_from_web")
* Estadisticas de expedientes inicializados por formulario de la web
*/
public function listStatisticsReservationFromWebAction(EntityManagerInterface $em, Request $request)
{
$clients = $em->getRepository(Client::class)->findAll();
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-from-web.html.twig',
array(
'data' => null,
// 'clients' => $clients,
// 'clientId' => 0,
'salas' => $salas,
'consulta' => null,
'dateStartReq' => null,
'dateEndReq' => null,
));
}
/**
* @Route("/responseliststatisticsfromweb/", name="reservations_greenpatio_response_list_statistics_from_web")
* Respuesta de expedientes inicializados por formulario de la web
*/
public function responseListStatisticsReservationFromWebAction(EntityManagerInterface $em, Request $request)
{
$salas = $em->getRepository(ReservationLoungeDetails::class)->findAll();
$dateRequest = $request->request->get('forecast');
// $clientId = $request->request->get('client');
$boolStatus = $request->request->get('boolStatus');
$selectedSalasNames = $request->request->get('selected_salas');
$arraySalasId = empty($request->request->get('tags')) ? null : $request->request->get('tags')['tags2'];
$dateStartReq = (!empty($dateRequest)) ? $dateRequest['date_start'] : '01-10-2025';
$dateEndReq = (!empty($dateRequest)) ? $dateRequest['date_end'] : '31-10-2025';
$data = $this->baseForecastWeb($dateStartReq,$dateEndReq, $boolStatus, $arraySalasId);
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
$clients = $em->getRepository(Client::class)->findAll();
$consulta = 'Del '. (new \DateTime($dateStartReq))->format('d/m/Y').' al '.(new \DateTime($dateEndReq))->format('d/m/Y').',';
if (!empty($boolStatus['Blocked']) and
!empty($boolStatus['Confirmed']) and
!empty($boolStatus['Quoted']) and
!empty($boolStatus['Invoiced']) and
!empty($boolStatus['Cancel'])
){
$consulta.=' todos los expedientes,';
} else {
$consulta.=' los expedientes';
if (!empty($boolStatus['Blocked'])) { $consulta .= ' Bloqueados,'; }
if (!empty($boolStatus['Confirmed'])) { $consulta .= ' Confirmados,'; }
if (!empty($boolStatus['Quoted'])) { $consulta .= ' Cotizados,'; }
if (!empty($boolStatus['Invoiced'])) { $consulta .= ' Facturados,'; }
if (!empty($boolStatus['Cancel'])) { $consulta .= ' Cancelados,'; }
}
if(empty($selectedSalasNames)) { $consulta.= ' de todas las salas.'; } else { $consulta.= ' en '.$selectedSalasNames.'.'; }
$boolBlocked = !empty($boolStatus['Blocked']) ? true : false ;
$boolConfirmed = !empty($boolStatus['Confirmed']) ? true : false;
$boolQuoted = !empty($boolStatus['Quoted']) ? true : false;
$boolInvoiced = !empty($boolStatus['Invoiced']) ? true : false;
$boolCancel = !empty($boolStatus['Cancel']) ? true : false;
return $this->render('MDS/GreenPatioBundle/reservations/list-statistics-from-web.html.twig',
array(
'data' => $data['reservations'],
'clients' => $clients,
'salas' => $salas,
'consulta' => $consulta,
'company' => $company,
// 'clientId' => $clientId,
'arrayStatusCont' => $data['arrayStatusCont'],
'dateStartReq' => $dateStartReq,
'dateEndReq' => $dateEndReq,
'boolBlocked' => $boolBlocked,
'boolConfirmed' => $boolConfirmed,
'boolQuoted' => $boolQuoted,
'boolInvoiced' => $boolInvoiced,
'boolCancel' => $boolCancel,
'selectedSalasNames' => $selectedSalasNames,
'arraySalasId' => empty($arraySalasId) ? null : implode(",", $arraySalasId),
'netoForeCast' => $data['netoForeCast'],
'vatForeCast' => $data['vatForeCast'],
'totalForeCast' => $data['totalForeCast'],
));
}
private function baseForecast($dateStartReq, $dateEndReq, $boolStatus, $clientId, $arraySalasId)
{
$em = $this->getDoctrine()->getManager();
$today = new \DateTime("now", NULL);
$data = [];
if (empty($boolStatus['Blocked'])){ $opBlocked = null; } else { $opBlocked = 'Bloqueo'; }
if (empty($boolStatus['Confirmed'])){ $opConfirmed = null; } else { $opConfirmed = 'Confirmed'; }
if (empty($boolStatus['Quoted'])){ $opQuoted = null; } else { $opQuoted = 'Cotizado'; }
if (empty($boolStatus['Invoiced'])){ $opInvoiced = null; } else { $opInvoiced = 'Invoiced'; }
if (empty($boolStatus['Cancel'])){ $opDeleted = null; } else { $opDeleted = 'Deleted'; }
$dateEndReq = empty($dateEndReq) ? null : new \Datetime($dateEndReq . '+ 1 days'); //Se le suma un dia, para que se considere el ultimo dia en la consulta
// Si solo introduce fecha de inicio
// Se consulta de fecha inicio a fecha actual
if (!empty($dateStartReq) and empty($dateEndReq) and empty($monthReq) and empty($yearReq)){
$parameters = array(
'start' => $dateStartReq,
'end'=> $today,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)){
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client != :clientId
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Si solo introduce fecha de fin
// Se consulta desde el inicio (2019) a la fecha indicada
if (!empty($dateEndReq) and empty($dateStartReq) and empty($monthReq) and empty($yearReq)){
$parameters = array(
'start' => '2019-01-01',
'end'=> $dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client != :clientId
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Si solo introduce mes
// Se consulta el mes indicado del año en curso
if (!empty($monthReq) and empty($dateStartReq) and empty($dateEndReq) and empty($yearReq)){
$stringStart = $today->format('Y').'-'.$monthReq.'-01';
$stringEnd = $today->format('Y').'-'.$monthReq.'-31'; // Todos los meses podrian ser consultados hasta el dia 31, incluso en febrero
$parameters = array(
'start' => $stringStart,
'end'=> $stringEnd,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client != :clientId
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Si solo introduce año
//Se consulta del 01-01 al 31-12 del año indicado
if (!empty($yearReq) and empty($dateStartReq) and empty($dateEndReq) and empty($monthReq)){
$stringStart = $yearReq.'-01-01';
$stringEnd = $yearReq.'-12-31';
$parameters = array(
'start' => $stringStart,
'end'=> $stringEnd,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client != :clientId
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Se introduce un mes de un año en especifico
if (!empty($yearReq) and !empty($monthReq) and empty($dateEndReq) and empty($dateStartReq)){
$stringStart = $yearReq.'-'.$monthReq.'-01';
$stringEnd = $yearReq.'-'.$monthReq.'-31';
$parameters = array(
'start' => $stringStart,
'end'=> $stringEnd,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client != :clientId
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Se introduce una fecha de inicio y una fecha de fin
if (!empty($dateEndReq) and !empty($dateStartReq) and empty($yearReq) and empty($monthReq)){
$parameters = array(
'start' => $dateStartReq,
'end'=> $dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)) {
// Se modifican los parametros para despreciar el campo cliente
$parameters = array(
'start' => $dateStartReq,
'end'=>$dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND (p.dateEnd BETWEEN :start AND :end)
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND (p.dateEnd BETWEEN :start AND :end)
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
// Se requiere que los eventos que finalicen en el periodo solicitado se
// reflejen en la respuesta incluso si el evento inicia antes del primer dÃa
// de la consulta. Solicitud: Rafael Guerrero y Gabriela Bracho.
if (empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart < :start
AND (p.dateEnd BETWEEN :start AND :end)
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart < :start
AND p.dateEnd BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$zData = $query->getResult();
// Agregamos los eventos que iniciando fuera del periodo de consulta, terminan durante el periodo de consulta. Solicitud: Rafael Guerrero y Gabriela Bracho.
foreach ($zData as $zItem){ $data[] = $zItem; }
}
// INICIO: Acotamos segun la(s) sala(s) seleccionada(s)
if (!empty($arraySalasId)) {
$zData = [];
foreach ($data as $item) {
if ($item->getStatus() == 'Invoiced') {
$zExiste = $em->getRepository(ReservationInvoiceItems::class)
->createQueryBuilder('r')
->where('r.reservationId = :reservationId')
->andWhere('r.lngIdLounge IN (:arrayIndices)')
->setParameter('reservationId', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
if (empty($zExiste)){
$zExiste = $em->getRepository(CvrReservationInvoiceItems::class)
->createQueryBuilder('r')
->where('r.reservationId = :reservationId')
->andWhere('r.lngIdLounge IN (:arrayIndices)')
->setParameter('reservationId', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
}
if (empty($zExiste)){
$zExiste = $em->getRepository(BlvReservationInvoiceItems::class)
->createQueryBuilder('r')
->where('r.reservationId = :reservationId')
->andWhere('r.lngIdLounge IN (:arrayIndices)')
->setParameter('reservationId', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
}
if (!empty($zExiste)) {
$zData[] = $item;
}
} else {
$zExiste = $em->getRepository(ReservationLoungeSimple::class)
->createQueryBuilder('r')
->where('r.idReservation = :idReservation')
->andWhere('r.idLounge IN (:arrayIndices)')
->setParameter('idReservation', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
if (!empty($zExiste)) {
$zData[] = $item;
}
}
}
$data = $zData;
}
// FIN: Acotamos segun la(s) sala(s) seleccionada(s)
//dd($data);
// ************************************************************************************************************************
// ************************************ AGREGAMOS LAS FACTURAS DE COMISION ************************************************
// ************************************************************************************************************************
// $parameters = array(
// 'start' => $dateStartReq,
// 'end'=> $dateEndReq,
// 'clientType'=> 'Supplier',
// );
//
// $dql = "SELECT p
// FROM App\MDS\GreenPatioBundle\Entity\ReservationInvoice p
// WHERE p.dateAt BETWEEN :start AND :end
// AND p.clientType = :clientType
// ORDER BY p.dateAt ASC";
//
//
// $query = $em->createQuery($dql)->setParameters($parameters);
// $invoiceSuppGp = $query->getResult();
//
// $dql = "SELECT p
// FROM App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice p
// WHERE p.dateAt BETWEEN :start AND :end
// AND p.clientType = :clientType
// ORDER BY p.dateAt ASC";
//
//
// $query = $em->createQuery($dql)->setParameters($parameters);
// $invoiceSuppCvr = $query->getResult();
//
// $dql = "SELECT p
// FROM App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice p
// WHERE p.dateAt BETWEEN :start AND :end
// AND p.clientType = :clientType
// ORDER BY p.dateAt ASC";
//
//
// $query = $em->createQuery($dql)->setParameters($parameters);
// $invoiceSuppBlv = $query->getResult();
// ************************************************************************************************************************
// ************************************ AGREGAMOS LAS FACTURAS DE COMISION ************************************************
// ************************************************************************************************************************
// if(!empty($invoiceSuppGp)){
// // Verificamos si esta dentro de $data la reserva
// foreach ($invoiceSuppGp as $item){
// $logExisteData = false;
// foreach ($data as $elem){
// if ($elem->getId() == $item->getReservationId()){ $logExisteData = true; }
// }
//
// if (!$logExisteData){
// $xResv = $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
// $data[] = $xResv;
// }
// }
// }
//
// if(!empty($invoiceSuppCvr)){
// // Verificamos si esta dentro de $data la reserva
// foreach ($invoiceSuppCvr as $item){
// $logExisteData = false;
// foreach ($data as $elem){
// if ($elem->getId() == $item->getReservationId()){ $logExisteData = true; }
// }
//
// if (!$logExisteData){
// $xResv = $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
// $data[] = $xResv;
// }
// }
// }
//
// if(!empty($invoiceSuppBlv)){
// // Verificamos si esta dentro de $data la reserva
// foreach ($invoiceSuppBlv as $item){
// $logExisteData = false;
// foreach ($data as $elem){
// if ($elem->getId() == $item->getReservationId()){ $logExisteData = true; }
// }
//
// if (!$logExisteData){
// $xResv = $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
// $data[] = $xResv;
// }
// }
// }
$newData = [];
$netoForeCast = $vatForeCast = $totalForeCast = 0;
foreach ($data as $item){
$neto = $vat = $total = 0;
$lounges = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple')->findByIdReservation($item->getId());
$txtArrayLoungesNames = [];
$arrayLoungesData = [];
foreach ($lounges as $elem){
//Verificamos que la sala se encuentre facturada, el expediente pudo entrar por una factura de comisión
// $isInvoicedLoungeGp = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems')->findByLngControlId($elem->getId());
// $isInvoicedLoungeCv = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceItems')->findByLngControlId($elem->getId());
// $isInvoicedLoungeBl = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceItems')->findByLngControlId($elem->getId());
//
// if (!empty($isInvoicedLoungeGp)){
// // Verificamos la fecha de la factura
// $xFact = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoice')->findOneById($isInvoicedLoungeGp[0]->getInvoiceId());
// if (!($xFact->getDateAt() >= $dateStartReq && $xFact->getDateAt() <= $dateEndReq)) {
// $isInvoicedLoungeGp = null;
// }
// }
//
// if (!empty($isInvoicedLoungeCv)){
// // Verificamos la fecha de la factura
// $xFact = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice')->findOneById($isInvoicedLoungeCv[0]->getInvoiceId());
// if (!($xFact->getDateAt() >= $dateStartReq && $xFact->getDateAt() <= $dateEndReq)) {
// $isInvoicedLoungeCv = null;
// }
// }
//
// if (!empty($isInvoicedLoungeBl)){
// // Verificamos la fecha de la factura
// $xFact = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice')->findOneById($isInvoicedLoungeBl[0]->getInvoiceId());
// if (!($xFact->getDateAt() >= $dateStartReq && $xFact->getDateAt() <= $dateEndReq)) {
// $isInvoicedLoungeBl = null;
// }
// }
// $isInvoicedLounge = array_merge($isInvoicedLoungeGp,$isInvoicedLoungeCv,$isInvoicedLoungeBl);
// if (!empty($isInvoicedLounge)) {
// if (true) {
if ($elem->getIdLounge() < 19) {
$location = 'Green Patio';
} elseif ($elem->getIdLounge() > 19 && $elem->getIdLounge() < 22) {
$location = 'Green Patio + Sala 25';
} elseif ($elem->getIdLounge() > 21 && $elem->getIdLounge() < 30) {
$location = 'Covarrubias';
} elseif ($elem->getIdLounge() > 29 && $elem->getIdLounge() < 40) {
$location = 'Bella View';
} else {
$location = 'Sala 25';
}
$category = empty($elem->getType()) ? 'SALA' : 'SALA ' . $elem->getType();
$arrayLoungesData[$item->getId()][] = array('loungeName' => $elem->getLoungeName(), 'idLounge' => $elem->getIdLounge(), 'servicePrice' => $elem->getServicePrice(), 'location' => $location, 'category' => $category);
if (!empty($elem->getServicePrice())) {
$neto = $neto + floatval($elem->getServicePrice());
$vat = $vat + (floatval($elem->getServicePrice()) * floatval($elem->getIva()) / 100);
$total = $total + (floatval($elem->getServicePrice()) * (1 + floatval($elem->getIva()) / 100));
$txtArrayLoungesNames[$elem->getIdLounge()] = $elem->getLoungeName();
}
// }
}
// INICIO: Agregamos los servicios
$servicesx = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationService')->findBy( array( 'reservationId' => $item->getId(), 'toinvoice' => true ));
$arrayServicesData = [];
foreach ($servicesx as $elem){
//Verificamos que el servicio se encuentre facturado, el expediente pudo entrar por una factura de comisión
// $isInvoicedServiceGp = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems')->findBySrvControlId($elem->getId());
// $isInvoicedServiceCv = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceItems')->findBySrvControlId($elem->getId());
// $isInvoicedServiceBl = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceItems')->findBySrvControlId($elem->getId());
//
// if (!empty($isInvoicedServiceGp)){
// // Verificamos la fecha de la factura
// $xFact = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoice')->findOneById($isInvoicedServiceGp[0]->getInvoiceId());
// if (!($xFact->getDateAt() >= $dateStartReq && $xFact->getDateAt() <= $dateEndReq)) {
// $isInvoicedServiceGp = null;
// }
// }
//
// if (!empty($isInvoicedServiceCv)){
// // Verificamos la fecha de la factura
// $xFact = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice')->findOneById($isInvoicedServiceCv[0]->getInvoiceId());
// if (!($xFact->getDateAt() >= $dateStartReq && $xFact->getDateAt() <= $dateEndReq)) {
// $isInvoicedServiceCv = null;
// }
// }
//
// if (!empty($isInvoicedServiceBl)){
// // Verificamos la fecha de la factura
// $xFact = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice')->findOneById($isInvoicedServiceBl[0]->getInvoiceId());
// if (!($xFact->getDateAt() >= $dateStartReq && $xFact->getDateAt() <= $dateEndReq)) {
// $isInvoicedServiceBl = null;
// }
// }
// $isInvoicedService = array_merge($isInvoicedServiceGp,$isInvoicedServiceCv,$isInvoicedServiceBl);
// if (!empty($isInvoicedService)) {
if (!empty($elem->getPrice())) {
if (($elem->getUnits() == 0) or (empty($elem->getUnits()))) {
$unitsx = 1;
} else {
$unitsx = $elem->getUnits();
}
if (($elem->getPax() == 0) or (empty($elem->getPax()))) {
$paxx = 1;
} else {
$paxx = $elem->getPax();
}
if (($elem->getToinvoice() == 0) or (empty($elem->getToinvoice()))) {
$toinvoicex = 0;
} else {
$toinvoicex = 1;
}
$pricex = (float)$elem->getPrice() * $unitsx * $paxx * $toinvoicex;
$category = ($elem->getServiceCatName() == 'Others') ? 'Otros' : $elem->getServiceCatName();
$arrayServicesData[$item->getId()][] = array(
'name' => $elem->getName(),
'serviceCatId' => $elem->getServiceCatId(),
'serviceCatName' => $elem->getServiceCatName(),
'price' => $elem->getPrice(),
'category' => $category,
);
switch ($elem->getIva()) {
case '21':
$ivax = 0.21;
$ivaxPlus = 1.21;
break;
case '10':
$ivax = 0.10;
$ivaxPlus = 1.10;
break;
case '0':
$ivax = 0;
$ivaxPlus = 1;
break;
default:
$ivax = 0.21;
$ivaxPlus = 1.21;
break;
}
$neto = $neto + $pricex;
$vat = $vat + ($pricex * $ivax);
$total = $total + ($pricex * $ivaxPlus);
}
// }
}
// FIN: Agregamos los servicios
// INICIO: Agregamos las facturas de comisión
$repo = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoice');
$qb = $repo->createQueryBuilder('ri');
$qb->where('ri.reservationId = :resId')
->andWhere('ri.clientType = :clientType')
// ->andWhere('ri.dateAt BETWEEN :dateStart AND :dateEnd')
->setParameter('resId', $item->getId())
->setParameter('clientType', 'Supplier')
// ->setParameter('dateStart', $dateStartReq)
// ->setParameter('dateEnd', $dateEndReq)
;
$supInvoicesxGp = $qb->getQuery()->getResult();
$repo = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice');
$qb = $repo->createQueryBuilder('ri');
$qb->where('ri.reservationId = :resId')
->andWhere('ri.clientType = :clientType')
// ->andWhere('ri.dateAt BETWEEN :dateStart AND :dateEnd')
->setParameter('resId', $item->getId())
->setParameter('clientType', 'Supplier')
// ->setParameter('dateStart', $dateStartReq)
// ->setParameter('dateEnd', $dateEndReq)
;
$supInvoicesxCv = $qb->getQuery()->getResult();
$repo = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice');
$qb = $repo->createQueryBuilder('ri');
$qb->where('ri.reservationId = :resId')
->andWhere('ri.clientType = :clientType')
// ->andWhere('ri.dateAt BETWEEN :dateStart AND :dateEnd')
->setParameter('resId', $item->getId())
->setParameter('clientType', 'Supplier')
// ->setParameter('dateStart', $dateStartReq)
// ->setParameter('dateEnd', $dateEndReq)
;
$supInvoicesxBl = $qb->getQuery()->getResult();
if (!empty($supInvoicesxGp)){
foreach ($supInvoicesxGp as $supInv){
$supInvIsRec = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRec')->findBy(array('invoiceToRec' => $supInv->getId()));
if (empty($supInvIsRec)) { // Solo agregamos si no estan rectificadas las facturas de comision
if ($supInv->getDateAt() >= $dateStartReq && $supInv->getDateAt() <= $dateEndReq) {
$supInvItemGp = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems')->findBy(array('invoiceId' => $supInv->getId()));
foreach ($supInvItemGp as $itemSupInv) {
$arrayServicesData[$itemSupInv->getId() . 'InvSupGp'][] = array(
'name' => $itemSupInv->getSrvName(),
'serviceCatId' => $itemSupInv->getSrvServiceCatId(),
'serviceCatName' => $itemSupInv->getSrvServiceCatName(),
'price' => $itemSupInv->getSrvOver(),
'category' => 'Factura de Comisión',
);
$neto += $itemSupInv->getSrvOver();
$vat += $itemSupInv->getSrvOver() * 0.21;
$total += $itemSupInv->getSrvOver() * 1.21;
}
}
}
}
}
if (!empty($supInvoicesxCv)){
foreach ($supInvoicesxCv as $supInv){
$supInvIsRec = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceRec')->findBy(array('invoiceToRec' => $supInv->getId()));
if (empty($supInvIsRec)) { // Solo agregamos si no estan rectificadas las facturas de comision
if ($supInv->getDateAt() >= $dateStartReq && $supInv->getDateAt() <= $dateEndReq) {
$supInvItemCv = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceItems')->findBy(array('invoiceId' => $supInv->getId()));
foreach ($supInvItemCv as $itemSupInv) {
$arrayServicesData[$itemSupInv->getId() . 'InvSupCvr'][] = array(
'name' => $itemSupInv->getSrvName(),
'serviceCatId' => $itemSupInv->getSrvServiceCatId(),
'serviceCatName' => $itemSupInv->getSrvServiceCatName(),
'price' => $itemSupInv->getSrvOver(),
'category' => 'Factura de Comisión',
);
$neto += $itemSupInv->getSrvOver();
$vat += $itemSupInv->getSrvOver() * 0.21;
$total += $itemSupInv->getSrvOver() * 1.21;
}
}
}
}
}
if (!empty($supInvoicesxBl)){
foreach ($supInvoicesxBl as $supInv){
$supInvIsRec = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceRec')->findBy(array('invoiceToRec' => $supInv->getId()));
if (empty($supInvIsRec)) { // Solo agregamos si no estan rectificadas las facturas de comision
if ($supInv->getDateAt() >= $dateStartReq && $supInv->getDateAt() <= $dateEndReq) {
$supInvItemBl = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceItems')->findBy(array('invoiceId' => $supInv->getId()));
foreach ($supInvItemBl as $itemSupInv) {
$arrayServicesData[$itemSupInv->getId() . 'InvSupBlv'][] = array(
'name' => $itemSupInv->getSrvName(),
'serviceCatId' => $itemSupInv->getSrvServiceCatId(),
'serviceCatName' => $itemSupInv->getSrvServiceCatName(),
'price' => $itemSupInv->getSrvOver(),
'category' => 'Factura de Comisión',
);
$neto += $itemSupInv->getSrvOver();
$vat += $itemSupInv->getSrvOver() * 0.21;
$total += $itemSupInv->getSrvOver() * 1.21;
}
}
}
}
}
// Agregamos las rectificativas que pueden anular las facturas de comision
if (false) {
$repo = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRec');
$qb = $repo->createQueryBuilder('ri');
$qb->where('ri.reservationId = :resId')
->andWhere('ri.clientType = :clientType')
// ->andWhere('ri.dateAt BETWEEN :dateStart AND :dateEnd')
->setParameter('resId', $item->getId())
->setParameter('clientType', 'Supplier')
// ->setParameter('dateStart', $dateStartReq)
// ->setParameter('dateEnd', $dateEndReq)
;
$supInvoicesxGp = $qb->getQuery()->getResult();
if (!empty($supInvoicesxGp)) {
foreach ($supInvoicesxGp as $supInv) {
if ($supInv->getDateAt() >= $dateStartReq && $supInv->getDateAt() <= $dateEndReq) {
$supInvItemGp = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRecItems')->findBy(array('invoiceId' => $supInv->getId()));
foreach ($supInvItemGp as $itemSupInv) {
$arrayServicesData[$itemSupInv->getId() . 'InvSupGpRec'][] = array(
'name' => $itemSupInv->getSrvName(),
'serviceCatId' => $itemSupInv->getSrvServiceCatId(),
'serviceCatName' => $itemSupInv->getSrvServiceCatName(),
'price' => $itemSupInv->getSrvOver(),
'category' => 'Factura de Comisión Rectificativa',
);
$neto += $itemSupInv->getSrvOver();
$vat += $itemSupInv->getSrvOver() * 0.21;
$total += $itemSupInv->getSrvOver() * 1.21;
}
}
}
}
$repo = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceRec');
$qb = $repo->createQueryBuilder('ri');
$qb->where('ri.reservationId = :resId')
->andWhere('ri.clientType = :clientType')
// ->andWhere('ri.dateAt BETWEEN :dateStart AND :dateEnd')
->setParameter('resId', $item->getId())
->setParameter('clientType', 'Supplier')
// ->setParameter('dateStart', $dateStartReq)
// ->setParameter('dateEnd', $dateEndReq)
;
$supInvoicesxCv = $qb->getQuery()->getResult();
if (!empty($supInvoicesxCv)) {
foreach ($supInvoicesxCv as $supInv) {
if ($supInv->getDateAt() >= $dateStartReq && $supInv->getDateAt() <= $dateEndReq) {
$supInvItemCv = $em->getRepository('App\MDS\GreenPatioBundle\Entity\CvrReservationInvoiceRecItems')->findBy(array('invoiceId' => $supInv->getId()));
foreach ($supInvItemCv as $itemSupInv) {
$arrayServicesData[$itemSupInv->getId() . 'InvSupCvrRec'][] = array(
'name' => $itemSupInv->getSrvName(),
'serviceCatId' => $itemSupInv->getSrvServiceCatId(),
'serviceCatName' => $itemSupInv->getSrvServiceCatName(),
'price' => $itemSupInv->getSrvOver(),
'category' => 'Factura de Comisión Rectificativa',
);
$neto += $itemSupInv->getSrvOver();
$vat += $itemSupInv->getSrvOver() * 0.21;
$total += $itemSupInv->getSrvOver() * 1.21;
}
}
}
}
$repo = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceRec');
$qb = $repo->createQueryBuilder('ri');
$qb->where('ri.reservationId = :resId')
->andWhere('ri.clientType = :clientType')
// ->andWhere('ri.dateAt BETWEEN :dateStart AND :dateEnd')
->setParameter('resId', $item->getId())
->setParameter('clientType', 'Supplier')
// ->setParameter('dateStart', $dateStartReq)
// ->setParameter('dateEnd', $dateEndReq)
;
$supInvoicesxBl = $qb->getQuery()->getResult();
if (!empty($supInvoicesxBl)) {
foreach ($supInvoicesxBl as $supInv) {
if ($supInv->getDateAt() >= $dateStartReq && $supInv->getDateAt() <= $dateEndReq) {
$supInvItemBl = $em->getRepository('App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceRecItems')->findBy(array('invoiceId' => $supInv->getId()));
foreach ($supInvItemBl as $itemSupInv) {
$arrayServicesData[$itemSupInv->getId() . 'InvSupBlvRec'][] = array(
'name' => $itemSupInv->getSrvName(),
'serviceCatId' => $itemSupInv->getSrvServiceCatId(),
'serviceCatName' => $itemSupInv->getSrvServiceCatName(),
'price' => $itemSupInv->getSrvOver(),
'category' => 'Factura de Comisión Rectificativa',
);
$neto += $itemSupInv->getSrvOver();
$vat += $itemSupInv->getSrvOver() * 0.21;
$total += $itemSupInv->getSrvOver() * 1.21;
}
}
}
}
}
// FIN: Agregamos las facturas de comisión
$clientName = $em->getRepository(Client::class)->findOneById($item->getClient());
if (!empty($clientName)){ $clientName = $clientName->getName(); } else { $clientName = null; }
$dateReference = ($item->getDateStart())->format('Ymd');
$createdBy = $em->getRepository(User::class)->findOneById($item->getCreatedBy());
$createdBy = $createdBy->getName().' '.$createdBy->getLastName();
switch ($item->getStatus()){
case 'Deleted': $status = 'Cancelado'; break;
case 'Bloqueo': $status = 'Bloquado'; break;
case 'Cotizado': $status = 'Cotizado'; break;
case 'Confirmed': $status = 'Confirmado'; break;
case 'Invoiced': $status = 'Facturado'; break;
default: $status = ''; break;
}
$newData[] = array(
'dateReference' => $dateReference,
'reservationId' => $item->getId(),
'title' => $item->getTitle(),
'clientId' => $item->getClient(),
'clientName' => $clientName,
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'status' => $status,
'createdAt' => $item->getCreatedAt(),
'txtArrayLoungesNames' => $txtArrayLoungesNames,
'createdBy' => $createdBy,
'arrayLoungesData' => $arrayLoungesData,
'arrayServicesData' => $arrayServicesData,
'neto' => $neto,
'vat' => $vat,
'total' => $total,
);
if (!empty($status) and !($status == 'Cancelado')){
$netoForeCast = $netoForeCast + $neto;
$vatForeCast = $vatForeCast + $vat;
$totalForeCast = $totalForeCast + $total;
}
}
$data = array(
'reservations' => $newData,
'netoForeCast' => $netoForeCast,
'vatForeCast' => $vatForeCast,
'totalForeCast' => $totalForeCast,
);
return $data;
}
private function baseForecastClient($dateStartReq, $dateEndReq, $boolStatus, $clientId)
{
$em = $this->getDoctrine()->getManager();
$today = new \DateTime("now", NULL);
$data = [];
if (empty($boolStatus['Blocked'])){ $opBlocked = null; } else { $opBlocked = 'Bloqueo'; }
if (empty($boolStatus['Confirmed'])){ $opConfirmed = null; } else { $opConfirmed = 'Confirmed'; }
if (empty($boolStatus['Quoted'])){ $opQuoted = null; } else { $opQuoted = 'Cotizado'; }
if (empty($boolStatus['Invoiced'])){ $opInvoiced = null; } else { $opInvoiced = 'Invoiced'; }
if (empty($boolStatus['Cancel'])){ $opDeleted = null; } else { $opDeleted = 'Deleted'; }
$dateEndReq = empty($dateEndReq) ? null : new \Datetime($dateEndReq . '+ 1 days'); //Se le suma un dia, para que se considere el ultimo dia en la consulta
// Si solo introduce fecha de inicio
// Se consulta de fecha inicio a fecha actual
if (!empty($dateStartReq) and empty($dateEndReq) and empty($monthReq) and empty($yearReq)){
$parameters = array(
'start' => $dateStartReq,
'end'=> $today,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)){
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client != :clientId
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Si solo introduce fecha de fin
// Se consulta desde el inicio (2019) a la fecha indicada
if (!empty($dateEndReq) and empty($dateStartReq) and empty($monthReq) and empty($yearReq)){
$parameters = array(
'start' => '2019-01-01',
'end'=> $dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client != :clientId
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Se introduce una fecha de inicio y una fecha de fin
if (!empty($dateEndReq) and !empty($dateStartReq) and empty($yearReq) and empty($monthReq)){
$parameters = array(
'start' => $dateStartReq,
'end'=> $dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
'clientId'=> $clientId,
);
if (empty($clientId)) {
// Se modifican los parametros para despreciar el campo cliente
$parameters = array(
'start' => $dateStartReq,
'end'=>$dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND (p.dateEnd BETWEEN :start AND :end)
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND (p.dateEnd BETWEEN :start AND :end)
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
// Se requiere que los eventos que finalicen en el periodo solicitado se
// reflejen en la respuesta incluso si el evento inicia antes del primer dÃa
// de la consulta. Solicitud: Rafael Guerrero y Gabriela Bracho.
if (empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart < :start
AND (p.dateEnd BETWEEN :start AND :end)
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
ORDER BY p.dateStart ASC
";
} else {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart < :start
AND p.dateEnd BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.client = :clientId
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$zData = $query->getResult();
// Agregamos los eventos que iniciando fuera del periodo de consulta, terminan durante el periodo de consulta. Solicitud: Rafael Guerrero y Gabriela Bracho.
foreach ($zData as $zItem){ $data[] = $zItem; }
}
$newData = array();
$netoForeCast = 0; $vatForeCast = 0; $totalForeCast = 0;
$arrayClients = [];
foreach ($data as $item){
$neto = 0; $vat = 0; $total = 0;
// $lounges = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple')->findByIdReservation($item->getId());
$lounges = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems')->findBy( array( 'reservationId' => $item->getId(), 'itemType' => 'LOUNGE' ));
$txtArrayLoungesNames = array(); $arrayLoungesData = array(); $benefit = 0; $benefitPerc = 0;
foreach ($lounges as $elem){
if ($elem->getLngIdLounge() < 19) {
$location = 'Green Patio';
} elseif ($elem->getLngIdLounge() > 19 && $elem->getLngIdLounge() < 22) {
$location = 'Green Patio + Sala 25';
} elseif ($elem->getLngIdLounge() > 21) {
$location = 'Covarrubias';
} else {
$location = 'Sala 25';
}
// $category = empty($elem->getType()) ? 'SALA' : 'SALA '.$elem->getType();
$category = 'SALA ';
$arrayLoungesData[$item->getId()][] = array('loungeName'=> $elem->getLngLoungeName(), 'idLounge'=> $elem->getLngIdLounge(), 'servicePrice'=> $elem->getLngServicePrice(), 'location'=> $location, 'category'=> $category );
if (!empty($elem->getLngServicePrice())) {
$neto = $neto + floatval($elem->getLngServicePrice());
$vat = $vat + (floatval($elem->getLngServicePrice()) * 0.21);
$total = $total + (floatval($elem->getLngServicePrice()) * 1.21);
$txtArrayLoungesNames[$elem->getLngIdLounge()] = $elem->getLngLoungeName();
$benefit += floatval($elem->getLngServicePrice());
}
}
// Salas rectificadas
$loungesRec = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRecItems')->findBy( array( 'reservationId' => $item->getId(), 'itemType' => 'LOUNGE' ));
foreach ($loungesRec as $elem){
if ($elem->getLngIdLounge() < 19) {
$location = 'Green Patio';
} elseif ($elem->getLngIdLounge() > 19 && $elem->getLngIdLounge() < 22) {
$location = 'Green Patio + Sala 25';
} elseif ($elem->getLngIdLounge() > 21) {
$location = 'Covarrubias';
} else {
$location = 'Sala 25';
}
$category = 'SALA ';
$arrayLoungesData['R'.$item->getId()][] = array('loungeName'=> $elem->getLngLoungeName(), 'idLounge'=> $elem->getLngIdLounge(), 'servicePrice'=> $elem->getLngServicePrice(), 'location'=> $location, 'category'=> $category );
if (!empty($elem->getLngServicePrice())) {
$neto = $neto + floatval($elem->getLngServicePrice());
$vat = $vat + (floatval($elem->getLngServicePrice()) * 0.21);
$total = $total + (floatval($elem->getLngServicePrice()) * 1.21);
$txtArrayLoungesNames[$elem->getLngIdLounge()] = $elem->getLngLoungeName();
$benefit += floatval($elem->getLngServicePrice());
}
}
// INICIO: Agregamos los servicios
$servicesx = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationService')->findBy( array( 'reservationId' => $item->getId(), ));
$arrayServicesData = array();
foreach ($servicesx as $elem){
if (!empty($elem->getPrice())) {
if (($elem->getUnits() == 0) or (empty($elem->getUnits()))){ $unitsx = 1; } else { $unitsx = $elem->getUnits(); }
if (($elem->getPax() == 0) or (empty($elem->getPax()))){ $paxx = 1; } else { $paxx = $elem->getPax(); }
if (($elem->getToinvoice() == 0) or (empty($elem->getToinvoice()))){ $toinvoicex = 0; } else { $toinvoicex = 1; }
//Se determina el monto de Comision y Over a sumar o restar al precio
if ($elem->getOpCommission() == 1){
// Comision positiva
if ($elem->getOpOver() == 1){
// Over positivo
if (!empty($elem->getCommission())){
$commision = (($elem->getPrice() * $unitsx * $paxx) * ($elem->getCommission() / 100 )); $over = $elem->getOver();
} else {
$commision = 0; $over = $elem->getOver();
}
} else {
// Over negativo
if (!empty($elem->getCommission())){
$commision = (($elem->getPrice() * $unitsx * $paxx) * ($elem->getCommission() / 100 )); $over = ((-1) * $elem->getOver());
} else {
$commision = 0; $over = ((-1) * $elem->getOver());
}
}
} else {
// Comision negativa
if ($elem->getOpOver() == 1){
// Over positivo
if (!empty($elem->getCommission())){
$commision = ((-1) * (($elem->getPrice() * $unitsx * $paxx) * ($elem->getCommission() / 100 ))); $over = $elem->getOver();
} else {
$commision = 0; $over = $elem->getOver();
}
} else {
// Over negativo
if (!empty($elem->getCommission())){
$commision = ((-1) * (($elem->getPrice() * $unitsx * $paxx) * ($elem->getCommission() / 100 ))); $over = ((-1) * $elem->getOver());
} else {
$commision = 0; $over = ((-1) * $elem->getOver());
}
}
}
// Se determina el precio final y beneficio
$pricex = (($elem->getPrice() * $unitsx * $paxx) + $commision + $over) * $toinvoicex;
if ($toinvoicex == 0){
//Si no va a factura el servicio es un costo, habra que restar el precio base, comision y over
$benefit -= ($elem->getPrice() * $unitsx * $paxx);
$benefit -= $commision;
$benefit -= $over;
} else {
$benefit += $commision;
$benefit += $over;
}
$category = ($elem->getServiceCatName() == 'Others') ? 'Otros' : $elem->getServiceCatName();
$arrayServicesData[$item->getId()][] = array(
'name'=> $elem->getName(),
'serviceCatId'=> $elem->getServiceCatId(),
'serviceCatName'=> $elem->getServiceCatName(),
'price'=> $elem->getPrice(),
'category'=> $category,
);
switch ($elem->getIva()){
case '21': $ivax = 0.21; $ivaxPlus = 1.21; break;
case '10': $ivax = 0.10; $ivaxPlus = 1.10; break;
case '0': $ivax = 0; $ivaxPlus = 1; break;
default: $ivax = 0.21; $ivaxPlus = 1.21; break;
}
$neto = $neto + $pricex;
$vat = $vat + ($pricex * $ivax);
$total = $total + ($pricex * $ivaxPlus);
}
}
// FIN: Agregamos los servicios
$clientName = $em->getRepository(Client::class)->findOneById($item->getClient());
if (!empty($clientName)){ $clientName = $clientName->getName(); } else { $clientName = null; }
$dateReference = ($item->getDateStart())->format('Ymd');
$createdBy = $em->getRepository(User::class)->findOneById($item->getCreatedBy());
$createdBy = $createdBy->getName().' '.$createdBy->getLastName();
switch ($item->getStatus()){
case 'Deleted': $status = 'Cancelado'; break;
case 'Bloqueo': $status = 'Bloquado'; break;
case 'Cotizado': $status = 'Cotizado'; break;
case 'Confirmed': $status = 'Confirmado'; break;
case 'Invoiced': $status = 'Facturado'; break;
default: $status = ''; break;
}
$benefitPerc = ($neto == 0) ? 0 : (($benefit * 100)/$neto) ;
$newData[] = array(
'dateReference' => $dateReference,
'reservationId' => $item->getId(),
'title' => $item->getTitle(),
'clientId' => $item->getClient(),
'clientName' => $clientName,
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'status' => $status,
'createdAt' => $item->getCreatedAt(),
'txtArrayLoungesNames' => $txtArrayLoungesNames,
'createdBy' => $createdBy,
'arrayLoungesData' => $arrayLoungesData,
'arrayServicesData' => $arrayServicesData,
'neto' => $neto,
'vat' => $vat,
'total' => $total,
'beneficio' => $benefit,
'benefitPerc' => $benefitPerc,
);
if (!empty($status) and !($status == 'Cancelado')){
$netoForeCast = $netoForeCast + $neto;
$vatForeCast = $vatForeCast + $vat;
$totalForeCast = $totalForeCast + $total;
}
}
foreach($newData as $item){
$arrayClients[$item['clientId']]['reservas'][] = $item;
$arrayClients[$item['clientId']]['netoTotalCliente'] = (array_key_exists('netoTotalCliente', $arrayClients[$item['clientId']])) ? ($arrayClients[$item['clientId']]['netoTotalCliente'] + $item['neto']) : $item['neto'];
$arrayClients[$item['clientId']]['totalCliente'] = (array_key_exists('totalCliente', $arrayClients[$item['clientId']])) ? ($arrayClients[$item['clientId']]['totalCliente'] + $item['total']) : $item['total'];
$arrayClients[$item['clientId']]['percFacturaTotalClienteContraFacturaTotalEventos'] = 0;
$arrayClients[$item['clientId']]['beneficioCliente'] = (array_key_exists('beneficioCliente', $arrayClients[$item['clientId']])) ? ($arrayClients[$item['clientId']]['beneficioCliente'] + $item['beneficio']) : $item['beneficio'];
$arrayClients[$item['clientId']]['numeroEventosCliente'] = count($arrayClients[$item['clientId']]['reservas']);
$arrayClients[$item['clientId']]['rentabilidadPercBenefit'] = 0;
}
foreach ($arrayClients as $key => $item){
$arrayClients[$key]['percFacturaTotalClienteContraFacturaTotalEventos'] = (($item['netoTotalCliente'] * 100) / $netoForeCast);
if ($item['netoTotalCliente'] == 0){
// Si no aparece en factura el neto del cliente sera 0, la rentabilidad sera 0
$arrayClients[$key]['rentabilidadPercBenefit'] = 0;
} else {
$arrayClients[$key]['rentabilidadPercBenefit'] = (($item['beneficioCliente'] * 100) / $item['netoTotalCliente']);
}
}
// Ordenamos el arreglo de mayor a menor por el campo 'percFacturaTotalClienteContraFacturaTotalEventos'
uasort($arrayClients, function ($a, $b) { return $b['percFacturaTotalClienteContraFacturaTotalEventos'] <=> $a['percFacturaTotalClienteContraFacturaTotalEventos']; });
$data = array(
'reservationsClients' => $arrayClients,
'netoForeCast' => $netoForeCast,
'vatForeCast' => $vatForeCast,
'totalForeCast' => $totalForeCast,
);
return $data;
}
private function baseForecastWeb($dateStartReq, $dateEndReq, $boolStatus, $arraySalasId)
{
$em = $this->getDoctrine()->getManager();
$today = new \DateTime("now", NULL);
$data = [];
$clientId = null;
$arrayStatusCont =[ 'Iniciado' => 0, 'Cancelado' => 0, 'Bloqueado' => 0, 'Cotizado' => 0, 'Confirmado' => 0, 'Facturado' => 0 ];
if (empty($boolStatus['Blocked'])){ $opBlocked = null; } else { $opBlocked = 'Bloqueo'; }
if (empty($boolStatus['Confirmed'])){ $opConfirmed = null; } else { $opConfirmed = 'Confirmed'; }
if (empty($boolStatus['Quoted'])){ $opQuoted = null; } else { $opQuoted = 'Cotizado'; }
if (empty($boolStatus['Invoiced'])){ $opInvoiced = null; } else { $opInvoiced = 'Invoiced'; }
if (empty($boolStatus['Cancel'])){ $opDeleted = null; } else { $opDeleted = 'Deleted'; }
$dateEndReq = empty($dateEndReq) ? null : new \Datetime($dateEndReq . '+ 1 days'); //Se le suma un dia, para que se considere el ultimo dia en la consulta
// Si solo introduce fecha de inicio
// Se consulta de fecha inicio a fecha actual
if (!empty($dateStartReq) and empty($dateEndReq) and empty($monthReq) and empty($yearReq)){
$parameters = array(
'start' => $dateStartReq,
'end'=> $today,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
if (!empty($clientId)){
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.infoFormWeb <> null
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Si solo introduce fecha de fin
// Se consulta desde el inicio (2019) a la fecha indicada
if (!empty($dateEndReq) and empty($dateStartReq) and empty($monthReq) and empty($yearReq)){
$parameters = array(
'start' => '2019-01-01',
'end'=> $dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
if (!empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.infoFormWeb <> null
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Si solo introduce mes
// Se consulta el mes indicado del año en curso
if (!empty($monthReq) and empty($dateStartReq) and empty($dateEndReq) and empty($yearReq)){
$stringStart = $today->format('Y').'-'.$monthReq.'-01';
$stringEnd = $today->format('Y').'-'.$monthReq.'-31'; // Todos los meses podrian ser consultados hasta el dia 31, incluso en febrero
$parameters = array(
'start' => $stringStart,
'end'=> $stringEnd,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
if (!empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.infoFormWeb <> null
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Si solo introduce año
//Se consulta del 01-01 al 31-12 del año indicado
if (!empty($yearReq) and empty($dateStartReq) and empty($dateEndReq) and empty($monthReq)){
$stringStart = $yearReq.'-01-01';
$stringEnd = $yearReq.'-12-31';
$parameters = array(
'start' => $stringStart,
'end'=> $stringEnd,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
if (!empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.infoFormWeb <> null
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Se introduce un mes de un año en especifico
if (!empty($yearReq) and !empty($monthReq) and empty($dateEndReq) and empty($dateStartReq)){
$stringStart = $yearReq.'-'.$monthReq.'-01';
$stringEnd = $yearReq.'-'.$monthReq.'-31';
$parameters = array(
'start' => $stringStart,
'end'=> $stringEnd,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
if (!empty($clientId)) {
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.infoFormWeb <> null
ORDER BY p.dateStart ASC
";
}
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
}
// Se introduce una fecha de inicio y una fecha de fin
if (!empty($dateEndReq) and !empty($dateStartReq) and empty($yearReq) and empty($monthReq)){
$parameters = array(
'start' => $dateStartReq,
'end'=> $dateEndReq,
'opBlocked'=> $opBlocked,
'opConfirmed'=> $opConfirmed,
'opQuoted'=> $opQuoted,
'opInvoiced'=> $opInvoiced,
'opDeleted'=> $opDeleted,
);
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\Reservation p
WHERE p.dateStart BETWEEN :start AND :end
AND (p.dateEnd BETWEEN :start AND :end)
AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
AND p.infoFormWeb IS NOT NULL
ORDER BY p.dateStart ASC
";
$query = $em->createQuery($dql)->setParameters($parameters);
$data = $query->getResult();
//dd('check', $data);
// Se requiere que los eventos que finalicen en el periodo solicitado se
// reflejen en la respuesta incluso si el evento inicia antes del primer dÃa
// de la consulta. Solicitud: Rafael Guerrero y Gabriela Bracho.
// if (!empty($clientId)) {
// $dql = "SELECT p
// FROM App\MDS\GreenPatioBundle\Entity\Reservation p
// WHERE p.dateStart < :start
// AND p.dateEnd BETWEEN :start AND :end
// AND ((p.status = :opBlocked) OR (p.status = :opConfirmed) OR (p.status = :opQuoted) OR (p.status = :opInvoiced) OR (p.status = :opDeleted))
// AND p.infoFormWeb <> null
// ORDER BY p.dateStart ASC
// ";
// }
//
// $query = $em->createQuery($dql)->setParameters($parameters);
// $zData = $query->getResult();
//
// // Agregamos los eventos que iniciando fuera del periodo de consulta, terminan durante el periodo de consulta. Solicitud: Rafael Guerrero y Gabriela Bracho.
// foreach ($zData as $zItem){ $data[] = $zItem; }
}
// INICIO: Acotamos segun la(s) sala(s) seleccionada(s)
if (!empty($arraySalasId)) {
$zData = [];
foreach ($data as $item) {
if ($item->getStatus() == 'Invoiced') {
$zExiste = $em->getRepository(ReservationInvoiceItems::class)
->createQueryBuilder('r')
->where('r.reservationId = :reservationId')
->andWhere('r.lngIdLounge IN (:arrayIndices)')
->setParameter('reservationId', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
if (empty($zExiste)){
$zExiste = $em->getRepository(CvrReservationInvoiceItems::class)
->createQueryBuilder('r')
->where('r.reservationId = :reservationId')
->andWhere('r.lngIdLounge IN (:arrayIndices)')
->setParameter('reservationId', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
}
if (empty($zExiste)){
$zExiste = $em->getRepository(BlvReservationInvoiceItems::class)
->createQueryBuilder('r')
->where('r.reservationId = :reservationId')
->andWhere('r.lngIdLounge IN (:arrayIndices)')
->setParameter('reservationId', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
}
if (!empty($zExiste)) {
$zData[] = $item;
}
} else {
$zExiste = $em->getRepository(ReservationLoungeSimple::class)
->createQueryBuilder('r')
->where('r.idReservation = :idReservation')
->andWhere('r.idLounge IN (:arrayIndices)')
->setParameter('idReservation', $item->getId())
->setParameter('arrayIndices', $arraySalasId)
->getQuery()
->getResult();
if (!empty($zExiste)) {
$zData[] = $item;
}
}
}
$data = $zData;
}
// FIN: Acotamos segun la(s) sala(s) seleccionada(s)
//dd('la data', $data);
// ************************************************************************************************************************
// ************************************ AGREGAMOS LAS FACTURAS DE COMISION ************************************************
// ************************************************************************************************************************
$parameters = array(
'start' => $dateStartReq,
'end'=> $today,
'clientType'=> 'Supplier',
);
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\ReservationInvoice p
WHERE p.dateAt BETWEEN :start AND :end
AND p.clientType = :clientType
ORDER BY p.dateAt ASC";
$query = $em->createQuery($dql)->setParameters($parameters);
$invoiceSuppGp = $query->getResult();
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice p
WHERE p.dateAt BETWEEN :start AND :end
AND p.clientType = :clientType
ORDER BY p.dateAt ASC";
$query = $em->createQuery($dql)->setParameters($parameters);
$invoiceSuppCvr = $query->getResult();
$dql = "SELECT p
FROM App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice p
WHERE p.dateAt BETWEEN :start AND :end
AND p.clientType = :clientType
ORDER BY p.dateAt ASC";
$query = $em->createQuery($dql)->setParameters($parameters);
$invoiceSuppBlv = $query->getResult();
// ************************************************************************************************************************
// ************************************ AGREGAMOS LAS FACTURAS DE COMISION ************************************************
// ************************************************************************************************************************
if(!empty($invoiceSuppGp)){
// Verificamos si esta dentro de $data la reserva
foreach ($invoiceSuppGp as $item){
$logExisteData = false;
foreach ($data as $elem){
if ($elem->getId() == $item->getReservationId()){ $logExisteData = true; }
}
if (!$logExisteData){
$xResv = $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
if (!empty($xResv->getInfoFormWeb())) { $data[] = $xResv; } // Solo se agregaran expedientes de la web
}
}
}
if(!empty($invoiceSuppCvr)){
// Verificamos si esta dentro de $data la reserva
foreach ($invoiceSuppCvr as $item){
$logExisteData = false;
foreach ($data as $elem){
if ($elem->getId() == $item->getReservationId()){ $logExisteData = true; }
}
if (!$logExisteData){
$xResv = $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
if (!empty($xResv->getInfoFormWeb())) { $data[] = $xResv; } // Solo se agregaran expedientes de la web
}
}
}
if(!empty($invoiceSuppBlv)){
// Verificamos si esta dentro de $data la reserva
foreach ($invoiceSuppBlv as $item){
$logExisteData = false;
foreach ($data as $elem){
if ($elem->getId() == $item->getReservationId()){ $logExisteData = true; }
}
if (!$logExisteData){
$xResv = $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
if (!empty($xResv->getInfoFormWeb())) { $data[] = $xResv; } // Solo se agregaran expedientes de la web
}
}
}
//dd($invoiceSuppGp, $invoiceSuppCvr, $invoiceSuppBlv, $data, 'BUSCAR LAS FACTURAS DE COMISION');
$newData = [];
$netoForeCast = $vatForeCast = $totalForeCast = 0;
foreach ($data as $item){
$neto = $vat = $total = 0;
$lounges = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple')->findByIdReservation($item->getId());
$txtArrayLoungesNames = [];
$arrayLoungesData = [];
foreach ($lounges as $elem){
if ($elem->getIdLounge() < 19) {
$location = 'Green Patio';
} elseif ($elem->getIdLounge() > 19 && $elem->getIdLounge() < 22) {
$location = 'Green Patio + Sala 25';
} elseif ($elem->getIdLounge() > 21 && $elem->getIdLounge() < 30) {
$location = 'Covarrubias';
} elseif ($elem->getIdLounge() > 29 && $elem->getIdLounge() < 40) {
$location = 'Bella View';
} else {
$location = 'Sala 25';
}
$category = empty($elem->getType()) ? 'SALA' : 'SALA '.$elem->getType();
$arrayLoungesData[$item->getId()][] = array('loungeName'=> $elem->getLoungeName(), 'idLounge'=> $elem->getIdLounge(), 'servicePrice'=> $elem->getServicePrice(), 'location'=> $location, 'category'=> $category );
if (!empty($elem->getServicePrice())) {
$neto = $neto + floatval($elem->getServicePrice());
$vat = $vat + (floatval($elem->getServicePrice()) * floatval($elem->getIva())/100);
$total = $total + (floatval($elem->getServicePrice()) * (1 + floatval($elem->getIva())/100));
$txtArrayLoungesNames[$elem->getIdLounge()] = $elem->getLoungeName();
}
}
// INICIO: Agregamos los servicios
$servicesx = $em->getRepository('App\MDS\GreenPatioBundle\Entity\ReservationService')->findBy( array( 'reservationId' => $item->getId(), 'toinvoice' => true ));
$arrayServicesData = [];
foreach ($servicesx as $elem){
if (!empty($elem->getPrice())) {
if (($elem->getUnits() == 0) or (empty($elem->getUnits()))){ $unitsx = 1; } else { $unitsx = $elem->getUnits(); }
if (($elem->getPax() == 0) or (empty($elem->getPax()))){ $paxx = 1; } else { $paxx = $elem->getPax(); }
if (($elem->getToinvoice() == 0) or (empty($elem->getToinvoice()))){ $toinvoicex = 0; } else { $toinvoicex = 1; }
$pricex = (float)$elem->getPrice() * $unitsx * $paxx * $toinvoicex;
$category = ($elem->getServiceCatName() == 'Others') ? 'Otros' : $elem->getServiceCatName();
$arrayServicesData[$item->getId()][] = array(
'name'=> $elem->getName(),
'serviceCatId'=> $elem->getServiceCatId(),
'serviceCatName'=> $elem->getServiceCatName(),
'price'=> $elem->getPrice(),
'category'=> $category,
);
switch ($elem->getIva()){
case '21': $ivax = 0.21; $ivaxPlus = 1.21; break;
case '10': $ivax = 0.10; $ivaxPlus = 1.10; break;
case '0': $ivax = 0; $ivaxPlus = 1; break;
default: $ivax = 0.21; $ivaxPlus = 1.21; break;
}
$neto = $neto + $pricex;
$vat = $vat + ($pricex * $ivax);
$total = $total + ($pricex * $ivaxPlus);
}
}
// FIN: Agregamos los servicios
$clientName = $em->getRepository(Client::class)->findOneById($item->getClient());
if (!empty($clientName)){ $clientName = $clientName->getName(); } else { $clientName = null; }
$dateReference = ($item->getDateStart())->format('Ymd');
$createdBy = $em->getRepository(User::class)->findOneById($item->getCreatedBy());
$createdBy = $createdBy->getName().' '.$createdBy->getLastName();
switch ($item->getStatus()){
case 'Iniciado': $status = 'Iniciado'; $arrayStatusCont['Iniciado'] += 1 ; break;
case 'Deleted': $status = 'Cancelado'; $arrayStatusCont['Cancelado'] += 1 ; break;
case 'Bloqueo': $status = 'Bloqueado'; $arrayStatusCont['Bloqueado'] += 1 ; break;
case 'Cotizado': $status = 'Cotizado'; $arrayStatusCont['Cotizado'] += 1 ; break;
case 'Confirmed': $status = 'Confirmado'; $arrayStatusCont['Confirmado'] += 1 ; break;
case 'Invoiced': $status = 'Facturado'; $arrayStatusCont['Facturado'] += 1 ; break;
default: $status = ''; break;
}
$newData[] = array(
'dateReference' => $dateReference,
'reservationId' => $item->getId(),
'title' => $item->getTitle(),
'clientId' => $item->getClient(),
'clientName' => $clientName,
'infoFormWeb' => str_replace('||', '<br>',$item->getInfoFormWeb()),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'status' => $status,
'createdAt' => $item->getCreatedAt(),
'txtArrayLoungesNames' => $txtArrayLoungesNames,
'createdBy' => $createdBy,
'arrayLoungesData' => $arrayLoungesData,
'arrayServicesData' => $arrayServicesData,
'neto' => $neto,
'vat' => $vat,
'total' => $total,
);
if (!empty($status) and !($status == 'Cancelado')){
$netoForeCast = $netoForeCast + $neto;
$vatForeCast = $vatForeCast + $vat;
$totalForeCast = $totalForeCast + $total;
}
}
$data = array(
'reservations' => $newData,
'arrayStatusCont' => $arrayStatusCont,
'netoForeCast' => $netoForeCast,
'vatForeCast' => $vatForeCast,
'totalForeCast' => $totalForeCast,
);
return $data;
}
};