<?php
/**
* Created by Mediterranean Develup Solutions
* User: jorge.defreitas@develup.solutions
* Date: 31/10/2017
* Time: 9:55
*/
namespace App\MDS\EventsPresentationBundle\Controller;
use App\Entity\Activities;
use App\Entity\Cities;
use App\Entity\Client;
use App\Entity\Configuration;
use App\Entity\Country;
use App\Entity\Destination;
use App\Entity\DestinationDescription;
use App\Entity\DestinationGallery;
use App\Entity\Ideas;
use App\Entity\PresentationGallery;
use App\Entity\PresentationMusic;
use App\Entity\PresentationVideo;
use App\Entity\ProposalsInvoiceSummary;
use App\Entity\Provinces;
use App\Entity\Regions;
use App\Entity\SettingsCompany;
use App\Entity\Supplier;
use App\Entity\SupplierAccommodation;
use App\Entity\SupplierActivities;
use App\Entity\SupplierAv;
use App\Entity\SupplierCreative;
use App\Entity\SupplierCruise;
use App\Entity\SupplierDescription;
use App\Entity\SupplierEntertainment;
use App\Entity\SupplierGallery;
use App\Entity\SupplierGifts;
use App\Entity\SupplierGuide;
use App\Entity\SupplierIdeaServicesControl;
use App\Entity\SupplierItineraries;
use App\Entity\SupplierLounge;
use App\Entity\SupplierMenu;
use App\Entity\SupplierOthers;
use App\Entity\SupplierServicesControl;
use App\Entity\SupplierServicesDescription;
use App\Entity\SupplierSettingsType;
use App\Entity\SupplierTechnology;
use App\Entity\SupplierTransport;
use App\Entity\User;
use App\MDS\EventsBundle\Entity\Proposal;
use App\MDS\EventsBundle\Entity\ProposalAgendaPresupuesto;
use App\MDS\EventsBundle\Entity\ProposalAgendaPresupuestoControl;
use App\MDS\EventsBundle\Entity\ProposalAgents;
use App\MDS\EventsBundle\Entity\ProposalControl;
use App\MDS\EventsBundle\Entity\ProposalDiscount;
use App\MDS\EventsBundle\Entity\ProposalDocument;
use App\MDS\EventsBundle\Entity\ProposalDescription;
use App\MDS\EventsBundle\Entity\ProposalFee;
use App\MDS\EventsBundle\Entity\ProposalFeeInvoice;
use App\MDS\EventsBundle\Entity\ProposalInvoice;
use App\MDS\EventsBundle\Entity\ProposalInvoiceDepositControl;
use App\MDS\EventsBundle\Entity\ProposalInvoiceDepositItems;
use App\MDS\EventsBundle\Entity\ProposalPaymentsClient;
use App\MDS\EventsBundle\Entity\ProposalProforma;
use App\MDS\EventsBundle\Entity\ProposalsSupplierServicesAssistantName;
use App\MDS\EventsBundle\Entity\ProposalSupplierControl;
use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudget;
use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudgetControl;
use App\MDS\EventsBundle\Entity\ProposalSupplierServicesCostsClient;
use App\MDS\EventsBundle\Entity\ProposalTracing;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use JMS\Serializer\SerializerBuilder;
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 Swift_Mailer;
use Swift_Message;
use Swift_SmtpTransport;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
use Doctrine\ORM\EntityManagerInterface;
class ProposalPresentationController extends AbstractController
{
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @Route("/home/{token}", name="presentation_home_token")
*/
public function homeAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$proposalControl = $em->getRepository(ProposalControl::class)->findOneByProposalId($proposal->getId());
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$image = $em->getRepository(PresentationGallery::class)->findAll();
$video = $em->getRepository(PresentationVideo::class)->findAll();
shuffle($video);
// d($video);
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
switch ($proposal->getLanguage()) {
case 'CASTELLANO':
$idioma = "es";
break;
case 'ENGLISH':
$idioma = "en";
break;
case 'TURKISH':
$idioma = "tr";
break;
case 'RUSSIAN':
$idioma = "ru";
break;
case 'CHINESE':
$idioma = "zh";
break;
case 'PORTUGUESE':
$idioma = "pt";
break;
case 'ARAB':
$idioma = "ar";
break;
case 'ITALIAN':
$idioma = "it";
break;
case 'KOREAN':
$idioma = "ko";
break;
}
$request->setDefaultLocale($idioma);
$request->getSession()->set('_locale', $idioma);
}
$urlvideo = '/assets/video/login/VOLAR.mp4';
$idvideo = '0';
return $this->render(
'MDS/EventsPresentationBundle/presentation/presentation-client.html.twig',
array(
'token' => $token,
'video' => $urlvideo,
'videos' => $video,
'idvideo' => $idvideo,
'image' => $image,
'destino' => $destino,
// 'agendas' => $showAgenda,
)
);
}
/**
* @Route("/disclaimer/{token}", name="presentation_disclaimer")
*/
public function disclaimerAction($token, Request $request)
{
$request->getSession()->set('_disclaimer', 'ok');
return $this->redirectToRoute(
'presentation_cover_token',
array(
'token' => $token,
)
);
}
/**
* @Route("/readDisclaimer/{token}", name="read_disclaimer")
*/
public function disclaimerPageAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$request->getSession()->set('_disclaimer', 'ok');
$sidebarData = $this->sidebarAction($token, "", "");
$disclaimer = $request->getSession()->get('_disclaimer');
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabledPresentation' => '0',
)
);
$data_destination = array();
$countDestino = 0;
$selectType = explode(",", $proposal->getSelectType());
foreach ($proposal_Control as $proposalControl) {
$countDestino++;
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = array();
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$data_destination[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
return $this->render(
'MDS/EventsPresentationBundle/presentation/start-client.html.twig',
array(
'token' => $token,
'client' => $client,
'proposal' => $proposal,
'destination' => $data_destination,
'countDestino' => $countDestino,
'sidebar' => $sidebarData,
'disclaimer' => $disclaimer,
'legal' => true,
'selectType' => $selectType,
// 'agendas' => $showAgenda,
)
);
}
/**
* @Route("/printDisclaimer/", name="print_disclaimer")
*/
public function printPageAction(Request $request)
{
return $this->render('MDS/EventsPresentationBundle/presentation/disclaimer.html.twig');
}
/**
* @Route("/destination/{token}", name="presentation_destination_view_token")
*/
public function DestinationViewAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
if (empty($description)) {
$description = array(
'description' => ""
);
}
$data_destionation[$destino->getTitle()] = array(
'image' => $gallery['0'],
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
// $sidebarData = $this->sidebarAction($token, "", "");
return $this->render(
'MDS/EventsPresentationBundle/presentation/destinos.html.twig',
array(
'token' => $token,
'proposal' => $proposal,
'destination' => $data_destionation,
'company' => $company,
'client' => $client,
'selectType' => $selectType,
// 'sidebar' => $sidebarData
)
);
}
/**
* @Route("/cover/{token}", name="presentation_cover_token")
*/
public function coverAction($token, Request $request)
{
//d('entra en cover con token');
$disclaimer = $request->getSession()->get('_disclaimer');
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
// d($proposal);
// exit();
$parameters = array(
'proposalId' => $proposal->getId(),
'recommended' => '1',
'priority' => '0',
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesBudgetControl p
WHERE p.proposalId = :proposalId
AND p.recommended = :recommended
AND p.priority != :priority
ORDER BY p.priority ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$controlbudgets = $query->getResult();
$parametersNew = array(
'proposalId' => $proposal->getId(),
'recommended' => '0',
'priority' => '0',
);
$dqlNew = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesBudgetControl p
WHERE p.proposalId = :proposalId
AND p.recommended = :recommended
AND p.priority != :priority
ORDER BY p.priority ASC';
$queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
$controlbudgetsNew = $queryNew->getResult();
$controlbudget = array();
foreach ($controlbudgets as $controlbudge) {
$imagen = array();
$control_query = $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($controlbudge->getId());
foreach ($control_query as $controlquery) {
// d($controlquery);
if (count($imagen) <= "3") { // 3 porque tomamos en cuenta el 0 que tambien toma del indice de array
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlquery->getSupplierId());
if (!is_null($controlgeneral)) {
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
$imagen[$controlgeneral->getId()] = $imagenSmall;
}
}
}
}
$controlbudget[] = array(
'budget' => $controlbudge,
'imagen' => $imagen,
);
}
// d($controlbudget);
$descriptionpresenta = $em->getRepository(ProposalDescription::class)->findOneBy(
array(
'proposalId' => $proposal->getId(),
'language' => $proposal->getLanguage()
)
);
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon." && is_null($disclaimer)) {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
$ipclient = $request->getClientIp();
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$mailAgent[] = $agent->getEmail();
$agentMail = $agent->getEmail();
$passGmail = $agent->getPassGmail();
$firmGmail = $agent->getFirmGmail();
$mailAgentSent = array(
$agent->getEmail() => $agent->getName() . ' ' . $agent->getLastName()
);
$data = array(
'body' => 'P#' . $proposal->getId() . ', ' . $proposal->getTitle() . ' <br> Alerta De Presentación Vista por cliente: ' . $proposal->getViewedAt()->format('d/m/Y H:i:s') . '<br>Ip del Cliente:' . $ipclient,
'firm' => $firmGmail,
);
$mailTodos = array_merge($mailAgent);
// EJECUTAR ENVIO DE ALERTA DE VISTO POR CLIENTE
$transporter = new Swift_SmtpTransport();
$transporter->setHost('smtp.gmail.com')
->setEncryption('ssl') //ssl / tls
->setPort(465) // 465 / 587
->setUsername('desarrollo@develup.solutions')
->setPassword('utvh hzoi wfdo ztjs');
$mailer = new Swift_Mailer($transporter);
$message = new Swift_Message();
$message->setSubject('P#' . $proposal->getId() . ', Alerta De Presentación Vista por cliente')
->setSender($agentMail)
->setFrom($mailAgentSent)
->setReplyTo($mailAgentSent)
->setTo($mailTodos)
->setBody(
$this->renderView(
'mail/structure-mail.html.twig',
array('data' => $data)
),
'text/html'
);
$mailer->send($message);
// Guardo en historico de seguimiento
$textHistory = $this->translator->trans('Presentation View by client');
$history = $this->TracingHistoryOperations($proposal->getId(), $textHistory . ', Ip:' . $ipclient);
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
$selectType_array = explode(",", $proposal->getSelectType());
// foreach ($selectType_array as $type){
// $servicesType = $this->servicesAction($token, $type, '');
// $selectType[$type] = $servicesType;
// }
}
// d($selectType);
// exit();
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
foreach ($client as $item) {
$item->setTitle(strtoupper($item->getTitle()));
}
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabledPresentation' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = array();
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => ($description != null ? $description->getDescription() : null),
);
// d($data_destionation[$destino->getTitle()]);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
// d($company);
//////////////////////////////////////////////
/* CODIGO PARA TRAER A LOS AGENTES */
////////////////////////////////////////////
$agentMaster = array();
if (!empty($proposal->getAgentId())) {
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$agentMaster = array(
'name' => $agent->getName(),
'lastname' => $agent->getLastname(),
'picture' => $agent->getPicture(),
);
}
////////////////////////////////////////////
/* FIN CODIGO PARA TRAER A LOS AGENTES */
//////////////////////////////////////////
//d($proposal, $client, $company, $data_destionation);
//d( $agentMaster);
$sidebarData = $this->sidebarAction($token, "", "");
$serializer = SerializerBuilder::create()->build();
$arraySidebar = $serializer->toArray($sidebarData);
// d($services);
$agendas = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
array(
'proposalId' => $proposal->getId()
),
array(
'priority' => 'DESC',
'recommended' => 'ASC',
)
);
// $showAgenda = array();
// foreach ($agendas as $item) {
// $showAgenda[] = $item;
// }
if (is_null($disclaimer)) {
$disclaimer = $request->getSession()->set('_disclaimer', 'ok');
}
$musica = $em->getRepository(PresentationMusic::class)->findOneBy(
array(
'id' => $proposal->getIdMusic()
)
);
// d($controlbudgetsNew);
return $this->render(
'MDS/EventsPresentationBundle/presentation/start-client.html.twig',
array(
'token' => $token,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
'destination' => $data_destionation,
// 'agent'=> $agentMaster,
'countDestino' => $cont_destino,
// 'sidebar'=>$arraySidebar,
'descripction' => $descriptionpresenta,
'budgets' => $controlbudget,
'budgetNew' => $controlbudgetsNew,
'disclaimer' => $disclaimer,
'legal' => false,
'idea' => '',
'activity' => '',
'music' => $musica,
// 'agendas' => $showAgenda
// 'destino' => $destino_details,
// 'gallerys' => $gallery_details,
// 'description' => $description_details,
)
);
}
/**
* @Route("/agent/{token}", name="presentation_agent_token")
*/
public function AgentAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
//////////////////////////////////////////////
/* CODIGO PARA TRAER A LOS AGENTES */
////////////////////////////////////////////
/* inicio array con los agentes */
$agentes_data = $em->getRepository(ProposalAgents::class)->findOneByIdProp($proposal->getId());
$agentArray = array();
if (!is_null($proposal->getAgentId())) {
// $agenteTwo=array();
// if(!empty($proposal->getAgentTwoId())){
// $agenteTwo= explode(",", $proposal->getAgentTwoId());
// array_push($agentArray, $agenteTwo);
// }
// d($proposal->getAgencommercialId());
$agentes_data = $em->getRepository(ProposalAgents::class)->findOneByIdProp($proposal->getId());
$agentes_data->getAgOne() == 0 ? null : array_push($agentArray, $agentes_data->getAgOne());
$agentes_data->getAgTwo() == 0 ? null : array_push($agentArray, $agentes_data->getAgTwo());
$agentes_data->getAgThree() == 0 ? null : array_push($agentArray, $agentes_data->getAgThree());
$agentes_data->getAgFour() == 0 ? null : array_push($agentArray, $agentes_data->getAgFour());
// d($agentAraData);
$agentProposal = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$teamLeader = $em->getRepository(User::class)->findOneBy(
array(
'team' => $agentProposal->getTeam(),
'teamleader' => 1,
)
);
if (!empty($teamLeader)) {
array_push($agentArray, $teamLeader->getId());
}
$proposal->getAgencommercialId() == 0 ? null : array_push($agentArray, $proposal->getAgencommercialId());
array_push($agentArray, 6);
array_push($agentArray, 14);
// array_push($agentArray, 1);
// array_push($agentArray, 1);
// $dataAgents=array();
// d($agentArray);
foreach ($agentArray as $agent) {
// d($agent); exit();
if ($agent != 0) {
$users = $em->getRepository(User::class)->findOneById($agent);
$dataAgents[] = array(
'id' => $agent,
'fullname' => $users->getName() . ' ' . $users->getLastName(),
'picture' => $users->getPicture(),
'jobtitle' => $users->getJobTitle(),
'description' => $users->getDescription(),
);
}
}
// d($dataAgents);
/* fin array con los agentes */
}
////////////////////////////////////////////
/* FIN CODIGO PARA TRAER A LOS AGENTES */
//////////////////////////////////////////
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
// d($controlbudgetsNew);
return $this->render(
'MDS/EventsPresentationBundle/presentation/agent.html.twig',
array(
'token' => $token,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
// 'destination' => $data_destionation,
'dataAgents' => $dataAgents,
)
);
}
/**
* @Route("/slider/getImage/", name="get_city_image")
*/
public function getImageAction(Request $request)
{
// $selectedCity = $ciudad;
$selectedCity = $_POST['selectedCity'];
$em = $this->getDoctrine()->getManager();
// $imageOfDestination = $em->getRepository(Regions::class)->findBycountry_id($cod_pais);
$destino = $em->getRepository(Destination::class)->findOneBy(array(
'title' => $selectedCity,
));
$imageOfDestination = $em->getRepository(DestinationGallery::class)->findOneBy(
array(
'destinationId' => $destino->getId()
)
);
$result = array(
'imageCityFound' => $imageOfDestination->getImageSmall(),
);
$response = new JsonResponse($result);
// return 'hola';
return $response;
}
/**
* @Route("budget/xls/{idp}/{token}", name="presentation_xls_view")
*/
public function xlsViewAction($token, $idp, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$country = $em->getRepository(Country::class)->findOneById($client->getCountry());
$client->setCountry($country->getCountry());
$regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
$client->setRegion($regions->getRegion());
$province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
$client->setProvince($province->getName());
$cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
$client->setPopulation($cities->getCity());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
$controlproposal = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$controlbudget = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
$controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
$filtro2 = array();
foreach ($controlproposal as $consultabudget2) {
$filtro2[] = $consultabudget2->getDestinationId();
}
$services_supplier = array();
$services_ideas = array();
$budget = array();
$content_data = array();
$destination = array();
// $totales_neto="";
// $totales_total="";
$totales_neto = 0;
$totales_total = 0;
$totales_iva = array();
$data = array();
foreach ($filtro2 as $destinobudget) {
$destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
$destino = $destination->getTitle();
$consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
array(
'controlId' => $idp,
'destinationId' => $destinobudget,
'itemsserviceIdFather' => '0'
),
array(
'rank' => 'DESC'
)
);
$filtro = array();
foreach ($consulta_budget as $consultabudget) {
if (!is_null($consultabudget->getIdeaId())) {
$filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
}
if (!is_null($consultabudget->getActivityId())) {
$filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
$filtro['whiteservice']['0'][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
$filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
}
// $filtro[$consultabudget->getSupplierId()] = $consultabudget;
}
// d($filtro);
//
$master = "";
$services = array();
$whiteservice = array();
$idea = array();
$activity = array();
$supplier = array();
foreach ($filtro as $key => $ideaOsupplier) {
// d("·········································", $ideaOsupplier);
foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
// d($ideaOsupplierAdentro);
$services = array();
// $total_neto="";
// $total_total="";
$total_neto = 0;
$total_total = 0;
foreach ($ideaOsupplierAdentro as $servicesbudget) {
// d($servicesbudget);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
if ($key == "whiteservice") {
$services_white = $em->getRepository(SettingsCompany::class)->findOneById('1');
$master = "whiteservice";
$services[] = array(
'service' => $servicesbudget
);
$whiteservice[$services_white->getId()] = array(
'datos' => $services_white,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
}
if ($key == "activity") {
$services_activity = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
$master = "activity";
$services[] = array(
'service' => $servicesbudget
);
$activity[$services_activity->getId()] = array(
'datos' => $services_activity,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
}
if ($key == "idea") {
$services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
$master = "idea";
$services[] = array(
'service' => $servicesbudget
);
$idea[$services_ideas->getId()] = array(
'datos' => $services_ideas,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
}
if ($key == "supplier") {
if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
$servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
$master = "supplier";
// foreach($services_supplier as $servicessupplier){
if (!is_null($servicessupplier)) {
switch ($servicessupplier->getStar()) {
case 1:
$servicessupplier->setStar('<i class="icon-star-full2"></i>');
break;
case 2:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 3:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 4:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 5:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP');
break;
case 6:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 7:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
case 8:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
}
}
$services[] = array(
'service' => $servicesbudget
);
$supplier[$servicessupplier->getId()] = array(
'datos' => $servicessupplier,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
}
}
}
}
}
$content_data = array(
'supplier' => $supplier,
'idea' => $idea,
'activity' => $activity,
'whiteservice' => $whiteservice,
);
$data[] = array(
'destination' => $destination,
'container' => $content_data
);
}
////////////////////////////////////////////////////////////////////////////////////////////////
/* FIN CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
/* CODIGO PARA TRAER A LOS AGENTES */
////////////////////////////////////////////
$agentMaster = array();
if (!empty($proposal->getAgentId())) {
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$agentMaster = array(
'name' => $agent->getName(),
'lastname' => $agent->getLastname(),
'picture' => $agent->getPicture(),
);
}
// d($data);
// $services = $this->servicesAction($token, '', '');
/*Traducciones*/
if (!($proposal->getLanguage() == 'ENGLISH')) {
// Por defecto para todos los idiomas sera un presupuesto en castellano
$transcategory = $this->translator->trans('Category');
$transname = $this->translator->trans('Name');
$transprice = $this->translator->trans('Price');
$transpricevat = $this->translator->trans('Price with Vat');
$transunits = $this->translator->trans('Units');
$transpax = $this->translator->trans('Pax');
$transdays = $this->translator->trans('Days');
$transstart = $this->translator->trans('Start');
$transend = $this->translator->trans('End');
$transnet = $this->translator->trans('Net');
$transiva = $this->translator->trans('Iva');
$transtotal = $this->translator->trans('Total');
} else {
$transcategory = 'Category';
$transname = 'Name';
$transprice = 'Price';
$transpricevat = 'Price with Vat';
$transunits = 'Units';
$transpax = 'Pax';
$transdays = 'Days';
$transstart = 'Start';
$transend = 'End';
$transnet = 'Net';
$transiva = 'Vat';
$transtotal = 'Total';
}
$total = 0;
$neto = 0;
// Solicita el servicio de excel
$phpExcelObject = new Spreadsheet;;
$phpExcelObject->getProperties()->setCreator("InOut Travel")
->setLastModifiedBy("InOut Travel")
->setTitle("InOut Travel")
->setSubject("InOut Travel")
->setDescription("InOut Travel, generado usando clases de PHP")
->setKeywords("office 2005 openxml php")
->setCategory("Presupuestos");
$fill = new Fill();
$numberFormat = new NumberFormat();
$alignment = new Alignment();
$estilo = array(
'alignment' => array(
'horizontal' => $alignment::HORIZONTAL_RIGHT,
)
);
$i = 5;
$tot = 0;
$k = 0;
$activesheet = $phpExcelObject->getActiveSheet();
$drawingobject = new Drawing;
$drawingobject->setName('Image name');
$drawingobject->setDescription('Image description');
// $drawingobject->setPath(getcwd().'/assets/images/logo/logo20.png');
$drawingobject->setPath(getcwd() . '/assets/images/logo/logo2022.png');
$drawingobject->setHeight(60);
$drawingobject->setOffsetY(20);
$drawingobject->setCoordinates('K1');
$drawingobject->setWorksheet($activesheet);
$phpExcelObject
->getActiveSheet()
->getStyle('B3:H3')
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('FFA420');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('C3', 'PRESUPUESTO : ' . $proposal->getId() . '/' . $idp . ' PROPUESTA : ' . $proposal->getTitle());
$celdaNeto = '';
$celdaTotal = '';
foreach ($data as $key => $destination) {
// d($destination['container']['supplier']);
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $i . ':M' . $i)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('FFA420');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $i, $destination['destination']->getTitle());
// d($destination['destination']->getTitle());
$j = $i + 1;
if (empty($proposal->getCommission()) or $proposal->getCommission() == 'National') {
if (!empty($destination['container']['supplier'])) {
foreach ($destination['container']['supplier'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':L' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
if (
$valueSup['datos']->getType() == "HOTEL" or
$valueSup['datos']->getType() == "RESTAURANTE"
) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getCompany());
} else {
$type = $this->translator->trans($valueSup['datos']->getType());
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $type);
}
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transunits)
->setCellValue('F' . ($j + 1), $transpax)
->setCellValue('G' . ($j + 1), $transdays)
->setCellValue('H' . ($j + 1), $transstart)
->setCellValue('I' . ($j + 1), $transend)
->setCellValue('J' . ($j + 1), $transnet)
->setCellValue('K' . ($j + 1), $transiva)
->setCellValue('L' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
->setCellValue('E' . $k, $valueService['service']->getUnits())
->setCellValue('F' . $k, $celdaServicioPax)
->setCellValue('G' . $k, $valueService['service']->getDays())
->setCellValue('H' . $k, $inDate)
->setCellValue('I' . $k, $outDate)
->setCellValue('J' . $k, $celdaServicioNeto)
->setCellValue('K' . $k, $valueService['service']->getIva())
// ->setCellValue('L' . $k, $valueService['service']->getTotal());
->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $k)
->getNumberFormat()
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $k)
->getNumberFormat()
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
->setFormatCode('#,##0.00 €');
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('I' . ($j - 1), 'SUBTOTAL')
->setCellValue('J' . ($j - 1), $valueSup['neto'])
->setCellValue('L' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . ($j - 1),
'=SUM(L' . ($i + 2) . ':L' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . ($j - 1),
'=SUM(J' . ($i + 2) . ':J' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(J' . ($i + 2) . ':J' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(L' . ($i + 2) . ':L' . ($j - 2) . ')';
}
$i = $j + 1;
}
if (!empty($destination['container']['idea'])) {
foreach ($destination['container']['idea'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':L' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getName());
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transunits)
->setCellValue('F' . ($j + 1), $transpax)
->setCellValue('G' . ($j + 1), $transdays)
->setCellValue('H' . ($j + 1), $transstart)
->setCellValue('I' . ($j + 1), $transend)
->setCellValue('J' . ($j + 1), $transnet)
->setCellValue('K' . ($j + 1), $transiva)
->setCellValue('L' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
->setCellValue('E' . $k, $valueService['service']->getUnits())
->setCellValue('F' . $k, $celdaServicioPax)
->setCellValue('G' . $k, $valueService['service']->getDays())
->setCellValue('H' . $k, $inDate)
->setCellValue('I' . $k, $outDate)
->setCellValue('J' . $k, $celdaServicioNeto)
->setCellValue('K' . $k, $valueService['service']->getIva())
->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
// ->setCellValue('L' . $k, $valueService['service']->getTotal());
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('I' . ($j - 1), 'SUBTOTAL')
->setCellValue('J' . ($j - 1), $valueSup['neto'])
->setCellValue('L' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . ($j - 1),
'=SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . ($j - 1),
'=SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')';
}
$i = $j + 1;
}
if (!empty($destination['container']['activity'])) {
foreach ($destination['container']['activity'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':L' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getName());
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transunits)
->setCellValue('F' . ($j + 1), $transpax)
->setCellValue('G' . ($j + 1), $transdays)
->setCellValue('H' . ($j + 1), $transstart)
->setCellValue('I' . ($j + 1), $transend)
->setCellValue('J' . ($j + 1), $transnet)
->setCellValue('K' . ($j + 1), $transiva)
->setCellValue('L' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
->setCellValue('E' . $k, $valueService['service']->getUnits())
->setCellValue('F' . $k, $celdaServicioPax)
->setCellValue('G' . $k, $valueService['service']->getDays())
->setCellValue('H' . $k, $inDate)
->setCellValue('I' . $k, $outDate)
->setCellValue('J' . $k, $celdaServicioNeto)
->setCellValue('K' . $k, $valueService['service']->getIva())
->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
// ->setCellValue('L' . $k, $valueService['service']->getTotal());
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('I' . ($j - 1), 'SUBTOTAL')
->setCellValue('J' . ($j - 1), $valueSup['neto'])
->setCellValue('L' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . ($j - 1),
'=SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . ($j - 1),
'=SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')';
}
$i = $j + 1;
}
if (!empty($destination['container']['whiteservice'])) {
foreach ($destination['container']['whiteservice'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':L' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getCompany());
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transunits)
->setCellValue('F' . ($j + 1), $transpax)
->setCellValue('G' . ($j + 1), $transdays)
->setCellValue('H' . ($j + 1), $transstart)
->setCellValue('I' . ($j + 1), $transend)
->setCellValue('J' . ($j + 1), $transnet)
->setCellValue('K' . ($j + 1), $transiva)
->setCellValue('L' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
->setCellValue('E' . $k, $valueService['service']->getUnits())
->setCellValue('F' . $k, $celdaServicioPax)
->setCellValue('G' . $k, $valueService['service']->getDays())
->setCellValue('H' . $k, $inDate)
->setCellValue('I' . $k, $outDate)
->setCellValue('J' . $k, $celdaServicioNeto)
->setCellValue('K' . $k, $valueService['service']->getIva())
->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
// ->setCellValue('L' . $k, $valueService['service']->getTotal());
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('I' . ($j - 1), 'SUBTOTAL')
->setCellValue('J' . ($j - 1), $valueSup['neto'])
->setCellValue('L' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . ($j - 1),
'=SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . ($j - 1),
'=SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')';
}
$i = $j + 1;
}
} else {
// *****************************************************************************************************
// Caso internacional
// *****************************************************************************************************
if (!empty($destination['container']['supplier'])) {
foreach ($destination['container']['supplier'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':M' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
if (
$valueSup['datos']->getType() == "HOTEL" or
$valueSup['datos']->getType() == "RESTAURANTE"
) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getCompany());
} else {
$type = $this->translator->trans($valueSup['datos']->getType());
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $type);
}
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transpricevat)
->setCellValue('F' . ($j + 1), $transunits)
->setCellValue('G' . ($j + 1), $transpax)
->setCellValue('H' . ($j + 1), $transdays)
->setCellValue('I' . ($j + 1), $transstart)
->setCellValue('J' . ($j + 1), $transend)
->setCellValue('K' . ($j + 1), $transnet)
->setCellValue('L' . ($j + 1), $transiva)
->setCellValue('M' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
$celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
$celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
}
if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
$celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
}
$valueTotalUnit = round($valueTotalUnit, 2);
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
// ->setCellValue('E' . $k, $valueTotalUnit)
->setCellValue('E' . $k, $celdaValueTotalUnit)
->setCellValue('F' . $k, $valueService['service']->getUnits())
->setCellValue('G' . $k, $celdaServicioPax)
->setCellValue('H' . $k, $valueService['service']->getDays())
->setCellValue('I' . $k, $inDate)
->setCellValue('J' . $k, $outDate)
->setCellValue('K' . $k, $celdaServicioNeto)
->setCellValue('L' . $k, $valueService['service']->getIva())
->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
// ->setCellValue('M' . $k, $valueService['service']->getTotal());
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . ($j - 1), 'SUBTOTAL')
->setCellValue('K' . ($j - 1), $valueSup['neto'])
->setCellValue('M' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'M' . ($j - 1),
'=SUM(M' . ($i + 2) . ':M' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'K' . ($j - 1),
'=SUM(K' . ($i + 2) . ':K' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(K' . ($i + 2) . ':K' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(M' . ($i + 2) . ':M' . ($j - 2) . ')';
}
$i = $j + 1;
}
if (!empty($destination['container']['idea'])) {
foreach ($destination['container']['idea'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':M' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getName());
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transpricevat)
->setCellValue('F' . ($j + 1), $transunits)
->setCellValue('G' . ($j + 1), $transpax)
->setCellValue('H' . ($j + 1), $transdays)
->setCellValue('I' . ($j + 1), $transstart)
->setCellValue('J' . ($j + 1), $transend)
->setCellValue('K' . ($j + 1), $transnet)
->setCellValue('L' . ($j + 1), $transiva)
->setCellValue('M' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
$celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
$celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
}
if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
$celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
}
$valueTotalUnit = round($valueTotalUnit, 2);
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
// ->setCellValue('E' . $k, $valueTotalUnit)
->setCellValue('E' . $k, $celdaValueTotalUnit)
->setCellValue('F' . $k, $valueService['service']->getUnits())
->setCellValue('G' . $k, $celdaServicioPax)
->setCellValue('H' . $k, $valueService['service']->getDays())
->setCellValue('I' . $k, $inDate)
->setCellValue('J' . $k, $outDate)
->setCellValue('K' . $k, $celdaServicioNeto)
->setCellValue('L' . $k, $valueService['service']->getIva())
->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
// ->setCellValue('M' . $k, $valueService['service']->getTotal());
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . ($j - 1), 'SUBTOTAL')
->setCellValue('K' . ($j - 1), $valueSup['neto'])
->setCellValue('M' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'M' . ($j - 1),
'=SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'K' . ($j - 1),
'=SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')';
}
$i = $j + 1;
}
if (!empty($destination['container']['activity'])) {
foreach ($destination['container']['activity'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':M' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getName());
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transpricevat)
->setCellValue('F' . ($j + 1), $transunits)
->setCellValue('G' . ($j + 1), $transpax)
->setCellValue('H' . ($j + 1), $transdays)
->setCellValue('I' . ($j + 1), $transstart)
->setCellValue('J' . ($j + 1), $transend)
->setCellValue('K' . ($j + 1), $transnet)
->setCellValue('L' . ($j + 1), $transiva)
->setCellValue('M' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
$celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
$celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
}
if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
$celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
}
$valueTotalUnit = round($valueTotalUnit, 2);
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
// ->setCellValue('E' . $k, $valueTotalUnit)
->setCellValue('E' . $k, $celdaValueTotalUnit)
->setCellValue('F' . $k, $valueService['service']->getUnits())
->setCellValue('G' . $k, $celdaServicioPax)
->setCellValue('H' . $k, $valueService['service']->getDays())
->setCellValue('I' . $k, $inDate)
->setCellValue('J' . $k, $outDate)
->setCellValue('K' . $k, $celdaServicioNeto)
->setCellValue('L' . $k, $valueService['service']->getIva())
->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
// ->setCellValue('M' . $k, $valueService['service']->getTotal());
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . ($j - 1), 'SUBTOTAL')
->setCellValue('K' . ($j - 1), $valueSup['neto'])
->setCellValue('M' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'M' . ($j - 1),
'=SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'K' . ($j - 1),
'=SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')';
}
$i = $j + 1;
}
if (!empty($destination['container']['whiteservice'])) {
foreach ($destination['container']['whiteservice'] as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':M' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $valueSup['datos']->getCompany());
if (!empty($valueSup['services'])) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . ($j + 1), $transcategory)
->setCellValue('B' . ($j + 1), $transname)
->setCellValue('D' . ($j + 1), $transprice)
->setCellValue('E' . ($j + 1), $transpricevat)
->setCellValue('F' . ($j + 1), $transunits)
->setCellValue('G' . ($j + 1), $transpax)
->setCellValue('H' . ($j + 1), $transdays)
->setCellValue('I' . ($j + 1), $transstart)
->setCellValue('J' . ($j + 1), $transend)
->setCellValue('K' . ($j + 1), $transnet)
->setCellValue('L' . ($j + 1), $transiva)
->setCellValue('M' . ($j + 1), $transtotal);
$k = $j + 2;
foreach ($valueSup['services'] as $keyService => $valueService) {
$inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
$catName = $this->translator->trans($valueService['service']->getServiceCatName());
$valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
$celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
$celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
}
if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
$celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
}
$valueTotalUnit = round($valueTotalUnit, 2);
$celdaServicioPax = $valueService['service']->getPax();
if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
} else {
if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
$celdaServicioPax = 1;
}
$celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $catName)
->setCellValue('B' . $k, $valueService['service']->getName())
->setCellValue('D' . $k, $valueService['service']->getPrice())
// ->setCellValue('E' . $k, $valueTotalUnit)
->setCellValue('E' . $k, $celdaValueTotalUnit)
->setCellValue('F' . $k, $valueService['service']->getUnits())
->setCellValue('G' . $k, $celdaServicioPax)
->setCellValue('H' . $k, $valueService['service']->getDays())
->setCellValue('I' . $k, $inDate)
->setCellValue('J' . $k, $outDate)
->setCellValue('K' . $k, $celdaServicioNeto)
->setCellValue('L' . $k, $valueService['service']->getIva())
->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
// ->setCellValue('M' . $k, $valueService['service']->getTotal());
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $k)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$k++;
}
}
$j = $k + 1;
//SUBTOTALES
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . ($j - 1), 'SUBTOTAL')
->setCellValue('K' . ($j - 1), $valueSup['neto'])
->setCellValue('M' . ($j - 1), $valueSup['total']);
$neto += $valueSup['neto'];
$total += $valueSup['total'];
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($j - 1 == $i) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'M' . ($j - 1),
'=SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'K' . ($j - 1),
'=SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')';
}
$i = $j + 1;
}
}
// $i=$j+1;
}
$tot = $i + 1;
if (empty($proposal->getCommission()) or $proposal->getCommission() == 'National') {
$phpExcelObject
->getActiveSheet()
->getStyle('I' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
// ->setRGB('57A639')
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
// ->setRGB('57A639')
->setRGB('7ec8e0');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('I' . $tot, $transnet . ': ')
->setCellValue('K' . $tot, $transtotal . ': ')
->setCellValue('J' . $tot, $celdaNeto)
->setCellValue('L' . $tot, $celdaTotal);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
foreach (range('H' . $tot, 'L' . $tot) as $columnID) {
$phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
$phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 2))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 3))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 4))->applyFromArray($estilo);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('L' . ($tot + 2), 'INOUT TRAVEL')
->setCellValue('L' . ($tot + 3), 'events@inout-travel.com')
->setCellValue('L' . ($tot + 4), '+34 911 878 393');
$phpExcelObject
->getActiveSheet()
->getStyle('k' . ($tot + 2) . ':' . 'L' . ($tot + 4))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('F18E0D');
} else { // Caso Internacional (pie de pagina)
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
// ->setRGB('57A639')
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
// ->setRGB('57A639')
->setRGB('7ec8e0');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . $tot, $transnet . ': ')
->setCellValue('L' . $tot, $transtotal . ': ')
->setCellValue('K' . $tot, $celdaNeto)
->setCellValue('M' . $tot, $celdaTotal);
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
// ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
// ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
foreach (range('I' . $tot, 'M' . $tot) as $columnID) {
$phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
$phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 2))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 3))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 4))->applyFromArray($estilo);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('M' . ($tot + 2), 'INOUT TRAVEL')
->setCellValue('M' . ($tot + 3), 'events@inout-travel.com')
->setCellValue('M' . ($tot + 4), '+34 911 878 393');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . ($tot + 2) . ':' . 'M' . ($tot + 4))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('F18E0D');
}
$phpExcelObject->getActiveSheet()->setTitle('Simple');
// 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,
// $company->getCompany().' proposal - '.$proposal->getId().'.xlsx'
'In_Out_Travel_presupuesto-' . $idp . '_proposal-' . $proposal->getId() . '.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("/budget/xls/{token}", name="proposal_xls_budget")
*
*/
public function xlsAction($token, EntityManagerInterface $em, Request $request)
{
$totales_neto_sub = $totales_iva_sub = $totales_con_iva_sub = $totales_paying_sub = $totales_pago_sub = $totales_benefit_moneda_sub = 0;
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute( 'presentation_error_cancel', array( 'token' => $token ) );
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
$available_destination = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => "0"
)
);
$data_supplier = array();
foreach ($available_destination as $availabledestination) {
/* Data Supplier agregados */
$service_supplier = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'controlDestinationId' => $availabledestination->getId(),
'disabled' => "0"
),
array(
'rank' => 'ASC'
)
);
$controlgeneral = array(); $master = null;
foreach ($service_supplier as $suppliercontrol) {
$destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
//cambiar el estatus de colores
$colorlabel = "";
switch ($suppliercontrol->getStatus()) {
case 'Pending': $colorlabel = "bg-danger"; break;
case 'Confirmed': $colorlabel = "bg-success"; break;
}
$sqlactivities = "";
if (!is_null($suppliercontrol->getActivityId())) {
$master = "activity";
$sqlactivities = $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
}
$sqlideas = "";
if (!is_null($suppliercontrol->getIdeaId())) {
$master = "idea";
$sqlideas = $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
}
$sqlsuppliers = "";
if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
$master = "supplier";
$sqlsuppliers = $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
if (!is_null($sqlsuppliers)) {
switch ($sqlsuppliers->getStar()) {
case 1: $sqlsuppliers->setStar('<i class="icon-star-full2"></i>'); break;
case 2: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 3: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 4: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 5: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP'); break;
case 6: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 7: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL'); break;
}
}
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
}
$sqlcompany = "";
if ($suppliercontrol->getSupplierId() == "0") {
$master = "company";
$sqlcompany = $em->getRepository(SettingsCompany::class)->findOneById('1');
if (!is_null($sqlcompany)) {
$imagenSmall = $sqlcompany->getPicture();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
} else {
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
}
// ORDEN DESCENDENTE Y POR SERVICES
$parameters = array(
'controlId' => $suppliercontrol->getId(),
'serviceIdFather' => '0',
'directPayment' => '0',
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServices p
WHERE p.controlId = :controlId
AND p.serviceIdFather = :serviceIdFather
AND p.directPayment = :directPayment
ORDER BY p.serviceCatId, p.rank ASC ';
$query = $em->createQuery($dql)->setParameters($parameters);
$data_service_supplier = $query->getResult();
$service_supplier_data = array();
$calculos_totatales = array();
$totales_neto = '0';
$totales_iva = '0';
$totales_con_iva = '0';
$totales_paying = '0';
$totales_pago = '0';
$totales_benefit_moneda = '0';
$totales_benefit_porsentaje = '0';
foreach ($data_service_supplier as $data_service) {
//COLOR POR SERVICIO
$contcolor = "";
switch ($data_service->getServiceCatName()) {
case "Accommodation": $contcolor = 'teal'; break;
case "Menu": $contcolor = 'purple'; break;
case "Lounge": $contcolor = 'warning'; break;
case "Activities": $contcolor = 'blue'; break;
case "Itineraries": $contcolor = 'indigo'; break;
case "Cruise": $contcolor = 'brown'; break;
case "Transport": $contcolor = 'grey'; break;
case "Av": $contcolor = 'slate'; break;
case "Creative": $contcolor = 'orange'; break;
case "Gifts": $contcolor = 'pink'; break;
case "Entertainment": $contcolor = 'green'; break;
case "Guide": $contcolor = 'orange'; break;
case "Others": $contcolor = 'danger'; break;
case "Technology": $contcolor = 'grey-800'; break;
case "Assistant": $contcolor = 'indigo-800'; break;
case "DDR": $contcolor = 'green-300'; break;
}
$idcat = $data_service->getServiceCatId();
$price = $data_service->getPrice();
$units = $data_service->getUnits();
$pax = $data_service->getPax();
$opcommission = $data_service->getOpCommission();
$commission = $data_service->getCommission();
$opover = $data_service->getOpOver();
$over = $data_service->getOver();
$opiva = $data_service->getOpIva();
$iva = $data_service->getIva();
$dateInAt = $data_service->getDateInAt();
$dateOutAt = $data_service->getDateOutAt();
if (!is_null($dateInAt) and !is_null($dateOutAt)) {
$days = $dateInAt->diff($dateOutAt);
$day = $days->days;
} else {
$day = "0";
}
$directPayment = $data_service->getDirectPayment();
if ($data_service->getSupplierId() == "0") {
$name_company = $em->getRepository(SettingsCompany::class)->findOneById('1');
$namesupplier = $name_company->getCompany();
}
if (!is_null($data_service->getSupplierId()) && $data_service->getSupplierId() != "0") {
$name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
$namesupplier = $name_supplier->getName();
}
if (!is_null($data_service->getActivityId())) {
$name_supplier = $em->getRepository(Activities::class)->findOneById($data_service->getActivityId());
$namesupplier = $name_supplier->getName();
}
if (!is_null($data_service->getIdeaId())) {
$name_supplier = $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
$namesupplier = $name_supplier->getName();
}
$calculos = $this->CalculoTotalesservices($price, $units, $pax, $day, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat);
$data_service->setPrice($calculos['precio']); //ojo aqui
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
$data_service->setPrice($calculos['precio']); //ojo aqui
$service_supplier_data[$data_service->getServiceCatName()][] = array(
'calculos' => $calculos,
'services_data' => $data_service,
'contcolor' => $contcolor,
);
if ($data_service->getBreakdown() == false) {
$totales_neto += $calculos['total_neto'];
$totales_iva += $calculos['sub_total_iva'];
$totales_con_iva += $calculos['total'];
$totales_paying += $calculos['total_paying'];
$totales_pago += $calculos['total_pago'];
$totales_benefit_moneda += $calculos['benefit_moneda'];
} else {
$totales_neto += $totales_neto_sub;
$totales_iva += $totales_iva_sub;
$totales_con_iva += $totales_con_iva_sub;
$totales_paying += $totales_paying_sub;
$totales_pago += $totales_pago_sub;
$totales_benefit_moneda += $totales_benefit_moneda_sub;
}
if ($totales_benefit_moneda == '0') {
$totales_benefit_porsentaje = '0';
} else {
if ($totales_pago == 0 or is_null($totales_pago)) {
$totales_benefit_porsentaje = 0;
} else {
$totales_benefit_porsentaje = $totales_benefit_moneda * 100 / $totales_pago;
}
}
}
$calculos_totatales = array(
'totales_neto' => $totales_neto,
'totales_iva' => $totales_iva,
'totales_con_iva' => $totales_con_iva,
'totales_paying' => $totales_paying,
'totales_benefit_moneda' => $totales_benefit_moneda,
'totales_benefit_porsentaje' => $totales_benefit_porsentaje
);
if ($master == "company") { $typeMaster = $sqlcompany->getCompany(); }
if ($master == "supplier") { $typeMaster = $sqlsuppliers->getType(); }
if ($master == "activity") { $typeMaster = "Activity"; }
if ($master == "idea") { $typeMaster = "IDEA"; }
$data_supplier[$destination->getTitle()][$typeMaster][] = array(
'colorlabel' => $colorlabel,
'control' => $suppliercontrol,
'master' => $master,
'supplier' => $sqlsuppliers,
'idea' => $sqlideas,
'company' => $sqlcompany,
'activity' => $sqlactivities,
'image' => $imagenSmall,
'services' => $service_supplier_data,
'totales_services' => $calculos_totatales
);
}
}
$fees = $em->getRepository(ProposalFee::class)->findByProposalId($proposal->getId()); $theFee = [];
if (!empty($fees)) {
// Solo se haran los calculos si el Fee va a la factura, en caso contrario es un fee oculto y ya estará cargado en los servicios
if ($fees[0]->getToinvoice() == true) {
foreach ($fees as $fee) {
$xFeeAmount = empty($fee->getAmount()) ? 0 : $fee->getAmount();
if ($fee->getType() == 0) {
$theFee = array(
'valorDirecto' => null,
'montoPorcentaje' => $xFeeAmount,
);
} else {
$theFee = array(
'valorDirecto' => $xFeeAmount,
'montoPorcentaje' => null,
);
}
}
}
} else {
$theFee = null;
}
$total = 0;
$neto = 0;
// Solicita el servicio de excel
$phpExcelObject = new Spreadsheet;;
$phpExcelObject->getProperties()->setCreator("InOut Travel")
->setLastModifiedBy("InOut Travel")
->setTitle("InOut Travel")
->setSubject("InOut Travel")
->setDescription("InOut Travel, generado usando clases de PHP")
->setKeywords("office 2005 openxml php")
->setCategory("Archivo de ejemplo");
$fill = new Fill();
$numberFormat = new NumberFormat();
$alignment = new Alignment();
$i = 5;
$tot = 0;
$activesheet = $phpExcelObject->getActiveSheet();
$drawingobject = new Drawing;
$drawingobject->setName('Image name');
$drawingobject->setDescription('Image description');
$drawingobject->setPath(getcwd() . '/assets/images/logo/logo2022.png');
$drawingobject->setHeight(60);
$drawingobject->setOffsetY(20);
$drawingobject->setCoordinates('K1');
$drawingobject->setWorksheet($activesheet);
$phpExcelObject
->getActiveSheet()
->getStyle('B3:H3')
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('FFA420');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('C3', 'PRESUPUESTO: ' . $proposal->getTitle());
if (empty($proposal->getCommission()) or $proposal->getCommission() == 'National') {
// *****************************************************************************************************
// Caso Nacional
// *****************************************************************************************************
$celdaNeto = '';
$celdaTotal = '';
foreach ($data_supplier as $key => $value) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $i . ':L' . $i)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('FFA420');
$keytrans = strtoupper($this->translator->trans($key));
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $i, $keytrans);
// d($phpExcelObject);
$j = $i + 1;
foreach ($value as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':L' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$keySuptrans = strtoupper($this->translator->trans($keySup));
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $keySuptrans);
$drawingobject = new Drawing;
$service = $j + 1;
foreach ($valueSup as $keySupAll => $valueSupAll) {
$totalSub = 0;
$netoSub = 0;
if (!is_null($valueSupAll['master'])) {
$type = $valueSupAll['master'];
if ($type == 'idea' or $type == 'activity') {
$name = $valueSupAll[$type]->getName();
} else {
$name = "";
if (!empty($valueSupAll['supplier'])) {
// d($valueSupAll['supplier']->getType());
if (
$valueSupAll['supplier']->getType() == "ENTRETENIMIENTO" or
$valueSupAll['supplier']->getType() == "TRANSPORTE" or
$valueSupAll['supplier']->getType() == "GUÍAS" or
$valueSupAll['supplier']->getType() == "OTROS" or
$valueSupAll['supplier']->getType() == "AUDIOVISUAL" or
$valueSupAll['supplier']->getType() == "AUDIOVISUALES" or
$valueSupAll['supplier']->getType() == "MÚSICA" or
$valueSupAll['supplier']->getType() == "ASISTENCIA"
) {
$name = "";
$valueSupAll[$type]->setCompany('');
$valueSupAll[$type]->setName('');
} else {
$name = $valueSupAll[$type]->getCompany();
}
}
}
if ($name != '') {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $service . ':C' . $service)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DA9694');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $service, $name);
}
}
$estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ) );
$k = $service + 1;
if (!empty($valueSupAll[$type])) {
foreach ($valueSupAll['services'] as $keyService => $valueService) {
if (!($proposal->getLanguage() == 'ENGLISH')) {
// Por defecto para todos los idiomas sera un presupuesto en castellano
$keyServiceTrad = $this->translator->trans($keyService);
} else {
// El otro idioma es ingles
$keyServiceTrad = $keyService;
}
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $k . ':L' . $k)
->applyFromArray($estilo)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('497E76');
$estiloL = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_LEFT, ) );
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $k)
->applyFromArray($estiloL);
if (!($proposal->getLanguage() == 'ENGLISH')) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $keyServiceTrad)
->setCellValue('D' . $k, 'Precio Unitario')
->setCellValue('E' . $k, 'Cantidad')
->setCellValue('F' . $k, 'Personas')
->setCellValue('G' . $k, 'Días')
->setCellValue('H' . $k, 'Inicio')
->setCellValue('I' . $k, 'Fin')
->setCellValue('J' . $k, 'Neto')
->setCellValue('K' . $k, 'Iva')
->setCellValue('L' . $k, 'Total');
} else {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $keyServiceTrad)
->setCellValue('D' . $k, 'Price')
->setCellValue('E' . $k, 'Qty')
->setCellValue('F' . $k, 'People')
->setCellValue('G' . $k, 'Days')
->setCellValue('H' . $k, 'Start')
->setCellValue('I' . $k, 'End')
->setCellValue('J' . $k, 'Net')
->setCellValue('K' . $k, 'Vat')
->setCellValue('L' . $k, 'Total');
}
$l = $k + 1;
foreach ($valueService as $keyServiceDetail => $valueServiceDetail) {
// d($valueServiceDetail['services_data']->getServiceCatId());
$idServiceCategory = $valueServiceDetail['services_data']->getServiceCatId();
$inDate = date_format($valueServiceDetail['services_data']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueServiceDetail['services_data']->getDateOutAt(), 'd/m/Y');
$valueTotalUnit = $valueServiceDetail['calculos']['total'] / $valueServiceDetail['calculos']['total_days'];
if (!empty($valueServiceDetail['services_data']->getUnits()) and ($valueServiceDetail['services_data']->getUnits() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getUnits();
}
if (!empty($valueServiceDetail['services_data']->getPax()) and ($valueServiceDetail['services_data']->getPax() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getPax();
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $l, $valueServiceDetail['services_data']->getName())
->setCellValue('D' . $l, $valueServiceDetail['calculos']['precio'])
->setCellValue('E' . $l, $valueServiceDetail['services_data']->getUnits())
->setCellValue('F' . $l, $valueServiceDetail['services_data']->getPax())
->setCellValue('G' . $l, $valueServiceDetail['calculos']['total_days'])
->setCellValue('H' . $l, $inDate)
->setCellValue('I' . $l, $outDate)
->setCellValue('K' . $l, $valueServiceDetail['services_data']->getIva());
if ($idServiceCategory == 1 or $idServiceCategory == 10 or $idServiceCategory == 8 or $idServiceCategory == 13) {
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . $l,
'=(D' . $l . '*E' . $l . '*G' . $l . ')'
);
} else {
if ($valueServiceDetail['services_data']->getPax() == 0 or is_null($valueServiceDetail['services_data']->getPax())) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('F' . $l, 1);
}
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . $l,
'=(D' . $l . '*E' . $l . '*F' . $l . '*G' . $l . ')'
);
}
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . $l,
'=J' . $l . '+(K' . $l . '*J' . $l . '/100)'
);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $l)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $l)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$netoSub = $netoSub + $valueServiceDetail['calculos']['total_neto'];
$totalSub = $totalSub + $valueServiceDetail['calculos']['total'];
$neto = $neto + $valueServiceDetail['calculos']['total_neto'];
$total = $total + $valueServiceDetail['calculos']['total'];
$l++;
}
$k = $l + 1;
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('I' . ($k - 1), 'SUBTOTAL')
->setCellValue('J' . ($k - 1), $netoSub)
->setCellValue('L' . ($k - 1), $totalSub);
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($k - 1) . ':L' . ($k - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('I' . ($k - 1) . ':L' . ($k - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($k - 1 == $service) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . ($k - 1),
'=SUM(L' . $service . ':L' . ($k - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . ($k - 1),
'=SUM(J' . $service . ':J' . ($k - 2) . ')'
);
if (empty($celdaNeto)) {
$celdaNeto = '=';
} else {
$celdaNeto = $celdaNeto . ' + ';
}
$celdaNeto = $celdaNeto . 'SUM(J' . $service . ':J' . ($k - 2) . ')';
if (empty($celdaTotal)) {
$celdaTotal = '=';
} else {
$celdaTotal = $celdaTotal . ' + ';
}
$celdaTotal = $celdaTotal . 'SUM(L' . $service . ':L' . ($k - 2) . ')';
}
$service = $k + 1;
}
$j = $service + 1;
}
$i = $j + 1;
$tot = $j - 1;
}
if (!empty($theFee)){
$phpExcelObject
->getActiveSheet()
->getStyle('I' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
if (empty($theFee['valorDirecto'])){
// Fee de porcentaje
$phpExcelObject->getActiveSheet()
->setCellValue(
'I' . $tot,
'FEE '.$theFee['montoPorcentaje'].'%'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . $tot,
'=('.substr($celdaNeto, 1).') * ('.$theFee['montoPorcentaje'].'/100 )'
);
$celdaNeto = $celdaNeto . '+ (('.substr($celdaNeto, 1).') * ('.$theFee['montoPorcentaje'].'/100 ))';
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . $tot,
'=J'.$tot.' * (1.21)'
);
$celdaTotal = $celdaTotal . '+ L'.$tot;
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
} else {
// Fee de valor directo
$phpExcelObject->getActiveSheet()
->setCellValue(
'I' . $tot,
'FEE'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'J' . $tot,
$theFee['valorDirecto']
);
$celdaNeto = $celdaNeto . ' + '.$theFee['valorDirecto'];
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject->getActiveSheet()
->setCellValue(
'L' . $tot,
'=J'.$tot.' * (1.21)'
);
$celdaTotal = $celdaTotal . ' + L'.$tot;
}
$tot = $tot + 2;
}
#####################################################
# TOTAL Y NETO #
#####################################################
$phpExcelObject
->getActiveSheet()
->getStyle('I' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('I' . $tot, 'NETO: ')
->setCellValue('K' . $tot, 'TOTAL: ')
->setCellValue('J' . $tot, $celdaNeto)
->setCellValue('L' . $tot, $celdaTotal);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
#####################################################
# FIN TOTAL Y NETO #
#####################################################
foreach (range('H' . $tot, 'L' . $tot) as $columnID) {
$phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
$estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ));
$phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 2))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 3))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 4))->applyFromArray($estilo);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('L' . ($tot + 2), 'INOUT TRAVEL')
->setCellValue('L' . ($tot + 3), 'events@inout-travel.com')
->setCellValue('L' . ($tot + 4), '+34 911 878 393');
$phpExcelObject
->getActiveSheet()
->getStyle('k' . ($tot + 2) . ':' . 'L' . ($tot + 4))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('F18E0D');
} else {
// *****************************************************************************************************
// Caso internacional
// *****************************************************************************************************
$celdaNeto = '';
$celdaTotal = '';
foreach ($data_supplier as $key => $value) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $i . ':M' . $i)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('FFA420');
$keytrans = strtoupper($this->translator->trans($key));
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $i, $keytrans);
// d($phpExcelObject);
$j = $i + 1;
foreach ($value as $keySup => $valueSup) {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $j . ':M' . $j)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('B5B8B1');
$keySuptrans = strtoupper($this->translator->trans($keySup));
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('E' . $j, $keySuptrans);
$drawingobject = new Drawing;
$service = $j + 1;
foreach ($valueSup as $keySupAll => $valueSupAll) {
$totalSub = 0;
$netoSub = 0;
if (!is_null($valueSupAll['master'])) {
$type = $valueSupAll['master'];
if ($type == 'idea' or $type == 'activity') {
$name = $valueSupAll[$type]->getName();
} else {
$name = "";
if (!empty($valueSupAll['supplier'])) {
// d($valueSupAll['supplier']->getType());
if (
$valueSupAll['supplier']->getType() == "ENTRETENIMIENTO" or
$valueSupAll['supplier']->getType() == "TRANSPORTE" or
$valueSupAll['supplier']->getType() == "GUÍAS" or
$valueSupAll['supplier']->getType() == "OTROS" or
$valueSupAll['supplier']->getType() == "AUDIOVISUAL" or
$valueSupAll['supplier']->getType() == "AUDIOVISUALES" or
$valueSupAll['supplier']->getType() == "MÚSICA" or
$valueSupAll['supplier']->getType() == "ASISTENCIA"
) {
$name = "";
$valueSupAll[$type]->setCompany('');
$valueSupAll[$type]->setName('');
} else {
$name = $valueSupAll[$type]->getCompany();
}
}
}
if ($name != '') {
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $service . ':C' . $service)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DA9694');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $service, $name);
}
}
$estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ) );
$k = $service + 1;
if (!empty($valueSupAll[$type])) {
foreach ($valueSupAll['services'] as $keyService => $valueService) {
if (!($proposal->getLanguage() == 'ENGLISH')) {
// Por defecto para todos los idiomas sera un presupuesto en castellano
$keyServiceTrad = $this->translator->trans($keyService);
} else {
// El otro idioma es ingles
$keyServiceTrad = $keyService;
}
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $k . ':M' . $k)
->applyFromArray($estilo)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('497E76');
$estiloL = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_LEFT, ) );
$phpExcelObject
->getActiveSheet()
->getStyle('A' . $k)
->applyFromArray($estiloL);
if (!($proposal->getLanguage() == 'ENGLISH')) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $keyServiceTrad)
->setCellValue('D' . $k, 'Precio Unitario')
->setCellValue('E' . $k, 'Precio con Iva')
->setCellValue('F' . $k, 'Cantidad')
->setCellValue('G' . $k, 'Personas')
->setCellValue('H' . $k, 'Días')
->setCellValue('I' . $k, 'Inicio')
->setCellValue('J' . $k, 'Fin')
->setCellValue('K' . $k, 'Neto')
->setCellValue('L' . $k, 'Iva')
->setCellValue('M' . $k, 'Total');
} else {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $k, $keyServiceTrad)
->setCellValue('D' . $k, 'Price')
->setCellValue('E' . $k, 'Price with Vat')
->setCellValue('F' . $k, 'Qty')
->setCellValue('G' . $k, 'People')
->setCellValue('H' . $k, 'Days')
->setCellValue('I' . $k, 'Start')
->setCellValue('J' . $k, 'End')
->setCellValue('K' . $k, 'Net')
->setCellValue('L' . $k, 'Vat')
->setCellValue('M' . $k, 'Total');
}
$l = $k + 1;
foreach ($valueService as $keyServiceDetail => $valueServiceDetail) {
$idServiceCategory = $valueServiceDetail['services_data']->getServiceCatId();
$inDate = date_format($valueServiceDetail['services_data']->getDateInAt(), 'd/m/Y');
$outDate = date_format($valueServiceDetail['services_data']->getDateOutAt(), 'd/m/Y');
$valueTotalUnit = $valueServiceDetail['calculos']['total'] / $valueServiceDetail['calculos']['total_days'];
$celdaValueTotalUnit = '=(M' . $l . '/ H' . $l . ')';
if (!empty($valueServiceDetail['services_data']->getUnits()) and ($valueServiceDetail['services_data']->getUnits() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getUnits();
$celdaValueTotalUnit = '=((M' . $l . '/ H' . $l . ')/ F' . $l . ')';
}
if (!empty($valueServiceDetail['services_data']->getPax()) and ($valueServiceDetail['services_data']->getPax() > 1)) {
$valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getPax();
$celdaValueTotalUnit = '=(((M' . $l . '/ H' . $l . ')/ F' . $l . ')/ G' . $l . ')';
}
$valueTotalUnit = round($valueTotalUnit, 2);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A' . $l, $valueServiceDetail['services_data']->getName())
->setCellValue('D' . $l, $valueServiceDetail['calculos']['precio'])
->setCellValue('E' . $l, $celdaValueTotalUnit)
->setCellValue('F' . $l, $valueServiceDetail['services_data']->getUnits())
->setCellValue('G' . $l, $valueServiceDetail['services_data']->getPax())
->setCellValue('H' . $l, $valueServiceDetail['calculos']['total_days'])
->setCellValue('I' . $l, $inDate)
->setCellValue('J' . $l, $outDate)
->setCellValue('L' . $l, $valueServiceDetail['services_data']->getIva());
if ($idServiceCategory == 1 or $idServiceCategory == 10 or $idServiceCategory == 8 or $idServiceCategory == 13) {
$phpExcelObject->getActiveSheet()
->setCellValue(
'K' . $l,
'=(D' . $l . '*F' . $l . '*H' . $l . ')'
);
} else {
if ($valueServiceDetail['services_data']->getPax() == 0 or is_null($valueServiceDetail['services_data']->getPax())) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('G' . $l, 1);
}
$phpExcelObject->getActiveSheet()
->setCellValue(
'K' . $l,
'=(D' . $l . '*F' . $l . '*G' . $l . '*H' . $l . ')'
);
}
$phpExcelObject->getActiveSheet()
->setCellValue(
'M' . $l,
'=K' . $l . '+(L' . $l . '*K' . $l . '/100)'
);
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $l)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $l)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$netoSub = $netoSub + $valueServiceDetail['calculos']['total_neto'];
$totalSub = $totalSub + $valueServiceDetail['calculos']['total'];
$neto = $neto + $valueServiceDetail['calculos']['total_neto'];
$total = $total + $valueServiceDetail['calculos']['total'];
$l++;
}
$k = $l + 1;
}
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . ($k - 1), 'SUBTOTAL')
->setCellValue('K' . ($k - 1), $netoSub)
->setCellValue('M' . ($k - 1), $totalSub);
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($k - 1) . ':M' . ($k - 1))
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('J' . ($k - 1) . ':M' . ($k - 1))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('DF3A01');
}
if ($k - 1 == $service) {
// d($k,$k);
} else {
$phpExcelObject->getActiveSheet()
->setCellValue(
'M' . ($k - 1),
'=SUM(M' . $service . ':M' . ($k - 2) . ')'
);
$phpExcelObject->getActiveSheet()
->setCellValue(
'K' . ($k - 1),
'=SUM(K' . $service . ':K' . ($k - 2) . ')'
);
if (empty($celdaNeto)) { $celdaNeto = '='; } else { $celdaNeto = $celdaNeto . ' + '; }
$celdaNeto = $celdaNeto . 'SUM(K' . $service . ':K' . ($k - 2) . ')';
if (empty($celdaTotal)) { $celdaTotal = '='; } else { $celdaTotal = $celdaTotal . ' + '; }
$celdaTotal = $celdaTotal . 'SUM(M' . $service . ':M' . ($k - 2) . ')';
}
$service = $k + 1;
}
$j = $service + 1;
}
$i = $j + 1;
$tot = $j - 1;
}
#####################################################
# TOTAL Y NETO #
#####################################################
$phpExcelObject
->getActiveSheet()
->getStyle('J' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
// ->setRGB('57A639')
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('7ec8e0');
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $tot)
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
// ->setRGB('57A639')
->setRGB('7ec8e0');
if (!($proposal->getLanguage() == 'ENGLISH')) {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . $tot, 'NETO: ')
->setCellValue('L' . $tot, 'TOTAL: ')
->setCellValue('K' . $tot, $celdaNeto)
->setCellValue('M' . $tot, $celdaTotal);
} else {
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('J' . $tot, 'NET: ')
->setCellValue('L' . $tot, 'TOTAL: ')
->setCellValue('K' . $tot, $celdaNeto)
->setCellValue('M' . $tot, $celdaTotal);
}
$phpExcelObject
->getActiveSheet()
->getStyle('K' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
$phpExcelObject
->getActiveSheet()
->getStyle('M' . $tot)
->getNumberFormat()
->setFormatCode('#,##0.00 €');
#####################################################
# FIN TOTAL Y NETO #
#####################################################
foreach (range('I' . $tot, 'M' . $tot) as $columnID) {
$phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
$estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ));
$phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 2))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 3))->applyFromArray($estilo);
$phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 4))->applyFromArray($estilo);
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('M' . ($tot + 2), 'INOUT TRAVEL')
->setCellValue('M' . ($tot + 3), 'events@inout-travel.com')
->setCellValue('M' . ($tot + 4), '+34 911 878 393');
$phpExcelObject
->getActiveSheet()
->getStyle('L' . ($tot + 2) . ':' . 'M' . ($tot + 4))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('F18E0D');
} //FIN DEL IF DE LA COMMISSION
$phpExcelObject->getActiveSheet()->setTitle('Simple');
// 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,
// $company->getCompany().' proposal - '.$proposal->getId().'.xlsx'
'In Out Travel proposal - ' . $proposal->getId() . '.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("/budget/{token}", name="presentation_budget_token")
*/
public function budgetAction($token, EntityManagerInterface $em, Request $request)
{
$totales_neto_sub = $totales_iva_sub = $totales_con_iva_sub = $totales_paying_sub = $totales_pago_sub = $totales_benefit_moneda_sub = 0;
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute( 'presentation_error_cancel', array( 'token' => $token ) );
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
// $available_destination = $em->getRepository(ProposalControl::class)->findByProposalId($proposal->getId());
$available_destination = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => "0"
)
);
$data_supplier = array();
foreach ($available_destination as $availabledestination) {
/* Data Supplier agregados */
$service_supplier = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'controlDestinationId' => $availabledestination->getId(),
'disabled' => "0"
),
array(
'rank' => 'ASC'
)
);
$controlgeneral = array();
foreach ($service_supplier as $suppliercontrol) {
$destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
//cambiar el estatus de colores
$colorlabel = "";
switch ($suppliercontrol->getStatus()) {
case 'Pending': $colorlabel = "bg-danger"; break;
case 'Confirmed': $colorlabel = "bg-success"; break;
}
$sqlactivities = "";
if (!is_null($suppliercontrol->getActivityId())) {
$master = "activity";
$sqlactivities = $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
}
$sqlideas = "";
if (!is_null($suppliercontrol->getIdeaId())) {
$master = "idea";
$sqlideas = $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
}
$sqlsuppliers = "";
if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
$master = "supplier";
$sqlsuppliers = $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
if (!is_null($sqlsuppliers)) {
switch ($sqlsuppliers->getStar()) {
case 1: $sqlsuppliers->setStar('<i class="icon-star-full2"></i>'); break;
case 2: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 3: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 4: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 5: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP'); break;
case 6: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
case 7: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL'); break;
case 8: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL'); break;
}
}
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
}
$sqlcompany = "";
if ($suppliercontrol->getSupplierId() == "0") {
$master = "company";
$sqlcompany = $em->getRepository(SettingsCompany::class)->findOneById('1');
if (!is_null($sqlcompany)) {
$imagenSmall = $sqlcompany->getPicture();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
} else {
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
}
// ORDEN DESCENDENTE Y POR SERVICES
$parameters = array(
'controlId' => $suppliercontrol->getId(),
'serviceIdFather' => '0',
'directPayment' => '0',
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServices p
WHERE p.controlId = :controlId
AND p.serviceIdFather = :serviceIdFather
AND p.directPayment = :directPayment
ORDER BY p.serviceCatId, p.rank ASC ';
$query = $em->createQuery($dql)->setParameters($parameters);
$data_service_supplier = $query->getResult();
$service_supplier_data = array();
$calculos_totatales = array();
$totales_neto = '0';
$totales_iva = '0';
$totales_con_iva = '0';
$totales_paying = '0';
$totales_pago = '0';
$totales_benefit_moneda = '0';
$totales_benefit_porsentaje = '0';
foreach ($data_service_supplier as $data_service) {
//COLOR POR SERVICIO
$contcolor = "";
switch ($data_service->getServiceCatName()) {
case "Accommodation": $contcolor = 'teal'; break;
case "Menu": $contcolor = 'purple'; break;
case "Lounge": $contcolor = 'warning'; break;
case "Activities": $contcolor = 'blue'; break;
case "Itineraries": $contcolor = 'indigo'; break;
case "Cruise": $contcolor = 'brown'; break;
case "Transport": $contcolor = 'grey'; break;
case "Av": $contcolor = 'slate'; break;
case "Creative": $contcolor = 'orange'; break;
case "Gifts": $contcolor = 'pink'; break;
case "Entertainment": $contcolor = 'green'; break;
case "Guide": $contcolor = 'orange'; break;
case "Others": $contcolor = 'danger'; break;
case "Technology": $contcolor = 'grey-800'; break;
case "Assistant": $contcolor = 'indigo-800'; break;
case "DDR": $contcolor = 'green-300'; break;
}
$idcat = $data_service->getServiceCatId();
$price = $data_service->getPrice();
$units = $data_service->getUnits();
$pax = $data_service->getPax();
$opcommission = $data_service->getOpCommission();
$commission = $data_service->getCommission();
$opover = $data_service->getOpOver();
$over = $data_service->getOver();
$opiva = $data_service->getOpIva();
$iva = $data_service->getIva();
$dateInAt = $data_service->getDateInAt();
$dateOutAt = $data_service->getDateOutAt();
if (!is_null($dateInAt) and !is_null($dateOutAt)) {
$days = $dateInAt->diff($dateOutAt);
$day = $days->days;
} else {
$day = "0";
}
$directPayment = $data_service->getDirectPayment();
if ($data_service->getSupplierId() == "0") {
$name_company = $em->getRepository(Configuration::class)->findOneById('1');
$namesupplier = $name_company->getCompany();
}
if (!is_null($data_service->getSupplierId()) && $data_service->getSupplierId() != "0") {
$name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
$namesupplier = $name_supplier->getName();
}
if (!is_null($data_service->getActivityId())) {
$name_supplier = $em->getRepository(Activities::class)->findOneById($data_service->getActivityId());
$namesupplier = $name_supplier->getName();
}
if (!is_null($data_service->getIdeaId())) {
$name_supplier = $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
$namesupplier = $name_supplier->getName();
}
$calculos = $this->CalculoTotalesservices($price, $units, $pax, $day, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat);
$data_service->setPrice($calculos['precio']); //ojo aqui
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
$service_supplier_data[$data_service->getServiceCatName()][] = array(
'calculos' => $calculos,
'services_data' => $data_service,
'contcolor' => $contcolor,
);
if ($data_service->getBreakdown() == false) {
$totales_neto += $calculos['total_neto'];
$totales_iva += $calculos['sub_total_iva'];
$totales_con_iva += $calculos['total'];
$totales_paying += $calculos['total_paying'];
$totales_pago += $calculos['total_pago'];
$totales_benefit_moneda += $calculos['benefit_moneda'];
} else {
$totales_neto += $totales_neto_sub;
$totales_iva += $totales_iva_sub;
$totales_con_iva += $totales_con_iva_sub;
$totales_paying += $totales_paying_sub;
$totales_pago += $totales_pago_sub;
$totales_benefit_moneda += $totales_benefit_moneda_sub;
}
if ($totales_benefit_moneda == '0') {
$totales_benefit_porsentaje = '0';
} else {
if ($totales_pago == '0') {
$totales_benefit_porsentaje = '0';
} else {
// $totales_benefit_porsentaje = $totales_benefit_moneda * 100 / $totales_neto;
$totales_benefit_porsentaje = $totales_benefit_moneda * 100 / $totales_pago;
}
}
}
$calculos_totatales = array(
'totales_neto' => $totales_neto,
'totales_iva' => $totales_iva,
'totales_con_iva' => $totales_con_iva,
'totales_paying' => $totales_paying,
'totales_benefit_moneda' => $totales_benefit_moneda,
'totales_benefit_porsentaje' => $totales_benefit_porsentaje
);
if ($master == "company") { $typeMaster = $sqlcompany->getCompany(); }
if ($master == "supplier") { $typeMaster = $sqlsuppliers->getType(); }
if ($master == "activity") { $typeMaster = "Activity"; }
if ($master == "idea") { $typeMaster = "Idea"; }
$data_supplier[$destination->getTitle()][$typeMaster][] = array(
'colorlabel' => $colorlabel,
'control' => $suppliercontrol,
'master' => $master,
'supplier' => $sqlsuppliers,
'idea' => $sqlideas,
'activity' => $sqlactivities,
'company' => $sqlcompany,
'image' => $imagenSmall,
'services' => $service_supplier_data,
'totales_services' => $calculos_totatales
);
}
}
$controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
foreach ($controlbudgets as $controlbudge) {
$controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
}
////////////////////////////////////////////////////////////////////////////////////////////////
/* FIN CONTENIDO DEL PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
/* CODIGO PARA TRAER A LOS AGENTES */
////////////////////////////////////////////
$agentMaster = array();
if (!empty($proposal->getAgentId())) {
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$agentMaster = array(
'name' => $agent->getName(),
'lastname' => $agent->getLastname(),
'picture' => $agent->getPicture(),
);
}
////////////////////////////////////////////
/* FIN CODIGO PARA TRAER A LOS AGENTES */
//////////////////////////////////////////
$sidebarData = $this->sidebarAction($token, "", "");
$parametersNew = array(
'proposalId' => $proposal->getId(),
'recommended' => '0',
'priority' => '0',
);
$dqlNew = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesBudgetControl p
WHERE p.proposalId = :proposalId
AND p.recommended = :recommended
AND p.priority != :priority
ORDER BY p.priority ASC';
$queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
$controlbudgetsNew = $queryNew->getResult();
$today = new \DateTime("now");
// d($controlbudget);
return $this->render(
'MDS/EventsPresentationBundle/presentation/budget-client.html.twig',
array(
'token' => $token,
'today' => $today,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
'destination' => $data_destionation,
'agent' => $agentMaster,
'countDestino' => $cont_destino,
'datasupplier' => $data_supplier,
'budgets' => $controlbudget,
'sidebar' => $sidebarData,
'budgetNew' => $controlbudgetsNew,
// 'agendas' => $showAgenda,
)
);
}
public function CalculoTotalesservices($price, $units, $pax, $days, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat)
{
$price = trim($price);
$over = trim($over);
$price = str_replace(",", ".", $price);
$over = str_replace(",", ".", $over);
if (empty($iva)) {
$iva = 0;
}
if (empty($price)) {
$price = 0;
}
if (empty($commission)) {
$commission = 0;
}
$iva = $iva / 100;
if ($opiva == '0') {
$price = $price / ($iva + 1);
}
if (!empty($commission)) {
if ($opcommission == '0') {
$commission = (100 - $commission) / 100;
$precio_units = $price;
$price = $price * $commission;
}
if ($opcommission == '1') {
$commission = ($commission / 100) + 1;
$precio_units = $price * $commission;
}
} else {
$precio_units = $price;
}
//Units
if (empty($units) or $units == "0") {
$units = "1";
}
// Calculo Especial por categoria
//Alojamientos
if ($idcat == "1") {
$informativo_days = "si";
$pax = "1";
}
//Transporte
elseif ($idcat == "13") {
$informativo_days = "no";
$pax = "1";
// if($days > "1"){
// $days = "2";
// }else{
// $days = "1";
// }
}
//Lounge
elseif ($idcat == "10") {
$informativo_days = "no";
$pax = "1";
}
//Guia
elseif ($idcat == "8") {
$informativo_days = "no";
$pax = "1";
} else {
$informativo_days = "no";
}
//Pax
if (empty($pax) or $pax == "0") {
$pax = "1";
}
//Over
if (empty($over)) {
$over = "0";
}
if ($informativo_days == "no") {
//Days
if (empty($days) or $days == "0") {
$days = "1";
} else {
$days = $days + 1;
}
}
if(empty($days) or $days == "0"){
$days = "1";
}
$total_items = $price * $units * $pax * $days;
// $total_pdirect = $price * $units * $pax * $days;
$total_over = $over * $units * $pax * $days;
if (!empty($commission)) {
if ($opcommission == '0') {
$total_neto = $total_items / $commission;
}
if ($opcommission == '1') {
$total_neto = $total_items * $commission;
}
} else {
$total_neto = $total_items;
}
if ($opover == '0') {
$total_neto = $total_neto - $total_over;
$precio_units = $precio_units - $over;
}
if ($opover == '1') {
$total_neto = $total_neto + $total_over;
$precio_units = $precio_units + $over;
}
$total_paying = $total_items * ($iva + 1);
if ($directPayment == true) {
$total_neto = $total_neto - $total_paying;
}
$total_comision = "0";
$total_pago = $total_items;
$total_iva = $total_items * $iva;
$sub_total_iva = $total_neto * $iva;
$total = $total_neto + $sub_total_iva;
if ($directPayment == true) {
$benefit_moneda = $total_neto;
$total_paying = "0";
} else {
$benefit_moneda = $total_neto - $total_items;
}
$data_calculos = array(
'precio' => $precio_units,
'total_days' => $days,
'sub_total' => $total_items,
'sub_total_iva' => $sub_total_iva,
'total_neto' => $total_neto,
'total_iva' => $total_iva,
'total_paying' => $total_paying,
'total_pago' => $total_pago,
'total_comision' => $total_comision,
'total' => $total,
'benefit_moneda' => $benefit_moneda,
'commission' => $commission,
// 'commission_1' => $commission_1,
'units' => $units,
'pax' => $pax,
'over' => $over,
);
// d($data_calculos);
return $data_calculos;
}
/**
* @Route("/mybudgetsadd/{token}", name="presentation_mybudgets_add_token")
*/
public function mybudgetsAddAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
// d($request);
// exit();
$incluir = "";
$proposalid = $request->request->get('proposalid');
$incluir = $request->request->get('incluir');
// $incluir_sub = $request->request->get('incluir_sub');
$services = $request->request->get('services');
$name = $request->request->get('name');
$byclient = "1";
$status = "Pending";
// $proposal = $em->getRepository(Proposal::class)->findOneById($proposalid);
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$user_id = '0';
} else {
$user_id = $user_logueado->getId();
}
if (!empty($incluir)) {
$control = new ProposalSupplierServicesBudgetControl();
$control->setProposalId($proposalid);
$control->setStatus($status);
$control->setName($name);
$control->setByClient($byclient);
$em->persist($control);
$em->flush();
$controlid = $control->getId();
// d($controlid);
foreach ($incluir as $padentro) {
$id = $padentro['id'];
if (array_key_exists($id, $services)) {
$services_proposal = $em->getRepository(ProposalSupplierServices::class)->findOneById($id);
//COLOR POR SERVICIO
$contcolor = "";
switch ($services_proposal->getServiceCatName()) {
case "Accommodation":
$contcolor = 'teal';
break;
case "Menu":
$contcolor = 'purple';
break;
case "Lounge":
$contcolor = 'warning';
break;
case "Activities":
$contcolor = 'blue';
break;
case "Itineraries":
$contcolor = 'indigo';
break;
case "Cruise":
$contcolor = 'brown';
break;
case "Transport":
$contcolor = 'grey';
break;
case "Av":
$contcolor = 'slate';
break;
case "Creative":
$contcolor = 'orange';
break;
case "Gifts":
$contcolor = 'pink';
break;
case "Entertainment":
$contcolor = 'green';
break;
case "Guide":
$contcolor = 'orange';
break;
case "Others":
$contcolor = 'danger';
break;
case "Technology":
$contcolor = 'grey-800';
break;
case "Assistant":
$contcolor = 'indigo-800';
break;
case "DDR":
$contcolor = 'green-300';
break;
}
$var = $services[$id];
// UNITS
if (empty($var['units']) or $var['units'] == 0) {
$units = "1";
} else {
$units = $var['units'];
}
// PAX
if (empty($var['pax']) or $var['pax'] == 0) {
$pax = "1";
} else {
$pax = $var['pax'];
}
// Calculo Especial por categoria
//Alojamientos
if ($services_proposal->getServiceCatId() == "1") {
$pax = "1";
}
//Transporte
elseif ($services_proposal->getServiceCatId() == "13") {
$pax = "1";
}
//Lounge
elseif ($services_proposal->getServiceCatId() == "10") {
$pax = "1";
}
//Guia
elseif ($services_proposal->getServiceCatId() == "8") {
$pax = "1";
}
// CALCULO DEL NETO
$netamount = $var['price'] * $units * $pax * $var['days'];
// CALCULO DEL TOTAL
$iva = ($var['iva'] / 100) + 1;
$total = $netamount * $iva;
$servicesBudget = new ProposalSupplierServicesBudget();
$servicesBudget->setControlId($controlid);
$servicesBudget->setItemsServiceId($id);
$servicesBudget->setItemsserviceIdFather('0');
$servicesBudget->setProposalId($proposalid);
$servicesBudget->setDestinationId($services_proposal->getDestinationId());
$servicesBudget->setSupplierId($services_proposal->getSupplierId());
$servicesBudget->setIdeaId($services_proposal->getIdeaId());
$servicesBudget->setActivityId($services_proposal->getActivityId());
$servicesBudget->setServiceId($services_proposal->getServiceId());
$servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
$servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
$servicesBudget->setContColor($contcolor);
$servicesBudget->setName($services_proposal->getName());
$servicesBudget->setPrice($var['price']);
$servicesBudget->setCurrency($services_proposal->getCurrency());
$servicesBudget->setUnits($var['units']);
$servicesBudget->setPax($var['pax']);
$servicesBudget->setDays($var['days']);
$servicesBudget->setDateInAt($services_proposal->getDateInAt());
$servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
$servicesBudget->setNetAmount($netamount);
$servicesBudget->setIva($var['iva']);
$servicesBudget->setTotal($total);
$servicesBudget->setStatus($status);
$servicesBudget->setRank($var['rank']);
$servicesBudget->setCreatedId($user_id);
$servicesBudget->setUpdatedId($user_id);
$em->persist($servicesBudget);
$em->flush();
}
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$time = new \DateTime("now");
$ipclient = $request->getClientIp();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$mailAgent[] = $agent->getEmail();
$agentMail = $agent->getEmail();
$passGmail = $agent->getPassGmail();
$firmGmail = $agent->getFirmGmail();
$mailAgentSent = array(
$agent->getEmail() => $agent->getName() . ' ' . $agent->getLastName()
);
$data = array(
'body' => 'P#' . $proposal->getId() . ', ' . $proposal->getTitle() . '<br><a href="http://inout.mante.solutions/events/proposal/makeyourbudget/budget/view/' . $proposal->getId() . '/' . $control->getId() . '">Ver Presupuesto</a><br><br>Alerta De Presupuesto Creado por el cliente: ' . $time->format('d/m/Y H:i:s') . '<br><br>Ip del Cliente:<b>' . $ipclient . '</b>',
'firm' => $firmGmail,
);
$mailTodos = array_merge($mailAgent);
// EJECUTAR ENVIO DE ALERTA DE VISTO POR CLIENTE
$transporter = new Swift_SmtpTransport();
$transporter->setHost('smtp.gmail.com')
->setEncryption('ssl') //ssl / tls
->setPort(465) // 465 / 587
->setUsername('desarrollo@develup.solutions')
->setPassword('utvh hzoi wfdo ztjs');
$mailer = new Swift_Mailer($transporter);
$message = new Swift_Message();
$message->setSubject('P#' . $proposal->getId() . ', Alerta De Presupuesto Creado por el cliente')
->setSender($agentMail)
->setFrom($mailAgentSent)
->setReplyTo($mailAgentSent)
->setTo($mailTodos)
->setBody(
$this->renderView(
'mail/structure-mail.html.twig',
array('data' => $data)
),
'text/html'
);
$mailer->send($message);
}
}
return $this->redirectToRoute(
'presentation_mybudgets_view_token',
array(
'idp' => $controlid,
'token' => $token,
)
);
}
/**
* @Route("/mybudgetsview/{idp}/{token}", name="presentation_mybudgets_view_token")
*/
public function mybudgetsViewAction($token, $idp, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$country = $em->getRepository(Country::class)->findOneById($client->getCountry());
$client->setCountry($country->getCountry());
$regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
$client->setRegion($regions->getRegion());
$province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
$client->setProvince($province->getName());
$cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
$client->setPopulation($cities->getCity());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
$controlproposal = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
$controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
foreach ($controlbudgets as $controlbudge) {
$controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
}
$controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
$filtro2 = array();
foreach ($controlproposal as $consultabudget2) {
$filtro2[] = $consultabudget2->getDestinationId();
}
$services_supplier = array();
$services_ideas = array();
$budget = array();
$content_data = array();
$destination = array();
// $totales_neto="";
// $totales_total="";
$totales_neto = 0;
$totales_total = 0;
$totales_iva = array();
$data = array();
foreach ($filtro2 as $destinobudget) {
$destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
$destino = $destination->getTitle();
$consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
array(
'controlId' => $idp,
'destinationId' => $destinobudget,
'itemsserviceIdFather' => '0'
),
array(
'rank' => 'DESC'
)
);
$filtro = array();
foreach ($consulta_budget as $consultabudget) {
if (!is_null($consultabudget->getActivityId())) {
$filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
}
if (!is_null($consultabudget->getIdeaId())) {
$filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
$filtro['whiteservice']['0'][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
$filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
}
// $filtro[$consultabudget->getSupplierId()] = $consultabudget;
}
// d($filtro);
//
$master = "";
$services = array();
$whiteservice = array();
$idea = array();
$activity = array();
$supplier = array();
foreach ($filtro as $key => $ideaOsupplier) {
// d("·········································", $ideaOsupplier);
foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
// d($ideaOsupplierAdentro);
$services = array();
// $total_neto="";
// $total_total="";
$total_neto = 0;
$total_total = 0;
foreach ($ideaOsupplierAdentro as $servicesbudget) {
if ($key == "whiteservice") {
$services_white = $em->getRepository(Configuration::class)->findOneById('1');
$master = "whiteservice";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
$whiteservice[$services_white->getId()] = array(
'datos' => $services_white,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
}
if ($key == "activity") {
$services_activities = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
$master = "activity";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($servicesbudget->getActivityId());
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
$activity[$services_activities->getId()] = array(
'datos' => $services_activities,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total,
'image' => $imagenSmall,
);
}
if ($key == "idea") {
$services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
$master = "idea";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($servicesbudget->getIdeaId());
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
$idea[$services_ideas->getId()] = array(
'datos' => $services_ideas,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total,
'image' => $imagenSmall,
);
}
if ($key == "supplier") {
if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
$servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
$master = "supplier";
// foreach($services_supplier as $servicessupplier){
if (!is_null($servicessupplier)) {
switch ($servicessupplier->getStar()) {
case 1:
$servicessupplier->setStar('<i class="icon-star-full2"></i>');
break;
case 2:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 3:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 4:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 5:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP');
break;
case 6:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 7:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
case 8:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
}
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
// d($servicesbudget); exit();
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($servicesbudget->getSupplierId());
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
}
$services[] = array(
'service' => $servicesbudget
);
$supplier[$servicessupplier->getId()] = array(
'datos' => $servicessupplier,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total,
'image' => $imagenSmall,
);
}
}
}
}
}
$content_data = array(
'supplier' => $supplier,
'idea' => $idea,
'activity' => $activity,
'whiteservice' => $whiteservice,
);
$data[] = array(
'destination' => $destination,
'container' => $content_data
);
}
////////////////////////////////////////////////////////////////////////////////////////////////
/* FIN CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
/* CODIGO PARA TRAER A LOS AGENTES */
////////////////////////////////////////////
$agentMaster = array();
if (!empty($proposal->getAgentId())) {
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$agentMaster = array(
'name' => $agent->getName(),
'lastname' => $agent->getLastname(),
'picture' => $agent->getPicture(),
);
}
$parametersNew = array(
'proposalId' => $proposal->getId(),
'recommended' => '0',
'priority' => '0',
);
$dqlNew = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesBudgetControl p
WHERE p.proposalId = :proposalId
AND p.recommended = :recommended
AND p.priority != :priority
ORDER BY p.priority ASC';
$queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
$controlbudgetsNew = $queryNew->getResult();
$sidebarData = $this->sidebarAction($token, "", "");
return $this->render(
'MDS/EventsPresentationBundle/presentation/budgetview-client.html.twig',
array(
'token' => $token,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
'destination' => $data_destionation,
'budgetcontrol' => $data_controlbudgets,
'agent' => $agentMaster,
'countDestino' => $cont_destino,
'budgets' => $controlbudget,
'budgetNew' => $controlbudgetsNew,
'data' => $data,
'totales_neto' => $totales_neto,
'ivas' => $totales_iva,
'totales' => $totales_total,
'confirm' => $controlbudgetBoton,
'sidebar' => $sidebarData,
// 'agendas' => $showAgenda,
)
);
}
/**
* @Route("/mybudgetssave/{idp}/{token}", name="presentation_mybudgets_save_token")
*/
public function mybudgetsSaveAction($token, $idp, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$country = $em->getRepository(Country::class)->findOneById($client->getCountry());
$client->setCountry($country->getCountry());
$regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
$client->setRegion($regions->getRegion());
$province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
$client->setProvince($province->getName());
$cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
$client->setPopulation($cities->getCity());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
$controlproposal = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
$controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
foreach ($controlbudgets as $controlbudge) {
if (is_null($controlbudge->getByClient())) {
$byclient = "";
} else {
$byclient = "a";
}
$controlbudget[$controlbudge->getRecommended() . $byclient][] = $controlbudge;
}
$controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
$filtro2 = array();
foreach ($controlproposal as $consultabudget2) {
$filtro2[] = $consultabudget2->getDestinationId();
}
$services_supplier = array();
$services_ideas = array();
$budget = array();
$content_data = array();
$destination = array();
// $totales_neto="";
// $totales_total="";
$totales_neto = 0;
$totales_total = 0;
$totales_iva = array();
$data = array();
foreach ($filtro2 as $destinobudget) {
$destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
$destino = $destination->getTitle();
$consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
array(
'controlId' => $idp,
'destinationId' => $destinobudget,
'itemsserviceIdFather' => '0'
),
array(
'rank' => 'DESC'
)
);
$filtro = array();
foreach ($consulta_budget as $consultabudget) {
if (!is_null($consultabudget->getActivityId())) {
$filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
}
if (!is_null($consultabudget->getIdeaId())) {
$filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
$filtro['whiteservice']['0'][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
$filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
}
// $filtro[$consultabudget->getSupplierId()] = $consultabudget;
}
// d($filtro);
//
$master = "";
$services = array();
$whiteservice = array();
$idea = array();
$activity = array();
$supplier = array();
foreach ($filtro as $key => $ideaOsupplier) {
// d("·········································", $ideaOsupplier);
foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
// d($ideaOsupplierAdentro);
$services = array();
// $total_neto="";
// $total_total="";
$total_neto = 0;
$total_total = 0;
foreach ($ideaOsupplierAdentro as $servicesbudget) {
// d($servicesbudget);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
if ($key == "whiteservice") {
$services_white = $em->getRepository(Configuration::class)->findOneById('1');
$master = "whiteservice";
$imagenSmall = $services_white->getPicture();
$services[] = array(
'service' => $servicesbudget
);
$whiteservice[$services_white->getId()] = array(
'datos' => $services_white,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total,
'image' => $imagenSmall,
);
}
if ($key == "activity") {
$services_activities = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
$master = "activity";
$services[] = array(
'service' => $servicesbudget
);
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($servicesbudget->getActivityId());
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
$activity[$services_activities->getId()] = array(
'datos' => $services_activities,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total,
'image' => $imagenSmall,
);
}
if ($key == "idea") {
$services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
$master = "idea";
$services[] = array(
'service' => $servicesbudget
);
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($servicesbudget->getIdeaId());
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
$idea[$services_ideas->getId()] = array(
'datos' => $services_ideas,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total,
'image' => $imagenSmall,
);
}
if ($key == "supplier") {
if (is_null($servicesbudget->getIdeaId())) {
$servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
$master = "supplier";
// foreach($services_supplier as $servicessupplier){
if (!is_null($servicessupplier)) {
switch ($servicessupplier->getStar()) {
case 1:
$servicessupplier->setStar('<i class="icon-star-full2"></i>');
break;
case 2:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 3:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 4:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 5:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP');
break;
case 6:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 7:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
case 8:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
}
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($servicesbudget->getSupplierId());
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
}
$services[] = array(
'service' => $servicesbudget
);
$supplier[$servicessupplier->getId()] = array(
'datos' => $servicessupplier,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total,
'image' => $imagenSmall,
);
}
}
}
}
}
$content_data = array(
'supplier' => $supplier,
'idea' => $idea,
'activity' => $activity,
'whiteservice' => $whiteservice,
);
$data[] = array(
'destination' => $destination,
'container' => $content_data
);
}
////////////////////////////////////////////////////////////////////////////////////////////////
/* FIN CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
/* CODIGO PARA TRAER A LOS AGENTES */
////////////////////////////////////////////
$agentMaster = array();
if (!empty($proposal->getAgentId())) {
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$agentMaster = array(
'name' => $agent->getName(),
'lastname' => $agent->getLastname(),
'picture' => $agent->getPicture(),
);
}
$parametersNew = array(
'proposalId' => $proposal->getId(),
'recommended' => '0',
'priority' => '0',
);
$dqlNew = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesBudgetControl p
WHERE p.proposalId = :proposalId
AND p.recommended = :recommended
AND p.priority != :priority
ORDER BY p.priority ASC';
$queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
$controlbudgetsNew = $queryNew->getResult();
$sidebarData = $this->sidebarAction($token, "", "");
return $this->render(
'MDS/EventsPresentationBundle/presentation/budgetview-save-client.html.twig',
array(
'token' => $token,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
'destination' => $data_destionation,
'budgetcontrol' => $data_controlbudgets,
'agent' => $agentMaster,
'countDestino' => $cont_destino,
'budgets' => $controlbudget,
'budgetNew' => $controlbudgetsNew,
'data' => $data,
'totales_neto' => $totales_neto,
'ivas' => $totales_iva,
'totales' => $totales_total,
'confirm' => $controlbudgetBoton,
'sidebar' => $sidebarData,
'idp' => $idp,
// 'agendas' => $showAgenda,
)
);
}
/**
* @Route("/mybudgetsconfirmed/{idp}/{token}", name="presentation_mybudgets_confirmed_token")
*/
public function mybudgetsConfirmedAction($token, $idp, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
if (($proposal->getStatus() != "Invoiced") and ($proposal->getStatus() != "Unblocked")) {
$proposal->setStatus('Confirmed');
}
$controlbudget = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
$controlbudget->setStatus('Confirmed');
$budgets = $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($idp);
foreach ($budgets as $budget) {
$services = $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getItemsserviceId());
if (!empty($services)) {
$services->setStatus('Confirmed');
$em->persist($services);
}
}
$em->persist($controlbudget);
$em->persist($proposal);
$em->flush();
$event = 'The item has ben saved Successfully';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajebudgetclient', $successMessage);
////////////////////////////////////////////////////////////////////////////////////////////////
/* FIN CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
return $this->redirectToRoute(
'presentation_mybudgets_view_token',
array(
'idp' => $idp,
'token' => $token,
)
);
}
/**
* @Route("/destinationAjax/{idd}/{token}", name="presentation_destination_ajax")
*/
public function destinationAjaxViewAction($token, $idd, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
$destino_details = $em->getRepository(Destination::class)->findOneById($idd);
$gallery_details = $em->getRepository(DestinationGallery::class)->findByDestinationId($idd);
$description_details = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $idd,
'language' => $proposal->getLanguage()
)
);
$response_body =
array(
'token' => $token,
'countDestino' => $cont_destino,
// 'agent'=>$agentMaster,
'destino' => $destino_details,
'gallerys' => $gallery_details,
'description' => $description_details,
// 'sidebar' => $sidebarData
);
// d($response_body);
//
// d($response);
$serializer = SerializerBuilder::create()->build();
$array = $serializer->toArray($response_body);
$response = new JsonResponse($array);
return $response;
}
/**
* @Route("/download/{token}", name="presentation_document_list")
*/
public function downloadAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$selectType = explode(",", $proposal->getSelectType());
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$document = $em->getRepository(ProposalDocument::class)->findBy(
array('proposalId' => $proposal->getId())
);
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
$agentMaster = array();
if (!empty($proposal->getAgentId())) {
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$agentMaster = array(
'name' => $agent->getName(),
'lastname' => $agent->getLastname(),
'picture' => $agent->getPicture(),
);
}
$parametersNew = array(
'proposalId' => $proposal->getId(),
'recommended' => '0',
'priority' => '0',
);
$dqlNew = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesBudgetControl p
WHERE p.proposalId = :proposalId
AND p.recommended = :recommended
AND p.priority != :priority
ORDER BY p.priority ASC';
$queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
$controlbudgetsNew = $queryNew->getResult();
//d($proposal, $client, $company, $data_destionation);
$sidebarData = $this->sidebarAction($token, "", "");
return $this->render(
'MDS/EventsPresentationBundle/presentation/document.html.twig',
array(
'token' => $token,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
'destination' => $data_destionation,
'budgetNew' => $controlbudgetsNew,
'document' => $document,
'countDestino' => $cont_destino,
'sidebar' => $sidebarData,
'agent' => $agentMaster,
// 'agendas' => $showAgenda,
)
);
}
/**
* @Route("/esp-detail/{type}/{idd}/{idi}/{token}", name="presentation_idea_view_detail_token")
*/
public function ideaViewDetailAction($type, $token, $idd, $idi, Request $request)
{
// $type='idea';
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
////////////////////////////////////////////////////////////////////////////////////////////////
/* INICIO CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
$typeM = strtoupper($type);
$ideas_services = array();
$activities_services = array();
$supplier_services = array();
if ($type == "idea") {
$ideas = $em->getRepository(Ideas::class)->findOneBy(
array(
'id' => $idi
)
);
if (!is_null($ideas)) {
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($idi);
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
$data_idea = array(
'datos' => $ideas,
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
);
$ideas_services = array(
'ideas' => $data_idea,
);
}
}
if ($type == "activity") {
$activities = $em->getRepository(Activities::class)->findOneBy(
array(
'id' => $idi
)
);
if (!is_null($activities)) {
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($idi);
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
$data_activity = array(
'datos' => $activities,
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
);
$activities_services = array(
'activities' => $data_activity,
);
}
}
$data = array(
'type' => $typeM,
'ideas' => $ideas_services,
'activities' => $activities_services,
'supplier' => $supplier_services
);
////////////////////////////////////////////////////////////////////////////////////////////////
/* FIN CONTENIDO DEL MI PRESUPUESTO */
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
/* CODIGO PARA TRAER A LOS AGENTES */
////////////////////////////////////////////
$agentMaster = array();
if (!empty($proposal->getAgentId())) {
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$agentMaster = array(
'name' => $agent->getName(),
'lastname' => $agent->getLastname(),
'picture' => $agent->getPicture(),
);
}
////////////////////////////////////////////
/* FIN CODIGO PARA TRAER A LOS AGENTES */
//////////////////////////////////////////
$sidebarData = $this->sidebarAction($token, $typeM, $idd);
//d($data,$selectType);
return $this->render(
'MDS/EventsPresentationBundle/presentation/service-detail-client.html.twig',
array(
'token' => $token,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
'destination' => $data_destionation,
'countDestino' => $cont_destino,
'agent' => $agentMaster,
'data' => $data,
'activity' => $activities_services,
'idea' => $ideas_services,
'sidebar' => $sidebarData,
// 'agendas' => $showAgenda,
)
);
}
/**
* @Route("/service-detail-ajax/{type}/{idd}/{ids}/{token}", name="presentation_services_detail_ajax")
*/
public function ajaxServicesDetailAction($token, $type, $idd, $ids, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_destionation = array();
$cont_destino = 0;
foreach ($proposal_Control as $proposalControl) {
$cont_destino += 1;
$destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
$gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
$description = $em->getRepository(DestinationDescription::class)->findOneBy(
array(
'destinationId' => $proposalControl->getDestinationId(),
'language' => $proposal->getLanguage()
)
);
$data_destionation[$destino->getTitle()] = array(
'destino' => $destino,
'gallery' => $gallery,
'description' => $description,
);
}
$typeStr = str_replace("-", " ", $type);
$typeM = strtoupper($typeStr);
$controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'destinoId' => $idd,
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$ideas_services = array();
$supplier_services = array();
$data_supplier = array();
$data = array();
foreach ($controlservices as $controlServicesProposal) {
if (is_null($controlServicesProposal->getIdeaId()) && $type != "idea" && $controlServicesProposal->getSupplierId() != "0") {
// d($controlServicesProposal);
/*consulta Proveedor*/
$supplier = $em->getRepository(Supplier::class)->findOneBy(
array(
'id' => $controlServicesProposal->getSupplierId(),
'type' => $typeM,
)
);
//d($supplier);
if (!is_null($supplier)) {
//d($typeM);
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
$data_supplier = array(
'datos' => $supplier,
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
);
// d($data_supplier);
/*consulta Hoteles para salones*/
//
$services = $em->getRepository(ProposalSupplierServices::class)->findBy(
array(
'controlId' => $controlServicesProposal->getId(),
'supplierId' => $controlServicesProposal->getSupplierId(),
// 'serviceCatId' => $idcat,
)
);
//d($services);
$servicesArray = array();
foreach ($services as $servicesSupplier) {
/*consulta Lounge*/
// d($typeM);
if (
$servicesSupplier->getServiceId() != "0" &&
(
$typeM == "RESTAURANTE" or
$typeM == "HOTEL" or
$typeM == "HOTEL URBANO PERIFERIA" or
$typeM == "HOTEL DE COSTA" or
$typeM == "HOTEL URBANO DENTRO DE LA CIUDAD" or
$typeM == "HOTEL URBANO CÉNTRICO" or
$typeM == "SALON" or
$typeM == "LUGARES DE EVENTOS"
)
) {
$idcat = '10'; // Lounge
$servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
if (!is_null($servicesSup)) {
$controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
array(
'servicesId' => $servicesSup->getId(),
'servicesCat' => $idcat,
)
);
$servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
$servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
array(
'servicesId' => $servicesSup->getId(),
'controlId' => $servicesSupplier->getServiceId(),
'language' => $proposal->getLanguage()
)
);
//paquete de tipo
$serviceCapacity = $em->getRepository('App:SupplierLoungeCapacity')->findBy(array('serviceId' => $servicesSup->getId()));
if (!empty($serviceCapacity)) {
foreach ($serviceCapacity as $item) {
switch ($item->getType()) {
case 1:
$item->setType("Teatro");
break;
case 2:
$item->setType("Cocktail");
break;
case 3:
$item->setType("Banquete");
break;
case 4:
$item->setType("Imperial");
break;
case 5:
$item->setType("Montaje en U");
break;
case 6:
$item->setType("Cabaret");
break;
case 0:
$item->setType("Escuela");
break;
}
//
}
} else {
$serviceCapacity = array();
}
/* ARMO EL CONTENIDO GLOBAL */
$servicesArray[$servicesSup->getId()] = array(
'services' => $servicesSup,
'gallery' => $servicesGallery,
'descripcion' => $servicesDescription,
'capacity' => $serviceCapacity,
);
//d($typeM);
}
}
}
// d($data_supplier);
if ($data_supplier['datos']->getId() == $ids) {
$supplier_services[] = array(
'supplier' => $data_supplier,
'services' => $servicesArray,
);
}
}
}
$data = array(
'type' => $typeM,
'ideas' => $ideas_services,
'supplier' => $supplier_services
);
}
//d($data);
$response_body = array(
'token' => $token,
'selectType' => $selectType,
'countDestino' => $cont_destino,
'data' => $data,
'idd' => $idd,
'idea' => '',
'activity' => '',
);
$serializer = SerializerBuilder::create()->build();
$array = $serializer->toArray($response_body);
$response = new JsonResponse($array);
return $response;
}
/**
* @Route("/type-ajax/{idd}/{token}", name="presentation_type_ajax")
*/
public function ServicesViewAjaxDetailAction($token, $idd, Request $request)
{
$em = $this->getDoctrine()->getManager();
$type = '';
$sidebarData = $this->sidebarAction($token, $type, $idd);
////////////////////////////////////////////
/* FIN CODIGO PARA TRAER A LOS AGENTES */
//////////////////////////////////////////
//d($data);
$response_body = array(
'token' => $token,
'selectType' => $type,
'idd' => $idd,
'sidebar' => $sidebarData,
);
$serializer = SerializerBuilder::create()->build();
$array = $serializer->toArray($response_body);
$response = new JsonResponse($array);
return $response;
}
/**
* @Route("/services/{type}/{token}", name="presentation_services_view_token")
*/
public function ServicesViewAction($token, $type, Request $request)
{
//Services
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
switch ($type) {
case 1:
$nameType = "hotel";
$transType = strtoupper($this->translator->trans("Hotel"));
$varType = "1";
$viewGroupService = "1";
break;
case 2:
$nameType = "restaurante";
$transType = strtoupper($this->translator->trans("Restaurant"));
$varType = "2";
$viewGroupService = "1";
break;
case 3:
$nameType = "actividad";
$transType = strtoupper($this->translator->trans("Activities"));
$varType = "3";
$viewGroupService = "0";
break;
case 4:
$nameType = "idea";
$transType = strtoupper($this->translator->trans("Ideas"));
$varType = "4";
$viewGroupService = "0";
break;
case 5:
$nameType = "audiovisual";
$transType = strtoupper($this->translator->trans("Audiovisual"));
$varType = "5";
$viewGroupService = "1";
break;
case 6:
$nameType = "tecnologia";
$transType = strtoupper($this->translator->trans("Technology Services"));
$varType = "6";
$viewGroupService = "1";
break;
case 7:
$nameType = "lugares de eventos";
$transType = strtoupper($this->translator->trans("Places of Events"));
$varType = "7";
$viewGroupService = "1";
break;
case 8:
$nameType = "otros";
$transType = strtoupper($this->translator->trans("Others"));
$varType = "8";
$viewGroupService = "0";
break;
case 9:
$nameType = "catering";
$transType = strtoupper($this->translator->trans("Catering"));
$varType = "9";
$viewGroupService = "0";
break;
case 10:
$nameType = "excursiones";
$transType = strtoupper($this->translator->trans("Excursions"));
$varType = "10";
$viewGroupService = "0";
break;
case 11:
$nameType = "musica";
$transType = strtoupper($this->translator->trans("Music"));
$varType = "11";
$viewGroupService = "0";
break;
case 12:
$nameType = "actividades";
$transType = strtoupper($this->translator->trans("Activities"));
$varType = "12";
$viewGroupService = "0";
break;
case 13:
$nameType = "cruceros";
$transType = strtoupper($this->translator->trans("Cruise ships"));
$varType = "13";
$viewGroupService = "0";
break;
case 14:
$nameType = "guias";
$transType = strtoupper($this->translator->trans("Guides"));
$varType = "14";
$viewGroupService = "0";
break;
case 15:
$nameType = "entretenimiento ";
$transType = strtoupper($this->translator->trans("Entertainment"));
$varType = "15";
$viewGroupService = "0";
break;
case 16:
$nameType = "salon ";
$transType = strtoupper($this->translator->trans("Lounge"));
$varType = "16";
$viewGroupService = "0";
break;
case 17:
$nameType = "transporte ";
$transType = strtoupper($this->translator->trans("Transport"));
$varType = "17";
$viewGroupService = "0";
break;
case 18:
$nameType = "regalos ";
$transType = strtoupper($this->translator->trans("Gifts"));
$varType = "18";
$viewGroupService = "0";
break;
case 19:
$nameType = "itinerarios ";
$transType = strtoupper($this->translator->trans("Itineraries"));
$varType = "19";
$viewGroupService = "0";
break;
default:
break;
//crear los demas numero por servicos
}
$typeM = strtoupper($nameType);
// $typeM = strtoupper($type);
// $transType = $type;
$controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
// 'destinoId' => $idd,
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
$data_idea = array();
$data_supplier = array();
$data_all = array();
$data = array();
$servicesArray = array();
foreach ($controlservices as $controlServicesProposal) {
if (!is_null($controlServicesProposal->getIdeaId()) && $nameType == "idea") {
// d('idea');
/* IDEA */
/*consulta Proveedor*/
$ideas = $em->getRepository(Ideas::class)->findOneBy(
array(
'id' => $controlServicesProposal->getIdeaId()
)
);
// d($ideas);
if (!is_null($ideas)) {
if ($ideas->getDestinationId() != 0) {
$ideasDestination = $em->getRepository(Destination::class)->findOneById($ideas->getDestinationId());
$citiesData = $em->getRepository(Cities::class)->findOneById($ideasDestination->getPopulation());
$cities = $citiesData->getCity();
} else {
$cities = null;
}
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($controlServicesProposal->getIdeaId());
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
$data_all[] = array(
'id' => $ideas->getId(),
'name' => $ideas->getName(),
'img' => $gallerySupplier['0'],
'cities' => $cities,
'type' => $typeM,
'typeajax' => "idea",
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
'services' => null,
'ids' => $varType,
// 'idd' => $ideasDestination,
'viewGroupService' => $viewGroupService,
);
}
}
//Actividades
if (!is_null($controlServicesProposal->getActivityId()) && $nameType == "actividad") {
// d('idea');
/* IDEA */
/*consulta Proveedor*/
$activities = $em->getRepository(Activities::class)->findOneBy(
array(
'id' => $controlServicesProposal->getActivityId()
)
);
if (!is_null($activities)) {
// $activitiesDestination = $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
// $cities = $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
if ($activities->getDestinationId() != 0) {
$activitiesDestination = $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
$citiesData = $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
$cities = $citiesData->getCity();
} else {
$cities = null;
}
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($controlServicesProposal->getActivityId());
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
$data_all[] = array(
'id' => $activities->getId(),
'name' => $activities->getName(),
'img' => $gallerySupplier['0'],
'cities' => $cities,
'type' => $typeM,
'typeajax' => "actividad",
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
'services' => null,
'ids' => $varType,
// 'idd' => $activitiesDestination,
'viewGroupService' => $viewGroupService,
);
}
}
if (is_null($controlServicesProposal->getIdeaId()) && $nameType != "idea" && is_null($controlServicesProposal->getActivityId()) && $nameType != "actividad" && $controlServicesProposal->getSupplierId() != "0") {
// d($controlServicesProposal);
/*consulta Proveedor*/
$supplier = $em->getRepository(Supplier::class)->findOneBy(
array(
'id' => $controlServicesProposal->getSupplierId(),
'type' => $typeM,
)
);
if (!is_null($supplier)) {
/* OJO AQUI */
$cities = $em->getRepository(Cities::class)->findOneById($supplier->getPopulation());
//d($typeM);
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
if ($varType == "5") {
$idcat = '3';
/*consulta de los servicios del supplier*/
$services = $em->getRepository(ProposalSupplierServices::class)->findBy(
array(
'controlId' => $controlServicesProposal->getId(),
'supplierId' => $controlServicesProposal->getSupplierId(),
'serviceCatId' => $idcat,
)
);
foreach ($services as $servicesSupplier) {
$destino = $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
/*consulta Lounge*/
// d($servicesSupplier);
if ($servicesSupplier->getServiceId() != "0") {
// $idcat = '10'; // Lounge
$servicesSup = $em->getRepository(SupplierAv::class)->findOneBy(
array(
'id' => $servicesSupplier->getServiceId(),
'responsible' => "RENDERS 3D",
)
);
if (!empty($servicesSup)) {
$controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
array(
'servicesId' => $servicesSup->getId(),
'servicesCat' => $idcat,
)
);
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
$servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
array(
'servicesId' => $servicesSup->getId(),
'controlId' => $servicesSupplier->getServiceId(),
'language' => $proposal->getLanguage()
)
);
} else {
$controlSup = array();
$gallerySupplier = array();
$servicesDescription = array();
}
//paquete de tipo
$serviceCapacity = array();
/* ARMO EL CONTENIDO GLOBAL */
$servicesArray[] = array(
'services' => $servicesSup,
'gallery' => $gallerySupplier,
'descripcion' => $servicesDescription,
'capacity' => $serviceCapacity,
);
//d($typeM);
// array_push($galleryNuevaSupplier, $servicesGallery);
// d($servicesGallery);
}
}
//
$data_all[$supplier->getId()] = array(
'id' => $supplier->getId(),
'name' => $viewGroupService == "0" ? '' : $supplier->getName(),
// 'nameav' => $nameav,
'img' => empty($gallerySupplier) ? null : $gallerySupplier['0'],
'cities' => $cities->getCity(),
'type' => $transType,
'typeajax' => "supplier",
'gallery' => $gallerySupplier,
'description' => null,
'services' => $servicesArray,
'ids' => $varType,
// 'idd' => $destino,
'viewGroupService' => $viewGroupService,
);
//
} else {
$idcat = '10';
/*consulta de los servicios del supplier*/
$services = $em->getRepository(ProposalSupplierServices::class)->findBy(
array(
'controlId' => $controlServicesProposal->getId(),
'supplierId' => $controlServicesProposal->getSupplierId(),
'serviceCatId' => $idcat,
)
);
$servicesArray = array();
foreach ($services as $servicesSupplier) {
$destino = $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
/*consulta Lounge*/
// d($typeM);
if ($servicesSupplier->getServiceId() != "0") {
// $idcat = '10'; // Lounge
$servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
$controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
array(
'servicesId' => $servicesSup->getId(),
'servicesCat' => $idcat,
)
);
// d($servicesSup,$idcat,$controlSup);
$servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
$servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
array(
'servicesId' => $servicesSup->getId(),
'controlId' => $servicesSupplier->getServiceId(),
'language' => $proposal->getLanguage()
)
);
// d($servicesSup,$servicesGallery);
//paquete de tipo
$serviceCapacity = $em->getRepository('App:SupplierLoungeCapacity')->findByServiceId($servicesSup->getId());
foreach ($serviceCapacity as $item) {
switch ($item->getType()) {
case 1:
$item->setType("Teatro");
break;
case 2:
$item->setType("Cocktail");
break;
case 3:
$item->setType("Banquete");
break;
case 4:
$item->setType("Imperial");
break;
case 5:
$item->setType("Montaje en U");
break;
case 6:
$item->setType("Cabaret");
break;
case 0:
$item->setType("Escuela");
break;
}
//
}
/* ARMO EL CONTENIDO GLOBAL */
$servicesArray[] = array(
'services' => $servicesSup,
'gallery' => $servicesGallery,
'descripcion' => $servicesDescription,
'capacity' => $serviceCapacity,
);
//d($typeM);
}
}
$data_all[$supplier->getId()] = array(
'id' => $supplier->getId(),
'name' => $viewGroupService == "0" ? '' : $supplier->getName(),
// 'nameav' => $nameav,
'img' => empty($gallerySupplier) ? null : $gallerySupplier['0'],
'cities' => $cities->getCity(),
'type' => $transType,
'typeajax' => "supplier",
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
'services' => $servicesArray,
'ids' => $varType,
// 'idd' => $destino,
'viewGroupService' => $viewGroupService,
);
// $descriptionSupplierexter[] = $descriptionSupplier->getDescription();
}
}
}
}
//d($descriptionSupplierexter);
// d($data_all);
// exit();
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
return $this->render(
'MDS/EventsPresentationBundle/presentation/services.html.twig',
array(
'token' => $token,
'type' => $transType,
'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
'data' => $data_all,
)
);
}
/**
* @Route("/services-ajax/{id}/{type}/{ssi}/{token}", name="presentation_services_view_token_ajax")
*/
public function ServicesAjaxViewAction($token, $type, $id, $ssi, Request $request)
{
// var_dump($token, "", $type,"", $id, "", $ssi);die();
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
if ($type == "idea") {
$controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'ideaId' => $id,
)
);
}
if ($type == "actividad") {
$controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'activityId' => $id,
)
);
}
if ($type == "supplier") {
$controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'supplierId' => $id,
)
);
}
$data_idea = array();
$data_supplier = array();
$data_all = array();
$data = array();
foreach ($controlservices as $controlServicesProposal) {
if (!is_null($controlServicesProposal->getIdeaId()) && $type == "idea") {
// d('idea');
/* IDEA */
/*consulta Proveedor*/
$ideas = $em->getRepository(Ideas::class)->findOneBy(
array(
'id' => $controlServicesProposal->getIdeaId()
)
);
if (!is_null($ideas)) {
$ideasDestination = $em->getRepository(Destination::class)->findOneById($ideas->getDestinationId());
$cities = $em->getRepository(Cities::class)->findOneById($ideasDestination->getPopulation());
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($controlServicesProposal->getIdeaId());
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
$data_all = array(
'id' => $ideas->getId(),
'name' => $ideas->getName(),
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
'services' => null,
);
}
}
//Actividades
if (!is_null($controlServicesProposal->getActivityId()) && $type == "actividad") {
// d('idea');
/* IDEA */
/*consulta Proveedor*/
$activities = $em->getRepository(Activities::class)->findOneBy(
array(
'id' => $controlServicesProposal->getActivityId()
)
);
if (!is_null($activities)) {
$activitiesDestination = $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
$cities = $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($controlServicesProposal->getActivityId());
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
$data_all = array(
'id' => $activities->getId(),
'name' => $activities->getName(),
'gallery' => $gallerySupplier,
'description' => $descriptionSupplier,
'services' => null,
);
}
}
if (is_null($controlServicesProposal->getIdeaId()) && $type != "idea" && is_null($controlServicesProposal->getActivityId()) && $type != "actividad" && $controlServicesProposal->getSupplierId() != "0") {
// d($controlServicesProposal);
/*consulta Proveedor*/
$supplier = $em->getRepository(Supplier::class)->findOneBy(
array(
'id' => $controlServicesProposal->getSupplierId(),
)
);
if (!is_null($supplier)) {
/* OJO AQUI */
$cities = $em->getRepository(Cities::class)->findOneById($supplier->getPopulation());
// d($supplier);
//d($typeM);
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
$id = $controlgeneral->getId();
$gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
array(
'supplierId' => $id,
'servicesCatId' => '0',
'servicesId' => '0',
)
);
$descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
array(
'supplierId' => $id,
'language' => $proposal->getLanguage()
)
);
// $idcat = '10';
/*consulta de los servicios del supplier*/
$services = $em->getRepository(ProposalSupplierServices::class)->findBy(
array(
'controlId' => $controlServicesProposal->getId(),
'supplierId' => $controlServicesProposal->getSupplierId(),
// 'serviceCatId' => $idcat,
)
);
$servicesArray = array();
if ($ssi == 1) {
foreach ($services as $servicesSupplier) {
///////////////////////////////////////////
/// estoy aqui
/// /////////////
// d($servicesSupplier, $servicesSupplier->getServiceCatId() );
$destino = $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
/*consulta Lounge*/
// d($typeM);
if ($servicesSupplier->getServiceId() != "0") {
//$idcat = '10'; // Lounge
///
// $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
switch ($servicesSupplier->getServiceCatId()) {
case 1:
$servicesSup = $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
break;
case 2:
$servicesSup = $em->getRepository(SupplierActivities::class)->findOneById($servicesSupplier->getServiceId());
break;
case 3:
$servicesSup = $em->getRepository(SupplierAv::class)->findOneById($servicesSupplier->getServiceId());
break;
case 4:
$servicesSup = $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
break;
case 5:
$servicesSup = $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
break;
case 6:
$servicesSup = $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
break;
case 7:
$servicesSup = $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
break;
case 8:
$servicesSup = $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
break;
case 9:
$servicesSup = $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
break;
case 10:
$servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
break;
case 11:
$servicesSup = $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
break;
case 12:
$servicesSup = $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
break;
case 13:
$servicesSup = $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
break;
case 14:
$servicesSup = $em->getRepository(SupplierTechnology::class)->findOneById($servicesSupplier->getServiceId());
break;
}
if (!empty($servicesSup)) {
$controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
array(
'servicesId' => $servicesSup->getId(),
'servicesCat' => $servicesSupplier->getServiceCatId(),
// 'servicesCat' => $idcat,
)
);
$servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
foreach ($servicesGallery as $servicesga) {
array_push($gallerySupplier, $servicesga);
}
$servicesDescription[] = $em->getRepository(SupplierServicesDescription::class)->findOneBy(
array(
'servicesId' => $servicesSup->getId(),
'controlId' => $controlSup->getId(),
'language' => $proposal->getLanguage()
)
);
$serviceCapacity = array();
if ($servicesSupplier->getServiceCatId() == 10) {
//paquete de tipo
$serviceCapacityBase = $em->getRepository('App:SupplierLoungeCapacity')->findByServiceId($servicesSup->getId());
$serviceCapacity = array();
if (!empty($serviceCapacityBase)) {
foreach ($serviceCapacityBase as $item) {
switch ($item->getType()) {
case 1:
$item->setType("teatro");
break;
case 2:
$item->setType("cocktail");
break;
case 3:
$item->setType("banquete");
break;
case 4:
$item->setType("imperial");
break;
case 5:
$item->setType("montaje en U");
break;
case 6:
$item->setType("cabaret");
break;
case 0:
$item->setType("escuela");
break;
}
$serviceCapacity[] = $item;
}
}
/* ARMO EL CONTENIDO GLOBAL */
$servicesArray[] = array(
'services' => $servicesSup,
'gallery' => $servicesGallery,
'descripcion' => $servicesDescription,
'capacity' => $serviceCapacity,
);
//d($typeM);
}
}
}
}
}
$data_all = array(
'id' => $supplier->getId(),
'name' => $ssi == "0" ? '' : $supplier->getName(),
'gallery' => $gallerySupplier,
'description' => is_null($descriptionSupplier['0']) ? $servicesDescription : $descriptionSupplier,
'services' => $servicesArray,
);
}
}
}
// d($data_all);
// exit();
$serializer = SerializerBuilder::create()->build();
$array = $serializer->toArray($data_all);
$response = new JsonResponse($array);
return $response;
}
/**
* @Route("/servicesview/{idcat}/{token}", name="presentation_services_view_all_token")
*/
public function ServicesViewAllAction($token, $idcat, Request $request)
{
//Suppliers
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
/*consulta de los servicios del supplier*/
$services = $em->getRepository(ProposalSupplierServices::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'serviceCatId' => $idcat,
)
);
$servicesArray = array();
$transType = "Not Available";
if (!empty($services)) {
foreach ($services as $servicesSupplier) {
$transType = $this->translator->trans($servicesSupplier->getServiceCatName());
/*consulta Lounge*/
// d($typeM);
if ($servicesSupplier->getServiceId() != "0") {
// $idcat = '10'; // Lounge
// $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = "";
switch ($idcat) {
case 11:
$servicesSup = $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
$transType = $this->translator->trans("Menu");
$varCat = "11";
break;
case 5:
$servicesSup = $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
$transType = $this->translator->trans("Cruise");
$varCat = "5";
break;
case 6:
$servicesSup = $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
$transType = $this->translator->trans("Entertainment");
$varCat = "6";
break;
case 4:
$servicesSup = $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
$transType = $this->translator->trans("Comunicación");
$varCat = "4";
break;
case 7:
$servicesSup = $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
$transType = $this->translator->trans("Gifts");
$varCat = "7";
break;
case 8:
$servicesSup = $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
$transType = $this->translator->trans("Guide");
$varCat = "8";
break;
case 9:
$servicesSup = $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
$transType = $this->translator->trans("Itineraries");
$varCat = "9";
break;
case 13:
$servicesSup = $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
$transType = $this->translator->trans("Transport");
$varCat = "13";
break;
case 12:
$servicesSup = $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
$transType = $this->translator->trans("Others");
$varCat = "12";
break;
case 1:
$servicesSup = $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
$transType = $this->translator->trans("Accommodation");
$varCat = "1";
break;
}
$controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
array(
'servicesId' => $servicesSup->getId(),
'servicesCat' => $idcat,
)
);
$servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
$servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
array(
'servicesId' => $servicesSup->getId(),
'controlId' => $servicesSupplier->getServiceId(),
'language' => $proposal->getLanguage()
)
);
/* ARMO EL CONTENIDO GLOBAL */
$servicesArray[] = array(
'services' => $servicesSup,
'name' => strtoupper($nameServices),
'img' => isset($servicesGallery['0']) ? $servicesGallery['0'] : null,
'cities' => null,
'type' => $transType,
'ids' => $varCat,
'gallery' => $servicesGallery,
'descripcion' => $servicesDescription,
// 'capacity' =>$serviceCapacity,
);
// d($servicesArray);
}
}
}
return $this->render(
'MDS/EventsPresentationBundle/presentation/services-view.html.twig',
array(
'token' => $token,
'type' => $transType,
// 'company' => $company,
'proposal' => $proposal,
'client' => $client,
'selectType' => $selectType,
// 'destination' => $data_destionation,
// 'countDestino' => $cont_destino,
// 'agent'=>$agentMaster,
'data' => $servicesArray,
// 'idd'=>$idd,
// 'sidebar' => $sidebarData,
)
);
}
/**
* @Route("/servicesview-Ajax/{ids}/{idcat}/{token}", name="presentation_services_view_all_token_ajax")
*/
public function ServicesViewAjaxAllAction($token, $ids, $idcat, Request $request)
{
// d($token);
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
/*consulta de los servicios del supplier*/
$services = $em->getRepository(ProposalSupplierServices::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'serviceCatId' => $idcat,
)
);
$servicesArray = array();
// d($services);
$transType = "Not Available";
if (!empty($services)) {
foreach ($services as $servicesSupplier) {
$transType = $this->translator->trans($servicesSupplier->getServiceCatName());
/*consulta Lounge*/
// d($typeM);
if ($servicesSupplier->getServiceId() != "0") {
$nameServices = "";
switch ($idcat) {
case 11:
$servicesSup = $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
break;
case 5:
$servicesSup = $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
break;
case 6:
$servicesSup = $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
break;
case 4:
$servicesSup = $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
break;
case 7:
$servicesSup = $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
break;
case 8:
$servicesSup = $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
break;
case 9:
$servicesSup = $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
break;
case 13:
$servicesSup = $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
break;
case 12:
$servicesSup = $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
break;
case 2:
$servicesSup = $em->getRepository(SupplierActivities::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getTitle();
break;
case 1:
$servicesSup = $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
$nameServices = $servicesSup->getName();
break;
}
$controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
array(
'servicesId' => $ids,
'servicesCat' => $idcat,
)
);
$servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
$servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
array(
'servicesId' => $ids,
'controlId' => $servicesSupplier->getServiceId(),
'language' => $proposal->getLanguage()
)
);
/* ARMO EL CONTENIDO GLOBAL */
$servicesArray = array(
'services' => $servicesSupplier->getServiceId(),
'name' => $nameServices,
'gallery' => $servicesGallery,
'descripcion' => $servicesDescription,
// 'capacity' =>$serviceCapacity,
);
// d($servicesArray);
}
}
}
$serializer = SerializerBuilder::create()->build();
$array = $serializer->toArray($servicesArray);
$response = new JsonResponse($array);
return $response;
}
protected function sidebarAction($token, $typeSide, $idd)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
/* inicio array con los agentes */
$dataAgents = array();
if (!is_null($proposal->getAgentId())) {
$agenteTwo = array();
if (!empty($proposal->getAgentTwoId())) {
$agenteTwo = explode(",", $proposal->getAgentTwoId());
} else {
$agenteTwo[0] = $proposal->getAgentId();
}
$agentProposal = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
$teamLeader = $em->getRepository(User::class)->findOneBy(
array(
'team' => $agentProposal->getTeam(),
'teamleader' => 1,
)
);
if (!empty($teamLeader)) {
$leader = $teamLeader->getId();
} else {
$leader = $proposal->getAgentId();
}
$agentArray = array();
array_push($agentArray, $proposal->getAgentId());
array_push($agentArray, $agenteTwo[0]);
array_push($agentArray, $leader);
array_push($agentArray, 6);
array_push($agentArray, 14);
// array_push($agentArray, 1);
// array_push($agentArray, 1);
// $dataAgents=array();
//d($agentArray);
foreach ($agentArray as $agent) {
//d($agent);
$users = $em->getRepository(User::class)->findOneById($agent);
$dataAgents[] = array(
'id' => $agent,
'fullname' => $users->getName() . ' ' . $users->getLastName(),
'picture' => $users->getPicture()
);
}
/* fin array con los agentes */
}
/* inicio array con los supplier */
$parameters = array(
'proposalId' => $proposal->getId(),
'serviceIdFather' => '0',
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServices p
WHERE p.proposalId = :proposalId AND p.serviceIdFather = :serviceIdFather
ORDER BY p.supplierId ASC ';
$query = $em->createQuery($dql)->setParameters($parameters);
$data_service_supplier = $query->getResult();
$supplier_Id = array();
$idea_Id = array();
$activity_Id = array();
foreach ($data_service_supplier as $dataservicesupplier) {
$controlservices_supplier = $em->getRepository(ProposalSupplierControl::class)->findOneBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
'id' => $dataservicesupplier->getControlId(),
)
);
if (!empty($controlservices_supplier)) {
$proposal_Control = $em->getRepository(ProposalControl::class)->findOneBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
'id' => $controlservices_supplier->getControlDestinationId(),
)
);
if (!empty($proposal_Control)) {
if ($dataservicesupplier->getSupplierId() != "0") {
if (!is_null($controlservices_supplier->getIdeaId())) {
$idea_Id[$controlservices_supplier->getIdeaId()] = array(
'ideaid' => $controlservices_supplier->getIdeaId(),
'destinoid' => $controlservices_supplier->getDestinoId(),
);
}
if (!is_null($controlservices_supplier->getActivityId())) {
$activity_Id[$controlservices_supplier->getActivityId()] = array(
'activityid' => $controlservices_supplier->getActivityId(),
'destinoid' => $controlservices_supplier->getDestinoId(),
);
}
if (!is_null($dataservicesupplier->getSupplierId())) {
$supplier_Id[$dataservicesupplier->getSupplierId()] = array(
'supplierid' => $dataservicesupplier->getSupplierId(),
'destinoid' => $controlservices_supplier->getDestinoId(),
);
}
$destination_Id[$controlservices_supplier->getDestinoId()] = $controlservices_supplier->getDestinoId();
}
}
}
}
$all_Idea_control = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'disabled' => '0',
)
);
foreach ($all_Idea_control as $allIdea) {
if (!is_null($allIdea->getIdeaId())) {
$idea_Id[$allIdea->getIdeaId()] = array(
'ideaid' => $allIdea->getIdeaId(),
'destinoid' => $allIdea->getDestinoId(),
);
}
if (!is_null($allIdea->getActivityId())) {
$activity_Id[$allIdea->getActivityId()] = array(
'activityid' => $allIdea->getActivityId(),
'destinoid' => $allIdea->getDestinoId(),
);
}
}
// d($supplier_Id, $idea_Id, $activity_Id);
/* Fin array con los supplier */
if (is_null($proposal->getSelectType())) {
$select_Type = array();
} else {
$select_Type = explode(",", $proposal->getSelectType());
}
$type = array();
if (!empty($destination_Id)) {
foreach ($select_Type as $selectType) {
// d($selectType);
$destination = array();
if ($selectType == "IDEA") {
foreach ($destination_Id as $destinationId) {
$ideas = array();
foreach ($idea_Id as $ideaId) {
if ($destinationId == $ideaId['destinoid']) {
$ideas_query = $em->getRepository(Ideas::class)->findOneBy(
array(
'id' => $ideaId['ideaid'],
)
);
if (!empty($ideas_query)) {
$ideas[] = $ideas_query;
}
}
}
$destino = $em->getRepository(Destination::class)->findOneById($destinationId);
if (count($ideas) != 0) {
$destination[$destino->getId()] = array(
'destination' => $destino,
'data' => $ideas,
);
}
}
}
if (($selectType == "ACTIVITY") or ($selectType == "ACTIVIDADES")) {
foreach ($destination_Id as $destinationId) {
$activity = array();
foreach ($activity_Id as $activityId) {
if ($destinationId == $activityId['destinoid']) {
$activities_query = $em->getRepository(Activities::class)->findOneBy(
array(
'id' => $activityId['activityid'],
)
);
if (!empty($activities_query)) {
$activity[] = $activities_query;
}
}
}
$destino = $em->getRepository(Destination::class)->findOneById($destinationId);
if (count($activity) != 0) {
$destination[$destino->getId()] = array(
'destination' => $destino,
'data' => $activity,
);
}
}
}
foreach ($destination_Id as $destinationId) {
$supplier = array();
foreach ($supplier_Id as $supplierId) {
if ($destinationId == $supplierId['destinoid']) {
$supplier_query = $em->getRepository("App:Supplier")->findOneBy(
array(
'id' => $supplierId['supplierid'],
'type' => $selectType, // Funcion conversora
)
);
if (!empty($supplier_query)) {
$supplier[] = $supplier_query;
}
}
}
$destino = $em->getRepository(Destination::class)->findOneById($destinationId);
if (count($supplier) != 0) {
$destination[$destino->getId()] = array(
'destination' => $destino,
'data' => $supplier,
);
}
}
if (count($destination) != 0) {
$type[] = array(
'type' => $selectType,
'destination' => $destination,
);
}
}
}
$budgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'recommended' => 1,
)
);
$agendas = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
array(
'proposalId' => $proposal->getId()
),
array(
'priority' => 'ASC',
'recommended' => 'ASC',
)
);
$showAgenda = array();
foreach ($agendas as $item) {
$showAgenda[] = $item;
}
$data[] = array(
'agent' => $dataAgents,
'type' => $type,
'typeSide' => $typeSide,
'idd' => $idd,
'budgetslist' => $budgets,
'agendas' => $showAgenda,
);
// d($data);
// exit();
return $data;
}
/**
* @Route("/proposal/invoice/print/{id}", name="proposal_invoice_detector_print_externo")
*/
public function detectorInvoicePrintAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoiceconsulta = array();
$typeconsulta = '';
$invoice = $em->getRepository(ProposalInvoice::class)->findOneByProposalId($id);
if (!empty($invoice)) {
$invoiceconsulta = $invoice;
$typeconsulta = $invoice->getType();
}
if (!empty($invoiceconsulta)) {
$type = $typeconsulta;
// $number = $invoiceconsulta->getId();
$number = $invoiceconsulta->getNumber();
$date = $invoiceconsulta->getDateAt();
$prefix = $invoiceconsulta->getPrefix();
$data = $this->baseInvoiceProposal($id, $type, $number, $prefix, $date, $request);
$token = $data['token'];
} else {
return $this->redirectToRoute(
'proposal_invoice_proforma_print_externo',
array(
'id' => $id
)
);
}
$fees = $em->getRepository(ProposalFeeInvoice::class)->findByProposalId($id);
if (!empty($fees)) {
$fees[0]->setAmount($fees[0]->getFeeNet());
if (!($fees[0]->getToInvoice())) {
$fees = null;
}
} // Si no se debe mostrar en factura se pone a null
$summary = $em->getRepository(ProposalsInvoiceSummary::class)->findOneByProposalId($id);
$summaryInvoice = !empty($summary);
$summaryInvoiceText = !empty($summary) ? $summary->getDescription() : null;
return $this->render(
'MDS/EventsBundle/services/services-invoice-print-proposal.html.twig',
array(
'id' => $id,
'type' => $data['type'],
'number' => $data['number'],
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $token,
'proposal' => $data['proposal'],
'company' => $data['company'],
'clients' => $data['clients'],
'datasupplier' => $data['datasupplier'],
'totales_neto_antes' => $data['totales_neto_antes'],
'totales_neto' => $data['totales_neto'],
'bases_imponibles' => $data['bases_imponibles'],
'totales_antes' => $data['totales_antes'],
'totales' => $data['totales'],
'balance' => $data['balance'],
'totales_generales' => $data['totales_generales'],
'currency' => $data['currency'],
'detail_iva' => 'no',
'discounts' => $data['discounts'],
'fees' => $fees,
'paymentInvoice' => $data['paymentInvoice'],
'invoiceDesposit' => $data['invoiceDesposit'],
'summaryInvoice' => $summaryInvoice,
'summaryInvoiceText' => $summaryInvoiceText,
)
);
}
/**
* @Route("/proposal/invoice/proforma/print/{id}", name="proposal_invoice_proforma_print_externo")
*/
public function detailsProformaPrintAction($id, Request $request)
{
// dd($id);
$data = array();
// $token = "";
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(ProposalProforma::class)->findOneByProposalId($id);
if (!empty($proforma)) {
$type = 'Proforma';
$number = $proforma->getId();
$date = $proforma->getDateAt();
$prefix = $proforma->getPrefix();
$data = $this->baseInvoiceProposal($id, $type, $number, $prefix, $date, $request);
$token = $data['token'];
} else {
return $this->redirectToRoute('proposal_generate_proforma',
array(
'id' => $id
)
);
}
$fees = $em->getRepository(ProposalFee::class)->findByProposalId($id);
if (!empty($fees)) {
if (!($fees[0]->getToInvoice())) {
$fees = null;
}
} // Si no se debe mostrar en factura se pone a null
$summaryInvoice = $em->getRepository(ProposalsInvoiceSummary::class)->findOneByProposalId($id);
return $this->render(
'MDS/EventsBundle/services/services-invoice-print-proposal.html.twig',
array(
'id' => $id,
'type' => $data['type'],
'number' => $data['number'],
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $token,
'proposal' => $data['proposal'],
'company' => $data['company'],
'clients' => $data['clients'],
'datasupplier' => $data['datasupplier'],
'totales_neto_antes' => $data['totales_neto_antes'],
'totales_neto' => $data['totales_neto'],
'bases_imponibles' => $data['bases_imponibles'],
'totales_antes' => $data['totales_antes'],
'totales' => $data['totales'],
'balance' => $data['balance'],
'totales_generales' => $data['totales_generales'],
'currency' => $data['currency'],
'detail_iva' => 'yes',
'discounts' => $data['discounts'],
'fees' => $fees,
'paymentInvoice' => $data['paymentInvoice'],
'invoiceDesposit' => $data['invoiceDesposit'],
'summaryInvoice' => $summaryInvoice,
)
);
}
private function baseInvoiceProposal($id, $type, $number, $prefix, $date, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneById($id);
$services_supplier = $em->getRepository(ProposalSupplierServicesCostsClient::class)->findBy(
array(
'proposalId' => $id,
'serviceIdFather' => '0'
),
array(
'id' => 'ASC'
)
);
$data_iva = array();
$supplier_control = array();
foreach ($services_supplier as $servicessupplier) {
if (!is_null($servicessupplier->getActivityId())) {
$supplier_control[$servicessupplier->getActivityId()] = array(
'master' => 'activity',
'id' => $servicessupplier->getActivityId(),
'destinoId' => $servicessupplier->getDestinationId(),
);
}
if (!is_null($servicessupplier->getIdeaId())) {
$supplier_control[$servicessupplier->getIdeaId()] = array(
'master' => 'idea',
'id' => $servicessupplier->getIdeaId(),
'destinoId' => $servicessupplier->getDestinationId(),
);
}
if ((!is_null($servicessupplier->getSupplierId())) && ($servicessupplier->getIdeaId() == null) and ($servicessupplier->getActivityId() == null)) {
$supplier_control[$servicessupplier->getSupplierId()] = array(
'master' => 'supplier',
'id' => $servicessupplier->getSupplierId(),
'destinoId' => $servicessupplier->getDestinationId(),
);
}
}
$data_serviceCat = array();
$data_supplier = array();
$totales_neto_all = 0;
$totales_all = 0;
$currency = 0;
$data_service_supplier = array();
foreach ($supplier_control as $suppliercontrol) {
// $destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol['destinoId']);
$destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol['destinoId']);
$colorlabel = "bg-success-300";
$sqlactivities = "";
if ($suppliercontrol['master'] == 'activity') {
$master = "activity";
$sqlactivities = $em->getRepository(Activities::class)->findOneById($suppliercontrol['id']);
// ORDEN DESCENDENTE Y POR SERVICES
$parameters = array(
'proposalId' => $id,
'serviceIdFather' => '0',
'activityId' => $suppliercontrol['id']
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesCostsClient p
WHERE p.proposalId = :proposalId AND p.activityId = :activityId AND p.serviceIdFather = :serviceIdFather
ORDER BY p.serviceCatId, p.rank ASC ';
$query = $em->createQuery($dql)->setParameters($parameters);
$data_service_supplier = $query->getResult();
}
$sqlideas = "";
if ($suppliercontrol['master'] == 'idea') {
$master = "idea";
$sqlideas = $em->getRepository(Ideas::class)->findOneById($suppliercontrol['id']);
// ORDEN DESCENDENTE Y POR SERVICES
$parameters = array(
'proposalId' => $id,
'serviceIdFather' => '0',
'ideaId' => $suppliercontrol['id']
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesCostsClient p
WHERE p.proposalId = :proposalId AND p.ideaId = :ideaId AND p.serviceIdFather = :serviceIdFather
ORDER BY p.serviceCatId, p.rank ASC ';
$query = $em->createQuery($dql)->setParameters($parameters);
$data_service_supplier = $query->getResult();
}
$sqlsuppliers = "";
if ($suppliercontrol['master'] == 'supplier') {
$master = "supplier";
$sqlsuppliers = $em->getRepository(Supplier::class)->findOneById($suppliercontrol['id']);
if (!is_null($sqlsuppliers)) {
switch ($sqlsuppliers->getStar()) {
case 1:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i>');
break;
case 2:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 3:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 4:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 5:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP');
break;
case 6:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 7:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
case 8:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
break;
}
}
// ORDEN DESCENDENTE Y POR SERVICES
$parameters = array(
'proposalId' => $id,
'serviceIdFather' => '0',
'supplierId' => $suppliercontrol['id']
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesCostsClient p
WHERE p.proposalId = :proposalId AND p.supplierId = :supplierId AND p.ideaId is null AND p.activityId is null AND p.serviceIdFather = :serviceIdFather
ORDER BY p.serviceCatId, p.rank ASC ';
$query = $em->createQuery($dql)->setParameters($parameters);
$data_service_supplier = $query->getResult();
// Agrupamos asistencias de In-Out por ID de Agente
$new_data_service_supplier = array();
$arregloAcumulador = array();
$acumulador = array();
if ($sqlsuppliers->getCompany() == 'IN OUT TRAVEL & EVENTS') {
// El proveedor es In Out
foreach ($data_service_supplier as $dtsp) {
$zNameSrvOrNameUsr = $em->getRepository(ProposalsSupplierServicesAssistantName::class)->findOneByPrpSupSrvId($dtsp->getServiceIdProposal());
if ($dtsp->getServiceCatId() != 15) {
$new_data_service_supplier[] = $dtsp;
} else {
// Tenemos una asistencia de In Out
// vamos acumulando precios, over, etc
if ((!array_key_exists($dtsp->getAssistantId() . '-' . $dtsp->getPrice(), $arregloAcumulador)) and (!is_null($dtsp->getAssistantId()))) {
$zAg = $em->getRepository(User::class)->findOneById($dtsp->getAssistantId());
if (empty($zNameSrvOrNameUsr) && !empty($zAg)) {
$dtsp->setName('Staff In Out Events: ' . $zAg->getName() . ' ' . $zAg->getLastName());
}
$dtsp->setUnits(1);
$arregloAcumulador[$dtsp->getAssistantId() . '-' . $dtsp->getPrice()] = $dtsp;
} else {
if ((!is_null($dtsp->getAssistantId()))) {
// Antes se comprobaba sololo con el id ahora el id del agente y el precio de la asistencia
// $tempAcum = $arregloAcumulador[$dtsp->getAssistantId()];
$tempAcum = $arregloAcumulador[$dtsp->getAssistantId() . '-' . $dtsp->getPrice()];
$tempAcum->setUnits($tempAcum->getUnits() + 1);
//Si el dia de inicio es menor actualizas (para establecer rangos de varios dias)
if ($dtsp->getDateInAt() < $tempAcum->getDateInAt()) {
$tempAcum->setDateInAt($dtsp->getDateInAt());
}
//Si el dia de fin es mayor actualizas (para establecer rangos de varios dias)
if ($dtsp->getDateOutAt() > $tempAcum->getDateOutAt()) {
$tempAcum->setDateOutAt($dtsp->getDateOutAt());
}
// Antes se comprobaba sololo con el id ahora el id del agente y el precio de la asistencia
// $arregloAcumulador[$dtsp->getAssistantId()] = $tempAcum;
$arregloAcumulador[$dtsp->getAssistantId() . '-' . $dtsp->getPrice()] = $tempAcum;
} else {
// Tenemos una asistencia de un agente EXTERNO - este agente no se encuentra en el listado de agentes de In Out
if (array_key_exists($dtsp->getName(), $arregloAcumulador)) {
$tempAcum = $arregloAcumulador[$dtsp->getName()];
$tempAcum->setUnits($tempAcum->getUnits() + 1);
if (empty($zNameSrvOrNameUsr)) {
$tempAcum->setName('Staff In Out Events: ' . $dtsp->getName());
}
$arregloAcumulador[$dtsp->getName()] = $tempAcum;
} else {
$arregloAcumulador[$dtsp->getName()] = $dtsp;
if (empty($zNameSrvOrNameUsr)) {
$arregloAcumulador[$dtsp->getName()]->setName('Staff In Out Events: ' . $dtsp->getName());
}
}
}
}
}
}
//
foreach ($arregloAcumulador as $aAc) {
$new_data_service_supplier[] = $aAc;
}
$data_service_supplier = $new_data_service_supplier;
}
// FIN - Agrupamos asistencias de In-Out por ID de Agente
}
$imagenSmall = null;
$service_supplier_data = array();
$totales_neto = '0';
$totales_iva = '0';
$totales_con_iva = '0';
$totales_paying = '0';
$totales_pago = '0';
$totales_benefit_moneda = '0';
$totales_benefit_porsentaje = '0';
foreach ($data_service_supplier as $data_service) {
// d($data_service->getId());
//Currency
$currency = $data_service->getCurrency();
if (isset($currency)) {
$currency = "Euro";
}
if ($currency == "Euro") {
$currency = "€";
}
if ($currency == "Dolar") {
$currency = " $";
}
if ($currency == "MXN") {
$currency = " MXN";
}
$data_service->setCurrency($currency);
$idcat = $data_service->getServiceCatId();
$price = $data_service->getPrice();
$units = $data_service->getUnits();
$pax = $data_service->getPax();
$opcommission = $data_service->getOpCommission();
$commission = $data_service->getCommission();
$opover = $data_service->getOpOver();
$over = $data_service->getOver();
$opiva = $data_service->getOpIva();
$iva = $data_service->getIva();
$dateInAt = $data_service->getDateInAt();
$dateOutAt = $data_service->getDateOutAt();
if (!is_null($dateInAt) and !is_null($dateOutAt)) {
$days = $dateInAt->diff($dateOutAt);
$day = $days->days;
// if (($data_service->getSupplierId() == '4') and ($data_service->getServiceCatId() == '15')){
// $day ="0";
// }
} else {
$day = "0";
// if (($data_service->getSupplierId() == '4') and ($data_service->getServiceCatId() == '15')){
// $day ="0";
// }
}
if (!is_null($data_service->getIdeaId())) {
$name_supplier = $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
if (empty($name_supplier)) {
$namesupplier = '';
} else {
$namesupplier = $name_supplier->getName();
}
}
if (!is_null($data_service->getSupplierId()) and $data_service->getIdeaId() == null) {
$name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
if (empty($name_supplier)) {
$namesupplier = '';
} else {
$namesupplier = $name_supplier->getName();
}
}
// $name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
// $namesupplier = $name_supplier->getName();
if ($type == 'No Vat Invoice') {
$iva = "0";
$data_service->setIva($iva);
}
$calculos = $this->CalculoTotalesservicesDos($price, $units, $pax, $day, $opcommission, $commission, $opover, $over, $opiva, $iva, $idcat);
$data_service->setPrice($calculos['precio']); //ojo aqui
$service_supplier_data[] = array(
'calculos' => $calculos,
'services_data' => $data_service,
'namesupplier' => $namesupplier
);
$totales_neto += $calculos['total_neto'];
$totales_iva += $calculos['sub_total_iva'];
$totales_con_iva += $calculos['total'];
$totales_paying += $calculos['total_paying'];
$totales_pago += $calculos['total_pago'];
$totales_benefit_moneda += $calculos['benefit_moneda'];
/* base imponible por servicios */
if (empty($base_imponible_service[$idcat])) {
$base_imponible_service[$idcat] = 0;
}
$base_imponible_service[$idcat] += $calculos['total_neto'];
$data_serviceCat[$idcat] = array(
'idcat' => $idcat,
'total_neto' => $base_imponible_service[$idcat],
);
/* base impobnible detalles por diferentes Ivas */
if (empty($base_imponible_iva[$iva])) {
$base_imponible_iva[$iva] = 0;
}
$base_imponible_iva[$iva] += $calculos['total_neto'];
if (empty($totales_ivas_all[$iva])) {
$totales_ivas_all[$iva] = 0;
}
$totales_ivas_all[$iva] += $calculos['sub_total_iva'];
$totales_neto_all += $calculos['total_neto'];
$totales_all += $calculos['total'];
$data_iva[$iva] = array(
'iva' => $iva,
'ivas' => $totales_ivas_all[$iva],
'total_iva' => $base_imponible_iva[$iva]
);
if ($totales_benefit_moneda == '0') {
$totales_benefit_porsentaje = '0';
} else {
if ($totales_neto != 0) {
$totales_benefit_porsentaje = $totales_benefit_moneda / $totales_neto * 100; // arreglado or esteban
} else {
$totales_benefit_porsentaje = 0;
}
}
}
$calculos_totatales = array(
'totales_neto' => $totales_neto,
'totales_iva' => $totales_iva,
'totales_con_iva' => $totales_con_iva,
'totales_paying' => $totales_paying,
'totales_benefit_moneda' => $totales_benefit_moneda,
'totales_benefit_porsentaje' => $totales_benefit_porsentaje
);
$data_supplier[$destination->getTitle()][] = array(
'master' => $master,
'colorlabel' => $colorlabel,
'control' => "1",
'supplier' => $sqlsuppliers,
'idea' => $sqlideas,
'activity' => $sqlactivities,
'image' => $imagenSmall,
'services' => $service_supplier_data,
'totales_services' => $calculos_totatales
);
}
$totales_neto_antes = $totales_neto_all;
$totales_antes = $totales_all;
/*Group Everything*/
if ($type == 'Group Everything') {
$data_supplier = array();
$service_supplier_data = array();
$messageitems = $this->translator->trans('Grouped Services');
$data_service = array(
"price" => $totales_neto_antes,
"name" => $messageitems,
"units" => 1,
"iva" => $iva,
"dateInAt" => "2018-4-4",
"dateOutAt" => "2018-4-4",
);
$calculos = array(
"precio" => $totales_neto_antes,
"total_days" => 1,
"sub_total" => $totales_neto_antes,
"sub_total_iva" => 0,
"total_neto" => $totales_neto_antes,
"total_iva" => 0,
"total_paying" => 0,
"total_pago" => 0,
"total_comision" => "0",
"total" => $totales_antes,
"benefit_moneda" => 0,
);
$service_supplier_data[] = array(
'calculos' => $calculos,
'services_data' => $data_service,
'namesupplier' => ""
);
$calculos_totatales = array(
'totales_neto' => $totales_neto_antes,
'totales_iva' => "",
'totales_con_iva' => $totales_antes,
'totales_paying' => "",
'totales_benefit_moneda' => "",
'totales_benefit_porsentaje' => ""
);
$data_supplier[$messageitems][] = array(
'master' => '',
'colorlabel' => '',
'control' => "1",
'supplier' => '',
'idea' => '',
'activity' => '',
'image' => '',
'services' => $service_supplier_data,
'totales_services' => $calculos_totatales
);
}
$data_serviceOut = array(
'idcat' => null,
'total_neto' => $totales_neto_all,
);
array_push($data_serviceCat, $data_serviceOut);
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
$parameters = array(
'id' => $proposal->getclientId(),
);
$dql = 'SELECT cl, c.country, re.region, p.name, r.city
FROM App:Client cl
INNER JOIN App:Country c WITH c.id = cl.country
INNER JOIN App:Regions re WITH re.id = cl.region
INNER JOIN App:Provinces p WITH p.id = cl.province
INNER JOIN App:Cities r WITH r.id = cl.population
WHERE cl.id = :id';
$query = $em->createQuery($dql)->setParameters($parameters);
$client = $query->getResult();
$data_invoice = array();
$inv_neto_total = 0;
$inv_total = 0;
$invoice_deposit_control = $em->getRepository(ProposalInvoiceDepositControl::class)->findByProposalId($proposal->getId());
if (!empty($invoice_deposit_control)) {
foreach ($invoice_deposit_control as $invoicedepositcontrol) {
$data_items_inv = array();
$invoice_deposit_items = $em->getRepository(ProposalInvoiceDepositItems::class)->findByControlId($invoicedepositcontrol->getId());
foreach ($invoice_deposit_items as $invoicedeposititems) {
$invamount = $invoicedeposititems->getAmount();
$invamount_iva = $invoicedeposititems->getIva();
$invamount_el_iva = $invamount * ($invamount_iva / 100);
$invamount_con_iva = $invamount * (($invamount_iva / 100) + 1);
$inv_neto_total += $invamount;
$inv_total += $invamount_con_iva;
if (is_null($invoicedepositcontrol->getNumber())) {
$numInvoice = $invoicedepositcontrol->getId();
} else {
$numInvoice = $invoicedepositcontrol->getNumber();
}
$data_items_inv[] = array(
'numInvoice' => $numInvoice,
'name' => $invoicedeposititems->getName(),
'amount' => $invoicedeposititems->getAmount(),
'iva' => $invoicedeposititems->getIva(),
'ivaamount' => $invamount_el_iva,
'total' => $invamount_con_iva,
);
foreach ($data_iva as $items_iva) {
if ($items_iva['iva'] == $invoicedeposititems->getIva()) {
$new_iva = $items_iva['iva'];
$new_ivas = $items_iva['ivas'] - $invamount_el_iva;
$new_total_iva = $items_iva['total_iva'] - $invoicedeposititems->getAmount();
$new_data_iva = array(
'iva' => $new_iva,
'ivas' => $new_ivas,
'total_iva' => $new_total_iva
);
$data_iva = array_replace($data_iva, array($new_iva => $new_data_iva));
}
}
}
$data_invoice[] = array(
'itemsInvoice' => $data_items_inv,
);
}
// d($inv_neto_total, $inv_total);
$totales_neto_all = $totales_neto_all - $inv_neto_total;
$totales_all = $totales_all - $inv_total;
// d($totales_neto_all, $totales_all);
}
$consulta_discount = $em->getRepository(ProposalDiscount::class)->findByProposalId($id);
$cuantosdiscount = count($consulta_discount);
$totales_generales = "";
$descuento = array();
if (!empty($consulta_discount)) {
// d($data_serviceCat);
$quitar_en_todos = 0.00;
$datos_total_neto_suma = 0.00;
foreach ($data_serviceCat as $dataserviceat) {
$name = "";
$amount = "";
$type_des = "";
$iva_discount = "";
$datos_idcat = $dataserviceat['idcat'];
$datos_total_neto = $dataserviceat['total_neto'];
$totales_neto_des = $datos_total_neto;
$datosiva_neto_des = $datos_total_neto;
$calculo_net_negativo = "";
$total_con_iva_desc = "";
$contarveces = 1;
foreach ($consulta_discount as $consultadiscount) {
if ($dataserviceat['idcat'] == null) {
if ($contarveces > 1) {
$totales_neto_des = $datos_total_neto_suma;
$datosiva_neto_des = $datos_total_neto_suma;
$datos_total_neto = $datos_total_neto_suma;
} else {
if ($cuantosdiscount > 1) {
$totales_neto_des = $dataserviceat['total_neto'] - $quitar_en_todos;
$datosiva_neto_des = $dataserviceat['total_neto'] - $quitar_en_todos;
$datos_total_neto = $dataserviceat['total_neto'] - $quitar_en_todos;
}
}
$contarveces += 1;
}
if ($dataserviceat['idcat'] == $consultadiscount->getServiceId()) {
$iva = $consultadiscount->getIva() / 100;
if ($consultadiscount->getType() == "0") {
$por = $consultadiscount->getAmount() / 100;
// $datosiva_neto_des = $datosiva_neto_des / ($por + 1) ;
$datosiva_neto_des = $datosiva_neto_des - ($datosiva_neto_des * $por);
$name = $consultadiscount->getName();
$type_des = $consultadiscount->getType();
$amount = $consultadiscount->getAmount();
}
if ($consultadiscount->getType() == "1") {
$datosiva_neto_des = $datosiva_neto_des - $consultadiscount->getAmount();
$name = $consultadiscount->getName();
$type_des = $consultadiscount->getType();
$amount = $consultadiscount->getAmount();
}
// d($dataserviceat['idcat'], $datos_total_neto);
// resultados en negativo
$calculo_net_negativo = $datosiva_neto_des - $datos_total_neto;
// d($calculo_net_negativo);
$total_desc = "0";
// resultados para calculos
$calculo_net = $datos_total_neto - $datosiva_neto_des;
if ($consultadiscount->getOpIva() == '0') {
$iva_discount = $calculo_net - ($calculo_net / ($iva + 1));
$calculo_net_negativo = $calculo_net_negativo + $iva_discount;
$totales_neto_des = $totales_neto_des + $iva_discount;
$total_desc = $iva_discount;
}
if ($consultadiscount->getOpIva() == '1') {
$iva_discount = $calculo_net * $iva;
$total_desc = $iva_discount;
}
if ($type == 'No Vat Invoice') {
$iva_discount = "0";
}
// if($dataserviceat['idcat'] == null){
$datos_total_neto_suma = $datos_total_neto - abs((float)$calculo_net_negativo);
// }
$quitar_en_todos = $quitar_en_todos + abs((float)$calculo_net_negativo);
$total_con_iva_desc = $calculo_net_negativo - $iva_discount;
$totales_neto_all = $totales_neto_all - abs((float)$calculo_net_negativo);
$totales_all = $totales_all - abs($total_con_iva_desc);
$descuento[] = array(
'name' => $name,
'type' => $type_des,
'amount' => $amount,
'iva' => $consultadiscount->getIva(),
'iva_amount' => $iva_discount,
'totales_neto_des' => $calculo_net_negativo,
'total' => $total_con_iva_desc,
);
// Nueva actualizacion 17-07-2019 Recalcular Ivas
foreach ($data_iva as $items_iva) {
if ($items_iva['iva'] == $consultadiscount->getIva()) {
$new_iva = $items_iva['iva'];
$new_ivas = $items_iva['ivas'] - $iva_discount;
$new_total_iva = $items_iva['total_iva'] - $iva_discount;
$new_data_iva = array(
'iva' => $new_iva,
'ivas' => $new_ivas,
'total_iva' => $new_total_iva
);
$data_iva = array_replace($data_iva, array($new_iva => $new_data_iva));
}
}
}
}
}
}
$payments = $em->getRepository(ProposalPaymentsClient::class)->findByProposalId($id);
$amount_pay = 0;
foreach ($payments as $payment) {
$amount_pay = $amount_pay + $payment->getAmount();
}
$totales_all = round($totales_all, 2);
$totales_total = $totales_all;
if (!empty($payments)) {
$totales_all = $totales_all - $amount_pay;
}
$data = array(
'id' => $id,
'type' => $type,
'number' => $number,
'prefix' => $prefix,
'date' => $date,
'token' => $proposal->getAccessKey(),
'proposal' => $proposal,
'company' => $company,
'clients' => $client,
'datasupplier' => $data_supplier,
'totales_neto_antes' => $totales_neto_antes,
'totales_neto' => $totales_neto_all,
'totales_generales' => $totales_generales,
'bases_imponibles' => $data_iva,
'totales_antes' => $totales_antes,
'totales' => $totales_total,
'balance' => $totales_all,
'currency' => $currency,
'paymentInvoice' => $amount_pay,
'discounts' => $descuento,
'invoiceDesposit' => $data_invoice,
);
// ************************************************ FEE ************************************************************
$fees = $em->getRepository(ProposalFee::class)->findByProposalId($id);
$feesInvoice = $em->getRepository(ProposalFeeInvoice::class)->findByProposalId($id);
if (!empty($feesInvoice)) {
// Fee en factura
// Solo se haran los calculos si el Fee va a la factura, en caso contrario es un fee oculto y ya estará cargado en los servicios
if ($feesInvoice[0]->getToinvoice() == true) {
foreach ($feesInvoice as $feeInv) {
if ($feeInv->getType() == 0) {
// Tenemos un porcentaje en el Fee de la factura, debe calcularse
$feeNet = ($data['totales_neto_antes'] * $feeInv->getAmount()) / 100;
} else {
$feeNet = $feeInv->getAmount();
}
$feeTotal = $feeNet * 1.21; //El fee siempre será al 21%, Esteban Rincón
if ($feeInv->getToInvoice() == true) {
$data['totales_neto'] += $feeNet;
$data['totales'] += $feeTotal;
$data['balance'] += $feeTotal;
if (array_key_exists('21', $data['bases_imponibles'])) {
$data['bases_imponibles']['21']['ivas'] += $feeNet * 0.21;
$data['bases_imponibles']['21']['total_iva'] += $feeNet;
} else {
$data['bases_imponibles']['21']['iva'] = '21';
$data['bases_imponibles']['21']['ivas'] = $feeNet * 0.21;
$data['bases_imponibles']['21']['total_iva'] = $feeNet;
}
}
if ($feeInv->getFeeNet() == 0 or empty($feeInv->getFeeNet())) {
// La asignación solo se hace la primera vez
$feeInv->setFeeNet($feeNet);
$feeInv->setFeeTotal($feeTotal);
$em->persist($feeInv);
$em->flush();
}
}
}
} else {
// Fee en proforma
if (!empty($fees)) {
// Solo se haran los calculos si el Fee va a la factura, en caso contrario es un fee oculto y ya estará cargado en los servicios
if ($fees[0]->getToinvoice() == true) {
foreach ($fees as $fee) {
if ($fee->getType() == 0) {
// Tenemos un porcentaje, debe calcularse
$amount = ($data['totales_neto_antes'] * $fee->getAmount()) / 100;
$fee->setAmount($amount);
}
$fee->setFeeTotal($fee->getAmount() * 1.21); //El fee siempre será al 21%, Esteban Rincón
if ($fee->getToInvoice() == true) {
$data['totales_neto'] += $fee->getAmount();
$data['totales'] += $fee->getFeeTotal();
$data['balance'] += $fee->getFeeTotal();
if (array_key_exists('21', $data['bases_imponibles'])) {
$data['bases_imponibles']['21']['ivas'] += $fee->getAmount() * 0.21;
$data['bases_imponibles']['21']['total_iva'] += $fee->getAmount();
} else {
$data['bases_imponibles']['21']['iva'] = '21';
$data['bases_imponibles']['21']['ivas'] = $fee->getAmount() * 0.21;
$data['bases_imponibles']['21']['total_iva'] = $fee->getAmount();
}
}
}
}
}
}
// ************************************************ FEE ************************************************************
return $data;
}
/**
* @Route("/proposal/invoicedeposit/print/proforma/{id}", name="proposal_invoice_deposit_proforma_print_externo")
*/
public function printdetailsProformadepositAction($id, Request $request)
{
$data = array();
$controlId = null;
$type = "Proforma";
$prefix = "PFD-";
$date = new \DateTime('now');
$data = $this->baseInvoiceDepositProposal($id, $controlId, $type, $id, $prefix, $date, $request);
return $this->render(
'MDS/EventsBundle/invoice/print-invoice-deposit-proforma.html.twig',
array(
'id' => $id,
'type' => $data['type'],
'number' => $data['number'],
'numberadmin' => $data['numberadmin'],
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $data['token'],
'proposal' => $data['proposal'],
'company' => $data['company'],
'clients' => $data['clients'],
'invoicedeposititems' => $data['invoicedeposititems'],
'totales_neto' => $data['totales_neto'],
'totales_iva' => $data['totales_iva'],
'totales' => $data['totales'],
'bases_imponibles' => $data['ivas'],
'currency' => $data['currency'],
)
);
}
/**
* @Route("/proposal/invoicedeposit/print/invoice/{id}/{fid}", name="proposal_invoice_deposit_invoice_print_externo")
*/
public function printdetailsInvoicedepositAction($id, $fid, Request $request)
{
$data = array();
$em = $this->getDoctrine()->getManager();
$invoicedepositcontrolconsulta = $em->getRepository(ProposalInvoiceDepositControl::class)->findOneBy(
array(
'proposalId' => $id,
'id' => $fid
)
);
$type = "Invoice";
$controlId = $invoicedepositcontrolconsulta->getId();
$date = $invoicedepositcontrolconsulta->getDateAt();
$prefix = $invoicedepositcontrolconsulta->getPrefix();
$data = $this->baseInvoiceDepositProposal($id, $controlId, $type, $id, $prefix, $date, $request);
return $this->render(
'MDS/EventsBundle/invoice/print-invoice-deposit-proforma.html.twig',
array(
'id' => $id,
'type' => $data['type'],
'number' => $data['number'],
'prefix' => $data['prefix'],
'numberadmin' => $data['numberadmin'],
'date' => $data['date'],
'token' => $data['token'],
'proposal' => $data['proposal'],
'company' => $data['company'],
'clients' => $data['clients'],
'invoicedeposititems' => $data['invoicedeposititems'],
'totales_neto' => $data['totales_neto'],
'totales_iva' => $data['totales_iva'],
'totales' => $data['totales'],
'bases_imponibles' => $data['ivas'],
'currency' => $data['currency'],
)
);
}
private function baseInvoiceDepositProposal($id, $controlId, $type, $number, $prefix, $date, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneById($id);
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
$parameters = array(
'id' => $proposal->getclientId(),
);
$dql = 'SELECT cl, c.country, re.region, p.name, r.city
FROM App:Client cl
INNER JOIN App:Country c WITH c.id = cl.country
INNER JOIN App:Regions re WITH re.id = cl.region
INNER JOIN App:Provinces p WITH p.id = cl.province
INNER JOIN App:Cities r WITH r.id = cl.population
WHERE cl.id = :id';
$query = $em->createQuery($dql)->setParameters($parameters);
$client = $query->getResult();
if (!is_null($controlId)) {
$invoicecontrol = $em->getRepository(ProposalInvoiceDepositControl::class)->findOneById($controlId);
if (!is_null($invoicecontrol->getNumber())) {
$numberadmin = $invoicecontrol->getNumber();
} else {
$numberadmin = null;
}
} else {
$numberadmin = null;
}
$invoicedeposititems = $em->getRepository(ProposalInvoiceDepositItems::class)->findBy(
array(
'proposalId' => $id,
'controlId' => $controlId,
)
);
$totales_neto_all = "0";
$totales_iva_all = "0";
$totales_con_iva_all = "0";
$data_iva = array();
foreach ($invoicedeposititems as $deposititems) {
$amount = $deposititems->getAmount();
$iva_base = $deposititems->getIva();
$iva = $iva_base / 100;
$amount_iva = ($iva_base != '0') ? ($amount * $iva) : 0;
// if ($iva_base != '0') {
// $amount_iva = $amount * $iva;
// }
$amount_con_iva = $amount + $amount_iva;
$totales_neto_all += $amount;
$totales_iva_all += $amount_iva;
$totales_con_iva_all += $amount_con_iva;
if (empty($totales_ivas_all[$iva_base])) {
$totales_ivas_all[$iva_base] = 0;
}
$totales_ivas_all[$iva_base] += $amount_iva;
$data_iva[$iva_base] = array(
'iva' => $iva_base,
'ivas' => $totales_ivas_all[$iva_base],
);
$data_deposititems[] = array(
'name' => $deposititems->getName(),
'amount' => $amount,
'iva' => $iva_base,
'total' => $amount_con_iva
);
}
$currency = "€";
$data = array(
'id' => $id,
'type' => $type,
'number' => $number,
'prefix' => $prefix,
'numberadmin' => $numberadmin,
'date' => $date,
'token' => $proposal->getAccessKey(),
'proposal' => $proposal,
'company' => $company,
'clients' => $client,
'invoicedeposititems' => $data_deposititems,
'totales_neto' => $totales_neto_all,
'totales_iva' => $totales_iva_all,
'totales' => $totales_con_iva_all,
'ivas' => $data_iva,
'currency' => $currency,
);
return $data;
}
public function CalculoTotalesservicesDos($price, $units, $pax, $days, $opcommission, $commission, $opover, $over, $opiva, $iva, $idcat)
{
$commission = (float)$commission;
$price = (float)trim($price);
$over = (float)trim($over);
//$price = str_replace(",", ".", $price);
//$over = str_replace(",", ".", $over);
$iva = $iva / 100;
if ($opiva == '0') {
$price = (float)$price / ($iva + 1);
}
if ($opcommission == '0') {
$commission = (100 - $commission) / 100;
$precio_units = $price;
$price = $price * $commission;
}
if ($opcommission == '1') {
$commission = ($commission / 100) + 1;
$precio_units = $price * $commission;
}
//Units
if (empty($units) or $units == "0") {
// d('entre');
$units = "1";
}
// Calculo Especial por categoria
//Alojamientos
if ($idcat == "1") {
$informativo_days = "si";
$pax = "1";
}
//Transporte
elseif ($idcat == "13") {
$informativo_days = "no";
$pax = "1";
// if($days > "1"){
// $days = "2";
// }else{
// $days = "1";
// }
}
//Lounge
elseif ($idcat == "10") {
$informativo_days = "no";
$pax = "1";
}
//Guia
elseif ($idcat == "8") {
$informativo_days = "no";
$pax = "1";
}
//Asistencia
elseif ($idcat == "15") {
$informativo_days = "no";
$days = '0';
} else {
$informativo_days = "no";
}
//Pax
if (empty($pax) or $pax == "0") {
$pax = "1";
}
if ($informativo_days == "no") {
//Days
if (empty($days) or $days == "0") {
$days = "1";
} else {
$days = $days + 1;
}
}
$total_items = $price * $units * $pax * $days;
// $total_pdirect = $price * $units * $pax * $days;
$total_over = (float)$over * (float)$units * (float)$pax * (float)$days;
if ($opcommission == '0') {
$total_neto = $total_items / $commission;
}
if ($opcommission == '1') {
$total_neto = $total_items * $commission;
}
if ($opover == '0') {
$total_neto = $total_neto - $total_over;
$precio_units = (float)$precio_units - (float)$over;
}
if ($opover == '1') {
$total_neto = $total_neto + $total_over;
$precio_units = (float)$precio_units + (float)$over;
}
$total_paying = $total_items * ($iva + 1);
$total_comision = "0";
$total_pago = $total_items;
$total_iva = $total_items * $iva;
$sub_total_iva = $total_neto * $iva;
$total = $total_neto + $sub_total_iva;
$benefit_moneda = $total_neto - $total_items;
$data_calculos = array(
'precio' => $precio_units,
'total_days' => $days,
'sub_total' => $total_items,
'sub_total_iva' => $sub_total_iva,
'total_neto' => $total_neto,
'total_iva' => $total_iva,
'total_paying' => $total_paying,
'total_pago' => $total_pago,
'total_comision' => $total_comision,
'total' => $total,
'benefit_moneda' => $benefit_moneda
);
return $data_calculos;
}
/**
* Añadido el 11/06/2018 por Miguel Aguire
*/
/**
* @Route("/invoice/{token}", name="proposal_presentation_invoice")
*/
public function detectorPresentationInvoiceAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'proposal' => $proposal,
'token' => $token
)
);
}
if (is_null($proposal->getSelectType())) {
$selectType = array();
} else {
$selectType = explode(",", $proposal->getSelectType());
}
$invoiceconsulta = array();
$typeconsulta = '';
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$invoice = $em->getRepository(ProposalInvoice::class)->findOneByProposalId($proposal->getId());
if (!empty($invoice)) {
$invoiceconsulta = $invoice;
$typeconsulta = $invoice->getType();
}
$parametersNew = array(
'proposalId' => $proposal->getId(),
'recommended' => '0',
'priority' => '0',
);
$dqlNew = 'SELECT p
FROM EventsBundle:ProposalSupplierServicesBudgetControl p
WHERE p.proposalId = :proposalId
AND p.recommended = :recommended
AND p.priority != :priority
ORDER BY p.priority ASC';
$queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
$controlbudgetsNew = $queryNew->getResult();
$sidebarData = $this->sidebarAction($token, "", "");
$noinvoice = false;
if (!empty($invoiceconsulta)) {
$type = $invoiceconsulta->getType();
$number = $invoiceconsulta->getNumber();
$date = $invoiceconsulta->getDateAt();
$prefix = $invoiceconsulta->getPrefix();
$data = $this->baseInvoiceProposal($proposal->getId(), $type, $number, $prefix, $date, $request);
$token = $data['token'];
return $this->render(
'MDS/EventsPresentationBundle/presentation/invoice.html.twig',
array(
'id' => $proposal->getId(),
'type' => $data['type'],
'number' => $data['number'],
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $token,
'proposal' => $data['proposal'],
'company' => $data['company'],
'clients' => $data['clients'],
'datasupplier' => $data['datasupplier'],
'totales_neto_antes' => $data['totales_neto_antes'],
'totales_neto' => $data['totales_neto'], // totales neto
'bases_imponibles' => $data['bases_imponibles'],
'totales_antes' => $data['totales_antes'],
'totales' => $data['totales'], // totales generales
'balance' => $data['balance'],
'totales_generales' => $data['totales_generales'],
'currency' => $data['currency'],
'detail_iva' => 'no',
'discounts' => $data['discounts'],
'paymentInvoice' => $data['paymentInvoice'],
'invoiceDesposit' => $data['invoiceDesposit'],
'mcp' => $data['proposal']->getMcp(),
'noinvoice' => $noinvoice,
'sidebar' => $sidebarData,
'client' => $client,
'budgetNew' => $controlbudgetsNew,
// 'agendas' => $showAgenda,
)
);
} else {
$noinvoice = true;
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
return $this->render(
'MDS/EventsPresentationBundle/presentation/invoice.html.twig',
array(
'id' => $proposal->getId(),
'proposal' => $proposal,
'noinvoice' => $noinvoice,
'sidebar' => $sidebarData,
'client' => $client,
'token' => $token,
'budgetNew' => $controlbudgetsNew,
'selectType' => $selectType,
// 'agendas' => $showAgenda,
'company' => $company,
)
);
}
}
/**
* @Route("/cancelled/{token}", name="presentation_error_cancel")
*/
public function canceledInvoiceAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$sidebarData = $this->sidebarAction($token, "", "");
return $this->render(
'MDS/EventsPresentationBundle/presentation/canceled_invoice.html.twig',
array(
'proposal' => $proposal,
'sidebar' => $sidebarData,
'client' => $client,
'token' => $token,
)
);
}
/**
* @Route("/disclaimer/", name="disclaimer")
*/
public function disclaimer($token, Request $request)
{
return $this->render(
'MDS/EventsPresentationBundle/presentation/disclaimer.html.twig'
);
}
/**
* @Route("/showDiary/{token}/{controlId}", name="presentation_show_diary")
*/
public function showDiaryAction($token, $controlId, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$sidebarData = $this->sidebarAction($token, "", "");
$diary = $em->getRepository(ProposalAgendaPresupuesto::class)->findBy(
array(
'proposalId' => $proposal->getId(),
'controlId' => $controlId,
),
array(
'dateInAt' => 'ASC',
)
);
$generalDiaryData = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findOneBy(
array(
'proposalId' => $proposal->getId(),
'controlId' => $controlId,
)
);
$diaryData = array();
$dateAux = null;
foreach ($diary as $data) {
$diaryData[$data->getDateInAt()->format('Y/m/d')]['services'][] = $data;
if ($dateAux != $data->getDateInAt()->format('Y/m/d')) {
$dateAux = $data->getDateInAt()->format('Y/m/d');
$diaryData[$data->getDateInAt()->format('Y/m/d')]['date'] = $dateAux;
}
// $diaryData[] = $data;
}
return $this->render(
'MDS/EventsPresentationBundle/presentation/agenda-presupuesto.html.twig',
array(
'proposal' => $proposal,
'sidebar' => $sidebarData,
'client' => $client,
'token' => $token,
'diary' => $diaryData,
'general' => $generalDiaryData,
// 'agendas' => $showAgenda,
)
);
}
/**
* @Route("/aboutUs/{token}", name="presentation_about_us")
*/
public function aboutUsAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$sidebarData = $this->sidebarAction($token, "", "");
return $this->render(
'MDS/EventsPresentationBundle/presentation/aboutUs.html.twig',
array(
'proposal' => $proposal,
'sidebar' => $sidebarData,
'client' => $client,
'token' => $token,
// 'agendas' => $showAgenda,
)
);
}
// Funcion para insertar historico de seguimiento
private function TracingHistoryOperations($id, $text)
{
$em = $this->getDoctrine()->getManager();
/* Obtengo usuario logueado */
$user_id = "0";
$history = new ProposalTracing();
$history->setDateAt(new \DateTime('now'));
$history->setText($text);
$history->setAgentId($user_id);
$history->setProposalId($id);
$history->setViewed('no');
$history->setCreatedId($user_id);
$history->setUpdatedId($user_id);
$em->persist($history);
$em->flush();
$success = 'success';
return $success;
}
/**
* @Route("/menu/{token}", name="presentation_menu_view_token")
*/
public function MenuAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
if (is_null($proposal->getSelectType())) {
$selectTypearray = array();
} else {
$selectTypearray = explode(",", $proposal->getSelectType());
}
// d($selectTypearray);
$selectType = array();
foreach ($selectTypearray as $selectTypedata) {
$agrupacionetiquetas = $em->getRepository(SupplierSettingsType::class)->findOneByBase($selectTypedata);
if (empty($agrupacionetiquetas)) {
$selectType['NoHay'][] = $selectTypedata;
} else {
if (is_null($agrupacionetiquetas->getGroupBase())) {
$selectType['NoHay'][] = $selectTypedata;
} else {
$selectType[$agrupacionetiquetas->getGroupBase()][] = $selectTypedata;
}
}
}
// d($selectType);
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$musica = $em->getRepository(PresentationMusic::class)->findOneBy(
array(
'id' => $proposal->getIdMusic()
)
);
return $this->render(
'MDS/EventsPresentationBundle/presentation/menu.html.twig',
array(
'token' => $token,
'proposal' => $proposal,
'selectType' => $selectType,
'company' => $company,
'client' => $client,
'music' => $musica,
)
);
}
/**
* @Route("/submenu/{idg}/{token}", name="presentation_submenu_view_token")
*/
public function SubmenuViewAction($idg, $token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
switch ($idg) {
case 1:
$namerGroup = "LOGÍSTICA";
break;
case 2:
$namerGroup = "PRODUCCIÓN";
break;
case 3:
$namerGroup = "TECNOLOGÍA";
break;
}
if (is_null($proposal->getSelectType())) {
$selectTypearray = array();
} else {
$selectTypearray = explode(",", $proposal->getSelectType());
}
// d($selectTypearray);
$selectType = array();
foreach ($selectTypearray as $selectTypedata) {
$agrupacionetiquetas = $em->getRepository(SupplierSettingsType::class)->findOneByBase($selectTypedata);
if (empty($agrupacionetiquetas)) {
$selectType['NoHay'][] = $selectTypedata;
} else {
if (is_null($agrupacionetiquetas->getGroupBase())) {
$selectType['NoHay'][] = $selectTypedata;
} else {
if ($namerGroup == $agrupacionetiquetas->getGroupBase()) {
$selectType[$agrupacionetiquetas->getGroupBase()][] = $selectTypedata;
}
}
}
}
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
// d($selectType);
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
//
return $this->render(
'MDS/EventsPresentationBundle/presentation/submenu.html.twig',
array(
'token' => $token,
'proposal' => $proposal,
'selectType' => $selectType,
'client' => $client,
'company' => $company,
)
);
}
/**
* @Route("/presupuesto/{token}", name="presentation_presupuesto_view_token")
*/
public function PresupuestoViewAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
if ($proposal->getStatus() == "Cancel") {
return $this->redirectToRoute(
'presentation_error_cancel',
array(
'token' => $token
)
);
}
if (is_null($proposal->getSelectType())) {
$selectTypearray = array();
} else {
$selectTypearray = explode(",", $proposal->getSelectType());
}
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if ($user_logueado == "anon.") {
$proposal->setViewedAt(new \DateTime("now"));
$em->persist($proposal);
$em->flush();
}
$controlbudget = array(
'0' => array(),
'1' => array(),
'0a' => array()
);
$controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
foreach ($controlbudgets as $controlbudge) {
if (is_null($controlbudge->getByClient())) {
$byclient = "";
} else {
$byclient = "a";
}
$controlbudget[$controlbudge->getRecommended() . $byclient][] = $controlbudge;
}
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
return $this->render(
'MDS/EventsPresentationBundle/presentation/presupuesto.html.twig',
array(
'token' => $token,
'proposal' => $proposal,
'budgets' => $controlbudget,
'client' => $client,
'company' => $company,
)
);
}
/**
* @Route("/idea/{token}", name="presentation_ideaview")
*/
public function IdeaViewAction($token, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$company = $em->getRepository(SettingsCompany::class)->findOneById('1');
$galeria = $em->getRepository(PresentationGallery::class)->findByProposalId($proposal->getId());
$description = $em->getRepository(ProposalDescription::class)->findOneBy(
array('proposalId' => $proposal->getId(), 'language' => $proposal->getLanguage())
);
// d($description);exit();
$musica = $em->getRepository(PresentationMusic::class)->findOneBy(
array(
'id' => $proposal->getIdMusic()
)
);
$video_sinservices = $em->getRepository(PresentationVideo::class)->findByProposalId($proposal->getId());
$datos_videos = array();
if (!empty($video_sinservices)) {
foreach ($video_sinservices as $videoview) {
$urlvideo = $videoview->getVideo();
$esyoutube = strpos($urlvideo, 'youtube');
if ($esyoutube !== false) {
$urvideo_final = '<iframe class="embed-responsive-item" src="' . $urlvideo . '"></iframe>';
}
$esvimeo = strpos($urlvideo, 'vimeo');
if ($esvimeo !== false) {
$urvideo_final = '<iframe allowfullscreen="" frameborder="0" mozallowfullscreen="" src="' . $urlvideo . '?title=0&byline=0&portrait=0" webkitallowfullscreen=""></iframe>';
}
$datos_videos[] = array(
'id' => $videoview->getId(),
'urlvideo' => $urvideo_final
);
}
}
$bg = '/assets/img/presentation-two/02hero.jpg';
// d($galeria); exit();
return $this->render(
'MDS/EventsPresentationBundle/presentation/idea.html.twig',
array(
'proposal' => $proposal,
'client' => $client,
'bg' => $bg,
'token' => $token,
'galeria' => $galeria,
'video' => $datos_videos,
'description' => $description,
'company' => $company,
'music' => $musica,
)
);
}
}