src/MDS/EventsPresentationBundle/Controller/ProposalPresentationController.php line 7572

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions
  4.  * User: jorge.defreitas@develup.solutions
  5.  * Date: 31/10/2017
  6.  * Time: 9:55
  7.  */
  8. namespace App\MDS\EventsPresentationBundle\Controller;
  9. use App\Entity\Activities;
  10. use App\Entity\Cities;
  11. use App\Entity\Client;
  12. use App\Entity\Configuration;
  13. use App\Entity\Country;
  14. use App\Entity\Destination;
  15. use App\Entity\DestinationDescription;
  16. use App\Entity\DestinationGallery;
  17. use App\Entity\Ideas;
  18. use App\Entity\PresentationGallery;
  19. use App\Entity\PresentationMusic;
  20. use App\Entity\PresentationVideo;
  21. use App\Entity\ProposalsInvoiceSummary;
  22. use App\Entity\Provinces;
  23. use App\Entity\Regions;
  24. use App\Entity\SettingsCompany;
  25. use App\Entity\Supplier;
  26. use App\Entity\SupplierAccommodation;
  27. use App\Entity\SupplierActivities;
  28. use App\Entity\SupplierAv;
  29. use App\Entity\SupplierCreative;
  30. use App\Entity\SupplierCruise;
  31. use App\Entity\SupplierDescription;
  32. use App\Entity\SupplierEntertainment;
  33. use App\Entity\SupplierGallery;
  34. use App\Entity\SupplierGifts;
  35. use App\Entity\SupplierGuide;
  36. use App\Entity\SupplierIdeaServicesControl;
  37. use App\Entity\SupplierItineraries;
  38. use App\Entity\SupplierLounge;
  39. use App\Entity\SupplierMenu;
  40. use App\Entity\SupplierOthers;
  41. use App\Entity\SupplierServicesControl;
  42. use App\Entity\SupplierServicesDescription;
  43. use App\Entity\SupplierSettingsType;
  44. use App\Entity\SupplierTechnology;
  45. use App\Entity\SupplierTransport;
  46. use App\Entity\User;
  47. use App\MDS\EventsBundle\Entity\Proposal;
  48. use App\MDS\EventsBundle\Entity\ProposalAgendaPresupuesto;
  49. use App\MDS\EventsBundle\Entity\ProposalAgendaPresupuestoControl;
  50. use App\MDS\EventsBundle\Entity\ProposalAgents;
  51. use App\MDS\EventsBundle\Entity\ProposalControl;
  52. use App\MDS\EventsBundle\Entity\ProposalDiscount;
  53. use App\MDS\EventsBundle\Entity\ProposalDocument;
  54. use App\MDS\EventsBundle\Entity\ProposalDescription;
  55. use App\MDS\EventsBundle\Entity\ProposalFee;
  56. use App\MDS\EventsBundle\Entity\ProposalFeeInvoice;
  57. use App\MDS\EventsBundle\Entity\ProposalInvoice;
  58. use App\MDS\EventsBundle\Entity\ProposalInvoiceDepositControl;
  59. use App\MDS\EventsBundle\Entity\ProposalInvoiceDepositItems;
  60. use App\MDS\EventsBundle\Entity\ProposalPaymentsClient;
  61. use App\MDS\EventsBundle\Entity\ProposalProforma;
  62. use App\MDS\EventsBundle\Entity\ProposalsSupplierServicesAssistantName;
  63. use App\MDS\EventsBundle\Entity\ProposalSupplierControl;
  64. use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
  65. use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudget;
  66. use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudgetControl;
  67. use App\MDS\EventsBundle\Entity\ProposalSupplierServicesCostsClient;
  68. use App\MDS\EventsBundle\Entity\ProposalTracing;
  69. use Symfony\Component\Routing\Annotation\Route;
  70. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  71. use Symfony\Component\HttpFoundation\JsonResponse;
  72. use Symfony\Component\HttpFoundation\Request;
  73. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  74. use JMS\Serializer\SerializerBuilder;
  75. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  76. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  77. use PhpOffice\PhpSpreadsheet\Style\Fill;
  78. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  79. use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
  80. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  81. use Swift_Mailer;
  82. use Swift_Message;
  83. use Swift_SmtpTransport;
  84. use Symfony\Component\HttpFoundation\StreamedResponse;
  85. use Symfony\Contracts\Translation\TranslatorInterface;
  86. use Doctrine\ORM\EntityManagerInterface;
  87. class ProposalPresentationController extends AbstractController
  88. {
  89.     private $translator;
  90.     public function __construct(TranslatorInterface $translator)
  91.     {
  92.         $this->translator = $translator;
  93.     }
  94.     /**
  95.      * @Route("/home/{token}", name="presentation_home_token")
  96.      */
  97.     public function homeAction($token, Request $request)
  98.     {
  99.         $em = $this->getDoctrine()->getManager();
  100.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  101.         if ($proposal->getStatus() == "Cancel") {
  102.             return $this->redirectToRoute(
  103.                 'presentation_error_cancel',
  104.                 array(
  105.                     'token' => $token
  106.                 )
  107.             );
  108.         }
  109.         $proposalControl = $em->getRepository(ProposalControl::class)->findOneByProposalId($proposal->getId());
  110.         $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  111.         $image = $em->getRepository(PresentationGallery::class)->findAll();
  112.         $video = $em->getRepository(PresentationVideo::class)->findAll();
  113.         shuffle($video);
  114.         //        d($video);
  115.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  116.         // Usuario Anonimo es = "anon."
  117.         if ($user_logueado == "anon.") {
  118.             switch ($proposal->getLanguage()) {
  119.                 case 'CASTELLANO':
  120.                     $idioma = "es";
  121.                     break;
  122.                 case 'ENGLISH':
  123.                     $idioma = "en";
  124.                     break;
  125.                 case 'TURKISH':
  126.                     $idioma = "tr";
  127.                     break;
  128.                 case 'RUSSIAN':
  129.                     $idioma = "ru";
  130.                     break;
  131.                 case 'CHINESE':
  132.                     $idioma = "zh";
  133.                     break;
  134.                 case 'PORTUGUESE':
  135.                     $idioma = "pt";
  136.                     break;
  137.                 case 'ARAB':
  138.                     $idioma = "ar";
  139.                     break;
  140.                 case 'ITALIAN':
  141.                     $idioma = "it";
  142.                     break;
  143.                 case 'KOREAN':
  144.                     $idioma = "ko";
  145.                     break;
  146.             }
  147.             $request->setDefaultLocale($idioma);
  148.             $request->getSession()->set('_locale', $idioma);
  149.         }
  150.         $urlvideo = '/assets/video/login/VOLAR.mp4';
  151.         $idvideo = '0';
  152.         return $this->render(
  153.             'MDS/EventsPresentationBundle/presentation/presentation-client.html.twig',
  154.             array(
  155.                 'token' => $token,
  156.                 'video' => $urlvideo,
  157.                 'videos' => $video,
  158.                 'idvideo' => $idvideo,
  159.                 'image' => $image,
  160.                 'destino' => $destino,
  161.                 //                'agendas' => $showAgenda,
  162.             )
  163.         );
  164.     }
  165.     /**
  166.      * @Route("/disclaimer/{token}", name="presentation_disclaimer")
  167.      */
  168.     public function disclaimerAction($token, Request $request)
  169.     {
  170.         $request->getSession()->set('_disclaimer', 'ok');
  171.         return $this->redirectToRoute(
  172.             'presentation_cover_token',
  173.             array(
  174.                 'token' => $token,
  175.             )
  176.         );
  177.     }
  178.     /**
  179.      * @Route("/readDisclaimer/{token}", name="read_disclaimer")
  180.      */
  181.     public function disclaimerPageAction($token, Request $request)
  182.     {
  183.         $em = $this->getDoctrine()->getManager();
  184.         $request->getSession()->set('_disclaimer', 'ok');
  185.         $sidebarData = $this->sidebarAction($token, "", "");
  186.         $disclaimer =  $request->getSession()->get('_disclaimer');
  187.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  188.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  189.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  190.             array(
  191.                 'proposalId' => $proposal->getId(),
  192.                 'disabledPresentation' => '0',
  193.             )
  194.         );
  195.         $data_destination = array();
  196.         $countDestino = 0;
  197.         $selectType = explode(",", $proposal->getSelectType());
  198.         foreach ($proposal_Control as $proposalControl) {
  199.             $countDestino++;
  200.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  201.             $description = array();
  202.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  203.             $data_destination[$destino->getTitle()] = array(
  204.                 'destino' => $destino,
  205.                 'gallery' => $gallery,
  206.                 'description' => $description,
  207.             );
  208.         }
  209.         return $this->render(
  210.             'MDS/EventsPresentationBundle/presentation/start-client.html.twig',
  211.             array(
  212.                 'token' => $token,
  213.                 'client' => $client,
  214.                 'proposal' => $proposal,
  215.                 'destination' => $data_destination,
  216.                 'countDestino' => $countDestino,
  217.                 'sidebar' => $sidebarData,
  218.                 'disclaimer' => $disclaimer,
  219.                 'legal' => true,
  220.                 'selectType' => $selectType,
  221.                 //                    'agendas' => $showAgenda,
  222.             )
  223.         );
  224.     }
  225.     /**
  226.      * @Route("/printDisclaimer/", name="print_disclaimer")
  227.      */
  228.     public function printPageAction(Request $request)
  229.     {
  230.         return $this->render('MDS/EventsPresentationBundle/presentation/disclaimer.html.twig');
  231.     }
  232.     /**
  233.      * @Route("/destination/{token}", name="presentation_destination_view_token")
  234.      */
  235.     public function DestinationViewAction($token, Request $request)
  236.     {
  237.         $em = $this->getDoctrine()->getManager();
  238.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  239.         if ($proposal->getStatus() == "Cancel") {
  240.             return $this->redirectToRoute(
  241.                 'presentation_error_cancel',
  242.                 array(
  243.                     'token' => $token
  244.                 )
  245.             );
  246.         }
  247.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  248.         // Usuario Anonimo es = "anon."
  249.         if ($user_logueado == "anon.") {
  250.             $proposal->setViewedAt(new \DateTime("now"));
  251.             $em->persist($proposal);
  252.             $em->flush();
  253.         }
  254.         $selectType = explode(",", $proposal->getSelectType());
  255.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  256.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  257.             array(
  258.                 'proposalId' => $proposal->getId(),
  259.                 'disabled' => '0',
  260.             )
  261.         );
  262.         $data_destionation = array();
  263.         $cont_destino = 0;
  264.         foreach ($proposal_Control as $proposalControl) {
  265.             $cont_destino += 1;
  266.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  267.             $gallery = $em->getRepository(DestinationGallery::class)->findByDestinationId($proposalControl->getDestinationId());
  268.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  269.                 array(
  270.                     'destinationId' => $proposalControl->getDestinationId(),
  271.                     'language' => $proposal->getLanguage()
  272.                 )
  273.             );
  274.             if (empty($description)) {
  275.                 $description = array(
  276.                     'description' => ""
  277.                 );
  278.             }
  279.             $data_destionation[$destino->getTitle()] = array(
  280.                 'image' => $gallery['0'],
  281.                 'destino' => $destino,
  282.                 'gallery' => $gallery,
  283.                 'description' => $description,
  284.             );
  285.         }
  286.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  287.         //        $sidebarData = $this->sidebarAction($token, "", "");
  288.         return $this->render(
  289.             'MDS/EventsPresentationBundle/presentation/destinos.html.twig',
  290.             array(
  291.                 'token' => $token,
  292.                 'proposal' => $proposal,
  293.                 'destination' => $data_destionation,
  294.                 'company' => $company,
  295.                 'client' => $client,
  296.                 'selectType' => $selectType,
  297.                 //                'sidebar' => $sidebarData
  298.             )
  299.         );
  300.     }
  301.     /**
  302.      * @Route("/cover/{token}", name="presentation_cover_token")
  303.      */
  304.     public function coverAction($token, Request $request)
  305.     {
  306.         //d('entra en cover con token');
  307.         $disclaimer =  $request->getSession()->get('_disclaimer');
  308.         $em = $this->getDoctrine()->getManager();
  309.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  310.         if ($proposal->getStatus() == "Cancel") {
  311.             return $this->redirectToRoute(
  312.                 'presentation_error_cancel',
  313.                 array(
  314.                     'token' => $token
  315.                 )
  316.             );
  317.         }
  318.         //        d($proposal);
  319.         //        exit();
  320.         $parameters = array(
  321.             'proposalId' => $proposal->getId(),
  322.             'recommended' => '1',
  323.             'priority' => '0',
  324.         );
  325.         $dql = 'SELECT p
  326.                 FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  327.                 WHERE p.proposalId = :proposalId 
  328.                 AND p.recommended = :recommended
  329.                 AND p.priority != :priority
  330.                 ORDER BY p.priority ASC';
  331.         $query = $em->createQuery($dql)->setParameters($parameters);
  332.         $controlbudgets = $query->getResult();
  333.         $parametersNew = array(
  334.             'proposalId' => $proposal->getId(),
  335.             'recommended' => '0',
  336.             'priority' => '0',
  337.         );
  338.         $dqlNew = 'SELECT p
  339.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  340.                     WHERE p.proposalId = :proposalId 
  341.                     AND p.recommended = :recommended
  342.                     AND p.priority != :priority
  343.                     ORDER BY p.priority ASC';
  344.         $queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
  345.         $controlbudgetsNew = $queryNew->getResult();
  346.         $controlbudget = array();
  347.         foreach ($controlbudgets as $controlbudge) {
  348.             $imagen = array();
  349.             $control_query = $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($controlbudge->getId());
  350.             foreach ($control_query as $controlquery) {
  351.                 //                d($controlquery);
  352.                 if (count($imagen) <= "3") { // 3 porque tomamos en cuenta el 0 que tambien toma del indice de array
  353.                     /*CONTROL GENERAL*/
  354.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlquery->getSupplierId());
  355.                     if (!is_null($controlgeneral)) {
  356.                         $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  357.                             array(
  358.                                 'supplierId' => $controlgeneral->getId(),
  359.                                 'servicesCatId' => '0',
  360.                                 'servicesCategory' => 'General',
  361.                                 'servicesId' => '0',
  362.                                 'controlId' => '0'
  363.                             )
  364.                         );
  365.                         if (!is_null($sqlsuppliers_gallery)) {
  366.                             $imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
  367.                             $imagen[$controlgeneral->getId()] = $imagenSmall;
  368.                         }
  369.                     }
  370.                 }
  371.             }
  372.             $controlbudget[] = array(
  373.                 'budget' => $controlbudge,
  374.                 'imagen' => $imagen,
  375.             );
  376.         }
  377.         //        d($controlbudget);
  378.         $descriptionpresenta = $em->getRepository(ProposalDescription::class)->findOneBy(
  379.             array(
  380.                 'proposalId' => $proposal->getId(),
  381.                 'language' => $proposal->getLanguage()
  382.             )
  383.         );
  384.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  385.         // Usuario Anonimo es = "anon."
  386.         if ($user_logueado == "anon." && is_null($disclaimer)) {
  387.             $proposal->setViewedAt(new \DateTime("now"));
  388.             $em->persist($proposal);
  389.             $em->flush();
  390.             $ipclient = $request->getClientIp();
  391.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  392.             $mailAgent[] = $agent->getEmail();
  393.             $agentMail = $agent->getEmail();
  394.             $passGmail = $agent->getPassGmail();
  395.             $firmGmail = $agent->getFirmGmail();
  396.             $mailAgentSent = array(
  397.                 $agent->getEmail() => $agent->getName() . ' ' . $agent->getLastName()
  398.             );
  399.             $data = array(
  400.                 '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,
  401.                 'firm' => $firmGmail,
  402.             );
  403.             $mailTodos = array_merge($mailAgent);
  404.             // EJECUTAR ENVIO DE ALERTA DE VISTO POR CLIENTE
  405.             $transporter = new Swift_SmtpTransport();
  406.             $transporter->setHost('smtp.gmail.com')
  407.                 ->setEncryption('ssl') //ssl / tls
  408.                 ->setPort(465) // 465 / 587
  409.                 ->setUsername('desarrollo@develup.solutions')
  410.                 ->setPassword('utvh hzoi wfdo ztjs');
  411.             $mailer = new Swift_Mailer($transporter);
  412.             $message = new Swift_Message();
  413.             $message->setSubject('P#' . $proposal->getId() . ', Alerta De Presentación Vista por cliente')
  414.                 ->setSender($agentMail)
  415.                 ->setFrom($mailAgentSent)
  416.                 ->setReplyTo($mailAgentSent)
  417.                 ->setTo($mailTodos)
  418.                 ->setBody(
  419.                     $this->renderView(
  420.                         'mail/structure-mail.html.twig',
  421.                         array('data' => $data)
  422.                     ),
  423.                     'text/html'
  424.                 );
  425.             $mailer->send($message);
  426.             // Guardo en historico de seguimiento
  427.             $textHistory = $this->translator->trans('Presentation View by client');
  428.             $history = $this->TracingHistoryOperations($proposal->getId(), $textHistory . ', Ip:' . $ipclient);
  429.         }
  430.         if (is_null($proposal->getSelectType())) {
  431.             $selectType = array();
  432.         } else {
  433.             $selectType = explode(",", $proposal->getSelectType());
  434.             $selectType_array = explode(",", $proposal->getSelectType());
  435.             //            foreach ($selectType_array as $type){
  436.             //                $servicesType = $this->servicesAction($token, $type, '');
  437.             //                $selectType[$type] = $servicesType;
  438.             //            }
  439.         }
  440.         //        d($selectType);
  441.         //        exit();
  442.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  443.         foreach ($client as $item) {
  444.             $item->setTitle(strtoupper($item->getTitle()));
  445.         }
  446.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  447.             array(
  448.                 'proposalId' => $proposal->getId(),
  449.                 'disabledPresentation' => '0',
  450.             )
  451.         );
  452.         $data_destionation = array();
  453.         $cont_destino = 0;
  454.         foreach ($proposal_Control as $proposalControl) {
  455.             $cont_destino += 1;
  456.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  457.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  458.             $description = array();
  459.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  460.                 array(
  461.                     'destinationId' => $proposalControl->getDestinationId(),
  462.                     'language' => $proposal->getLanguage()
  463.                 )
  464.             );
  465.             $data_destionation[$destino->getTitle()] = array(
  466.                 'destino' => $destino,
  467.                 'gallery' => $gallery,
  468.                 'description' => ($description != null ? $description->getDescription() : null),
  469.             );
  470.             //            d($data_destionation[$destino->getTitle()]);
  471.         }
  472.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  473.         //        d($company);
  474.         //////////////////////////////////////////////
  475.         /* CODIGO PARA TRAER A LOS AGENTES         */
  476.         ////////////////////////////////////////////
  477.         $agentMaster = array();
  478.         if (!empty($proposal->getAgentId())) {
  479.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  480.             $agentMaster = array(
  481.                 'name' => $agent->getName(),
  482.                 'lastname' => $agent->getLastname(),
  483.                 'picture' => $agent->getPicture(),
  484.             );
  485.         }
  486.         ////////////////////////////////////////////
  487.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  488.         //////////////////////////////////////////
  489.         //d($proposal, $client, $company, $data_destionation);
  490.         //d( $agentMaster);
  491.         $sidebarData = $this->sidebarAction($token, "", "");
  492.         $serializer = SerializerBuilder::create()->build();
  493.         $arraySidebar = $serializer->toArray($sidebarData);
  494.         //        d($services);
  495.         $agendas =  $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
  496.             array(
  497.                 'proposalId' => $proposal->getId()
  498.             ),
  499.             array(
  500.                 'priority' => 'DESC',
  501.                 'recommended' => 'ASC',
  502.             )
  503.         );
  504.         //        $showAgenda = array();
  505.         //        foreach ($agendas as $item) {
  506.         //            $showAgenda[] = $item;
  507.         //        }
  508.         if (is_null($disclaimer)) {
  509.             $disclaimer =  $request->getSession()->set('_disclaimer', 'ok');
  510.         }
  511.         $musica =  $em->getRepository(PresentationMusic::class)->findOneBy(
  512.             array(
  513.                 'id' => $proposal->getIdMusic()
  514.             )
  515.         );
  516.         //        d($controlbudgetsNew);
  517.         return $this->render(
  518.             'MDS/EventsPresentationBundle/presentation/start-client.html.twig',
  519.             array(
  520.                 'token' => $token,
  521.                 'company' => $company,
  522.                 'proposal' => $proposal,
  523.                 'client' => $client,
  524.                 'selectType' => $selectType,
  525.                 'destination' => $data_destionation,
  526.                 //                'agent'=> $agentMaster,
  527.                 'countDestino' => $cont_destino,
  528.                 //                'sidebar'=>$arraySidebar,
  529.                 'descripction' => $descriptionpresenta,
  530.                 'budgets' => $controlbudget,
  531.                 'budgetNew' => $controlbudgetsNew,
  532.                 'disclaimer' => $disclaimer,
  533.                 'legal' => false,
  534.                 'idea' => '',
  535.                 'activity' => '',
  536.                 'music' => $musica,
  537.                 //                'agendas' => $showAgenda
  538.                 //                'destino' => $destino_details,
  539.                 //                'gallerys' => $gallery_details,
  540.                 //                'description' => $description_details,
  541.             )
  542.         );
  543.     }
  544.     /**
  545.      * @Route("/agent/{token}", name="presentation_agent_token")
  546.      */
  547.     public function AgentAction($token, Request $request)
  548.     {
  549.         $em = $this->getDoctrine()->getManager();
  550.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  551.         if ($proposal->getStatus() == "Cancel") {
  552.             return $this->redirectToRoute(
  553.                 'presentation_error_cancel',
  554.                 array(
  555.                     'token' => $token
  556.                 )
  557.             );
  558.         }
  559.         //////////////////////////////////////////////
  560.         /* CODIGO PARA TRAER A LOS AGENTES         */
  561.         ////////////////////////////////////////////
  562.         /* inicio array con los agentes */
  563.         $agentes_data = $em->getRepository(ProposalAgents::class)->findOneByIdProp($proposal->getId());
  564.         $agentArray = array();
  565.         if (!is_null($proposal->getAgentId())) {
  566.             //            $agenteTwo=array();
  567.             //            if(!empty($proposal->getAgentTwoId())){
  568.             //                $agenteTwo= explode(",", $proposal->getAgentTwoId());
  569.             //                array_push($agentArray, $agenteTwo);
  570.             //            }
  571.             //            d($proposal->getAgencommercialId());
  572.             $agentes_data = $em->getRepository(ProposalAgents::class)->findOneByIdProp($proposal->getId());
  573.             $agentes_data->getAgOne() == 0 ? null : array_push($agentArray, $agentes_data->getAgOne());
  574.             $agentes_data->getAgTwo() == 0 ? null : array_push($agentArray, $agentes_data->getAgTwo());
  575.             $agentes_data->getAgThree() == 0 ? null : array_push($agentArray, $agentes_data->getAgThree());
  576.             $agentes_data->getAgFour() == 0 ? null : array_push($agentArray, $agentes_data->getAgFour());
  577.             //            d($agentAraData);
  578.             $agentProposal = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  579.             $teamLeader = $em->getRepository(User::class)->findOneBy(
  580.                 array(
  581.                     'team' => $agentProposal->getTeam(),
  582.                     'teamleader' => 1,
  583.                 )
  584.             );
  585.             if (!empty($teamLeader)) {
  586.                 array_push($agentArray, $teamLeader->getId());
  587.             }
  588.             $proposal->getAgencommercialId() == 0 ? null : array_push($agentArray, $proposal->getAgencommercialId());
  589.             array_push($agentArray, 6);
  590.             array_push($agentArray, 14);
  591.             //            array_push($agentArray, 1);
  592.             //            array_push($agentArray, 1);
  593.             //            $dataAgents=array();
  594.             //            d($agentArray);
  595.             foreach ($agentArray as $agent) {
  596.                 //                d($agent); exit();
  597.                 if ($agent != 0) {
  598.                     $users = $em->getRepository(User::class)->findOneById($agent);
  599.                     $dataAgents[] = array(
  600.                         'id' => $agent,
  601.                         'fullname' => $users->getName() . ' ' . $users->getLastName(),
  602.                         'picture' => $users->getPicture(),
  603.                         'jobtitle' => $users->getJobTitle(),
  604.                         'description' => $users->getDescription(),
  605.                     );
  606.                 }
  607.             }
  608.             //            d($dataAgents);
  609.             /* fin array con los agentes */
  610.         }
  611.         ////////////////////////////////////////////
  612.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  613.         //////////////////////////////////////////
  614.         if (is_null($proposal->getSelectType())) {
  615.             $selectType = array();
  616.         } else {
  617.             $selectType = explode(",", $proposal->getSelectType());
  618.         }
  619.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  620.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  621.         //        d($controlbudgetsNew);
  622.         return $this->render(
  623.             'MDS/EventsPresentationBundle/presentation/agent.html.twig',
  624.             array(
  625.                 'token' => $token,
  626.                 'company' => $company,
  627.                 'proposal' => $proposal,
  628.                 'client' => $client,
  629.                 'selectType' => $selectType,
  630.                 //                'destination' => $data_destionation,
  631.                 'dataAgents' => $dataAgents,
  632.             )
  633.         );
  634.     }
  635.     /**
  636.      * @Route("/slider/getImage/", name="get_city_image")
  637.      */
  638.     public function getImageAction(Request $request)
  639.     {
  640.         //        $selectedCity = $ciudad;
  641.         $selectedCity = $_POST['selectedCity'];
  642.         $em = $this->getDoctrine()->getManager();
  643.         //        $imageOfDestination = $em->getRepository(Regions::class)->findBycountry_id($cod_pais);
  644.         $destino = $em->getRepository(Destination::class)->findOneBy(array(
  645.             'title' => $selectedCity,
  646.         ));
  647.         $imageOfDestination = $em->getRepository(DestinationGallery::class)->findOneBy(
  648.             array(
  649.                 'destinationId' => $destino->getId()
  650.             )
  651.         );
  652.         $result = array(
  653.             'imageCityFound' => $imageOfDestination->getImageSmall(),
  654.         );
  655.         $response = new JsonResponse($result);
  656.         //        return 'hola';
  657.         return $response;
  658.     }
  659.     /**
  660.      * @Route("budget/xls/{idp}/{token}", name="presentation_xls_view")
  661.      */
  662.     public function xlsViewAction($token, $idp, Request $request)
  663.     {
  664.         $em = $this->getDoctrine()->getManager();
  665.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  666.         if ($proposal->getStatus() == "Cancel") {
  667.             return $this->redirectToRoute(
  668.                 'presentation_error_cancel',
  669.                 array(
  670.                     'token' => $token
  671.                 )
  672.             );
  673.         }
  674.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  675.         // Usuario Anonimo es = "anon."
  676.         if ($user_logueado == "anon.") {
  677.             $proposal->setViewedAt(new \DateTime("now"));
  678.             $em->persist($proposal);
  679.             $em->flush();
  680.         }
  681.         $selectType = explode(",", $proposal->getSelectType());
  682.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  683.         $country = $em->getRepository(Country::class)->findOneById($client->getCountry());
  684.         $client->setCountry($country->getCountry());
  685.         $regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
  686.         $client->setRegion($regions->getRegion());
  687.         $province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
  688.         $client->setProvince($province->getName());
  689.         $cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  690.         $client->setPopulation($cities->getCity());
  691.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  692.             array(
  693.                 'proposalId' => $proposal->getId(),
  694.                 'disabled' => '0',
  695.             )
  696.         );
  697.         $data_destionation = array();
  698.         $cont_destino = 0;
  699.         foreach ($proposal_Control as $proposalControl) {
  700.             $cont_destino += 1;
  701.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  702.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  703.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  704.                 array(
  705.                     'destinationId' => $proposalControl->getDestinationId(),
  706.                     'language' => $proposal->getLanguage()
  707.                 )
  708.             );
  709.             $data_destionation[$destino->getTitle()] = array(
  710.                 'destino' => $destino,
  711.                 'gallery' => $gallery,
  712.                 'description' => $description,
  713.             );
  714.         }
  715.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  716.         ////////////////////////////////////////////////////////////////////////////////////////////////
  717.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  718.         ////////////////////////////////////////////////////////////////////////////////////////////////
  719.         $controlproposal = $em->getRepository(ProposalControl::class)->findBy(
  720.             array(
  721.                 'proposalId' => $proposal->getId(),
  722.                 'disabled' => '0',
  723.             )
  724.         );
  725.         $controlbudget = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  726.         $controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  727.         $filtro2 = array();
  728.         foreach ($controlproposal as $consultabudget2) {
  729.             $filtro2[] = $consultabudget2->getDestinationId();
  730.         }
  731.         $services_supplier = array();
  732.         $services_ideas = array();
  733.         $budget = array();
  734.         $content_data = array();
  735.         $destination = array();
  736.         //        $totales_neto="";
  737.         //        $totales_total="";
  738.         $totales_neto = 0;
  739.         $totales_total = 0;
  740.         $totales_iva = array();
  741.         $data = array();
  742.         foreach ($filtro2 as $destinobudget) {
  743.             $destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
  744.             $destino = $destination->getTitle();
  745.             $consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  746.                 array(
  747.                     'controlId' => $idp,
  748.                     'destinationId' => $destinobudget,
  749.                     'itemsserviceIdFather' => '0'
  750.                 ),
  751.                 array(
  752.                     'rank' => 'DESC'
  753.                 )
  754.             );
  755.             $filtro = array();
  756.             foreach ($consulta_budget as $consultabudget) {
  757.                 if (!is_null($consultabudget->getIdeaId())) {
  758.                     $filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
  759.                 }
  760.                 if (!is_null($consultabudget->getActivityId())) {
  761.                     $filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
  762.                 }
  763.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
  764.                     $filtro['whiteservice']['0'][] = $consultabudget;
  765.                 }
  766.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
  767.                     $filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
  768.                 }
  769.                 //                $filtro[$consultabudget->getSupplierId()] = $consultabudget;
  770.             }
  771.             //            d($filtro);
  772.             //
  773.             $master = "";
  774.             $services = array();
  775.             $whiteservice = array();
  776.             $idea = array();
  777.             $activity = array();
  778.             $supplier = array();
  779.             foreach ($filtro as $key => $ideaOsupplier) {
  780.                 //                d("·········································", $ideaOsupplier);
  781.                 foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
  782.                     //                    d($ideaOsupplierAdentro);
  783.                     $services = array();
  784.                     //                    $total_neto="";
  785.                     //                    $total_total="";
  786.                     $total_neto = 0;
  787.                     $total_total = 0;
  788.                     foreach ($ideaOsupplierAdentro as $servicesbudget) {
  789.                         //                        d($servicesbudget);
  790.                         $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  791.                         if (empty($totales_iva[$servicesbudget->getIva()])) {
  792.                             $totales_iva[$servicesbudget->getIva()] = 0;
  793.                         }
  794.                         $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  795.                         $total_neto += $servicesbudget->getNetAmount();
  796.                         $totales_neto += $servicesbudget->getNetAmount();
  797.                         $total_total += $servicesbudget->getTotal();
  798.                         $totales_total += $servicesbudget->getTotal();
  799.                         if ($key == "whiteservice") {
  800.                             $services_white = $em->getRepository(SettingsCompany::class)->findOneById('1');
  801.                             $master = "whiteservice";
  802.                             $services[] = array(
  803.                                 'service' => $servicesbudget
  804.                             );
  805.                             $whiteservice[$services_white->getId()]  = array(
  806.                                 'datos' => $services_white,
  807.                                 'services' => $services,
  808.                                 'master' => $master,
  809.                                 'neto' => $total_neto,
  810.                                 'total' => $total_total
  811.                             );
  812.                         }
  813.                         if ($key == "activity") {
  814.                             $services_activity = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
  815.                             $master = "activity";
  816.                             $services[] = array(
  817.                                 'service' => $servicesbudget
  818.                             );
  819.                             $activity[$services_activity->getId()] = array(
  820.                                 'datos' => $services_activity,
  821.                                 'services' => $services,
  822.                                 'master' => $master,
  823.                                 'neto' => $total_neto,
  824.                                 'total' => $total_total
  825.                             );
  826.                         }
  827.                         if ($key == "idea") {
  828.                             $services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
  829.                             $master = "idea";
  830.                             $services[] = array(
  831.                                 'service' => $servicesbudget
  832.                             );
  833.                             $idea[$services_ideas->getId()] = array(
  834.                                 'datos' => $services_ideas,
  835.                                 'services' => $services,
  836.                                 'master' => $master,
  837.                                 'neto' => $total_neto,
  838.                                 'total' => $total_total
  839.                             );
  840.                         }
  841.                         if ($key == "supplier") {
  842.                             if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
  843.                                 $servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
  844.                                 $master = "supplier";
  845.                                 //                            foreach($services_supplier as $servicessupplier){
  846.                                 if (!is_null($servicessupplier)) {
  847.                                     switch ($servicessupplier->getStar()) {
  848.                                         case 1:
  849.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i>');
  850.                                             break;
  851.                                         case 2:
  852.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  853.                                             break;
  854.                                         case 3:
  855.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  856.                                             break;
  857.                                         case 4:
  858.                                             $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>');
  859.                                             break;
  860.                                         case 5:
  861.                                             $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');
  862.                                             break;
  863.                                         case 6:
  864.                                             $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>');
  865.                                             break;
  866.                                         case 7:
  867.                                             $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');
  868.                                             break;
  869.                                         case 8:
  870.                                             $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');
  871.                                             break;
  872.                                     }
  873.                                 }
  874.                                 $services[] = array(
  875.                                     'service' => $servicesbudget
  876.                                 );
  877.                                 $supplier[$servicessupplier->getId()] = array(
  878.                                     'datos' => $servicessupplier,
  879.                                     'services' => $services,
  880.                                     'master' => $master,
  881.                                     'neto' => $total_neto,
  882.                                     'total' => $total_total
  883.                                 );
  884.                             }
  885.                         }
  886.                     }
  887.                 }
  888.             }
  889.             $content_data = array(
  890.                 'supplier' => $supplier,
  891.                 'idea' => $idea,
  892.                 'activity' => $activity,
  893.                 'whiteservice' => $whiteservice,
  894.             );
  895.             $data[] = array(
  896.                 'destination' => $destination,
  897.                 'container' => $content_data
  898.             );
  899.         }
  900.         ////////////////////////////////////////////////////////////////////////////////////////////////
  901.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  902.         ////////////////////////////////////////////////////////////////////////////////////////////////
  903.         //////////////////////////////////////////////
  904.         /* CODIGO PARA TRAER A LOS AGENTES         */
  905.         ////////////////////////////////////////////
  906.         $agentMaster = array();
  907.         if (!empty($proposal->getAgentId())) {
  908.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  909.             $agentMaster = array(
  910.                 'name' => $agent->getName(),
  911.                 'lastname' => $agent->getLastname(),
  912.                 'picture' => $agent->getPicture(),
  913.             );
  914.         }
  915.         //            d($data);
  916.         //        $services = $this->servicesAction($token, '', '');
  917.         /*Traducciones*/
  918.         if (!($proposal->getLanguage() == 'ENGLISH')) {
  919.             // Por defecto para todos los idiomas sera un presupuesto en castellano
  920.             $transcategory = $this->translator->trans('Category');
  921.             $transname = $this->translator->trans('Name');
  922.             $transprice = $this->translator->trans('Price');
  923.             $transpricevat = $this->translator->trans('Price with Vat');
  924.             $transunits = $this->translator->trans('Units');
  925.             $transpax = $this->translator->trans('Pax');
  926.             $transdays = $this->translator->trans('Days');
  927.             $transstart = $this->translator->trans('Start');
  928.             $transend = $this->translator->trans('End');
  929.             $transnet = $this->translator->trans('Net');
  930.             $transiva = $this->translator->trans('Iva');
  931.             $transtotal = $this->translator->trans('Total');
  932.         } else {
  933.             $transcategory = 'Category';
  934.             $transname = 'Name';
  935.             $transprice = 'Price';
  936.             $transpricevat = 'Price with Vat';
  937.             $transunits = 'Units';
  938.             $transpax = 'Pax';
  939.             $transdays = 'Days';
  940.             $transstart = 'Start';
  941.             $transend = 'End';
  942.             $transnet = 'Net';
  943.             $transiva = 'Vat';
  944.             $transtotal = 'Total';
  945.         }
  946.         $total = 0;
  947.         $neto = 0;
  948.         // Solicita el servicio de excel
  949.         $phpExcelObject = new Spreadsheet;;
  950.         $phpExcelObject->getProperties()->setCreator("InOut Travel")
  951.             ->setLastModifiedBy("InOut Travel")
  952.             ->setTitle("InOut Travel")
  953.             ->setSubject("InOut Travel")
  954.             ->setDescription("InOut Travel, generado usando clases de PHP")
  955.             ->setKeywords("office 2005 openxml php")
  956.             ->setCategory("Presupuestos");
  957.         $fill = new Fill();
  958.         $numberFormat = new NumberFormat();
  959.         $alignment = new Alignment();
  960.         $estilo = array(
  961.             'alignment' => array(
  962.                 'horizontal' => $alignment::HORIZONTAL_RIGHT,
  963.             )
  964.         );
  965.         $i = 5;
  966.         $tot = 0;
  967.         $k = 0;
  968.         $activesheet = $phpExcelObject->getActiveSheet();
  969.         $drawingobject = new Drawing;
  970.         $drawingobject->setName('Image name');
  971.         $drawingobject->setDescription('Image description');
  972.         //        $drawingobject->setPath(getcwd().'/assets/images/logo/logo20.png');
  973.         $drawingobject->setPath(getcwd() . '/assets/images/logo/logo2022.png');
  974.         $drawingobject->setHeight(60);
  975.         $drawingobject->setOffsetY(20);
  976.         $drawingobject->setCoordinates('K1');
  977.         $drawingobject->setWorksheet($activesheet);
  978.         $phpExcelObject
  979.             ->getActiveSheet()
  980.             ->getStyle('B3:H3')
  981.             ->getFill()
  982.             ->setFillType($fill::FILL_SOLID)
  983.             ->getStartColor()
  984.             ->setRGB('FFA420');
  985.         $phpExcelObject->setActiveSheetIndex(0)
  986.             ->setCellValue('C3', 'PRESUPUESTO : ' . $proposal->getId() . '/' . $idp . ' PROPUESTA : ' . $proposal->getTitle());
  987.         $celdaNeto = '';
  988.         $celdaTotal = '';
  989.         foreach ($data as $key => $destination) {
  990.             //            d($destination['container']['supplier']);
  991.             $phpExcelObject
  992.                 ->getActiveSheet()
  993.                 ->getStyle('A' . $i . ':M' . $i)
  994.                 ->getFill()
  995.                 ->setFillType($fill::FILL_SOLID)
  996.                 ->getStartColor()
  997.                 ->setRGB('FFA420');
  998.             $phpExcelObject->setActiveSheetIndex(0)
  999.                 ->setCellValue('E' . $i, $destination['destination']->getTitle());
  1000.             //          d($destination['destination']->getTitle());
  1001.             $j = $i + 1;
  1002.             if (empty($proposal->getCommission()) or $proposal->getCommission() == 'National') {
  1003.                 if (!empty($destination['container']['supplier'])) {
  1004.                     foreach ($destination['container']['supplier'] as $keySup => $valueSup) {
  1005.                         $phpExcelObject
  1006.                             ->getActiveSheet()
  1007.                             ->getStyle('A' . $j . ':L' . $j)
  1008.                             ->getFill()
  1009.                             ->setFillType($fill::FILL_SOLID)
  1010.                             ->getStartColor()
  1011.                             ->setRGB('B5B8B1');
  1012.                         if (
  1013.                             $valueSup['datos']->getType() == "HOTEL" or
  1014.                             $valueSup['datos']->getType() == "RESTAURANTE"
  1015.                         ) {
  1016.                             $phpExcelObject->setActiveSheetIndex(0)
  1017.                                 ->setCellValue('E' . $j, $valueSup['datos']->getCompany());
  1018.                         } else {
  1019.                             $type = $this->translator->trans($valueSup['datos']->getType());
  1020.                             $phpExcelObject->setActiveSheetIndex(0)
  1021.                                 ->setCellValue('E' . $j, $type);
  1022.                         }
  1023.                         if (!empty($valueSup['services'])) {
  1024.                             $phpExcelObject->setActiveSheetIndex(0)
  1025.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1026.                                 ->setCellValue('B' . ($j + 1), $transname)
  1027.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1028.                                 ->setCellValue('E' . ($j + 1), $transunits)
  1029.                                 ->setCellValue('F' . ($j + 1), $transpax)
  1030.                                 ->setCellValue('G' . ($j + 1), $transdays)
  1031.                                 ->setCellValue('H' . ($j + 1), $transstart)
  1032.                                 ->setCellValue('I' . ($j + 1), $transend)
  1033.                                 ->setCellValue('J' . ($j + 1), $transnet)
  1034.                                 ->setCellValue('K' . ($j + 1), $transiva)
  1035.                                 ->setCellValue('L' . ($j + 1), $transtotal);
  1036.                             $k = $j + 2;
  1037.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1038.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1039.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1040.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1041.                                 $celdaServicioPax = $valueService['service']->getPax();
  1042.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1043.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
  1044.                                 } else {
  1045.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1046.                                         $celdaServicioPax = 1;
  1047.                                     }
  1048.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
  1049.                                 }
  1050.                                 $phpExcelObject->setActiveSheetIndex(0)
  1051.                                     ->setCellValue('A' . $k, $catName)
  1052.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1053.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1054.                                     ->setCellValue('E' . $k, $valueService['service']->getUnits())
  1055.                                     ->setCellValue('F' . $k, $celdaServicioPax)
  1056.                                     ->setCellValue('G' . $k, $valueService['service']->getDays())
  1057.                                     ->setCellValue('H' . $k, $inDate)
  1058.                                     ->setCellValue('I' . $k, $outDate)
  1059.                                     ->setCellValue('J' . $k, $celdaServicioNeto)
  1060.                                     ->setCellValue('K' . $k, $valueService['service']->getIva())
  1061.                                     //                                    ->setCellValue('L' . $k, $valueService['service']->getTotal());
  1062.                                     ->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
  1063.                                 $phpExcelObject
  1064.                                     ->getActiveSheet()
  1065.                                     ->getStyle('J' . $k)
  1066.                                     ->getNumberFormat()
  1067. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1068. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1069.                                     ->setFormatCode('#,##0.00 €');
  1070.                                 $phpExcelObject
  1071.                                     ->getActiveSheet()
  1072.                                     ->getStyle('L' . $k)
  1073.                                     ->getNumberFormat()
  1074. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1075. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1076.                                     ->setFormatCode('#,##0.00 €');
  1077.                                 $k++;
  1078.                             }
  1079.                         }
  1080.                         $j = $k + 1;
  1081.                         //SUBTOTALES
  1082.                         $phpExcelObject->setActiveSheetIndex(0)
  1083.                             ->setCellValue('I' . ($j - 1), 'SUBTOTAL')
  1084.                             ->setCellValue('J' . ($j - 1), $valueSup['neto'])
  1085.                             ->setCellValue('L' . ($j - 1), $valueSup['total']);
  1086.                         $neto += $valueSup['neto'];
  1087.                         $total += $valueSup['total'];
  1088.                         $phpExcelObject
  1089.                             ->getActiveSheet()
  1090.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1091.                             ->getNumberFormat()
  1092.                             ->setFormatCode('#,##0.00 €');
  1093. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1094. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1095.                         $phpExcelObject
  1096.                             ->getActiveSheet()
  1097.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1098.                             ->getFill()
  1099.                             ->setFillType($fill::FILL_SOLID)
  1100.                             ->getStartColor()
  1101.                             ->setRGB('DF3A01');
  1102.                     }
  1103.                     if ($j - 1 == $i) {
  1104.                         //                        d($k,$k);
  1105.                     } else {
  1106.                         $phpExcelObject->getActiveSheet()
  1107.                             ->setCellValue(
  1108.                                 'L' . ($j - 1),
  1109.                                 '=SUM(L' . ($i + 2) . ':L' . ($j - 2) . ')'
  1110.                             );
  1111.                         $phpExcelObject->getActiveSheet()
  1112.                             ->setCellValue(
  1113.                                 'J' . ($j - 1),
  1114.                                 '=SUM(J' . ($i + 2) . ':J' . ($j - 2) . ')'
  1115.                             );
  1116.                         if (empty($celdaNeto)) {
  1117.                             $celdaNeto = '=';
  1118.                         } else {
  1119.                             $celdaNeto = $celdaNeto . ' + ';
  1120.                         }
  1121.                         $celdaNeto = $celdaNeto . 'SUM(J' . ($i + 2) . ':J' . ($j - 2) . ')';
  1122.                         if (empty($celdaTotal)) {
  1123.                             $celdaTotal = '=';
  1124.                         } else {
  1125.                             $celdaTotal = $celdaTotal . ' + ';
  1126.                         }
  1127.                         $celdaTotal = $celdaTotal . 'SUM(L' . ($i + 2) . ':L' . ($j - 2) . ')';
  1128.                     }
  1129.                     $i = $j + 1;
  1130.                 }
  1131.                 if (!empty($destination['container']['idea'])) {
  1132.                     foreach ($destination['container']['idea'] as $keySup => $valueSup) {
  1133.                         $phpExcelObject
  1134.                             ->getActiveSheet()
  1135.                             ->getStyle('A' . $j . ':L' . $j)
  1136.                             ->getFill()
  1137.                             ->setFillType($fill::FILL_SOLID)
  1138.                             ->getStartColor()
  1139.                             ->setRGB('B5B8B1');
  1140.                         $phpExcelObject->setActiveSheetIndex(0)
  1141.                             ->setCellValue('E' . $j, $valueSup['datos']->getName());
  1142.                         if (!empty($valueSup['services'])) {
  1143.                             $phpExcelObject->setActiveSheetIndex(0)
  1144.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1145.                                 ->setCellValue('B' . ($j + 1), $transname)
  1146.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1147.                                 ->setCellValue('E' . ($j + 1), $transunits)
  1148.                                 ->setCellValue('F' . ($j + 1), $transpax)
  1149.                                 ->setCellValue('G' . ($j + 1), $transdays)
  1150.                                 ->setCellValue('H' . ($j + 1), $transstart)
  1151.                                 ->setCellValue('I' . ($j + 1), $transend)
  1152.                                 ->setCellValue('J' . ($j + 1), $transnet)
  1153.                                 ->setCellValue('K' . ($j + 1), $transiva)
  1154.                                 ->setCellValue('L' . ($j + 1), $transtotal);
  1155.                             $k = $j + 2;
  1156.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1157.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1158.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1159.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1160.                                 $celdaServicioPax = $valueService['service']->getPax();
  1161.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1162.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
  1163.                                 } else {
  1164.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1165.                                         $celdaServicioPax = 1;
  1166.                                     }
  1167.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
  1168.                                 }
  1169.                                 $phpExcelObject->setActiveSheetIndex(0)
  1170.                                     ->setCellValue('A' . $k, $catName)
  1171.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1172.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1173.                                     ->setCellValue('E' . $k, $valueService['service']->getUnits())
  1174.                                     ->setCellValue('F' . $k, $celdaServicioPax)
  1175.                                     ->setCellValue('G' . $k, $valueService['service']->getDays())
  1176.                                     ->setCellValue('H' . $k, $inDate)
  1177.                                     ->setCellValue('I' . $k, $outDate)
  1178.                                     ->setCellValue('J' . $k, $celdaServicioNeto)
  1179.                                     ->setCellValue('K' . $k, $valueService['service']->getIva())
  1180.                                     ->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
  1181.                                 //                                    ->setCellValue('L' . $k, $valueService['service']->getTotal());
  1182.                                 $phpExcelObject
  1183.                                     ->getActiveSheet()
  1184.                                     ->getStyle('J' . $k)
  1185.                                     ->getNumberFormat()
  1186.                                     ->setFormatCode('#,##0.00 €');
  1187. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1188. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1189.                                 $phpExcelObject
  1190.                                     ->getActiveSheet()
  1191.                                     ->getStyle('L' . $k)
  1192.                                     ->getNumberFormat()
  1193.                                     ->setFormatCode('#,##0.00 €');
  1194. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1195. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1196.                                 $k++;
  1197.                             }
  1198.                         }
  1199.                         $j = $k + 1;
  1200.                         //SUBTOTALES
  1201.                         $phpExcelObject->setActiveSheetIndex(0)
  1202.                             ->setCellValue('I' . ($j - 1), 'SUBTOTAL')
  1203.                             ->setCellValue('J' . ($j - 1), $valueSup['neto'])
  1204.                             ->setCellValue('L' . ($j - 1), $valueSup['total']);
  1205.                         $neto += $valueSup['neto'];
  1206.                         $total += $valueSup['total'];
  1207.                         $phpExcelObject
  1208.                             ->getActiveSheet()
  1209.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1210.                             ->getNumberFormat()
  1211.                             ->setFormatCode('#,##0.00 €');
  1212. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1213. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1214.                         $phpExcelObject
  1215.                             ->getActiveSheet()
  1216.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1217.                             ->getFill()
  1218.                             ->setFillType($fill::FILL_SOLID)
  1219.                             ->getStartColor()
  1220.                             ->setRGB('DF3A01');
  1221.                     }
  1222.                     if ($j - 1 == $i) {
  1223.                         //                        d($k,$k);
  1224.                     } else {
  1225.                         $phpExcelObject->getActiveSheet()
  1226.                             ->setCellValue(
  1227.                                 'L' . ($j - 1),
  1228.                                 '=SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')'
  1229.                             );
  1230.                         $phpExcelObject->getActiveSheet()
  1231.                             ->setCellValue(
  1232.                                 'J' . ($j - 1),
  1233.                                 '=SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')'
  1234.                             );
  1235.                         if (empty($celdaNeto)) {
  1236.                             $celdaNeto = '=';
  1237.                         } else {
  1238.                             $celdaNeto = $celdaNeto . ' + ';
  1239.                         }
  1240.                         $celdaNeto = $celdaNeto . 'SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')';
  1241.                         if (empty($celdaTotal)) {
  1242.                             $celdaTotal = '=';
  1243.                         } else {
  1244.                             $celdaTotal = $celdaTotal . ' + ';
  1245.                         }
  1246.                         $celdaTotal = $celdaTotal . 'SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')';
  1247.                     }
  1248.                     $i = $j + 1;
  1249.                 }
  1250.                 if (!empty($destination['container']['activity'])) {
  1251.                     foreach ($destination['container']['activity'] as $keySup => $valueSup) {
  1252.                         $phpExcelObject
  1253.                             ->getActiveSheet()
  1254.                             ->getStyle('A' . $j . ':L' . $j)
  1255.                             ->getFill()
  1256.                             ->setFillType($fill::FILL_SOLID)
  1257.                             ->getStartColor()
  1258.                             ->setRGB('B5B8B1');
  1259.                         $phpExcelObject->setActiveSheetIndex(0)
  1260.                             ->setCellValue('E' . $j, $valueSup['datos']->getName());
  1261.                         if (!empty($valueSup['services'])) {
  1262.                             $phpExcelObject->setActiveSheetIndex(0)
  1263.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1264.                                 ->setCellValue('B' . ($j + 1), $transname)
  1265.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1266.                                 ->setCellValue('E' . ($j + 1), $transunits)
  1267.                                 ->setCellValue('F' . ($j + 1), $transpax)
  1268.                                 ->setCellValue('G' . ($j + 1), $transdays)
  1269.                                 ->setCellValue('H' . ($j + 1), $transstart)
  1270.                                 ->setCellValue('I' . ($j + 1), $transend)
  1271.                                 ->setCellValue('J' . ($j + 1), $transnet)
  1272.                                 ->setCellValue('K' . ($j + 1), $transiva)
  1273.                                 ->setCellValue('L' . ($j + 1), $transtotal);
  1274.                             $k = $j + 2;
  1275.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1276.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1277.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1278.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1279.                                 $celdaServicioPax = $valueService['service']->getPax();
  1280.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1281.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
  1282.                                 } else {
  1283.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1284.                                         $celdaServicioPax = 1;
  1285.                                     }
  1286.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
  1287.                                 }
  1288.                                 $phpExcelObject->setActiveSheetIndex(0)
  1289.                                     ->setCellValue('A' . $k, $catName)
  1290.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1291.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1292.                                     ->setCellValue('E' . $k, $valueService['service']->getUnits())
  1293.                                     ->setCellValue('F' . $k, $celdaServicioPax)
  1294.                                     ->setCellValue('G' . $k, $valueService['service']->getDays())
  1295.                                     ->setCellValue('H' . $k, $inDate)
  1296.                                     ->setCellValue('I' . $k, $outDate)
  1297.                                     ->setCellValue('J' . $k, $celdaServicioNeto)
  1298.                                     ->setCellValue('K' . $k, $valueService['service']->getIva())
  1299.                                     ->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
  1300.                                 //                                    ->setCellValue('L' . $k, $valueService['service']->getTotal());
  1301.                                 $phpExcelObject
  1302.                                     ->getActiveSheet()
  1303.                                     ->getStyle('J' . $k)
  1304.                                     ->getNumberFormat()
  1305.                                     ->setFormatCode('#,##0.00 €');
  1306. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1307. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1308.                                 $phpExcelObject
  1309.                                     ->getActiveSheet()
  1310.                                     ->getStyle('L' . $k)
  1311.                                     ->getNumberFormat()
  1312.                                     ->setFormatCode('#,##0.00 €');
  1313. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1314. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1315.                                 $k++;
  1316.                             }
  1317.                         }
  1318.                         $j = $k + 1;
  1319.                         //SUBTOTALES
  1320.                         $phpExcelObject->setActiveSheetIndex(0)
  1321.                             ->setCellValue('I' . ($j - 1), 'SUBTOTAL')
  1322.                             ->setCellValue('J' . ($j - 1), $valueSup['neto'])
  1323.                             ->setCellValue('L' . ($j - 1), $valueSup['total']);
  1324.                         $neto += $valueSup['neto'];
  1325.                         $total += $valueSup['total'];
  1326.                         $phpExcelObject
  1327.                             ->getActiveSheet()
  1328.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1329.                             ->getNumberFormat()
  1330.                             ->setFormatCode('#,##0.00 €');
  1331. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1332. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1333.                         $phpExcelObject
  1334.                             ->getActiveSheet()
  1335.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1336.                             ->getFill()
  1337.                             ->setFillType($fill::FILL_SOLID)
  1338.                             ->getStartColor()
  1339.                             ->setRGB('DF3A01');
  1340.                     }
  1341.                     if ($j - 1 == $i) {
  1342.                         //                        d($k,$k);
  1343.                     } else {
  1344.                         $phpExcelObject->getActiveSheet()
  1345.                             ->setCellValue(
  1346.                                 'L' . ($j - 1),
  1347.                                 '=SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')'
  1348.                             );
  1349.                         $phpExcelObject->getActiveSheet()
  1350.                             ->setCellValue(
  1351.                                 'J' . ($j - 1),
  1352.                                 '=SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')'
  1353.                             );
  1354.                         if (empty($celdaNeto)) {
  1355.                             $celdaNeto = '=';
  1356.                         } else {
  1357.                             $celdaNeto = $celdaNeto . ' + ';
  1358.                         }
  1359.                         $celdaNeto = $celdaNeto . 'SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')';
  1360.                         if (empty($celdaTotal)) {
  1361.                             $celdaTotal = '=';
  1362.                         } else {
  1363.                             $celdaTotal = $celdaTotal . ' + ';
  1364.                         }
  1365.                         $celdaTotal = $celdaTotal . 'SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')';
  1366.                     }
  1367.                     $i = $j + 1;
  1368.                 }
  1369.                 if (!empty($destination['container']['whiteservice'])) {
  1370.                     foreach ($destination['container']['whiteservice'] as $keySup => $valueSup) {
  1371.                         $phpExcelObject
  1372.                             ->getActiveSheet()
  1373.                             ->getStyle('A' . $j . ':L' . $j)
  1374.                             ->getFill()
  1375.                             ->setFillType($fill::FILL_SOLID)
  1376.                             ->getStartColor()
  1377.                             ->setRGB('B5B8B1');
  1378.                         $phpExcelObject->setActiveSheetIndex(0)
  1379.                             ->setCellValue('E' . $j, $valueSup['datos']->getCompany());
  1380.                         if (!empty($valueSup['services'])) {
  1381.                             $phpExcelObject->setActiveSheetIndex(0)
  1382.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1383.                                 ->setCellValue('B' . ($j + 1), $transname)
  1384.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1385.                                 ->setCellValue('E' . ($j + 1), $transunits)
  1386.                                 ->setCellValue('F' . ($j + 1), $transpax)
  1387.                                 ->setCellValue('G' . ($j + 1), $transdays)
  1388.                                 ->setCellValue('H' . ($j + 1), $transstart)
  1389.                                 ->setCellValue('I' . ($j + 1), $transend)
  1390.                                 ->setCellValue('J' . ($j + 1), $transnet)
  1391.                                 ->setCellValue('K' . ($j + 1), $transiva)
  1392.                                 ->setCellValue('L' . ($j + 1), $transtotal);
  1393.                             $k = $j + 2;
  1394.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1395.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1396.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1397.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1398.                                 $celdaServicioPax = $valueService['service']->getPax();
  1399.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1400.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*G' . $k . ')';
  1401.                                 } else {
  1402.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1403.                                         $celdaServicioPax = 1;
  1404.                                     }
  1405.                                     $celdaServicioNeto = '=(D' . $k . '*E' . $k . '*F' . $k . '*G' . $k . ')';
  1406.                                 }
  1407.                                 $phpExcelObject->setActiveSheetIndex(0)
  1408.                                     ->setCellValue('A' . $k, $catName)
  1409.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1410.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1411.                                     ->setCellValue('E' . $k, $valueService['service']->getUnits())
  1412.                                     ->setCellValue('F' . $k, $celdaServicioPax)
  1413.                                     ->setCellValue('G' . $k, $valueService['service']->getDays())
  1414.                                     ->setCellValue('H' . $k, $inDate)
  1415.                                     ->setCellValue('I' . $k, $outDate)
  1416.                                     ->setCellValue('J' . $k, $celdaServicioNeto)
  1417.                                     ->setCellValue('K' . $k, $valueService['service']->getIva())
  1418.                                     ->setCellValue('L' . $k, '=SUM(' . 'J' . $k . ' + (J' . $k . '* K' . $k . ')/100)');
  1419.                                 //                                    ->setCellValue('L' . $k, $valueService['service']->getTotal());
  1420.                                 $phpExcelObject
  1421.                                     ->getActiveSheet()
  1422.                                     ->getStyle('J' . $k)
  1423.                                     ->getNumberFormat()
  1424.                                     ->setFormatCode('#,##0.00 €');
  1425. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1426. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1427.                                 $phpExcelObject
  1428.                                     ->getActiveSheet()
  1429.                                     ->getStyle('L' . $k)
  1430.                                     ->getNumberFormat()
  1431.                                     ->setFormatCode('#,##0.00 €');
  1432. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1433. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1434.                                 $k++;
  1435.                             }
  1436.                         }
  1437.                         $j = $k + 1;
  1438.                         //SUBTOTALES
  1439.                         $phpExcelObject->setActiveSheetIndex(0)
  1440.                             ->setCellValue('I' . ($j - 1), 'SUBTOTAL')
  1441.                             ->setCellValue('J' . ($j - 1), $valueSup['neto'])
  1442.                             ->setCellValue('L' . ($j - 1), $valueSup['total']);
  1443.                         $neto += $valueSup['neto'];
  1444.                         $total += $valueSup['total'];
  1445.                         $phpExcelObject
  1446.                             ->getActiveSheet()
  1447.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1448.                             ->getNumberFormat()
  1449.                             ->setFormatCode('#,##0.00 €');
  1450. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1451. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1452.                         $phpExcelObject
  1453.                             ->getActiveSheet()
  1454.                             ->getStyle('I' . ($j - 1) . ':L' . ($j - 1))
  1455.                             ->getFill()
  1456.                             ->setFillType($fill::FILL_SOLID)
  1457.                             ->getStartColor()
  1458.                             ->setRGB('DF3A01');
  1459.                     }
  1460.                     if ($j - 1 == $i) {
  1461.                         //                        d($k,$k);
  1462.                     } else {
  1463.                         $phpExcelObject->getActiveSheet()
  1464.                             ->setCellValue(
  1465.                                 'L' . ($j - 1),
  1466.                                 '=SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')'
  1467.                             );
  1468.                         $phpExcelObject->getActiveSheet()
  1469.                             ->setCellValue(
  1470.                                 'J' . ($j - 1),
  1471.                                 '=SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')'
  1472.                             );
  1473.                         if (empty($celdaNeto)) {
  1474.                             $celdaNeto = '=';
  1475.                         } else {
  1476.                             $celdaNeto = $celdaNeto . ' + ';
  1477.                         }
  1478.                         $celdaNeto = $celdaNeto . 'SUM(J' . ($i + 1) . ':J' . ($j - 2) . ')';
  1479.                         if (empty($celdaTotal)) {
  1480.                             $celdaTotal = '=';
  1481.                         } else {
  1482.                             $celdaTotal = $celdaTotal . ' + ';
  1483.                         }
  1484.                         $celdaTotal = $celdaTotal . 'SUM(L' . ($i + 1) . ':L' . ($j - 2) . ')';
  1485.                     }
  1486.                     $i = $j + 1;
  1487.                 }
  1488.             } else {
  1489.                 // *****************************************************************************************************
  1490.                 //                                      Caso internacional
  1491.                 // *****************************************************************************************************
  1492.                 if (!empty($destination['container']['supplier'])) {
  1493.                     foreach ($destination['container']['supplier'] as $keySup => $valueSup) {
  1494.                         $phpExcelObject
  1495.                             ->getActiveSheet()
  1496.                             ->getStyle('A' . $j . ':M' . $j)
  1497.                             ->getFill()
  1498.                             ->setFillType($fill::FILL_SOLID)
  1499.                             ->getStartColor()
  1500.                             ->setRGB('B5B8B1');
  1501.                         if (
  1502.                             $valueSup['datos']->getType() == "HOTEL" or
  1503.                             $valueSup['datos']->getType() == "RESTAURANTE"
  1504.                         ) {
  1505.                             $phpExcelObject->setActiveSheetIndex(0)
  1506.                                 ->setCellValue('E' . $j, $valueSup['datos']->getCompany());
  1507.                         } else {
  1508.                             $type = $this->translator->trans($valueSup['datos']->getType());
  1509.                             $phpExcelObject->setActiveSheetIndex(0)
  1510.                                 ->setCellValue('E' . $j, $type);
  1511.                         }
  1512.                         if (!empty($valueSup['services'])) {
  1513.                             $phpExcelObject->setActiveSheetIndex(0)
  1514.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1515.                                 ->setCellValue('B' . ($j + 1), $transname)
  1516.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1517.                                 ->setCellValue('E' . ($j + 1), $transpricevat)
  1518.                                 ->setCellValue('F' . ($j + 1), $transunits)
  1519.                                 ->setCellValue('G' . ($j + 1), $transpax)
  1520.                                 ->setCellValue('H' . ($j + 1), $transdays)
  1521.                                 ->setCellValue('I' . ($j + 1), $transstart)
  1522.                                 ->setCellValue('J' . ($j + 1), $transend)
  1523.                                 ->setCellValue('K' . ($j + 1), $transnet)
  1524.                                 ->setCellValue('L' . ($j + 1), $transiva)
  1525.                                 ->setCellValue('M' . ($j + 1), $transtotal);
  1526.                             $k = $j + 2;
  1527.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1528.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1529.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1530.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1531.                                 $valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
  1532.                                 $celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
  1533.                                 if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
  1534.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
  1535.                                     $celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
  1536.                                 }
  1537.                                 if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
  1538.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
  1539.                                     $celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
  1540.                                 }
  1541.                                 $valueTotalUnit = round($valueTotalUnit, 2);
  1542.                                 $celdaServicioPax = $valueService['service']->getPax();
  1543.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1544.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
  1545.                                 } else {
  1546.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1547.                                         $celdaServicioPax = 1;
  1548.                                     }
  1549.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
  1550.                                 }
  1551.                                 $phpExcelObject->setActiveSheetIndex(0)
  1552.                                     ->setCellValue('A' . $k, $catName)
  1553.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1554.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1555.                                     //                                    ->setCellValue('E' . $k, $valueTotalUnit)
  1556.                                     ->setCellValue('E' . $k, $celdaValueTotalUnit)
  1557.                                     ->setCellValue('F' . $k, $valueService['service']->getUnits())
  1558.                                     ->setCellValue('G' . $k, $celdaServicioPax)
  1559.                                     ->setCellValue('H' . $k, $valueService['service']->getDays())
  1560.                                     ->setCellValue('I' . $k, $inDate)
  1561.                                     ->setCellValue('J' . $k, $outDate)
  1562.                                     ->setCellValue('K' . $k, $celdaServicioNeto)
  1563.                                     ->setCellValue('L' . $k, $valueService['service']->getIva())
  1564.                                     ->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
  1565.                                 //                                    ->setCellValue('M' . $k, $valueService['service']->getTotal());
  1566.                                 $phpExcelObject
  1567.                                     ->getActiveSheet()
  1568.                                     ->getStyle('K' . $k)
  1569.                                     ->getNumberFormat()
  1570.                                     ->setFormatCode('#,##0.00 €');
  1571. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1572. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1573.                                 $phpExcelObject
  1574.                                     ->getActiveSheet()
  1575.                                     ->getStyle('M' . $k)
  1576.                                     ->getNumberFormat()
  1577.                                     ->setFormatCode('#,##0.00 €');
  1578. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1579. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1580.                                 $k++;
  1581.                             }
  1582.                         }
  1583.                         $j = $k + 1;
  1584.                         //SUBTOTALES
  1585.                         $phpExcelObject->setActiveSheetIndex(0)
  1586.                             ->setCellValue('J' . ($j - 1), 'SUBTOTAL')
  1587.                             ->setCellValue('K' . ($j - 1), $valueSup['neto'])
  1588.                             ->setCellValue('M' . ($j - 1), $valueSup['total']);
  1589.                         $neto += $valueSup['neto'];
  1590.                         $total += $valueSup['total'];
  1591.                         $phpExcelObject
  1592.                             ->getActiveSheet()
  1593.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  1594.                             ->getNumberFormat()
  1595.                             ->setFormatCode('#,##0.00 €');
  1596. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1597. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1598.                         $phpExcelObject
  1599.                             ->getActiveSheet()
  1600.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  1601.                             ->getFill()
  1602.                             ->setFillType($fill::FILL_SOLID)
  1603.                             ->getStartColor()
  1604.                             ->setRGB('DF3A01');
  1605.                     }
  1606.                     if ($j - 1 == $i) {
  1607.                         //                        d($k,$k);
  1608.                     } else {
  1609.                         $phpExcelObject->getActiveSheet()
  1610.                             ->setCellValue(
  1611.                                 'M' . ($j - 1),
  1612.                                 '=SUM(M' . ($i + 2) . ':M' . ($j - 2) . ')'
  1613.                             );
  1614.                         $phpExcelObject->getActiveSheet()
  1615.                             ->setCellValue(
  1616.                                 'K' . ($j - 1),
  1617.                                 '=SUM(K' . ($i + 2) . ':K' . ($j - 2) . ')'
  1618.                             );
  1619.                         if (empty($celdaNeto)) {
  1620.                             $celdaNeto = '=';
  1621.                         } else {
  1622.                             $celdaNeto = $celdaNeto . ' + ';
  1623.                         }
  1624.                         $celdaNeto = $celdaNeto . 'SUM(K' . ($i + 2) . ':K' . ($j - 2) . ')';
  1625.                         if (empty($celdaTotal)) {
  1626.                             $celdaTotal = '=';
  1627.                         } else {
  1628.                             $celdaTotal = $celdaTotal . ' + ';
  1629.                         }
  1630.                         $celdaTotal = $celdaTotal . 'SUM(M' . ($i + 2) . ':M' . ($j - 2) . ')';
  1631.                     }
  1632.                     $i = $j + 1;
  1633.                 }
  1634.                 if (!empty($destination['container']['idea'])) {
  1635.                     foreach ($destination['container']['idea'] as $keySup => $valueSup) {
  1636.                         $phpExcelObject
  1637.                             ->getActiveSheet()
  1638.                             ->getStyle('A' . $j . ':M' . $j)
  1639.                             ->getFill()
  1640.                             ->setFillType($fill::FILL_SOLID)
  1641.                             ->getStartColor()
  1642.                             ->setRGB('B5B8B1');
  1643.                         $phpExcelObject->setActiveSheetIndex(0)
  1644.                             ->setCellValue('E' . $j, $valueSup['datos']->getName());
  1645.                         if (!empty($valueSup['services'])) {
  1646.                             $phpExcelObject->setActiveSheetIndex(0)
  1647.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1648.                                 ->setCellValue('B' . ($j + 1), $transname)
  1649.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1650.                                 ->setCellValue('E' . ($j + 1), $transpricevat)
  1651.                                 ->setCellValue('F' . ($j + 1), $transunits)
  1652.                                 ->setCellValue('G' . ($j + 1), $transpax)
  1653.                                 ->setCellValue('H' . ($j + 1), $transdays)
  1654.                                 ->setCellValue('I' . ($j + 1), $transstart)
  1655.                                 ->setCellValue('J' . ($j + 1), $transend)
  1656.                                 ->setCellValue('K' . ($j + 1), $transnet)
  1657.                                 ->setCellValue('L' . ($j + 1), $transiva)
  1658.                                 ->setCellValue('M' . ($j + 1), $transtotal);
  1659.                             $k = $j + 2;
  1660.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1661.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1662.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1663.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1664.                                 $valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
  1665.                                 $celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
  1666.                                 if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
  1667.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
  1668.                                     $celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
  1669.                                 }
  1670.                                 if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
  1671.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
  1672.                                     $celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
  1673.                                 }
  1674.                                 $valueTotalUnit = round($valueTotalUnit, 2);
  1675.                                 $celdaServicioPax = $valueService['service']->getPax();
  1676.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1677.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
  1678.                                 } else {
  1679.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1680.                                         $celdaServicioPax = 1;
  1681.                                     }
  1682.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
  1683.                                 }
  1684.                                 $phpExcelObject->setActiveSheetIndex(0)
  1685.                                     ->setCellValue('A' . $k, $catName)
  1686.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1687.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1688.                                     //                                    ->setCellValue('E' . $k, $valueTotalUnit)
  1689.                                     ->setCellValue('E' . $k, $celdaValueTotalUnit)
  1690.                                     ->setCellValue('F' . $k, $valueService['service']->getUnits())
  1691.                                     ->setCellValue('G' . $k, $celdaServicioPax)
  1692.                                     ->setCellValue('H' . $k, $valueService['service']->getDays())
  1693.                                     ->setCellValue('I' . $k, $inDate)
  1694.                                     ->setCellValue('J' . $k, $outDate)
  1695.                                     ->setCellValue('K' . $k, $celdaServicioNeto)
  1696.                                     ->setCellValue('L' . $k, $valueService['service']->getIva())
  1697.                                     ->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
  1698.                                 //                                    ->setCellValue('M' . $k, $valueService['service']->getTotal());
  1699.                                 $phpExcelObject
  1700.                                     ->getActiveSheet()
  1701.                                     ->getStyle('K' . $k)
  1702.                                     ->getNumberFormat()
  1703.                                     ->setFormatCode('#,##0.00 €');
  1704. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1705. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1706.                                 $phpExcelObject
  1707.                                     ->getActiveSheet()
  1708.                                     ->getStyle('M' . $k)
  1709.                                     ->getNumberFormat()
  1710.                                     ->setFormatCode('#,##0.00 €');
  1711. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1712. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1713.                                 $k++;
  1714.                             }
  1715.                         }
  1716.                         $j = $k + 1;
  1717.                         //SUBTOTALES
  1718.                         $phpExcelObject->setActiveSheetIndex(0)
  1719.                             ->setCellValue('J' . ($j - 1), 'SUBTOTAL')
  1720.                             ->setCellValue('K' . ($j - 1), $valueSup['neto'])
  1721.                             ->setCellValue('M' . ($j - 1), $valueSup['total']);
  1722.                         $neto += $valueSup['neto'];
  1723.                         $total += $valueSup['total'];
  1724.                         $phpExcelObject
  1725.                             ->getActiveSheet()
  1726.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  1727.                             ->getNumberFormat()
  1728.                             ->setFormatCode('#,##0.00 €');
  1729. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1730. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1731.                         $phpExcelObject
  1732.                             ->getActiveSheet()
  1733.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  1734.                             ->getFill()
  1735.                             ->setFillType($fill::FILL_SOLID)
  1736.                             ->getStartColor()
  1737.                             ->setRGB('DF3A01');
  1738.                     }
  1739.                     if ($j - 1 == $i) {
  1740.                         //                        d($k,$k);
  1741.                     } else {
  1742.                         $phpExcelObject->getActiveSheet()
  1743.                             ->setCellValue(
  1744.                                 'M' . ($j - 1),
  1745.                                 '=SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')'
  1746.                             );
  1747.                         $phpExcelObject->getActiveSheet()
  1748.                             ->setCellValue(
  1749.                                 'K' . ($j - 1),
  1750.                                 '=SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')'
  1751.                             );
  1752.                         if (empty($celdaNeto)) {
  1753.                             $celdaNeto = '=';
  1754.                         } else {
  1755.                             $celdaNeto = $celdaNeto . ' + ';
  1756.                         }
  1757.                         $celdaNeto = $celdaNeto . 'SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')';
  1758.                         if (empty($celdaTotal)) {
  1759.                             $celdaTotal = '=';
  1760.                         } else {
  1761.                             $celdaTotal = $celdaTotal . ' + ';
  1762.                         }
  1763.                         $celdaTotal = $celdaTotal . 'SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')';
  1764.                     }
  1765.                     $i = $j + 1;
  1766.                 }
  1767.                 if (!empty($destination['container']['activity'])) {
  1768.                     foreach ($destination['container']['activity'] as $keySup => $valueSup) {
  1769.                         $phpExcelObject
  1770.                             ->getActiveSheet()
  1771.                             ->getStyle('A' . $j . ':M' . $j)
  1772.                             ->getFill()
  1773.                             ->setFillType($fill::FILL_SOLID)
  1774.                             ->getStartColor()
  1775.                             ->setRGB('B5B8B1');
  1776.                         $phpExcelObject->setActiveSheetIndex(0)
  1777.                             ->setCellValue('E' . $j, $valueSup['datos']->getName());
  1778.                         if (!empty($valueSup['services'])) {
  1779.                             $phpExcelObject->setActiveSheetIndex(0)
  1780.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1781.                                 ->setCellValue('B' . ($j + 1), $transname)
  1782.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1783.                                 ->setCellValue('E' . ($j + 1), $transpricevat)
  1784.                                 ->setCellValue('F' . ($j + 1), $transunits)
  1785.                                 ->setCellValue('G' . ($j + 1), $transpax)
  1786.                                 ->setCellValue('H' . ($j + 1), $transdays)
  1787.                                 ->setCellValue('I' . ($j + 1), $transstart)
  1788.                                 ->setCellValue('J' . ($j + 1), $transend)
  1789.                                 ->setCellValue('K' . ($j + 1), $transnet)
  1790.                                 ->setCellValue('L' . ($j + 1), $transiva)
  1791.                                 ->setCellValue('M' . ($j + 1), $transtotal);
  1792.                             $k = $j + 2;
  1793.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1794.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1795.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1796.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1797.                                 $valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
  1798.                                 $celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
  1799.                                 if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
  1800.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
  1801.                                     $celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
  1802.                                 }
  1803.                                 if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
  1804.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
  1805.                                     $celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
  1806.                                 }
  1807.                                 $valueTotalUnit = round($valueTotalUnit, 2);
  1808.                                 $celdaServicioPax = $valueService['service']->getPax();
  1809.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1810.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
  1811.                                 } else {
  1812.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1813.                                         $celdaServicioPax = 1;
  1814.                                     }
  1815.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
  1816.                                 }
  1817.                                 $phpExcelObject->setActiveSheetIndex(0)
  1818.                                     ->setCellValue('A' . $k, $catName)
  1819.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1820.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1821.                                     //                                    ->setCellValue('E' . $k, $valueTotalUnit)
  1822.                                     ->setCellValue('E' . $k, $celdaValueTotalUnit)
  1823.                                     ->setCellValue('F' . $k, $valueService['service']->getUnits())
  1824.                                     ->setCellValue('G' . $k, $celdaServicioPax)
  1825.                                     ->setCellValue('H' . $k, $valueService['service']->getDays())
  1826.                                     ->setCellValue('I' . $k, $inDate)
  1827.                                     ->setCellValue('J' . $k, $outDate)
  1828.                                     ->setCellValue('K' . $k, $celdaServicioNeto)
  1829.                                     ->setCellValue('L' . $k, $valueService['service']->getIva())
  1830.                                     ->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
  1831.                                 //                                    ->setCellValue('M' . $k, $valueService['service']->getTotal());
  1832.                                 $phpExcelObject
  1833.                                     ->getActiveSheet()
  1834.                                     ->getStyle('K' . $k)
  1835.                                     ->getNumberFormat()
  1836.                                     ->setFormatCode('#,##0.00 €');
  1837. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1838. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1839.                                 $phpExcelObject
  1840.                                     ->getActiveSheet()
  1841.                                     ->getStyle('M' . $k)
  1842.                                     ->getNumberFormat()
  1843.                                     ->setFormatCode('#,##0.00 €');
  1844. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1845. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1846.                                 $k++;
  1847.                             }
  1848.                         }
  1849.                         $j = $k + 1;
  1850.                         //SUBTOTALES
  1851.                         $phpExcelObject->setActiveSheetIndex(0)
  1852.                             ->setCellValue('J' . ($j - 1), 'SUBTOTAL')
  1853.                             ->setCellValue('K' . ($j - 1), $valueSup['neto'])
  1854.                             ->setCellValue('M' . ($j - 1), $valueSup['total']);
  1855.                         $neto += $valueSup['neto'];
  1856.                         $total += $valueSup['total'];
  1857.                         $phpExcelObject
  1858.                             ->getActiveSheet()
  1859.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  1860.                             ->getNumberFormat()
  1861.                             ->setFormatCode('#,##0.00 €');
  1862. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1863. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1864.                         $phpExcelObject
  1865.                             ->getActiveSheet()
  1866.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  1867.                             ->getFill()
  1868.                             ->setFillType($fill::FILL_SOLID)
  1869.                             ->getStartColor()
  1870.                             ->setRGB('DF3A01');
  1871.                     }
  1872.                     if ($j - 1 == $i) {
  1873.                         //                        d($k,$k);
  1874.                     } else {
  1875.                         $phpExcelObject->getActiveSheet()
  1876.                             ->setCellValue(
  1877.                                 'M' . ($j - 1),
  1878.                                 '=SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')'
  1879.                             );
  1880.                         $phpExcelObject->getActiveSheet()
  1881.                             ->setCellValue(
  1882.                                 'K' . ($j - 1),
  1883.                                 '=SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')'
  1884.                             );
  1885.                         if (empty($celdaNeto)) {
  1886.                             $celdaNeto = '=';
  1887.                         } else {
  1888.                             $celdaNeto = $celdaNeto . ' + ';
  1889.                         }
  1890.                         $celdaNeto = $celdaNeto . 'SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')';
  1891.                         if (empty($celdaTotal)) {
  1892.                             $celdaTotal = '=';
  1893.                         } else {
  1894.                             $celdaTotal = $celdaTotal . ' + ';
  1895.                         }
  1896.                         $celdaTotal = $celdaTotal . 'SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')';
  1897.                     }
  1898.                     $i = $j + 1;
  1899.                 }
  1900.                 if (!empty($destination['container']['whiteservice'])) {
  1901.                     foreach ($destination['container']['whiteservice'] as $keySup => $valueSup) {
  1902.                         $phpExcelObject
  1903.                             ->getActiveSheet()
  1904.                             ->getStyle('A' . $j . ':M' . $j)
  1905.                             ->getFill()
  1906.                             ->setFillType($fill::FILL_SOLID)
  1907.                             ->getStartColor()
  1908.                             ->setRGB('B5B8B1');
  1909.                         $phpExcelObject->setActiveSheetIndex(0)
  1910.                             ->setCellValue('E' . $j, $valueSup['datos']->getCompany());
  1911.                         if (!empty($valueSup['services'])) {
  1912.                             $phpExcelObject->setActiveSheetIndex(0)
  1913.                                 ->setCellValue('A' . ($j + 1), $transcategory)
  1914.                                 ->setCellValue('B' . ($j + 1), $transname)
  1915.                                 ->setCellValue('D' . ($j + 1), $transprice)
  1916.                                 ->setCellValue('E' . ($j + 1), $transpricevat)
  1917.                                 ->setCellValue('F' . ($j + 1), $transunits)
  1918.                                 ->setCellValue('G' . ($j + 1), $transpax)
  1919.                                 ->setCellValue('H' . ($j + 1), $transdays)
  1920.                                 ->setCellValue('I' . ($j + 1), $transstart)
  1921.                                 ->setCellValue('J' . ($j + 1), $transend)
  1922.                                 ->setCellValue('K' . ($j + 1), $transnet)
  1923.                                 ->setCellValue('L' . ($j + 1), $transiva)
  1924.                                 ->setCellValue('M' . ($j + 1), $transtotal);
  1925.                             $k = $j + 2;
  1926.                             foreach ($valueSup['services'] as $keyService => $valueService) {
  1927.                                 $inDate = date_format($valueService['service']->getDateInAt(), 'd/m/Y');
  1928.                                 $outDate = date_format($valueService['service']->getDateOutAt(), 'd/m/Y');
  1929.                                 $catName = $this->translator->trans($valueService['service']->getServiceCatName());
  1930.                                 $valueTotalUnit = $valueService['service']->getTotal() / $valueService['service']->getDays();
  1931.                                 $celdaValueTotalUnit = '=(M' . $k . '/ H' . $k . ')';
  1932.                                 if (!empty($valueService['service']->getUnits()) and ($valueService['service']->getUnits() > 1)) {
  1933.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getUnits();
  1934.                                     $celdaValueTotalUnit = '=((M' . $k . '/ H' . $k . ')/ F' . $k . ')';
  1935.                                 }
  1936.                                 if (!empty($valueService['service']->getPax()) and ($valueService['service']->getPax() > 1)) {
  1937.                                     $valueTotalUnit = $valueTotalUnit / $valueService['service']->getPax();
  1938.                                     $celdaValueTotalUnit = '=(((M' . $k . '/ H' . $k . ')/ F' . $k . ')/ G' . $k . ')';
  1939.                                 }
  1940.                                 $valueTotalUnit = round($valueTotalUnit, 2);
  1941.                                 $celdaServicioPax = $valueService['service']->getPax();
  1942.                                 if ($valueService['service']->getServiceCatId() == 1 or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == 8 or $valueService['service']->getServiceCatId() == 13) {
  1943.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*H' . $k . ')';
  1944.                                 } else {
  1945.                                     if ($valueService['service']->getPax() == 0 or is_null($valueService['service']->getPax())) {
  1946.                                         $celdaServicioPax = 1;
  1947.                                     }
  1948.                                     $celdaServicioNeto = '=(D' . $k . '*F' . $k . '*G' . $k . '*H' . $k . ')';
  1949.                                 }
  1950.                                 $phpExcelObject->setActiveSheetIndex(0)
  1951.                                     ->setCellValue('A' . $k, $catName)
  1952.                                     ->setCellValue('B' . $k, $valueService['service']->getName())
  1953.                                     ->setCellValue('D' . $k, $valueService['service']->getPrice())
  1954.                                     //                                    ->setCellValue('E' . $k, $valueTotalUnit)
  1955.                                     ->setCellValue('E' . $k, $celdaValueTotalUnit)
  1956.                                     ->setCellValue('F' . $k, $valueService['service']->getUnits())
  1957.                                     ->setCellValue('G' . $k, $celdaServicioPax)
  1958.                                     ->setCellValue('H' . $k, $valueService['service']->getDays())
  1959.                                     ->setCellValue('I' . $k, $inDate)
  1960.                                     ->setCellValue('J' . $k, $outDate)
  1961.                                     ->setCellValue('K' . $k, $celdaServicioNeto)
  1962.                                     ->setCellValue('L' . $k, $valueService['service']->getIva())
  1963.                                     ->setCellValue('M' . $k, '=SUM(' . 'K' . $k . ' + (K' . $k . '* L' . $k . ')/100)');
  1964.                                 //                                    ->setCellValue('M' . $k, $valueService['service']->getTotal());
  1965.                                 $phpExcelObject
  1966.                                     ->getActiveSheet()
  1967.                                     ->getStyle('K' . $k)
  1968.                                     ->getNumberFormat()
  1969.                                     ->setFormatCode('#,##0.00 €');
  1970. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1971. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1972.                                 $phpExcelObject
  1973.                                     ->getActiveSheet()
  1974.                                     ->getStyle('M' . $k)
  1975.                                     ->getNumberFormat()
  1976.                                     ->setFormatCode('#,##0.00 €');
  1977. //                                    ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1978. //                                    ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1979.                                 $k++;
  1980.                             }
  1981.                         }
  1982.                         $j = $k + 1;
  1983.                         //SUBTOTALES
  1984.                         $phpExcelObject->setActiveSheetIndex(0)
  1985.                             ->setCellValue('J' . ($j - 1), 'SUBTOTAL')
  1986.                             ->setCellValue('K' . ($j - 1), $valueSup['neto'])
  1987.                             ->setCellValue('M' . ($j - 1), $valueSup['total']);
  1988.                         $neto += $valueSup['neto'];
  1989.                         $total += $valueSup['total'];
  1990.                         $phpExcelObject
  1991.                             ->getActiveSheet()
  1992.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  1993.                             ->getNumberFormat()
  1994.                             ->setFormatCode('#,##0.00 €');
  1995. //                            ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  1996. //                            ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  1997.                         $phpExcelObject
  1998.                             ->getActiveSheet()
  1999.                             ->getStyle('J' . ($j - 1) . ':M' . ($j - 1))
  2000.                             ->getFill()
  2001.                             ->setFillType($fill::FILL_SOLID)
  2002.                             ->getStartColor()
  2003.                             ->setRGB('DF3A01');
  2004.                     }
  2005.                     if ($j - 1 == $i) {
  2006.                         //                        d($k,$k);
  2007.                     } else {
  2008.                         $phpExcelObject->getActiveSheet()
  2009.                             ->setCellValue(
  2010.                                 'M' . ($j - 1),
  2011.                                 '=SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')'
  2012.                             );
  2013.                         $phpExcelObject->getActiveSheet()
  2014.                             ->setCellValue(
  2015.                                 'K' . ($j - 1),
  2016.                                 '=SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')'
  2017.                             );
  2018.                         if (empty($celdaNeto)) {
  2019.                             $celdaNeto = '=';
  2020.                         } else {
  2021.                             $celdaNeto = $celdaNeto . ' + ';
  2022.                         }
  2023.                         $celdaNeto = $celdaNeto . 'SUM(K' . ($i + 1) . ':K' . ($j - 2) . ')';
  2024.                         if (empty($celdaTotal)) {
  2025.                             $celdaTotal = '=';
  2026.                         } else {
  2027.                             $celdaTotal = $celdaTotal . ' + ';
  2028.                         }
  2029.                         $celdaTotal = $celdaTotal . 'SUM(M' . ($i + 1) . ':M' . ($j - 2) . ')';
  2030.                     }
  2031.                     $i = $j + 1;
  2032.                 }
  2033.             }
  2034.             //            $i=$j+1;
  2035.         }
  2036.         $tot = $i + 1;
  2037.         if (empty($proposal->getCommission()) or $proposal->getCommission() == 'National') {
  2038.             $phpExcelObject
  2039.                 ->getActiveSheet()
  2040.                 ->getStyle('I' . $tot)
  2041.                 ->getFill()
  2042.                 ->setFillType($fill::FILL_SOLID)
  2043.                 ->getStartColor()
  2044.                 ->setRGB('7ec8e0');
  2045.             $phpExcelObject
  2046.                 ->getActiveSheet()
  2047.                 ->getStyle('K' . $tot)
  2048.                 ->getFill()
  2049.                 ->setFillType($fill::FILL_SOLID)
  2050.                 ->getStartColor()
  2051.                 ->setRGB('7ec8e0');
  2052.             $phpExcelObject
  2053.                 ->getActiveSheet()
  2054.                 ->getStyle('J' . $tot)
  2055.                 ->getFill()
  2056.                 ->setFillType($fill::FILL_SOLID)
  2057.                 ->getStartColor()
  2058.                 //            ->setRGB('57A639')
  2059.                 ->setRGB('7ec8e0');
  2060.             $phpExcelObject
  2061.                 ->getActiveSheet()
  2062.                 ->getStyle('L' . $tot)
  2063.                 ->getFill()
  2064.                 ->setFillType($fill::FILL_SOLID)
  2065.                 ->getStartColor()
  2066.                 //            ->setRGB('57A639')
  2067.                 ->setRGB('7ec8e0');
  2068.             $phpExcelObject->setActiveSheetIndex(0)
  2069.                 ->setCellValue('I' . $tot, $transnet . ': ')
  2070.                 ->setCellValue('K' . $tot, $transtotal . ': ')
  2071.                 ->setCellValue('J' . $tot, $celdaNeto)
  2072.                 ->setCellValue('L' . $tot, $celdaTotal);
  2073.             $phpExcelObject
  2074.                 ->getActiveSheet()
  2075.                 ->getStyle('J' . $tot)
  2076.                 ->getNumberFormat()
  2077.                 ->setFormatCode('#,##0.00 €');
  2078. //                ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  2079. //                ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  2080.             $phpExcelObject
  2081.                 ->getActiveSheet()
  2082.                 ->getStyle('L' . $tot)
  2083.                 ->getNumberFormat()
  2084.                 ->setFormatCode('#,##0.00 €');
  2085. //                ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  2086. //                ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  2087. //            foreach (range('H' . $tot, 'L' . $tot) as $columnID) {    // Cambio por la actualizacion de version de PHP
  2088.             foreach (range('H', 'L') as $columnID) {
  2089.                 $newColumnID = $columnID.$tot;
  2090.                 $phpExcelObject->getActiveSheet()->getColumnDimension($newColumnID)->setAutoSize(true);
  2091.             }
  2092.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 2))->applyFromArray($estilo);
  2093.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 3))->applyFromArray($estilo);
  2094.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 4))->applyFromArray($estilo);
  2095.             $phpExcelObject->setActiveSheetIndex(0)
  2096.                 ->setCellValue('L' . ($tot + 2), 'INOUT TRAVEL')
  2097.                 ->setCellValue('L' . ($tot + 3), 'events@inout-travel.com')
  2098.                 ->setCellValue('L' . ($tot + 4), '+34 911 878 393');
  2099.             $phpExcelObject
  2100.                 ->getActiveSheet()
  2101.                 ->getStyle('k' . ($tot + 2) . ':' . 'L' . ($tot + 4))
  2102.                 ->getFill()
  2103.                 ->setFillType($fill::FILL_SOLID)
  2104.                 ->getStartColor()
  2105.                 ->setRGB('F18E0D');
  2106.         } else { // Caso Internacional (pie de pagina)
  2107.             $phpExcelObject
  2108.                 ->getActiveSheet()
  2109.                 ->getStyle('J' . $tot)
  2110.                 ->getFill()
  2111.                 ->setFillType($fill::FILL_SOLID)
  2112.                 ->getStartColor()
  2113.                 ->setRGB('7ec8e0');
  2114.             $phpExcelObject
  2115.                 ->getActiveSheet()
  2116.                 ->getStyle('L' . $tot)
  2117.                 ->getFill()
  2118.                 ->setFillType($fill::FILL_SOLID)
  2119.                 ->getStartColor()
  2120.                 ->setRGB('7ec8e0');
  2121.             $phpExcelObject
  2122.                 ->getActiveSheet()
  2123.                 ->getStyle('K' . $tot)
  2124.                 ->getFill()
  2125.                 ->setFillType($fill::FILL_SOLID)
  2126.                 ->getStartColor()
  2127.                 //            ->setRGB('57A639')
  2128.                 ->setRGB('7ec8e0');
  2129.             $phpExcelObject
  2130.                 ->getActiveSheet()
  2131.                 ->getStyle('M' . $tot)
  2132.                 ->getFill()
  2133.                 ->setFillType($fill::FILL_SOLID)
  2134.                 ->getStartColor()
  2135.                 //            ->setRGB('57A639')
  2136.                 ->setRGB('7ec8e0');
  2137.             $phpExcelObject->setActiveSheetIndex(0)
  2138.                 ->setCellValue('J' . $tot, $transnet . ': ')
  2139.                 ->setCellValue('L' . $tot, $transtotal . ': ')
  2140.                 ->setCellValue('K' . $tot, $celdaNeto)
  2141.                 ->setCellValue('M' . $tot, $celdaTotal);
  2142.             $phpExcelObject
  2143.                 ->getActiveSheet()
  2144.                 ->getStyle('K' . $tot)
  2145.                 ->getNumberFormat()
  2146.                 ->setFormatCode('#,##0.00 €');
  2147. //                ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  2148. //                ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  2149.             $phpExcelObject
  2150.                 ->getActiveSheet()
  2151.                 ->getStyle('M' . $tot)
  2152.                 ->getNumberFormat()
  2153.                 ->setFormatCode('#,##0.00 €');
  2154. //                ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  2155. //                ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  2156. //            foreach (range('I' . $tot, 'M' . $tot) as $columnID) {        // Cambio por la actualizacion de version de PHP
  2157.             foreach (range('I', 'M') as $columnID) {
  2158.                 $newColumnID = $columnID.$tot;
  2159.                 $phpExcelObject->getActiveSheet()->getColumnDimension($newColumnID)->setAutoSize(true);
  2160.             }
  2161.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 2))->applyFromArray($estilo);
  2162.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 3))->applyFromArray($estilo);
  2163.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 4))->applyFromArray($estilo);
  2164.             $phpExcelObject->setActiveSheetIndex(0)
  2165.                 ->setCellValue('M' . ($tot + 2), 'INOUT TRAVEL')
  2166.                 ->setCellValue('M' . ($tot + 3), 'events@inout-travel.com')
  2167.                 ->setCellValue('M' . ($tot + 4), '+34 911 878 393');
  2168.             $phpExcelObject
  2169.                 ->getActiveSheet()
  2170.                 ->getStyle('L' . ($tot + 2) . ':' . 'M' . ($tot + 4))
  2171.                 ->getFill()
  2172.                 ->setFillType($fill::FILL_SOLID)
  2173.                 ->getStartColor()
  2174.                 ->setRGB('F18E0D');
  2175.         }
  2176.         $phpExcelObject->getActiveSheet()->setTitle('Simple');
  2177.         // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  2178.         $phpExcelObject->setActiveSheetIndex(0);
  2179.         // Crea el writer
  2180.         $writer = new Xlsx($phpExcelObject);
  2181.         // Envia la respuesta del controlador
  2182.         $response = new StreamedResponse(
  2183.             function () use ($writer) {
  2184.                 $writer->save('php://output');
  2185.             }
  2186.         );
  2187.         // Agrega los headers requeridos
  2188.         $dispositionHeader = $response->headers->makeDisposition(
  2189.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  2190.             //            $company->getCompany().' proposal - '.$proposal->getId().'.xlsx'
  2191.             'In_Out_Travel_presupuesto-' . $idp . '_proposal-' . $proposal->getId() . '.xlsx'
  2192.         );
  2193.         $response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
  2194.         $response->headers->set('Pragma', 'public');
  2195.         $response->headers->set('Cache-Control', 'maxage=1');
  2196.         $response->headers->set('Content-Disposition', $dispositionHeader);
  2197.         return $response;
  2198.     }
  2199.     /**
  2200.      * @Route("/budget/xls/{token}",  name="proposal_xls_budget")
  2201.      *
  2202.      */
  2203.     public function xlsAction($token, EntityManagerInterface $em, Request $request)
  2204.     {
  2205.         $totales_neto_sub = $totales_iva_sub  = $totales_con_iva_sub = $totales_paying_sub = $totales_pago_sub = $totales_benefit_moneda_sub = 0;
  2206.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  2207.         if ($proposal->getStatus() == "Cancel") {
  2208.             return $this->redirectToRoute( 'presentation_error_cancel', array( 'token' => $token ) );
  2209.         }
  2210.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  2211.         // Usuario Anonimo es = "anon."
  2212.         if ($user_logueado == "anon.") {
  2213.             $proposal->setViewedAt(new \DateTime("now"));
  2214.             $em->persist($proposal);
  2215.             $em->flush();
  2216.         }
  2217.         $selectType = explode(",", $proposal->getSelectType());
  2218.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  2219.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  2220.             array(
  2221.                 'proposalId' => $proposal->getId(),
  2222.                 'disabled' => '0',
  2223.             )
  2224.         );
  2225.         $data_destionation = array();
  2226.         $cont_destino = 0;
  2227.         foreach ($proposal_Control as $proposalControl) {
  2228.             $cont_destino += 1;
  2229.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  2230.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  2231.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  2232.                 array(
  2233.                     'destinationId' => $proposalControl->getDestinationId(),
  2234.                     'language' => $proposal->getLanguage()
  2235.                 )
  2236.             );
  2237.             $data_destionation[$destino->getTitle()] = array(
  2238.                 'destino' => $destino,
  2239.                 'gallery' => $gallery,
  2240.                 'description' => $description,
  2241.             );
  2242.         }
  2243.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  2244.         ////////////////////////////////////////////////////////////////////////////////////////////////
  2245.         /* INICIO CONTENIDO DEL PRESUPUESTO                                                           */
  2246.         ////////////////////////////////////////////////////////////////////////////////////////////////
  2247.         $available_destination = $em->getRepository(ProposalControl::class)->findBy(
  2248.             array(
  2249.                 'proposalId' => $proposal->getId(),
  2250.                 'disabled' => "0"
  2251.             )
  2252.         );
  2253.         $data_supplier = array();
  2254.         foreach ($available_destination as $availabledestination) {
  2255.             /* Data Supplier agregados */
  2256.             $service_supplier = $em->getRepository(ProposalSupplierControl::class)->findBy(
  2257.                 array(
  2258.                     'controlDestinationId' => $availabledestination->getId(),
  2259.                     'disabled' => "0"
  2260.                 ),
  2261.                 array(
  2262.                     'rank' => 'ASC'
  2263.                 )
  2264.             );
  2265.             $controlgeneral = array(); $master = null;
  2266.             foreach ($service_supplier as $suppliercontrol) {
  2267.                 $destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
  2268.                 //cambiar el estatus de colores
  2269.                 $colorlabel = "";
  2270.                 switch ($suppliercontrol->getStatus()) {
  2271.                     case 'Pending': $colorlabel = "bg-danger"; break;
  2272.                     case 'Confirmed': $colorlabel = "bg-success"; break;
  2273.                 }
  2274.                 $sqlactivities = "";
  2275.                 if (!is_null($suppliercontrol->getActivityId())) {
  2276.                     $master = "activity";
  2277.                     $sqlactivities = $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
  2278.                     /*CONTROL GENERAL*/
  2279.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
  2280.                 }
  2281.                 $sqlideas = "";
  2282.                 if (!is_null($suppliercontrol->getIdeaId())) {
  2283.                     $master = "idea";
  2284.                     $sqlideas = $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
  2285.                     /*CONTROL GENERAL*/
  2286.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
  2287.                 }
  2288.                 $sqlsuppliers = "";
  2289.                 if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
  2290.                     $master = "supplier";
  2291.                     $sqlsuppliers = $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
  2292.                     if (!is_null($sqlsuppliers)) {
  2293.                         switch ($sqlsuppliers->getStar()) {
  2294.                             case 1: $sqlsuppliers->setStar('<i class="icon-star-full2"></i>'); break;
  2295.                             case 2: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  2296.                             case 3: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  2297.                             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;
  2298.                             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;
  2299.                             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;
  2300.                             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;
  2301.                         }
  2302.                     }
  2303.                     /*CONTROL GENERAL*/
  2304.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
  2305.                 }
  2306.                 $sqlcompany = "";
  2307.                 if ($suppliercontrol->getSupplierId() == "0") {
  2308.                     $master = "company";
  2309.                     $sqlcompany = $em->getRepository(SettingsCompany::class)->findOneById('1');
  2310.                     if (!is_null($sqlcompany)) {
  2311.                         $imagenSmall = $sqlcompany->getPicture();
  2312.                     } else {
  2313.                         //Imagen no disponible (poner una generica)
  2314.                         $imagenSmall = null;
  2315.                     }
  2316.                 } else {
  2317.                     $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  2318.                         array(
  2319.                             'supplierId' => $controlgeneral->getId(),
  2320.                             'servicesCatId' => '0',
  2321.                             'servicesCategory' => 'General',
  2322.                             'servicesId' => '0',
  2323.                             'controlId' => '0'
  2324.                         )
  2325.                     );
  2326.                     if (!is_null($sqlsuppliers_gallery)) {
  2327.                         $imagenSmall = $sqlsuppliers_gallery->getImageSmall();
  2328.                     } else {
  2329.                         //Imagen no disponible (poner una generica)
  2330.                         $imagenSmall = null;
  2331.                     }
  2332.                 }
  2333.                 // ORDEN DESCENDENTE Y POR SERVICES
  2334.                 $parameters = array(
  2335.                     'controlId' => $suppliercontrol->getId(),
  2336.                     'serviceIdFather' => '0',
  2337.                     'directPayment' => '0',
  2338.                 );
  2339.                 $dql = 'SELECT p
  2340.                         FROM EventsBundle:ProposalSupplierServices p
  2341.                         WHERE p.controlId = :controlId 
  2342.                         AND p.serviceIdFather = :serviceIdFather
  2343.                         AND p.directPayment = :directPayment
  2344.                         ORDER BY p.serviceCatId, p.rank ASC ';
  2345.                 $query = $em->createQuery($dql)->setParameters($parameters);
  2346.                 $data_service_supplier = $query->getResult();
  2347.                 $service_supplier_data = array();
  2348.                 $calculos_totatales = array();
  2349.                 $totales_neto = '0';
  2350.                 $totales_iva = '0';
  2351.                 $totales_con_iva = '0';
  2352.                 $totales_paying = '0';
  2353.                 $totales_pago = '0';
  2354.                 $totales_benefit_moneda = '0';
  2355.                 $totales_benefit_porsentaje = '0';
  2356.                 foreach ($data_service_supplier as $data_service) {
  2357.                     //COLOR POR SERVICIO
  2358.                     $contcolor = "";
  2359.                     switch ($data_service->getServiceCatName()) {
  2360.                         case "Accommodation": $contcolor = 'teal'; break;
  2361.                         case "Menu": $contcolor = 'purple'; break;
  2362.                         case "Lounge": $contcolor = 'warning'; break;
  2363.                         case "Activities": $contcolor = 'blue'; break;
  2364.                         case "Itineraries": $contcolor = 'indigo'; break;
  2365.                         case "Cruise": $contcolor = 'brown'; break;
  2366.                         case "Transport": $contcolor = 'grey'; break;
  2367.                         case "Av": $contcolor = 'slate'; break;
  2368.                         case "Creative": $contcolor = 'orange'; break;
  2369.                         case "Gifts": $contcolor = 'pink'; break;
  2370.                         case "Entertainment": $contcolor = 'green'; break;
  2371.                         case "Guide": $contcolor = 'orange'; break;
  2372.                         case "Others": $contcolor = 'danger'; break;
  2373.                         case "Technology": $contcolor = 'grey-800'; break;
  2374.                         case "Assistant": $contcolor = 'indigo-800'; break;
  2375.                         case "DDR": $contcolor = 'green-300'; break;
  2376.                     }
  2377.                     $idcat = $data_service->getServiceCatId();
  2378.                     $price = $data_service->getPrice();
  2379.                     $units = $data_service->getUnits();
  2380.                     $pax = $data_service->getPax();
  2381.                     $opcommission = $data_service->getOpCommission();
  2382.                     $commission = $data_service->getCommission();
  2383.                     $opover = $data_service->getOpOver();
  2384.                     $over = $data_service->getOver();
  2385.                     $opiva = $data_service->getOpIva();
  2386.                     $iva = $data_service->getIva();
  2387.                     $dateInAt = $data_service->getDateInAt();
  2388.                     $dateOutAt = $data_service->getDateOutAt();
  2389.                     if (!is_null($dateInAt) and !is_null($dateOutAt)) {
  2390.                         $days = $dateInAt->diff($dateOutAt);
  2391.                         $day = $days->days;
  2392.                     } else {
  2393.                         $day = "0";
  2394.                     }
  2395.                     $directPayment = $data_service->getDirectPayment();
  2396.                     if ($data_service->getSupplierId() == "0") {
  2397.                         $name_company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  2398.                         $namesupplier = $name_company->getCompany();
  2399.                     }
  2400.                     if (!is_null($data_service->getSupplierId()) && $data_service->getSupplierId() != "0") {
  2401.                         $name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  2402.                         $namesupplier = $name_supplier->getName();
  2403.                     }
  2404.                     if (!is_null($data_service->getActivityId())) {
  2405.                         $name_supplier = $em->getRepository(Activities::class)->findOneById($data_service->getActivityId());
  2406.                         $namesupplier = $name_supplier->getName();
  2407.                     }
  2408.                     if (!is_null($data_service->getIdeaId())) {
  2409.                         $name_supplier = $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
  2410.                         $namesupplier = $name_supplier->getName();
  2411.                     }
  2412.                     $calculos = $this->CalculoTotalesservices($price, $units, $pax, $day, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat);
  2413.                     $data_service->setPrice($calculos['precio']); //ojo aqui
  2414.                     /*CONTROL GENERAL*/
  2415.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
  2416.                     $data_service->setPrice($calculos['precio']); //ojo aqui
  2417.                     $service_supplier_data[$data_service->getServiceCatName()][] = array(
  2418.                         'calculos' => $calculos,
  2419.                         'services_data' => $data_service,
  2420.                         'contcolor' => $contcolor,
  2421.                     );
  2422.                     if ($data_service->getBreakdown() == false) {
  2423.                         $totales_neto += $calculos['total_neto'];
  2424.                         $totales_iva += $calculos['sub_total_iva'];
  2425.                         $totales_con_iva += $calculos['total'];
  2426.                         $totales_paying += $calculos['total_paying'];
  2427.                         $totales_pago += $calculos['total_pago'];
  2428.                         $totales_benefit_moneda += $calculos['benefit_moneda'];
  2429.                     } else {
  2430.                         $totales_neto += $totales_neto_sub;
  2431.                         $totales_iva += $totales_iva_sub;
  2432.                         $totales_con_iva += $totales_con_iva_sub;
  2433.                         $totales_paying += $totales_paying_sub;
  2434.                         $totales_pago += $totales_pago_sub;
  2435.                         $totales_benefit_moneda += $totales_benefit_moneda_sub;
  2436.                     }
  2437.                     if ($totales_benefit_moneda == '0') {
  2438.                         $totales_benefit_porsentaje =  '0';
  2439.                     } else {
  2440.                         if ($totales_pago == 0 or is_null($totales_pago)) {
  2441.                             $totales_benefit_porsentaje = 0;
  2442.                         } else {
  2443.                             $totales_benefit_porsentaje =  $totales_benefit_moneda * 100 / $totales_pago;
  2444.                         }
  2445.                     }
  2446.                 }
  2447.                 $calculos_totatales = array(
  2448.                     'totales_neto' => $totales_neto,
  2449.                     'totales_iva' => $totales_iva,
  2450.                     'totales_con_iva' => $totales_con_iva,
  2451.                     'totales_paying' => $totales_paying,
  2452.                     'totales_benefit_moneda' => $totales_benefit_moneda,
  2453.                     'totales_benefit_porsentaje' => $totales_benefit_porsentaje
  2454.                 );
  2455.                 if ($master == "company") { $typeMaster = $sqlcompany->getCompany(); }
  2456.                 if ($master == "supplier") { $typeMaster = $sqlsuppliers->getType(); }
  2457.                 if ($master == "activity") { $typeMaster = "Activity"; }
  2458.                 if ($master == "idea") { $typeMaster = "IDEA"; }
  2459.                 $data_supplier[$destination->getTitle()][$typeMaster][] = array(
  2460.                     'colorlabel' => $colorlabel,
  2461.                     'control' => $suppliercontrol,
  2462.                     'master' => $master,
  2463.                     'supplier' => $sqlsuppliers,
  2464.                     'idea' => $sqlideas,
  2465.                     'company' => $sqlcompany,
  2466.                     'activity' => $sqlactivities,
  2467.                     'image' => $imagenSmall,
  2468.                     'services' => $service_supplier_data,
  2469.                     'totales_services' => $calculos_totatales
  2470.                 );
  2471.             }
  2472.         }
  2473.         $fees = $em->getRepository(ProposalFee::class)->findByProposalId($proposal->getId()); $theFee = [];
  2474.         if (!empty($fees)) {
  2475.             // 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
  2476.             if ($fees[0]->getToinvoice() == true) {
  2477.                 foreach ($fees as $fee) {
  2478.                     $xFeeAmount = empty($fee->getAmount()) ? 0 : $fee->getAmount();
  2479.                     if ($fee->getType() == 0) {
  2480.                         $theFee = array(
  2481.                             'valorDirecto' => null,
  2482.                             'montoPorcentaje' => $xFeeAmount,
  2483.                         );
  2484.                     } else {
  2485.                         $theFee = array(
  2486.                             'valorDirecto' => $xFeeAmount,
  2487.                             'montoPorcentaje' => null,
  2488.                         );
  2489.                     }
  2490.                 }
  2491.             }
  2492.         } else {
  2493.             $theFee = null;
  2494.         }
  2495.         $total = 0;
  2496.         $neto = 0;
  2497.         // Solicita el servicio de excel
  2498.         $phpExcelObject = new Spreadsheet();
  2499.         $phpExcelObject->getProperties()->setCreator("InOut Travel")
  2500.             ->setLastModifiedBy("InOut Travel")
  2501.             ->setTitle("InOut Travel")
  2502.             ->setSubject("InOut Travel")
  2503.             ->setDescription("InOut Travel, generado usando clases de PHP")
  2504.             ->setKeywords("office 2005 openxml php")
  2505.             ->setCategory("Archivo de ejemplo");
  2506.         $fill = new Fill();
  2507.         $numberFormat = new NumberFormat();
  2508.         $alignment = new Alignment();
  2509.         $i = 5;
  2510.         $tot = 0;
  2511.         $activesheet = $phpExcelObject->getActiveSheet();
  2512.         $drawingobject = new Drawing;
  2513.         $drawingobject->setName('Image name');
  2514.         $drawingobject->setDescription('Image description');
  2515.         $drawingobject->setPath(getcwd() . '/assets/images/logo/logo2022.png');
  2516.         $drawingobject->setHeight(60);
  2517.         $drawingobject->setOffsetY(20);
  2518.         $drawingobject->setCoordinates('K1');
  2519.         $drawingobject->setWorksheet($activesheet);
  2520.         $phpExcelObject
  2521.             ->getActiveSheet()
  2522.             ->getStyle('B3:H3')
  2523.             ->getFill()
  2524.             ->setFillType($fill::FILL_SOLID)
  2525.             ->getStartColor()
  2526.             ->setRGB('FFA420');
  2527.         $phpExcelObject->setActiveSheetIndex(0)
  2528.             ->setCellValue('C3', 'PRESUPUESTO: ' . $proposal->getTitle());
  2529.         if (empty($proposal->getCommission()) or $proposal->getCommission() == 'National') {
  2530.             // *****************************************************************************************************
  2531.             //                                      Caso Nacional
  2532.             // *****************************************************************************************************
  2533.             $celdaNeto = '';
  2534.             $celdaTotal = '';
  2535.             foreach ($data_supplier as $key => $value) {
  2536.                 $phpExcelObject
  2537.                     ->getActiveSheet()
  2538.                     ->getStyle('A' . $i . ':L' . $i)
  2539.                     ->getFill()
  2540.                     ->setFillType($fill::FILL_SOLID)
  2541.                     ->getStartColor()
  2542.                     ->setRGB('FFA420');
  2543.                 $keytrans = strtoupper($this->translator->trans($key));
  2544.                 $phpExcelObject->setActiveSheetIndex(0)
  2545.                     ->setCellValue('E' . $i, $keytrans);
  2546.                 $j = $i + 1;
  2547.                 foreach ($value as $keySup => $valueSup) {
  2548.                     $phpExcelObject
  2549.                         ->getActiveSheet()
  2550.                         ->getStyle('A' . $j . ':L' . $j)
  2551.                         ->getFill()
  2552.                         ->setFillType($fill::FILL_SOLID)
  2553.                         ->getStartColor()
  2554.                         ->setRGB('B5B8B1');
  2555.                     $keySuptrans = strtoupper($this->translator->trans($keySup));
  2556.                     $phpExcelObject->setActiveSheetIndex(0)
  2557.                         ->setCellValue('E' . $j, $keySuptrans);
  2558.                     $drawingobject = new Drawing;
  2559.                     $service = $j + 1;
  2560.                     foreach ($valueSup as $keySupAll => $valueSupAll) {
  2561.                         $totalSub = 0;
  2562.                         $netoSub = 0;
  2563.                         if (!is_null($valueSupAll['master'])) {
  2564.                             $type = $valueSupAll['master'];
  2565.                             if ($type == 'idea' or $type == 'activity') {
  2566.                                 $name = $valueSupAll[$type]->getName();
  2567.                             } else {
  2568.                                 $name = "";
  2569.                                 if (!empty($valueSupAll['supplier'])) {
  2570.                                     if (
  2571.                                         $valueSupAll['supplier']->getType() == "ENTRETENIMIENTO" or
  2572.                                         $valueSupAll['supplier']->getType() == "TRANSPORTE" or
  2573.                                         $valueSupAll['supplier']->getType() == "GUÍAS" or
  2574.                                         $valueSupAll['supplier']->getType() == "OTROS" or
  2575.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUAL" or
  2576.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUALES" or
  2577.                                         $valueSupAll['supplier']->getType() == "MÚSICA" or
  2578.                                         $valueSupAll['supplier']->getType() == "ASISTENCIA"
  2579.                                     ) {
  2580.                                         $name = "";
  2581.                                         $valueSupAll[$type]->setCompany('');
  2582.                                         $valueSupAll[$type]->setName('');
  2583.                                     } else {
  2584.                                         $name = $valueSupAll[$type]->getCompany();
  2585.                                     }
  2586.                                 }
  2587.                             }
  2588.                             if ($name != '') {
  2589.                                 $phpExcelObject
  2590.                                     ->getActiveSheet()
  2591.                                     ->getStyle('A' . $service . ':C' . $service)
  2592.                                     ->getFill()
  2593.                                     ->setFillType($fill::FILL_SOLID)
  2594.                                     ->getStartColor()
  2595.                                     ->setRGB('DA9694');
  2596.                                 $phpExcelObject->setActiveSheetIndex(0)
  2597.                                     ->setCellValue('A' . $service, $name);
  2598.                             }
  2599.                         }
  2600.                         $estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ) );
  2601.                         $k = $service + 1;
  2602.                         if (!empty($valueSupAll[$type])) {
  2603.                             foreach ($valueSupAll['services'] as $keyService => $valueService) {
  2604.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  2605.                                     // Por defecto para todos los idiomas sera un presupuesto en castellano
  2606.                                     $keyServiceTrad = $this->translator->trans($keyService);
  2607.                                 } else {
  2608.                                     // El otro idioma es ingles
  2609.                                     $keyServiceTrad = $keyService;
  2610.                                 }
  2611.                                 $phpExcelObject
  2612.                                     ->getActiveSheet()
  2613.                                     ->getStyle('A' . $k . ':L' . $k)
  2614.                                     ->applyFromArray($estilo)
  2615.                                     ->getFill()
  2616.                                     ->setFillType($fill::FILL_SOLID)
  2617.                                     ->getStartColor()
  2618.                                     ->setRGB('497E76');
  2619.                                 $estiloL = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_LEFT, ) );
  2620.                                 $phpExcelObject
  2621.                                     ->getActiveSheet()
  2622.                                     ->getStyle('A' . $k)
  2623.                                     ->applyFromArray($estiloL);
  2624.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  2625.                                     $phpExcelObject->setActiveSheetIndex(0)
  2626.                                         ->setCellValue('A' . $k, $keyServiceTrad)
  2627.                                         ->setCellValue('D' . $k, 'Precio Unitario')
  2628.                                         ->setCellValue('E' . $k, 'Cantidad')
  2629.                                         ->setCellValue('F' . $k, 'Personas')
  2630.                                         ->setCellValue('G' . $k, 'Días')
  2631.                                         ->setCellValue('H' . $k, 'Inicio')
  2632.                                         ->setCellValue('I' . $k, 'Fin')
  2633.                                         ->setCellValue('J' . $k, 'Neto')
  2634.                                         ->setCellValue('K' . $k, 'Iva')
  2635.                                         ->setCellValue('L' . $k, 'Total');
  2636.                                 } else {
  2637.                                     $phpExcelObject->setActiveSheetIndex(0)
  2638.                                         ->setCellValue('A' . $k, $keyServiceTrad)
  2639.                                         ->setCellValue('D' . $k, 'Price')
  2640.                                         ->setCellValue('E' . $k, 'Qty')
  2641.                                         ->setCellValue('F' . $k, 'People')
  2642.                                         ->setCellValue('G' . $k, 'Days')
  2643.                                         ->setCellValue('H' . $k, 'Start')
  2644.                                         ->setCellValue('I' . $k, 'End')
  2645.                                         ->setCellValue('J' . $k, 'Net')
  2646.                                         ->setCellValue('K' . $k, 'Vat')
  2647.                                         ->setCellValue('L' . $k, 'Total');
  2648.                                 }
  2649.                                 $l = $k + 1;
  2650.                                 foreach ($valueService as $keyServiceDetail => $valueServiceDetail) {
  2651.                                     $idServiceCategory = $valueServiceDetail['services_data']->getServiceCatId();
  2652.                                     $inDate = date_format($valueServiceDetail['services_data']->getDateInAt(), 'd/m/Y');
  2653.                                     $outDate = date_format($valueServiceDetail['services_data']->getDateOutAt(), 'd/m/Y');
  2654.                                     $valueTotalUnit = $valueServiceDetail['calculos']['total'] / $valueServiceDetail['calculos']['total_days'];
  2655.                                     if (!empty($valueServiceDetail['services_data']->getUnits()) and ($valueServiceDetail['services_data']->getUnits() > 1)) {
  2656.                                         $valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getUnits();
  2657.                                     }
  2658.                                     if (!empty($valueServiceDetail['services_data']->getPax()) and ($valueServiceDetail['services_data']->getPax() > 1)) {
  2659.                                         $valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getPax();
  2660.                                     }
  2661.                                     $phpExcelObject->setActiveSheetIndex(0)
  2662.                                         ->setCellValue('A' . $l, $valueServiceDetail['services_data']->getName())
  2663.                                         ->setCellValue('D' . $l, $valueServiceDetail['calculos']['precio'])
  2664.                                         ->setCellValue('E' . $l, $valueServiceDetail['services_data']->getUnits())
  2665.                                         ->setCellValue('F' . $l, $valueServiceDetail['services_data']->getPax())
  2666.                                         ->setCellValue('G' . $l, $valueServiceDetail['calculos']['total_days'])
  2667.                                         ->setCellValue('H' . $l, $inDate)
  2668.                                         ->setCellValue('I' . $l, $outDate)
  2669.                                         ->setCellValue('K' . $l, $valueServiceDetail['services_data']->getIva());
  2670.                                     if ($idServiceCategory == 1 or $idServiceCategory == 10 or $idServiceCategory == 8 or $idServiceCategory == 13) {
  2671.                                         $phpExcelObject->getActiveSheet()
  2672.                                             ->setCellValue(
  2673.                                                 'J' . $l,
  2674.                                                 '=(D' . $l . '*E' . $l . '*G' . $l . ')'
  2675.                                             );
  2676.                                     } else {
  2677.                                         if ($valueServiceDetail['services_data']->getPax() == 0 or is_null($valueServiceDetail['services_data']->getPax())) {
  2678.                                             $phpExcelObject->setActiveSheetIndex(0)
  2679.                                                 ->setCellValue('F' . $l, 1);
  2680.                                         }
  2681.                                         $phpExcelObject->getActiveSheet()
  2682.                                             ->setCellValue(
  2683.                                                 'J' . $l,
  2684.                                                 '=(D' . $l . '*E' . $l . '*F' . $l . '*G' . $l . ')'
  2685.                                             );
  2686.                                     }
  2687.                                     $phpExcelObject->getActiveSheet()
  2688.                                         ->setCellValue(
  2689.                                             'L' . $l,
  2690.                                             '=J' . $l . '+(K' . $l . '*J' . $l . '/100)'
  2691.                                         );
  2692.                                     $phpExcelObject
  2693.                                         ->getActiveSheet()
  2694.                                         ->getStyle('J' . $l)
  2695.                                         ->getNumberFormat()
  2696.                                         ->setFormatCode('#,##0.00 €');
  2697.                                     $phpExcelObject
  2698.                                         ->getActiveSheet()
  2699.                                         ->getStyle('L' . $l)
  2700.                                         ->getNumberFormat()
  2701.                                         ->setFormatCode('#,##0.00 €');
  2702.                                     $netoSub = $netoSub + $valueServiceDetail['calculos']['total_neto'];
  2703.                                     $totalSub = $totalSub + $valueServiceDetail['calculos']['total'];
  2704.                                     $neto = $neto + $valueServiceDetail['calculos']['total_neto'];
  2705.                                     $total = $total + $valueServiceDetail['calculos']['total'];
  2706.                                     $l++;
  2707.                                 }
  2708.                                 $k = $l + 1;
  2709.                             }
  2710.                             $phpExcelObject->setActiveSheetIndex(0)
  2711.                                 ->setCellValue('I' . ($k - 1), 'SUBTOTAL')
  2712.                                 ->setCellValue('J' . ($k - 1), $netoSub)
  2713.                                 ->setCellValue('L' . ($k - 1), $totalSub);
  2714.                             $phpExcelObject
  2715.                                 ->getActiveSheet()
  2716.                                 ->getStyle('I' . ($k - 1) . ':L' . ($k - 1))
  2717.                                 ->getNumberFormat()
  2718.                                 ->setFormatCode('#,##0.00 €');
  2719.                             $phpExcelObject
  2720.                                 ->getActiveSheet()
  2721.                                 ->getStyle('I' . ($k - 1) . ':L' . ($k - 1))
  2722.                                 ->getFill()
  2723.                                 ->setFillType($fill::FILL_SOLID)
  2724.                                 ->getStartColor()
  2725.                                 ->setRGB('DF3A01');
  2726.                         }
  2727.                         if ($k - 1 != $service) {
  2728.                             $phpExcelObject->getActiveSheet()
  2729.                                 ->setCellValue(
  2730.                                     'L' . ($k - 1),
  2731.                                     '=SUM(L' . $service . ':L' . ($k - 2) . ')'
  2732.                                 );
  2733.                             $phpExcelObject->getActiveSheet()
  2734.                                 ->setCellValue(
  2735.                                     'J' . ($k - 1),
  2736.                                     '=SUM(J' . $service . ':J' . ($k - 2) . ')'
  2737.                                 );
  2738.                             if (empty($celdaNeto)) {
  2739.                                 $celdaNeto = '=';
  2740.                             } else {
  2741.                                 $celdaNeto = $celdaNeto . ' + ';
  2742.                             }
  2743.                             $celdaNeto = $celdaNeto . 'SUM(J' . $service . ':J' . ($k - 2) . ')';
  2744.                             if (empty($celdaTotal)) {
  2745.                                 $celdaTotal = '=';
  2746.                             } else {
  2747.                                 $celdaTotal = $celdaTotal . ' + ';
  2748.                             }
  2749.                             $celdaTotal = $celdaTotal . 'SUM(L' . $service . ':L' . ($k - 2) . ')';
  2750.                         }
  2751.                         $service = $k + 1;
  2752.                     }
  2753.                     $j = $service + 1;
  2754.                 }
  2755.                 $i = $j + 1;
  2756.                 $tot = $j - 1;
  2757.             }
  2758.             if (!empty($theFee)){
  2759.                 $phpExcelObject
  2760.                     ->getActiveSheet()
  2761.                     ->getStyle('I' . $tot)
  2762.                     ->getFill()
  2763.                     ->setFillType($fill::FILL_SOLID)
  2764.                     ->getStartColor()
  2765.                     ->setRGB('7ec8e0');
  2766.                 $phpExcelObject
  2767.                     ->getActiveSheet()
  2768.                     ->getStyle('J' . $tot)
  2769.                     ->getFill()
  2770.                     ->setFillType($fill::FILL_SOLID)
  2771.                     ->getStartColor()
  2772.                     ->setRGB('7ec8e0');
  2773.                 $phpExcelObject
  2774.                     ->getActiveSheet()
  2775.                     ->getStyle('K' . $tot)
  2776.                     ->getFill()
  2777.                     ->setFillType($fill::FILL_SOLID)
  2778.                     ->getStartColor()
  2779.                     ->setRGB('7ec8e0');
  2780.                 $phpExcelObject
  2781.                     ->getActiveSheet()
  2782.                     ->getStyle('L' . $tot)
  2783.                     ->getFill()
  2784.                     ->setFillType($fill::FILL_SOLID)
  2785.                     ->getStartColor()
  2786.                     ->setRGB('7ec8e0');
  2787.                 if (empty($theFee['valorDirecto'])){
  2788.                     // Fee de porcentaje
  2789.                     $phpExcelObject->getActiveSheet()
  2790.                         ->setCellValue(
  2791.                             'I' . $tot,
  2792.                             'FEE '.$theFee['montoPorcentaje'].'%'
  2793.                         );
  2794.                     $phpExcelObject->getActiveSheet()
  2795.                         ->setCellValue(
  2796.                             'J' . $tot,
  2797.                             '=('.substr($celdaNeto, 1).') * ('.$theFee['montoPorcentaje'].'/100 )'
  2798.                         );
  2799.                     $celdaNeto = $celdaNeto . '+ (('.substr($celdaNeto, 1).') * ('.$theFee['montoPorcentaje'].'/100 ))';
  2800.                     $phpExcelObject
  2801.                         ->getActiveSheet()
  2802.                         ->getStyle('J' . $tot)
  2803.                         ->getNumberFormat()
  2804.                         ->setFormatCode('#,##0.00 €');
  2805.                     $phpExcelObject->getActiveSheet()
  2806.                         ->setCellValue(
  2807.                             'L' . $tot,
  2808.                             '=J'.$tot.' * (1.21)'
  2809.                         );
  2810.                     $celdaTotal = $celdaTotal . '+ L'.$tot;
  2811.                     $phpExcelObject
  2812.                         ->getActiveSheet()
  2813.                         ->getStyle('L' . $tot)
  2814.                         ->getNumberFormat()
  2815.                         ->setFormatCode('#,##0.00 €');
  2816.                 } else {
  2817.                     // Fee de valor directo
  2818.                     $phpExcelObject->getActiveSheet()
  2819.                         ->setCellValue(
  2820.                             'I' . $tot,
  2821.                             'FEE'
  2822.                         );
  2823.                     $phpExcelObject->getActiveSheet()
  2824.                         ->setCellValue(
  2825.                             'J' . $tot,
  2826.                             $theFee['valorDirecto']
  2827.                         );
  2828.                     $celdaNeto = $celdaNeto . ' + '.$theFee['valorDirecto'];
  2829.                     $phpExcelObject
  2830.                         ->getActiveSheet()
  2831.                         ->getStyle('J' . $tot)
  2832.                         ->getNumberFormat()
  2833.                         ->setFormatCode('#,##0.00 €');
  2834.                     $phpExcelObject
  2835.                         ->getActiveSheet()
  2836.                         ->getStyle('L' . $tot)
  2837.                         ->getNumberFormat()
  2838.                         ->setFormatCode('#,##0.00 €');
  2839.                     $phpExcelObject->getActiveSheet()
  2840.                         ->setCellValue(
  2841.                             'L' . $tot,
  2842.                             '=J'.$tot.' * (1.21)'
  2843.                         );
  2844.                     $celdaTotal = $celdaTotal . ' +  L'.$tot;
  2845.                 }
  2846.                 $tot = $tot + 2;
  2847.             }
  2848.             #####################################################
  2849.             # TOTAL Y NETO                                      #
  2850.             #####################################################
  2851.             $phpExcelObject
  2852.                 ->getActiveSheet()
  2853.                 ->getStyle('I' . $tot)
  2854.                 ->getFill()
  2855.                 ->setFillType($fill::FILL_SOLID)
  2856.                 ->getStartColor()
  2857.                 ->setRGB('7ec8e0');
  2858.             $phpExcelObject
  2859.                 ->getActiveSheet()
  2860.                 ->getStyle('J' . $tot)
  2861.                 ->getFill()
  2862.                 ->setFillType($fill::FILL_SOLID)
  2863.                 ->getStartColor()
  2864.                 ->setRGB('7ec8e0');
  2865.             $phpExcelObject
  2866.                 ->getActiveSheet()
  2867.                 ->getStyle('K' . $tot)
  2868.                 ->getFill()
  2869.                 ->setFillType($fill::FILL_SOLID)
  2870.                 ->getStartColor()
  2871.                 ->setRGB('7ec8e0');
  2872.             $phpExcelObject
  2873.                 ->getActiveSheet()
  2874.                 ->getStyle('L' . $tot)
  2875.                 ->getFill()
  2876.                 ->setFillType($fill::FILL_SOLID)
  2877.                 ->getStartColor()
  2878.                 ->setRGB('7ec8e0');
  2879.             $phpExcelObject->setActiveSheetIndex(0)
  2880.                 ->setCellValue('I' . $tot, 'NETO: ')
  2881.                 ->setCellValue('K' . $tot, 'TOTAL: ')
  2882.                 ->setCellValue('J' . $tot, $celdaNeto)
  2883.                 ->setCellValue('L' . $tot, $celdaTotal);
  2884.             $phpExcelObject
  2885.                 ->getActiveSheet()
  2886.                 ->getStyle('J' . $tot)
  2887.                 ->getNumberFormat()
  2888.                 ->setFormatCode('#,##0.00 €');
  2889.             $phpExcelObject
  2890.                 ->getActiveSheet()
  2891.                 ->getStyle('L' . $tot)
  2892.                 ->getNumberFormat()
  2893.                 ->setFormatCode('#,##0.00 €');
  2894.             #####################################################
  2895.             # FIN TOTAL Y NETO                                  #
  2896.             #####################################################
  2897.             // AutoSize solo de las columnas (H a L)
  2898.             foreach (range('H', 'L') as $columnID) {
  2899.                 $phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
  2900.             }
  2901.             $estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ));
  2902.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 2))->applyFromArray($estilo);
  2903.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 3))->applyFromArray($estilo);
  2904.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot + 4))->applyFromArray($estilo);
  2905.             $phpExcelObject->setActiveSheetIndex(0)
  2906.                 ->setCellValue('L' . ($tot + 2), 'INOUT TRAVEL')
  2907.                 ->setCellValue('L' . ($tot + 3), 'events@inout-travel.com')
  2908.                 ->setCellValue('L' . ($tot + 4), '+34 911 878 393');
  2909.             $phpExcelObject
  2910.                 ->getActiveSheet()
  2911.                 ->getStyle('k' . ($tot + 2) . ':' . 'L' . ($tot + 4))
  2912.                 ->getFill()
  2913.                 ->setFillType($fill::FILL_SOLID)
  2914.                 ->getStartColor()
  2915.                 ->setRGB('F18E0D');
  2916.         } else {
  2917.             // *****************************************************************************************************
  2918.             //                                      Caso internacional
  2919.             // *****************************************************************************************************
  2920.             $celdaNeto = '';
  2921.             $celdaTotal = '';
  2922.             foreach ($data_supplier as $key => $value) {
  2923.                 $phpExcelObject
  2924.                     ->getActiveSheet()
  2925.                     ->getStyle('A' . $i . ':M' . $i)
  2926.                     ->getFill()
  2927.                     ->setFillType($fill::FILL_SOLID)
  2928.                     ->getStartColor()
  2929.                     ->setRGB('FFA420');
  2930.                 $keytrans = strtoupper($this->translator->trans($key));
  2931.                 $phpExcelObject->setActiveSheetIndex(0)
  2932.                     ->setCellValue('E' . $i, $keytrans);
  2933.                 $j = $i + 1;
  2934.                 foreach ($value as $keySup => $valueSup) {
  2935.                     $phpExcelObject
  2936.                         ->getActiveSheet()
  2937.                         ->getStyle('A' . $j . ':M' . $j)
  2938.                         ->getFill()
  2939.                         ->setFillType($fill::FILL_SOLID)
  2940.                         ->getStartColor()
  2941.                         ->setRGB('B5B8B1');
  2942.                     $keySuptrans = strtoupper($this->translator->trans($keySup));
  2943.                     $phpExcelObject->setActiveSheetIndex(0)
  2944.                         ->setCellValue('E' . $j, $keySuptrans);
  2945.                     $drawingobject = new Drawing;
  2946.                     $service = $j + 1;
  2947.                     foreach ($valueSup as $keySupAll => $valueSupAll) {
  2948.                         $totalSub = 0;
  2949.                         $netoSub = 0;
  2950.                         if (!is_null($valueSupAll['master'])) {
  2951.                             $type = $valueSupAll['master'];
  2952.                             if ($type == 'idea' or $type == 'activity') {
  2953.                                 $name = $valueSupAll[$type]->getName();
  2954.                             } else {
  2955.                                 $name = "";
  2956.                                 if (!empty($valueSupAll['supplier'])) {
  2957.                                     if (
  2958.                                         $valueSupAll['supplier']->getType() == "ENTRETENIMIENTO" or
  2959.                                         $valueSupAll['supplier']->getType() == "TRANSPORTE" or
  2960.                                         $valueSupAll['supplier']->getType() == "GUÍAS" or
  2961.                                         $valueSupAll['supplier']->getType() == "OTROS" or
  2962.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUAL" or
  2963.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUALES" or
  2964.                                         $valueSupAll['supplier']->getType() == "MÚSICA" or
  2965.                                         $valueSupAll['supplier']->getType() == "ASISTENCIA"
  2966.                                     ) {
  2967.                                         $name = "";
  2968.                                         $valueSupAll[$type]->setCompany('');
  2969.                                         $valueSupAll[$type]->setName('');
  2970.                                     } else {
  2971.                                         $name = $valueSupAll[$type]->getCompany();
  2972.                                     }
  2973.                                 }
  2974.                             }
  2975.                             if ($name != '') {
  2976.                                 $phpExcelObject
  2977.                                     ->getActiveSheet()
  2978.                                     ->getStyle('A' . $service . ':C' . $service)
  2979.                                     ->getFill()
  2980.                                     ->setFillType($fill::FILL_SOLID)
  2981.                                     ->getStartColor()
  2982.                                     ->setRGB('DA9694');
  2983.                                 $phpExcelObject->setActiveSheetIndex(0)
  2984.                                     ->setCellValue('A' . $service, $name);
  2985.                             }
  2986.                         }
  2987.                         $estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ) );
  2988.                         $k = $service + 1;
  2989.                         if (!empty($valueSupAll[$type])) {
  2990.                             foreach ($valueSupAll['services'] as $keyService => $valueService) {
  2991.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  2992.                                     // Por defecto para todos los idiomas sera un presupuesto en castellano
  2993.                                     $keyServiceTrad = $this->translator->trans($keyService);
  2994.                                 } else {
  2995.                                     // El otro idioma es ingles
  2996.                                     $keyServiceTrad = $keyService;
  2997.                                 }
  2998.                                 $phpExcelObject
  2999.                                     ->getActiveSheet()
  3000.                                     ->getStyle('A' . $k . ':M' . $k)
  3001.                                     ->applyFromArray($estilo)
  3002.                                     ->getFill()
  3003.                                     ->setFillType($fill::FILL_SOLID)
  3004.                                     ->getStartColor()
  3005.                                     ->setRGB('497E76');
  3006.                                 $estiloL = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_LEFT, ) );
  3007.                                 $phpExcelObject
  3008.                                     ->getActiveSheet()
  3009.                                     ->getStyle('A' . $k)
  3010.                                     ->applyFromArray($estiloL);
  3011.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  3012.                                     $phpExcelObject->setActiveSheetIndex(0)
  3013.                                         ->setCellValue('A' . $k, $keyServiceTrad)
  3014.                                         ->setCellValue('D' . $k, 'Precio Unitario')
  3015.                                         ->setCellValue('E' . $k, 'Precio con Iva')
  3016.                                         ->setCellValue('F' . $k, 'Cantidad')
  3017.                                         ->setCellValue('G' . $k, 'Personas')
  3018.                                         ->setCellValue('H' . $k, 'Días')
  3019.                                         ->setCellValue('I' . $k, 'Inicio')
  3020.                                         ->setCellValue('J' . $k, 'Fin')
  3021.                                         ->setCellValue('K' . $k, 'Neto')
  3022.                                         ->setCellValue('L' . $k, 'Iva')
  3023.                                         ->setCellValue('M' . $k, 'Total');
  3024.                                 } else {
  3025.                                     $phpExcelObject->setActiveSheetIndex(0)
  3026.                                         ->setCellValue('A' . $k, $keyServiceTrad)
  3027.                                         ->setCellValue('D' . $k, 'Price')
  3028.                                         ->setCellValue('E' . $k, 'Price with Vat')
  3029.                                         ->setCellValue('F' . $k, 'Qty')
  3030.                                         ->setCellValue('G' . $k, 'People')
  3031.                                         ->setCellValue('H' . $k, 'Days')
  3032.                                         ->setCellValue('I' . $k, 'Start')
  3033.                                         ->setCellValue('J' . $k, 'End')
  3034.                                         ->setCellValue('K' . $k, 'Net')
  3035.                                         ->setCellValue('L' . $k, 'Vat')
  3036.                                         ->setCellValue('M' . $k, 'Total');
  3037.                                 }
  3038.                                 $l = $k + 1;
  3039.                                 foreach ($valueService as $keyServiceDetail => $valueServiceDetail) {
  3040.                                     $idServiceCategory = $valueServiceDetail['services_data']->getServiceCatId();
  3041.                                     $inDate = date_format($valueServiceDetail['services_data']->getDateInAt(), 'd/m/Y');
  3042.                                     $outDate = date_format($valueServiceDetail['services_data']->getDateOutAt(), 'd/m/Y');
  3043.                                     $valueTotalUnit = $valueServiceDetail['calculos']['total'] / $valueServiceDetail['calculos']['total_days'];
  3044.                                     $celdaValueTotalUnit = '=(M' . $l . '/ H' . $l . ')/ F' . $l;
  3045.                                     if (!empty($valueServiceDetail['services_data']->getUnits()) and ($valueServiceDetail['services_data']->getUnits() > 1)) {
  3046.                                         $valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getUnits();
  3047.                                         $celdaValueTotalUnit = '=((M' . $l . '/ H' . $l . ')/ F' . $l . ')';
  3048.                                     }
  3049.                                     if (!empty($valueServiceDetail['services_data']->getPax()) and ($valueServiceDetail['services_data']->getPax() > 1)) {
  3050.                                         $valueTotalUnit = $valueTotalUnit / $valueServiceDetail['services_data']->getPax();
  3051.                                         $celdaValueTotalUnit = '=(((M' . $l . '/ H' . $l . ')/ F' . $l . ')/ G' . $l . ')';
  3052.                                     }
  3053.                                     $valueTotalUnit = round($valueTotalUnit, 2);
  3054.                                     $phpExcelObject->setActiveSheetIndex(0)
  3055.                                         ->setCellValue('A' . $l, $valueServiceDetail['services_data']->getName())
  3056.                                         ->setCellValue('D' . $l, $valueServiceDetail['calculos']['precio'])
  3057.                                         ->setCellValue('E' . $l, $celdaValueTotalUnit)
  3058.                                         ->setCellValue('F' . $l, $valueServiceDetail['services_data']->getUnits())
  3059.                                         ->setCellValue('G' . $l, $valueServiceDetail['services_data']->getPax())
  3060.                                         ->setCellValue('H' . $l, $valueServiceDetail['calculos']['total_days'])
  3061.                                         ->setCellValue('I' . $l, $inDate)
  3062.                                         ->setCellValue('J' . $l, $outDate)
  3063.                                         ->setCellValue('L' . $l, $valueServiceDetail['services_data']->getIva());
  3064.                                     if ($idServiceCategory == 1 or $idServiceCategory == 10 or $idServiceCategory == 8 or $idServiceCategory == 13) {
  3065.                                         $phpExcelObject->getActiveSheet()
  3066.                                             ->setCellValue(
  3067.                                                 'K' . $l,
  3068.                                                 '=(D' . $l . '*F' . $l . '*H' . $l . ')'
  3069.                                             );
  3070.                                     } else {
  3071.                                         if ($valueServiceDetail['services_data']->getPax() == 0 or is_null($valueServiceDetail['services_data']->getPax())) {
  3072.                                             $phpExcelObject->setActiveSheetIndex(0)
  3073.                                                 ->setCellValue('G' . $l, 1);
  3074.                                         }
  3075.                                         $phpExcelObject->getActiveSheet()
  3076.                                             ->setCellValue(
  3077.                                                 'K' . $l,
  3078.                                                 '=(D' . $l . '*F' . $l . '*G' . $l . '*H' . $l . ')'
  3079.                                             );
  3080.                                     }
  3081.                                     $phpExcelObject->getActiveSheet()
  3082.                                         ->setCellValue(
  3083.                                             'M' . $l,
  3084.                                             '=K' . $l . '+(L' . $l . '*K' . $l . '/100)'
  3085.                                         );
  3086.                                     $phpExcelObject
  3087.                                         ->getActiveSheet()
  3088.                                         ->getStyle('K' . $l)
  3089.                                         ->getNumberFormat()
  3090.                                         ->setFormatCode('#,##0.00 €');
  3091.                                     $phpExcelObject
  3092.                                         ->getActiveSheet()
  3093.                                         ->getStyle('M' . $l)
  3094.                                         ->getNumberFormat()
  3095.                                         ->setFormatCode('#,##0.00 €');
  3096.                                     $netoSub = $netoSub + $valueServiceDetail['calculos']['total_neto'];
  3097.                                     $totalSub = $totalSub + $valueServiceDetail['calculos']['total'];
  3098.                                     $neto = $neto + $valueServiceDetail['calculos']['total_neto'];
  3099.                                     $total = $total + $valueServiceDetail['calculos']['total'];
  3100.                                     $l++;
  3101.                                 }
  3102.                                 $k = $l + 1;
  3103.                             }
  3104.                             $phpExcelObject->setActiveSheetIndex(0)
  3105.                                 ->setCellValue('J' . ($k - 1), 'SUBTOTAL')
  3106.                                 ->setCellValue('K' . ($k - 1), $netoSub)
  3107.                                 ->setCellValue('M' . ($k - 1), $totalSub);
  3108.                             $phpExcelObject
  3109.                                 ->getActiveSheet()
  3110.                                 ->getStyle('J' . ($k - 1) . ':M' . ($k - 1))
  3111.                                 ->getNumberFormat()
  3112.                                 ->setFormatCode('#,##0.00 €');
  3113.                             $phpExcelObject
  3114.                                 ->getActiveSheet()
  3115.                                 ->getStyle('J' . ($k - 1) . ':M' . ($k - 1))
  3116.                                 ->getFill()
  3117.                                 ->setFillType($fill::FILL_SOLID)
  3118.                                 ->getStartColor()
  3119.                                 ->setRGB('DF3A01');
  3120.                         }
  3121.                         if ($k - 1 != $service) {
  3122.                             $phpExcelObject->getActiveSheet()
  3123.                                 ->setCellValue(
  3124.                                     'M' . ($k - 1),
  3125.                                     '=SUM(M' . $service . ':M' . ($k - 2) . ')'
  3126.                                 );
  3127.                             $phpExcelObject->getActiveSheet()
  3128.                                 ->setCellValue(
  3129.                                     'K' . ($k - 1),
  3130.                                     '=SUM(K' . $service . ':K' . ($k - 2) . ')'
  3131.                                 );
  3132.                             if (empty($celdaNeto)) { $celdaNeto = '='; } else { $celdaNeto = $celdaNeto . ' + '; }
  3133.                             $celdaNeto = $celdaNeto . 'SUM(K' . $service . ':K' . ($k - 2) . ')';
  3134.                             if (empty($celdaTotal)) { $celdaTotal = '='; } else { $celdaTotal = $celdaTotal . ' + '; }
  3135.                             $celdaTotal = $celdaTotal . 'SUM(M' . $service . ':M' . ($k - 2) . ')';
  3136.                         }
  3137.                         $service = $k + 1;
  3138.                     }
  3139.                     $j = $service + 1;
  3140.                 }
  3141.                 $i = $j + 1;
  3142.                 $tot = $j - 1;
  3143.             }
  3144.             #####################################################
  3145.             # TOTAL Y NETO                                      #
  3146.             #####################################################
  3147.             $phpExcelObject
  3148.                 ->getActiveSheet()
  3149.                 ->getStyle('J' . $tot)
  3150.                 ->getFill()
  3151.                 ->setFillType($fill::FILL_SOLID)
  3152.                 ->getStartColor()
  3153.                 ->setRGB('7ec8e0');
  3154.             $phpExcelObject
  3155.                 ->getActiveSheet()
  3156.                 ->getStyle('K' . $tot)
  3157.                 ->getFill()
  3158.                 ->setFillType($fill::FILL_SOLID)
  3159.                 ->getStartColor()
  3160.                 ->setRGB('7ec8e0');
  3161.             $phpExcelObject
  3162.                 ->getActiveSheet()
  3163.                 ->getStyle('L' . $tot)
  3164.                 ->getFill()
  3165.                 ->setFillType($fill::FILL_SOLID)
  3166.                 ->getStartColor()
  3167.                 ->setRGB('7ec8e0');
  3168.             $phpExcelObject
  3169.                 ->getActiveSheet()
  3170.                 ->getStyle('M' . $tot)
  3171.                 ->getFill()
  3172.                 ->setFillType($fill::FILL_SOLID)
  3173.                 ->getStartColor()
  3174.                 ->setRGB('7ec8e0');
  3175.             if (!($proposal->getLanguage() == 'ENGLISH')) {
  3176.                 $phpExcelObject->setActiveSheetIndex(0)
  3177.                     ->setCellValue('J' . $tot, 'NETO: ')
  3178.                     ->setCellValue('L' . $tot, 'TOTAL: ')
  3179.                     ->setCellValue('K' . $tot, $celdaNeto)
  3180.                     ->setCellValue('M' . $tot, $celdaTotal);
  3181.             } else {
  3182.                 $phpExcelObject->setActiveSheetIndex(0)
  3183.                     ->setCellValue('J' . $tot, 'NET: ')
  3184.                     ->setCellValue('L' . $tot, 'TOTAL: ')
  3185.                     ->setCellValue('K' . $tot, $celdaNeto)
  3186.                     ->setCellValue('M' . $tot, $celdaTotal);
  3187.             }
  3188.             $phpExcelObject
  3189.                 ->getActiveSheet()
  3190.                 ->getStyle('K' . $tot)
  3191.                 ->getNumberFormat()
  3192.                 ->setFormatCode('#,##0.00 €');
  3193.             $phpExcelObject
  3194.                 ->getActiveSheet()
  3195.                 ->getStyle('M' . $tot)
  3196.                 ->getNumberFormat()
  3197.                 ->setFormatCode('#,##0.00 €');
  3198.             #####################################################
  3199.             # FIN TOTAL Y NETO                                  #
  3200.             #####################################################
  3201.             // AutoSize solo de las columnas (I a M)
  3202.             foreach (range('I', 'M') as $columnID) {
  3203.                 $phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
  3204.             }
  3205.             $estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ));
  3206.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 2))->applyFromArray($estilo);
  3207.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 3))->applyFromArray($estilo);
  3208.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot + 4))->applyFromArray($estilo);
  3209.             $phpExcelObject->setActiveSheetIndex(0)
  3210.                 ->setCellValue('M' . ($tot + 2), 'INOUT TRAVEL')
  3211.                 ->setCellValue('M' . ($tot + 3), 'events@inout-travel.com')
  3212.                 ->setCellValue('M' . ($tot + 4), '+34 911 878 393');
  3213.             $phpExcelObject
  3214.                 ->getActiveSheet()
  3215.                 ->getStyle('L' . ($tot + 2) . ':' . 'M' . ($tot + 4))
  3216.                 ->getFill()
  3217.                 ->setFillType($fill::FILL_SOLID)
  3218.                 ->getStartColor()
  3219.                 ->setRGB('F18E0D');
  3220.         } //FIN DEL IF DE LA COMMISSION
  3221.         $phpExcelObject->getActiveSheet()->setTitle('Simple');
  3222.         $phpExcelObject->setActiveSheetIndex(0);
  3223.         // Crea el writer
  3224.         $writer = new Xlsx($phpExcelObject);
  3225.         // Envia la respuesta del controlador
  3226.         $response = new StreamedResponse(
  3227.             function () use ($writer) {
  3228.                 $writer->save('php://output');
  3229.             }
  3230.         );
  3231.         // Agrega los headers requeridos
  3232.         $dispositionHeader = $response->headers->makeDisposition(
  3233.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  3234.             'In Out Travel proposal - ' . $proposal->getId() . '.xlsx'
  3235.         );
  3236.         $response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
  3237.         $response->headers->set('Pragma', 'public');
  3238.         $response->headers->set('Cache-Control', 'maxage=1');
  3239.         $response->headers->set('Content-Disposition', $dispositionHeader);
  3240.         return $response;
  3241.     }
  3242.     /**
  3243.      * @Route("/budget/{token}", name="presentation_budget_token")
  3244.      */
  3245.     public function budgetAction($token, EntityManagerInterface $em, Request $request)
  3246.     {
  3247.         $totales_neto_sub = $totales_iva_sub  = $totales_con_iva_sub = $totales_paying_sub = $totales_pago_sub = $totales_benefit_moneda_sub = 0;
  3248.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  3249.         if ($proposal->getStatus() == "Cancel") {
  3250.             return $this->redirectToRoute( 'presentation_error_cancel', array( 'token' => $token ) );
  3251.         }
  3252.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  3253.         // Usuario Anonimo es = "anon."
  3254.         if ($user_logueado == "anon.") {
  3255.             $proposal->setViewedAt(new \DateTime("now"));
  3256.             $em->persist($proposal);
  3257.             $em->flush();
  3258.         }
  3259.         $selectType = explode(",", $proposal->getSelectType());
  3260.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  3261.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  3262.             array(
  3263.                 'proposalId' => $proposal->getId(),
  3264.                 'disabled' => '0',
  3265.             )
  3266.         );
  3267.         $data_destionation = array();
  3268.         $cont_destino = 0;
  3269.         foreach ($proposal_Control as $proposalControl) {
  3270.             $cont_destino += 1;
  3271.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  3272.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  3273.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  3274.                 array(
  3275.                     'destinationId' => $proposalControl->getDestinationId(),
  3276.                     'language' => $proposal->getLanguage()
  3277.                 )
  3278.             );
  3279.             $data_destionation[$destino->getTitle()] = array(
  3280.                 'destino' => $destino,
  3281.                 'gallery' => $gallery,
  3282.                 'description' => $description,
  3283.             );
  3284.         }
  3285.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  3286.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3287.         /* INICIO CONTENIDO DEL PRESUPUESTO                                                           */
  3288.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3289.         //        $available_destination = $em->getRepository(ProposalControl::class)->findByProposalId($proposal->getId());
  3290.         $available_destination = $em->getRepository(ProposalControl::class)->findBy(
  3291.             array(
  3292.                 'proposalId' => $proposal->getId(),
  3293.                 'disabled' => "0"
  3294.             )
  3295.         );
  3296.         $data_supplier = array();
  3297.         foreach ($available_destination as $availabledestination) {
  3298.             /* Data Supplier agregados */
  3299.             $service_supplier = $em->getRepository(ProposalSupplierControl::class)->findBy(
  3300.                 array(
  3301.                     'controlDestinationId' => $availabledestination->getId(),
  3302.                     'disabled' => "0"
  3303.                 ),
  3304.                 array(
  3305.                     'rank' => 'ASC'
  3306.                 )
  3307.             );
  3308.             $controlgeneral = array();
  3309.             foreach ($service_supplier as $suppliercontrol) {
  3310.                 $destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
  3311.                 //cambiar el estatus de colores
  3312.                 $colorlabel = "";
  3313.                 switch ($suppliercontrol->getStatus()) {
  3314.                     case 'Pending': $colorlabel = "bg-danger"; break;
  3315.                     case 'Confirmed': $colorlabel = "bg-success"; break;
  3316.                 }
  3317.                 $sqlactivities = "";
  3318.                 if (!is_null($suppliercontrol->getActivityId())) {
  3319.                     $master = "activity";
  3320.                     $sqlactivities = $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
  3321.                     /*CONTROL GENERAL*/
  3322.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
  3323.                 }
  3324.                 $sqlideas = "";
  3325.                 if (!is_null($suppliercontrol->getIdeaId())) {
  3326.                     $master = "idea";
  3327.                     $sqlideas = $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
  3328.                     /*CONTROL GENERAL*/
  3329.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
  3330.                 }
  3331.                 $sqlsuppliers = "";
  3332.                 if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
  3333.                     $master = "supplier";
  3334.                     $sqlsuppliers = $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
  3335.                     if (!is_null($sqlsuppliers)) {
  3336.                         switch ($sqlsuppliers->getStar()) {
  3337.                             case 1: $sqlsuppliers->setStar('<i class="icon-star-full2"></i>'); break;
  3338.                             case 2: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  3339.                             case 3: $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  3340.                             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;
  3341.                             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;
  3342.                             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;
  3343.                             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;
  3344.                             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;
  3345.                         }
  3346.                     }
  3347.                     /*CONTROL GENERAL*/
  3348.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
  3349.                 }
  3350.                 $sqlcompany = "";
  3351.                 if ($suppliercontrol->getSupplierId() == "0") {
  3352.                     $master = "company";
  3353.                     $sqlcompany = $em->getRepository(SettingsCompany::class)->findOneById('1');
  3354.                     if (!is_null($sqlcompany)) {
  3355.                         $imagenSmall = $sqlcompany->getPicture();
  3356.                     } else {
  3357.                         //Imagen no disponible (poner una generica)
  3358.                         $imagenSmall = null;
  3359.                     }
  3360.                 } else {
  3361.                     $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  3362.                         array(
  3363.                             'supplierId' => $controlgeneral->getId(),
  3364.                             'servicesCatId' => '0',
  3365.                             'servicesCategory' => 'General',
  3366.                             'servicesId' => '0',
  3367.                             'controlId' => '0'
  3368.                         )
  3369.                     );
  3370.                     if (!is_null($sqlsuppliers_gallery)) {
  3371.                         $imagenSmall = $sqlsuppliers_gallery->getImageSmall();
  3372.                     } else {
  3373.                         //Imagen no disponible (poner una generica)
  3374.                         $imagenSmall = null;
  3375.                     }
  3376.                 }
  3377.                 // ORDEN DESCENDENTE Y POR SERVICES
  3378.                 $parameters = array(
  3379.                     'controlId' => $suppliercontrol->getId(),
  3380.                     'serviceIdFather' => '0',
  3381.                     'directPayment' => '0',
  3382.                 );
  3383.                 $dql = 'SELECT p
  3384.                         FROM EventsBundle:ProposalSupplierServices p
  3385.                         WHERE p.controlId = :controlId 
  3386.                         AND p.serviceIdFather = :serviceIdFather
  3387.                         AND p.directPayment = :directPayment
  3388.                         ORDER BY p.serviceCatId, p.rank ASC ';
  3389.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3390.                 $data_service_supplier = $query->getResult();
  3391.                 $service_supplier_data = array();
  3392.                 $calculos_totatales = array();
  3393.                 $totales_neto = '0';
  3394.                 $totales_iva = '0';
  3395.                 $totales_con_iva = '0';
  3396.                 $totales_paying = '0';
  3397.                 $totales_pago = '0';
  3398.                 $totales_benefit_moneda = '0';
  3399.                 $totales_benefit_porsentaje = '0';
  3400.                 foreach ($data_service_supplier as $data_service) {
  3401.                     //COLOR POR SERVICIO
  3402.                     $contcolor = "";
  3403.                     switch ($data_service->getServiceCatName()) {
  3404.                         case "Accommodation": $contcolor = 'teal'; break;
  3405.                         case "Menu": $contcolor = 'purple'; break;
  3406.                         case "Lounge": $contcolor = 'warning'; break;
  3407.                         case "Activities": $contcolor = 'blue'; break;
  3408.                         case "Itineraries": $contcolor = 'indigo'; break;
  3409.                         case "Cruise": $contcolor = 'brown'; break;
  3410.                         case "Transport": $contcolor = 'grey'; break;
  3411.                         case "Av": $contcolor = 'slate'; break;
  3412.                         case "Creative": $contcolor = 'orange'; break;
  3413.                         case "Gifts": $contcolor = 'pink'; break;
  3414.                         case "Entertainment": $contcolor = 'green'; break;
  3415.                         case "Guide": $contcolor = 'orange'; break;
  3416.                         case "Others": $contcolor = 'danger'; break;
  3417.                         case "Technology": $contcolor = 'grey-800'; break;
  3418.                         case "Assistant": $contcolor = 'indigo-800'; break;
  3419.                         case "DDR": $contcolor = 'green-300'; break;
  3420.                     }
  3421.                     $idcat = $data_service->getServiceCatId();
  3422.                     $price = $data_service->getPrice();
  3423.                     $units = $data_service->getUnits();
  3424.                     $pax = $data_service->getPax();
  3425.                     $opcommission = $data_service->getOpCommission();
  3426.                     $commission = $data_service->getCommission();
  3427.                     $opover = $data_service->getOpOver();
  3428.                     $over = $data_service->getOver();
  3429.                     $opiva = $data_service->getOpIva();
  3430.                     $iva = $data_service->getIva();
  3431.                     $dateInAt = $data_service->getDateInAt();
  3432.                     $dateOutAt = $data_service->getDateOutAt();
  3433.                     if (!is_null($dateInAt) and !is_null($dateOutAt)) {
  3434.                         $days = $dateInAt->diff($dateOutAt);
  3435.                         $day = $days->days;
  3436.                     } else {
  3437.                         $day = "0";
  3438.                     }
  3439.                     $directPayment = $data_service->getDirectPayment();
  3440.                     if ($data_service->getSupplierId() == "0") {
  3441.                         $name_company = $em->getRepository(Configuration::class)->findOneById('1');
  3442.                         $namesupplier = $name_company->getCompany();
  3443.                     }
  3444.                     if (!is_null($data_service->getSupplierId()) && $data_service->getSupplierId() != "0") {
  3445.                         $name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  3446.                         $namesupplier = $name_supplier->getName();
  3447.                     }
  3448.                     if (!is_null($data_service->getActivityId())) {
  3449.                         $name_supplier = $em->getRepository(Activities::class)->findOneById($data_service->getActivityId());
  3450.                         $namesupplier = $name_supplier->getName();
  3451.                     }
  3452.                     if (!is_null($data_service->getIdeaId())) {
  3453.                         $name_supplier = $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
  3454.                         $namesupplier = $name_supplier->getName();
  3455.                     }
  3456.                     $calculos = $this->CalculoTotalesservices($price, $units, $pax, $day, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat);
  3457.                     $data_service->setPrice($calculos['precio']); //ojo aqui
  3458.                     /*CONTROL GENERAL*/
  3459.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
  3460.                     $service_supplier_data[$data_service->getServiceCatName()][] = array(
  3461.                         'calculos' => $calculos,
  3462.                         'services_data' => $data_service,
  3463.                         'contcolor' => $contcolor,
  3464.                     );
  3465.                     if ($data_service->getBreakdown() == false) {
  3466.                         $totales_neto += $calculos['total_neto'];
  3467.                         $totales_iva += $calculos['sub_total_iva'];
  3468.                         $totales_con_iva += $calculos['total'];
  3469.                         $totales_paying += $calculos['total_paying'];
  3470.                         $totales_pago += $calculos['total_pago'];
  3471.                         $totales_benefit_moneda += $calculos['benefit_moneda'];
  3472.                     } else {
  3473.                         $totales_neto += $totales_neto_sub;
  3474.                         $totales_iva += $totales_iva_sub;
  3475.                         $totales_con_iva += $totales_con_iva_sub;
  3476.                         $totales_paying += $totales_paying_sub;
  3477.                         $totales_pago += $totales_pago_sub;
  3478.                         $totales_benefit_moneda += $totales_benefit_moneda_sub;
  3479.                     }
  3480.                     if ($totales_benefit_moneda == '0') {
  3481.                         $totales_benefit_porsentaje =  '0';
  3482.                     } else {
  3483.                         if ($totales_pago == '0') {
  3484.                             $totales_benefit_porsentaje =  '0';
  3485.                         } else {
  3486.                             //                        $totales_benefit_porsentaje =  $totales_benefit_moneda * 100 / $totales_neto;
  3487.                             $totales_benefit_porsentaje =  $totales_benefit_moneda * 100 / $totales_pago;
  3488.                         }
  3489.                     }
  3490.                 }
  3491.                 $calculos_totatales = array(
  3492.                     'totales_neto' => $totales_neto,
  3493.                     'totales_iva' => $totales_iva,
  3494.                     'totales_con_iva' => $totales_con_iva,
  3495.                     'totales_paying' => $totales_paying,
  3496.                     'totales_benefit_moneda' => $totales_benefit_moneda,
  3497.                     'totales_benefit_porsentaje' => $totales_benefit_porsentaje
  3498.                 );
  3499.                 if ($master == "company") { $typeMaster = $sqlcompany->getCompany(); }
  3500.                 if ($master == "supplier") { $typeMaster = $sqlsuppliers->getType(); }
  3501.                 if ($master == "activity") { $typeMaster = "Activity"; }
  3502.                 if ($master == "idea") { $typeMaster = "Idea"; }
  3503.                 $data_supplier[$destination->getTitle()][$typeMaster][] = array(
  3504.                     'colorlabel' => $colorlabel,
  3505.                     'control' => $suppliercontrol,
  3506.                     'master' => $master,
  3507.                     'supplier' => $sqlsuppliers,
  3508.                     'idea' => $sqlideas,
  3509.                     'activity' => $sqlactivities,
  3510.                     'company' => $sqlcompany,
  3511.                     'image' => $imagenSmall,
  3512.                     'services' => $service_supplier_data,
  3513.                     'totales_services' => $calculos_totatales
  3514.                 );
  3515.             }
  3516.         }
  3517.         $controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  3518.         foreach ($controlbudgets as $controlbudge) {
  3519.             $controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
  3520.         }
  3521.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3522.         /* FIN CONTENIDO DEL PRESUPUESTO                                                              */
  3523.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3524.         //////////////////////////////////////////////
  3525.         /* CODIGO PARA TRAER A LOS AGENTES         */
  3526.         ////////////////////////////////////////////
  3527.         $agentMaster = array();
  3528.         if (!empty($proposal->getAgentId())) {
  3529.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  3530.             $agentMaster = array(
  3531.                 'name' => $agent->getName(),
  3532.                 'lastname' => $agent->getLastname(),
  3533.                 'picture' => $agent->getPicture(),
  3534.             );
  3535.         }
  3536.         ////////////////////////////////////////////
  3537.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  3538.         //////////////////////////////////////////
  3539.         $sidebarData = $this->sidebarAction($token, "", "");
  3540.         $parametersNew = array(
  3541.             'proposalId' => $proposal->getId(),
  3542.             'recommended' => '0',
  3543.             'priority' => '0',
  3544.         );
  3545.         $dqlNew = 'SELECT p
  3546.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  3547.                     WHERE p.proposalId = :proposalId 
  3548.                     AND p.recommended = :recommended
  3549.                     AND p.priority != :priority
  3550.                     ORDER BY p.priority ASC';
  3551.         $queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
  3552.         $controlbudgetsNew = $queryNew->getResult();
  3553.         $today = new \DateTime("now");
  3554.         //        d($controlbudget);
  3555.         return $this->render(
  3556.             'MDS/EventsPresentationBundle/presentation/budget-client.html.twig',
  3557.             array(
  3558.                 'token' => $token,
  3559.                 'today' => $today,
  3560.                 'company' => $company,
  3561.                 'proposal' => $proposal,
  3562.                 'client' => $client,
  3563.                 'selectType' => $selectType,
  3564.                 'destination' => $data_destionation,
  3565.                 'agent' => $agentMaster,
  3566.                 'countDestino' => $cont_destino,
  3567.                 'datasupplier' => $data_supplier,
  3568.                 'budgets' => $controlbudget,
  3569.                 'sidebar' => $sidebarData,
  3570.                 'budgetNew' => $controlbudgetsNew,
  3571.                 //                'agendas' => $showAgenda,
  3572.             )
  3573.         );
  3574.     }
  3575.     public function CalculoTotalesservices($price, $units, $pax, $days, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat)
  3576.     {
  3577.         $price = trim($price);
  3578.         $over = trim($over);
  3579.         $price = str_replace(",", ".", $price);
  3580.         $over = str_replace(",", ".", $over);
  3581.         if (empty($iva)) {
  3582.             $iva = 0;
  3583.         }
  3584.         if (empty($price)) {
  3585.             $price = 0;
  3586.         }
  3587.         if (empty($commission)) {
  3588.             $commission = 0;
  3589.         }
  3590.         $iva = $iva / 100;
  3591.         if ($opiva == '0') {
  3592.             $price = $price / ($iva + 1);
  3593.         }
  3594.         if (!empty($commission)) {
  3595.             if ($opcommission == '0') {
  3596.                 $commission = (100 - $commission) / 100;
  3597.                 $precio_units = $price;
  3598.                 $price = $price * $commission;
  3599.             }
  3600.             if ($opcommission == '1') {
  3601.                 $commission = ($commission / 100) + 1;
  3602.                 $precio_units = $price * $commission;
  3603.             }
  3604.         } else {
  3605.             $precio_units = $price;
  3606.         }
  3607.         //Units
  3608.         if (empty($units) or $units == "0") {
  3609.             $units = "1";
  3610.         }
  3611.         // Calculo Especial por categoria
  3612.         //Alojamientos
  3613.         if ($idcat == "1") {
  3614.             $informativo_days = "si";
  3615.             $pax = "1";
  3616.         }
  3617.         //Transporte
  3618.         elseif ($idcat == "13") {
  3619.             $informativo_days = "no";
  3620.             $pax = "1";
  3621.             //            if($days > "1"){
  3622.             //                $days = "2";
  3623.             //            }else{
  3624.             //                $days = "1";
  3625.             //            }
  3626.         }
  3627.         //Lounge
  3628.         elseif ($idcat == "10") {
  3629.             $informativo_days = "no";
  3630.             $pax = "1";
  3631.         }
  3632.         //Guia
  3633.         elseif ($idcat == "8") {
  3634.             $informativo_days = "no";
  3635.             $pax = "1";
  3636.         } else {
  3637.             $informativo_days = "no";
  3638.         }
  3639.         //Pax
  3640.         if (empty($pax) or $pax == "0") {
  3641.             $pax = "1";
  3642.         }
  3643.         //Over
  3644.         if (empty($over)) {
  3645.             $over = "0";
  3646.         }
  3647.         if ($informativo_days == "no") {
  3648.             //Days
  3649.             if (empty($days) or $days == "0") {
  3650.                 $days = "1";
  3651.             } else {
  3652.                 $days = $days + 1;
  3653.             }
  3654.         }
  3655.         if(empty($days) or $days == "0"){
  3656.             $days = "1";
  3657.         }
  3658.         $total_items = $price * $units * $pax * $days;
  3659.         //        $total_pdirect = $price * $units * $pax * $days;
  3660.         $total_over = $over * $units * $pax * $days;
  3661.         if (!empty($commission)) {
  3662.             if ($opcommission == '0') {
  3663.                 $total_neto = $total_items / $commission;
  3664.             }
  3665.             if ($opcommission == '1') {
  3666.                 $total_neto = $total_items * $commission;
  3667.             }
  3668.         } else {
  3669.             $total_neto = $total_items;
  3670.         }
  3671.         if ($opover == '0') {
  3672.             $total_neto = $total_neto - $total_over;
  3673.             $precio_units = $precio_units - $over;
  3674.         }
  3675.         if ($opover == '1') {
  3676.             $total_neto = $total_neto +  $total_over;
  3677.             $precio_units = $precio_units + $over;
  3678.         }
  3679.         $total_paying = $total_items * ($iva + 1);
  3680.         if ($directPayment == true) {
  3681.             $total_neto = $total_neto - $total_paying;
  3682.         }
  3683.         $total_comision = "0";
  3684.         $total_pago = $total_items;
  3685.         $total_iva = $total_items * $iva;
  3686.         $sub_total_iva = $total_neto * $iva;
  3687.         $total = $total_neto + $sub_total_iva;
  3688.         if ($directPayment == true) {
  3689.             $benefit_moneda = $total_neto;
  3690.             $total_paying = "0";
  3691.         } else {
  3692.             $benefit_moneda = $total_neto - $total_items;
  3693.         }
  3694.         $data_calculos = array(
  3695.             'precio' => $precio_units,
  3696.             'total_days' => $days,
  3697.             'sub_total' => $total_items,
  3698.             'sub_total_iva' => $sub_total_iva,
  3699.             'total_neto' => $total_neto,
  3700.             'total_iva' => $total_iva,
  3701.             'total_paying' => $total_paying,
  3702.             'total_pago' => $total_pago,
  3703.             'total_comision' => $total_comision,
  3704.             'total' => $total,
  3705.             'benefit_moneda' => $benefit_moneda,
  3706.             'commission' => $commission,
  3707.             //            'commission_1' => $commission_1,
  3708.             'units' => $units,
  3709.             'pax' => $pax,
  3710.             'over' => $over,
  3711.         );
  3712.         //        d($data_calculos);
  3713.         return $data_calculos;
  3714.     }
  3715.     /**
  3716.      * @Route("/mybudgetsadd/{token}", name="presentation_mybudgets_add_token")
  3717.      */
  3718.     public function mybudgetsAddAction($token, Request $request)
  3719.     {
  3720.         $em = $this->getDoctrine()->getManager();
  3721.         //        d($request);
  3722.         //        exit();
  3723.         $incluir = "";
  3724.         $proposalid = $request->request->get('proposalid');
  3725.         $incluir = $request->request->get('incluir');
  3726.         //        $incluir_sub = $request->request->get('incluir_sub');
  3727.         $services = $request->request->get('services');
  3728.         $name = $request->request->get('name');
  3729.         $byclient = "1";
  3730.         $status = "Pending";
  3731.         //        $proposal = $em->getRepository(Proposal::class)->findOneById($proposalid);
  3732.         /* Obtengo usuario logueado */
  3733.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  3734.         // Usuario Anonimo es = "anon."
  3735.         if ($user_logueado == "anon.") {
  3736.             $user_id = '0';
  3737.         } else {
  3738.             $user_id = $user_logueado->getId();
  3739.         }
  3740.         if (!empty($incluir)) {
  3741.             $control = new ProposalSupplierServicesBudgetControl();
  3742.             $control->setProposalId($proposalid);
  3743.             $control->setStatus($status);
  3744.             $control->setName($name);
  3745.             $control->setByClient($byclient);
  3746.             $em->persist($control);
  3747.             $em->flush();
  3748.             $controlid = $control->getId();
  3749.             //            d($controlid);
  3750.             foreach ($incluir as $padentro) {
  3751.                 $id = $padentro['id'];
  3752.                 if (array_key_exists($id, $services)) {
  3753.                     $services_proposal = $em->getRepository(ProposalSupplierServices::class)->findOneById($id);
  3754.                     //COLOR POR SERVICIO
  3755.                     $contcolor = "";
  3756.                     switch ($services_proposal->getServiceCatName()) {
  3757.                         case "Accommodation":
  3758.                             $contcolor = 'teal';
  3759.                             break;
  3760.                         case "Menu":
  3761.                             $contcolor = 'purple';
  3762.                             break;
  3763.                         case "Lounge":
  3764.                             $contcolor = 'warning';
  3765.                             break;
  3766.                         case "Activities":
  3767.                             $contcolor = 'blue';
  3768.                             break;
  3769.                         case "Itineraries":
  3770.                             $contcolor = 'indigo';
  3771.                             break;
  3772.                         case "Cruise":
  3773.                             $contcolor = 'brown';
  3774.                             break;
  3775.                         case "Transport":
  3776.                             $contcolor = 'grey';
  3777.                             break;
  3778.                         case "Av":
  3779.                             $contcolor = 'slate';
  3780.                             break;
  3781.                         case "Creative":
  3782.                             $contcolor = 'orange';
  3783.                             break;
  3784.                         case "Gifts":
  3785.                             $contcolor = 'pink';
  3786.                             break;
  3787.                         case "Entertainment":
  3788.                             $contcolor = 'green';
  3789.                             break;
  3790.                         case "Guide":
  3791.                             $contcolor = 'orange';
  3792.                             break;
  3793.                         case "Others":
  3794.                             $contcolor = 'danger';
  3795.                             break;
  3796.                         case "Technology":
  3797.                             $contcolor = 'grey-800';
  3798.                             break;
  3799.                         case "Assistant":
  3800.                             $contcolor = 'indigo-800';
  3801.                             break;
  3802.                         case "DDR":
  3803.                             $contcolor = 'green-300';
  3804.                             break;
  3805.                     }
  3806.                     $var = $services[$id];
  3807.                     // UNITS
  3808.                     if (empty($var['units']) or $var['units'] == 0) {
  3809.                         $units = "1";
  3810.                     } else {
  3811.                         $units = $var['units'];
  3812.                     }
  3813.                     // PAX
  3814.                     if (empty($var['pax']) or $var['pax'] == 0) {
  3815.                         $pax = "1";
  3816.                     } else {
  3817.                         $pax = $var['pax'];
  3818.                     }
  3819.                     // Calculo Especial por categoria
  3820.                     //Alojamientos
  3821.                     if ($services_proposal->getServiceCatId() == "1") {
  3822.                         $pax = "1";
  3823.                     }
  3824.                     //Transporte
  3825.                     elseif ($services_proposal->getServiceCatId() == "13") {
  3826.                         $pax = "1";
  3827.                     }
  3828.                     //Lounge
  3829.                     elseif ($services_proposal->getServiceCatId() == "10") {
  3830.                         $pax = "1";
  3831.                     }
  3832.                     //Guia
  3833.                     elseif ($services_proposal->getServiceCatId() == "8") {
  3834.                         $pax = "1";
  3835.                     }
  3836.                     // CALCULO DEL NETO
  3837.                     $netamount = $var['price'] * $units * $pax * $var['days'];
  3838.                     // CALCULO DEL TOTAL
  3839.                     $iva = ($var['iva'] / 100) + 1;
  3840.                     $total = $netamount * $iva;
  3841.                     $servicesBudget = new ProposalSupplierServicesBudget();
  3842.                     $servicesBudget->setControlId($controlid);
  3843.                     $servicesBudget->setItemsServiceId($id);
  3844.                     $servicesBudget->setItemsserviceIdFather('0');
  3845.                     $servicesBudget->setProposalId($proposalid);
  3846.                     $servicesBudget->setDestinationId($services_proposal->getDestinationId());
  3847.                     $servicesBudget->setSupplierId($services_proposal->getSupplierId());
  3848.                     $servicesBudget->setIdeaId($services_proposal->getIdeaId());
  3849.                     $servicesBudget->setActivityId($services_proposal->getActivityId());
  3850.                     $servicesBudget->setServiceId($services_proposal->getServiceId());
  3851.                     $servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
  3852.                     $servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
  3853.                     $servicesBudget->setContColor($contcolor);
  3854.                     $servicesBudget->setName($services_proposal->getName());
  3855.                     $servicesBudget->setPrice($var['price']);
  3856.                     $servicesBudget->setCurrency($services_proposal->getCurrency());
  3857.                     $servicesBudget->setUnits($var['units']);
  3858.                     $servicesBudget->setPax($var['pax']);
  3859.                     $servicesBudget->setDays($var['days']);
  3860.                     $servicesBudget->setDateInAt($services_proposal->getDateInAt());
  3861.                     $servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
  3862.                     $servicesBudget->setNetAmount($netamount);
  3863.                     $servicesBudget->setIva($var['iva']);
  3864.                     $servicesBudget->setTotal($total);
  3865.                     $servicesBudget->setStatus($status);
  3866.                     $servicesBudget->setRank($var['rank']);
  3867.                     $servicesBudget->setCreatedId($user_id);
  3868.                     $servicesBudget->setUpdatedId($user_id);
  3869.                     $em->persist($servicesBudget);
  3870.                     $em->flush();
  3871.                 }
  3872.             }
  3873.             $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  3874.             // Usuario Anonimo es = "anon."
  3875.             if ($user_logueado == "anon.") {
  3876.                 $time = new \DateTime("now");
  3877.                 $ipclient = $request->getClientIp();
  3878.                 $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  3879.                 $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  3880.                 $mailAgent[] = $agent->getEmail();
  3881.                 $agentMail = $agent->getEmail();
  3882.                 $passGmail = $agent->getPassGmail();
  3883.                 $firmGmail = $agent->getFirmGmail();
  3884.                 $mailAgentSent = array(
  3885.                     $agent->getEmail() => $agent->getName() . ' ' . $agent->getLastName()
  3886.                 );
  3887.                 $data = array(
  3888.                     '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>',
  3889.                     'firm' => $firmGmail,
  3890.                 );
  3891.                 $mailTodos = array_merge($mailAgent);
  3892.                 // EJECUTAR ENVIO DE ALERTA DE VISTO POR CLIENTE
  3893.                 $transporter = new Swift_SmtpTransport();
  3894.                 $transporter->setHost('smtp.gmail.com')
  3895.                     ->setEncryption('ssl') //ssl / tls
  3896.                     ->setPort(465) // 465 / 587
  3897.                     ->setUsername('desarrollo@develup.solutions')
  3898.                     ->setPassword('utvh hzoi wfdo ztjs');
  3899.                 $mailer = new Swift_Mailer($transporter);
  3900.                 $message = new Swift_Message();
  3901.                 $message->setSubject('P#' . $proposal->getId() . ', Alerta De Presupuesto Creado por el cliente')
  3902.                     ->setSender($agentMail)
  3903.                     ->setFrom($mailAgentSent)
  3904.                     ->setReplyTo($mailAgentSent)
  3905.                     ->setTo($mailTodos)
  3906.                     ->setBody(
  3907.                         $this->renderView(
  3908.                             'mail/structure-mail.html.twig',
  3909.                             array('data' => $data)
  3910.                         ),
  3911.                         'text/html'
  3912.                     );
  3913.                 $mailer->send($message);
  3914.             }
  3915.         }
  3916.         return $this->redirectToRoute(
  3917.             'presentation_mybudgets_view_token',
  3918.             array(
  3919.                 'idp' => $controlid,
  3920.                 'token' => $token,
  3921.             )
  3922.         );
  3923.     }
  3924.     /**
  3925.      * @Route("/mybudgetsview/{idp}/{token}", name="presentation_mybudgets_view_token")
  3926.      */
  3927.     public function mybudgetsViewAction($token, $idp, Request $request)
  3928.     {
  3929.         $em = $this->getDoctrine()->getManager();
  3930.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  3931.         if ($proposal->getStatus() == "Cancel") {
  3932.             return $this->redirectToRoute(
  3933.                 'presentation_error_cancel',
  3934.                 array(
  3935.                     'token' => $token
  3936.                 )
  3937.             );
  3938.         }
  3939.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  3940.         // Usuario Anonimo es = "anon."
  3941.         if ($user_logueado == "anon.") {
  3942.             $proposal->setViewedAt(new \DateTime("now"));
  3943.             $em->persist($proposal);
  3944.             $em->flush();
  3945.         }
  3946.         $selectType = explode(",", $proposal->getSelectType());
  3947.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  3948.         $country = $em->getRepository(Country::class)->findOneById($client->getCountry());
  3949.         $client->setCountry($country->getCountry());
  3950.         $regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
  3951.         $client->setRegion($regions->getRegion());
  3952.         $province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
  3953.         $client->setProvince($province->getName());
  3954.         $cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  3955.         $client->setPopulation($cities->getCity());
  3956.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  3957.             array(
  3958.                 'proposalId' => $proposal->getId(),
  3959.                 'disabled' => '0',
  3960.             )
  3961.         );
  3962.         $data_destionation = array();
  3963.         $cont_destino = 0;
  3964.         foreach ($proposal_Control as $proposalControl) {
  3965.             $cont_destino += 1;
  3966.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  3967.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  3968.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  3969.                 array(
  3970.                     'destinationId' => $proposalControl->getDestinationId(),
  3971.                     'language' => $proposal->getLanguage()
  3972.                 )
  3973.             );
  3974.             $data_destionation[$destino->getTitle()] = array(
  3975.                 'destino' => $destino,
  3976.                 'gallery' => $gallery,
  3977.                 'description' => $description,
  3978.             );
  3979.         }
  3980.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  3981.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3982.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  3983.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3984.         $controlproposal = $em->getRepository(ProposalControl::class)->findBy(
  3985.             array(
  3986.                 'proposalId' => $proposal->getId(),
  3987.                 'disabled' => '0',
  3988.             )
  3989.         );
  3990.         $data_controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  3991.         $controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  3992.         foreach ($controlbudgets as $controlbudge) {
  3993.             $controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
  3994.         }
  3995.         $controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  3996.         $filtro2 = array();
  3997.         foreach ($controlproposal as $consultabudget2) {
  3998.             $filtro2[] = $consultabudget2->getDestinationId();
  3999.         }
  4000.         $services_supplier = array();
  4001.         $services_ideas = array();
  4002.         $budget = array();
  4003.         $content_data = array();
  4004.         $destination = array();
  4005.         //        $totales_neto="";
  4006.         //        $totales_total="";
  4007.         $totales_neto = 0;
  4008.         $totales_total = 0;
  4009.         $totales_iva = array();
  4010.         $data = array();
  4011.         foreach ($filtro2 as $destinobudget) {
  4012.             $destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
  4013.             $destino = $destination->getTitle();
  4014.             $consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  4015.                 array(
  4016.                     'controlId' => $idp,
  4017.                     'destinationId' => $destinobudget,
  4018.                     'itemsserviceIdFather' => '0'
  4019.                 ),
  4020.                 array(
  4021.                     'rank' => 'DESC'
  4022.                 )
  4023.             );
  4024.             $filtro = array();
  4025.             foreach ($consulta_budget as $consultabudget) {
  4026.                 if (!is_null($consultabudget->getActivityId())) {
  4027.                     $filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
  4028.                 }
  4029.                 if (!is_null($consultabudget->getIdeaId())) {
  4030.                     $filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
  4031.                 }
  4032.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
  4033.                     $filtro['whiteservice']['0'][] = $consultabudget;
  4034.                 }
  4035.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
  4036.                     $filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
  4037.                 }
  4038.                 //                $filtro[$consultabudget->getSupplierId()] = $consultabudget;
  4039.             }
  4040.             //            d($filtro);
  4041.             //
  4042.             $master = "";
  4043.             $services = array();
  4044.             $whiteservice = array();
  4045.             $idea = array();
  4046.             $activity = array();
  4047.             $supplier = array();
  4048.             foreach ($filtro as $key => $ideaOsupplier) {
  4049.                 //                d("·········································", $ideaOsupplier);
  4050.                 foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
  4051.                     //                    d($ideaOsupplierAdentro);
  4052.                     $services = array();
  4053.                     //                    $total_neto="";
  4054.                     //                    $total_total="";
  4055.                     $total_neto = 0;
  4056.                     $total_total = 0;
  4057.                     foreach ($ideaOsupplierAdentro as $servicesbudget) {
  4058.                         if ($key == "whiteservice") {
  4059.                             $services_white = $em->getRepository(Configuration::class)->findOneById('1');
  4060.                             $master = "whiteservice";
  4061.                             $services[] = array(
  4062.                                 'service' => $servicesbudget
  4063.                             );
  4064.                             $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4065.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  4066.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  4067.                             }
  4068.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4069.                             $totales_neto += $servicesbudget->getNetAmount();
  4070.                             $total_total += $servicesbudget->getTotal();
  4071.                             $totales_total += $servicesbudget->getTotal();
  4072.                             $whiteservice[$services_white->getId()]  = array(
  4073.                                 'datos' => $services_white,
  4074.                                 'services' => $services,
  4075.                                 'master' => $master,
  4076.                                 'neto' => $total_neto,
  4077.                                 'total' => $total_total
  4078.                             );
  4079.                         }
  4080.                         if ($key == "activity") {
  4081.                             $services_activities = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
  4082.                             $master = "activity";
  4083.                             $services[] = array(
  4084.                                 'service' => $servicesbudget
  4085.                             );
  4086.                             $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4087.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  4088.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  4089.                             }
  4090.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4091.                             $total_neto += $servicesbudget->getNetAmount();
  4092.                             $totales_neto += $servicesbudget->getNetAmount();
  4093.                             $total_total += $servicesbudget->getTotal();
  4094.                             $totales_total += $servicesbudget->getTotal();
  4095.                             /*CONTROL GENERAL*/
  4096.                             $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($servicesbudget->getActivityId());
  4097.                             $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  4098.                                 array(
  4099.                                     'supplierId' => $controlgeneral->getId(),
  4100.                                     'servicesCatId' => '0',
  4101.                                     'servicesCategory' => 'General',
  4102.                                     'servicesId' => '0',
  4103.                                     'controlId' => '0'
  4104.                                 )
  4105.                             );
  4106.                             if (!is_null($sqlsuppliers_gallery)) {
  4107.                                 $imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
  4108.                             } else {
  4109.                                 //Imagen no disponible (poner una generica)
  4110.                                 $imagenSmall = null;
  4111.                             }
  4112.                             $activity[$services_activities->getId()] = array(
  4113.                                 'datos' => $services_activities,
  4114.                                 'services' => $services,
  4115.                                 'master' => $master,
  4116.                                 'neto' => $total_neto,
  4117.                                 'total' => $total_total,
  4118.                                 'image' => $imagenSmall,
  4119.                             );
  4120.                         }
  4121.                         if ($key == "idea") {
  4122.                             $services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
  4123.                             $master = "idea";
  4124.                             $services[] = array(
  4125.                                 'service' => $servicesbudget
  4126.                             );
  4127.                             $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4128.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  4129.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  4130.                             }
  4131.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4132.                             $total_neto += $servicesbudget->getNetAmount();
  4133.                             $totales_neto += $servicesbudget->getNetAmount();
  4134.                             $total_total += $servicesbudget->getTotal();
  4135.                             $totales_total += $servicesbudget->getTotal();
  4136.                             /*CONTROL GENERAL*/
  4137.                             $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($servicesbudget->getIdeaId());
  4138.                             $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  4139.                                 array(
  4140.                                     'supplierId' => $controlgeneral->getId(),
  4141.                                     'servicesCatId' => '0',
  4142.                                     'servicesCategory' => 'General',
  4143.                                     'servicesId' => '0',
  4144.                                     'controlId' => '0'
  4145.                                 )
  4146.                             );
  4147.                             if (!is_null($sqlsuppliers_gallery)) {
  4148.                                 $imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
  4149.                             } else {
  4150.                                 //Imagen no disponible (poner una generica)
  4151.                                 $imagenSmall = null;
  4152.                             }
  4153.                             $idea[$services_ideas->getId()] = array(
  4154.                                 'datos' => $services_ideas,
  4155.                                 'services' => $services,
  4156.                                 'master' => $master,
  4157.                                 'neto' => $total_neto,
  4158.                                 'total' => $total_total,
  4159.                                 'image' => $imagenSmall,
  4160.                             );
  4161.                         }
  4162.                         if ($key == "supplier") {
  4163.                             if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
  4164.                                 $servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
  4165.                                 $master = "supplier";
  4166.                                 //                            foreach($services_supplier as $servicessupplier){
  4167.                                 if (!is_null($servicessupplier)) {
  4168.                                     switch ($servicessupplier->getStar()) {
  4169.                                         case 1:
  4170.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i>');
  4171.                                             break;
  4172.                                         case 2:
  4173.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4174.                                             break;
  4175.                                         case 3:
  4176.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4177.                                             break;
  4178.                                         case 4:
  4179.                                             $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>');
  4180.                                             break;
  4181.                                         case 5:
  4182.                                             $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');
  4183.                                             break;
  4184.                                         case 6:
  4185.                                             $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>');
  4186.                                             break;
  4187.                                         case 7:
  4188.                                             $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');
  4189.                                             break;
  4190.                                         case 8:
  4191.                                             $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');
  4192.                                             break;
  4193.                                     }
  4194.                                     $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4195.                                     if (empty($totales_iva[$servicesbudget->getIva()])) {
  4196.                                         $totales_iva[$servicesbudget->getIva()] = 0;
  4197.                                     }
  4198.                                     //                                d($servicesbudget); exit();
  4199.                                     $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4200.                                     $total_neto += $servicesbudget->getNetAmount();
  4201.                                     $totales_neto += $servicesbudget->getNetAmount();
  4202.                                     $total_total += $servicesbudget->getTotal();
  4203.                                     $totales_total += $servicesbudget->getTotal();
  4204.                                     /*CONTROL GENERAL*/
  4205.                                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($servicesbudget->getSupplierId());
  4206.                                     $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  4207.                                         array(
  4208.                                             'supplierId' => $controlgeneral->getId(),
  4209.                                             'servicesCatId' => '0',
  4210.                                             'servicesCategory' => 'General',
  4211.                                             'servicesId' => '0',
  4212.                                             'controlId' => '0'
  4213.                                         )
  4214.                                     );
  4215.                                     if (!is_null($sqlsuppliers_gallery)) {
  4216.                                         $imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
  4217.                                     } else {
  4218.                                         //Imagen no disponible (poner una generica)
  4219.                                         $imagenSmall = null;
  4220.                                     }
  4221.                                 }
  4222.                                 $services[] = array(
  4223.                                     'service' => $servicesbudget
  4224.                                 );
  4225.                                 $supplier[$servicessupplier->getId()] = array(
  4226.                                     'datos' => $servicessupplier,
  4227.                                     'services' => $services,
  4228.                                     'master' => $master,
  4229.                                     'neto' => $total_neto,
  4230.                                     'total' => $total_total,
  4231.                                     'image' => $imagenSmall,
  4232.                                 );
  4233.                             }
  4234.                         }
  4235.                     }
  4236.                 }
  4237.             }
  4238.             $content_data = array(
  4239.                 'supplier' => $supplier,
  4240.                 'idea' => $idea,
  4241.                 'activity' => $activity,
  4242.                 'whiteservice' => $whiteservice,
  4243.             );
  4244.             $data[] = array(
  4245.                 'destination' => $destination,
  4246.                 'container' => $content_data
  4247.             );
  4248.         }
  4249.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4250.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  4251.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4252.         //////////////////////////////////////////////
  4253.         /* CODIGO PARA TRAER A LOS AGENTES         */
  4254.         ////////////////////////////////////////////
  4255.         $agentMaster = array();
  4256.         if (!empty($proposal->getAgentId())) {
  4257.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  4258.             $agentMaster = array(
  4259.                 'name' => $agent->getName(),
  4260.                 'lastname' => $agent->getLastname(),
  4261.                 'picture' => $agent->getPicture(),
  4262.             );
  4263.         }
  4264.         $parametersNew = array(
  4265.             'proposalId' => $proposal->getId(),
  4266.             'recommended' => '0',
  4267.             'priority' => '0',
  4268.         );
  4269.         $dqlNew = 'SELECT p
  4270.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  4271.                     WHERE p.proposalId = :proposalId 
  4272.                     AND p.recommended = :recommended
  4273.                     AND p.priority != :priority
  4274.                     ORDER BY p.priority ASC';
  4275.         $queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
  4276.         $controlbudgetsNew = $queryNew->getResult();
  4277.         $sidebarData = $this->sidebarAction($token, "", "");
  4278.         return $this->render(
  4279.             'MDS/EventsPresentationBundle/presentation/budgetview-client.html.twig',
  4280.             array(
  4281.                 'token' => $token,
  4282.                 'company' => $company,
  4283.                 'proposal' => $proposal,
  4284.                 'client' => $client,
  4285.                 'selectType' => $selectType,
  4286.                 'destination' => $data_destionation,
  4287.                 'budgetcontrol' => $data_controlbudgets,
  4288.                 'agent' => $agentMaster,
  4289.                 'countDestino' => $cont_destino,
  4290.                 'budgets' => $controlbudget,
  4291.                 'budgetNew' => $controlbudgetsNew,
  4292.                 'data' => $data,
  4293.                 'totales_neto' => $totales_neto,
  4294.                 'ivas' => $totales_iva,
  4295.                 'totales' => $totales_total,
  4296.                 'confirm' => $controlbudgetBoton,
  4297.                 'sidebar' => $sidebarData,
  4298.                 //                'agendas' => $showAgenda,
  4299.             )
  4300.         );
  4301.     }
  4302.     /**
  4303.      * @Route("/mybudgetssave/{idp}/{token}", name="presentation_mybudgets_save_token")
  4304.      */
  4305.     public function mybudgetsSaveAction($token, $idp, Request $request)
  4306.     {
  4307.         $em = $this->getDoctrine()->getManager();
  4308.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4309.         if ($proposal->getStatus() == "Cancel") {
  4310.             return $this->redirectToRoute(
  4311.                 'presentation_error_cancel',
  4312.                 array(
  4313.                     'token' => $token
  4314.                 )
  4315.             );
  4316.         }
  4317.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  4318.         // Usuario Anonimo es = "anon."
  4319.         if ($user_logueado == "anon.") {
  4320.             $proposal->setViewedAt(new \DateTime("now"));
  4321.             $em->persist($proposal);
  4322.             $em->flush();
  4323.         }
  4324.         $selectType = explode(",", $proposal->getSelectType());
  4325.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4326.         $country = $em->getRepository(Country::class)->findOneById($client->getCountry());
  4327.         $client->setCountry($country->getCountry());
  4328.         $regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
  4329.         $client->setRegion($regions->getRegion());
  4330.         $province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
  4331.         $client->setProvince($province->getName());
  4332.         $cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  4333.         $client->setPopulation($cities->getCity());
  4334.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  4335.             array(
  4336.                 'proposalId' => $proposal->getId(),
  4337.                 'disabled' => '0',
  4338.             )
  4339.         );
  4340.         $data_destionation = array();
  4341.         $cont_destino = 0;
  4342.         foreach ($proposal_Control as $proposalControl) {
  4343.             $cont_destino += 1;
  4344.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4345.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4346.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  4347.                 array(
  4348.                     'destinationId' => $proposalControl->getDestinationId(),
  4349.                     'language' => $proposal->getLanguage()
  4350.                 )
  4351.             );
  4352.             $data_destionation[$destino->getTitle()] = array(
  4353.                 'destino' => $destino,
  4354.                 'gallery' => $gallery,
  4355.                 'description' => $description,
  4356.             );
  4357.         }
  4358.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  4359.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4360.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4361.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4362.         $controlproposal = $em->getRepository(ProposalControl::class)->findBy(
  4363.             array(
  4364.                 'proposalId' => $proposal->getId(),
  4365.                 'disabled' => '0',
  4366.             )
  4367.         );
  4368.         $data_controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  4369.         $controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  4370.         foreach ($controlbudgets as $controlbudge) {
  4371.             if (is_null($controlbudge->getByClient())) {
  4372.                 $byclient = "";
  4373.             } else {
  4374.                 $byclient = "a";
  4375.             }
  4376.             $controlbudget[$controlbudge->getRecommended() . $byclient][] = $controlbudge;
  4377.         }
  4378.         $controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  4379.         $filtro2 = array();
  4380.         foreach ($controlproposal as $consultabudget2) {
  4381.             $filtro2[] = $consultabudget2->getDestinationId();
  4382.         }
  4383.         $services_supplier = array();
  4384.         $services_ideas = array();
  4385.         $budget = array();
  4386.         $content_data = array();
  4387.         $destination = array();
  4388.         //        $totales_neto="";
  4389.         //        $totales_total="";
  4390.         $totales_neto = 0;
  4391.         $totales_total = 0;
  4392.         $totales_iva = array();
  4393.         $data = array();
  4394.         foreach ($filtro2 as $destinobudget) {
  4395.             $destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
  4396.             $destino = $destination->getTitle();
  4397.             $consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  4398.                 array(
  4399.                     'controlId' => $idp,
  4400.                     'destinationId' => $destinobudget,
  4401.                     'itemsserviceIdFather' => '0'
  4402.                 ),
  4403.                 array(
  4404.                     'rank' => 'DESC'
  4405.                 )
  4406.             );
  4407.             $filtro = array();
  4408.             foreach ($consulta_budget as $consultabudget) {
  4409.                 if (!is_null($consultabudget->getActivityId())) {
  4410.                     $filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
  4411.                 }
  4412.                 if (!is_null($consultabudget->getIdeaId())) {
  4413.                     $filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
  4414.                 }
  4415.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
  4416.                     $filtro['whiteservice']['0'][] = $consultabudget;
  4417.                 }
  4418.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
  4419.                     $filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
  4420.                 }
  4421.                 //                $filtro[$consultabudget->getSupplierId()] = $consultabudget;
  4422.             }
  4423.             //            d($filtro);
  4424.             //
  4425.             $master = "";
  4426.             $services = array();
  4427.             $whiteservice = array();
  4428.             $idea = array();
  4429.             $activity = array();
  4430.             $supplier = array();
  4431.             foreach ($filtro as $key => $ideaOsupplier) {
  4432.                 //                d("·········································", $ideaOsupplier);
  4433.                 foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
  4434.                     //                    d($ideaOsupplierAdentro);
  4435.                     $services = array();
  4436.                     //                    $total_neto="";
  4437.                     //                    $total_total="";
  4438.                     $total_neto = 0;
  4439.                     $total_total = 0;
  4440.                     foreach ($ideaOsupplierAdentro as $servicesbudget) {
  4441.                         //                        d($servicesbudget);
  4442.                         $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4443.                         if (empty($totales_iva[$servicesbudget->getIva()])) {
  4444.                             $totales_iva[$servicesbudget->getIva()] = 0;
  4445.                         }
  4446.                         $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4447.                         $total_neto += $servicesbudget->getNetAmount();
  4448.                         $totales_neto += $servicesbudget->getNetAmount();
  4449.                         $total_total += $servicesbudget->getTotal();
  4450.                         $totales_total += $servicesbudget->getTotal();
  4451.                         if ($key == "whiteservice") {
  4452.                             $services_white = $em->getRepository(Configuration::class)->findOneById('1');
  4453.                             $master = "whiteservice";
  4454.                             $imagenSmall = $services_white->getPicture();
  4455.                             $services[] = array(
  4456.                                 'service' => $servicesbudget
  4457.                             );
  4458.                             $whiteservice[$services_white->getId()]  = array(
  4459.                                 'datos' => $services_white,
  4460.                                 'services' => $services,
  4461.                                 'master' => $master,
  4462.                                 'neto' => $total_neto,
  4463.                                 'total' => $total_total,
  4464.                                 'image' => $imagenSmall,
  4465.                             );
  4466.                         }
  4467.                         if ($key == "activity") {
  4468.                             $services_activities = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
  4469.                             $master = "activity";
  4470.                             $services[] = array(
  4471.                                 'service' => $servicesbudget
  4472.                             );
  4473.                             /*CONTROL GENERAL*/
  4474.                             $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($servicesbudget->getActivityId());
  4475.                             $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  4476.                                 array(
  4477.                                     'supplierId' => $controlgeneral->getId(),
  4478.                                     'servicesCatId' => '0',
  4479.                                     'servicesCategory' => 'General',
  4480.                                     'servicesId' => '0',
  4481.                                     'controlId' => '0'
  4482.                                 )
  4483.                             );
  4484.                             if (!is_null($sqlsuppliers_gallery)) {
  4485.                                 $imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
  4486.                             } else {
  4487.                                 //Imagen no disponible (poner una generica)
  4488.                                 $imagenSmall = null;
  4489.                             }
  4490.                             $activity[$services_activities->getId()] = array(
  4491.                                 'datos' => $services_activities,
  4492.                                 'services' => $services,
  4493.                                 'master' => $master,
  4494.                                 'neto' => $total_neto,
  4495.                                 'total' => $total_total,
  4496.                                 'image' => $imagenSmall,
  4497.                             );
  4498.                         }
  4499.                         if ($key == "idea") {
  4500.                             $services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
  4501.                             $master = "idea";
  4502.                             $services[] = array(
  4503.                                 'service' => $servicesbudget
  4504.                             );
  4505.                             /*CONTROL GENERAL*/
  4506.                             $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($servicesbudget->getIdeaId());
  4507.                             $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  4508.                                 array(
  4509.                                     'supplierId' => $controlgeneral->getId(),
  4510.                                     'servicesCatId' => '0',
  4511.                                     'servicesCategory' => 'General',
  4512.                                     'servicesId' => '0',
  4513.                                     'controlId' => '0'
  4514.                                 )
  4515.                             );
  4516.                             if (!is_null($sqlsuppliers_gallery)) {
  4517.                                 $imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
  4518.                             } else {
  4519.                                 //Imagen no disponible (poner una generica)
  4520.                                 $imagenSmall = null;
  4521.                             }
  4522.                             $idea[$services_ideas->getId()] = array(
  4523.                                 'datos' => $services_ideas,
  4524.                                 'services' => $services,
  4525.                                 'master' => $master,
  4526.                                 'neto' => $total_neto,
  4527.                                 'total' => $total_total,
  4528.                                 'image' => $imagenSmall,
  4529.                             );
  4530.                         }
  4531.                         if ($key == "supplier") {
  4532.                             if (is_null($servicesbudget->getIdeaId())) {
  4533.                                 $servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
  4534.                                 $master = "supplier";
  4535.                                 //                            foreach($services_supplier as $servicessupplier){
  4536.                                 if (!is_null($servicessupplier)) {
  4537.                                     switch ($servicessupplier->getStar()) {
  4538.                                         case 1:
  4539.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i>');
  4540.                                             break;
  4541.                                         case 2:
  4542.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4543.                                             break;
  4544.                                         case 3:
  4545.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4546.                                             break;
  4547.                                         case 4:
  4548.                                             $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>');
  4549.                                             break;
  4550.                                         case 5:
  4551.                                             $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');
  4552.                                             break;
  4553.                                         case 6:
  4554.                                             $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>');
  4555.                                             break;
  4556.                                         case 7:
  4557.                                             $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');
  4558.                                             break;
  4559.                                         case 8:
  4560.                                             $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');
  4561.                                             break;
  4562.                                     }
  4563.                                     /*CONTROL GENERAL*/
  4564.                                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($servicesbudget->getSupplierId());
  4565.                                     $sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
  4566.                                         array(
  4567.                                             'supplierId' => $controlgeneral->getId(),
  4568.                                             'servicesCatId' => '0',
  4569.                                             'servicesCategory' => 'General',
  4570.                                             'servicesId' => '0',
  4571.                                             'controlId' => '0'
  4572.                                         )
  4573.                                     );
  4574.                                     if (!is_null($sqlsuppliers_gallery)) {
  4575.                                         $imagenSmall = "/assets/images/suppliers/gallery/" . $sqlsuppliers_gallery->getImageSmall();
  4576.                                     } else {
  4577.                                         //Imagen no disponible (poner una generica)
  4578.                                         $imagenSmall = null;
  4579.                                     }
  4580.                                 }
  4581.                                 $services[] = array(
  4582.                                     'service' => $servicesbudget
  4583.                                 );
  4584.                                 $supplier[$servicessupplier->getId()] = array(
  4585.                                     'datos' => $servicessupplier,
  4586.                                     'services' => $services,
  4587.                                     'master' => $master,
  4588.                                     'neto' => $total_neto,
  4589.                                     'total' => $total_total,
  4590.                                     'image' => $imagenSmall,
  4591.                                 );
  4592.                             }
  4593.                         }
  4594.                     }
  4595.                 }
  4596.             }
  4597.             $content_data = array(
  4598.                 'supplier' => $supplier,
  4599.                 'idea' => $idea,
  4600.                 'activity' => $activity,
  4601.                 'whiteservice' => $whiteservice,
  4602.             );
  4603.             $data[] = array(
  4604.                 'destination' => $destination,
  4605.                 'container' => $content_data
  4606.             );
  4607.         }
  4608.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4609.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  4610.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4611.         //////////////////////////////////////////////
  4612.         /* CODIGO PARA TRAER A LOS AGENTES         */
  4613.         ////////////////////////////////////////////
  4614.         $agentMaster = array();
  4615.         if (!empty($proposal->getAgentId())) {
  4616.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  4617.             $agentMaster = array(
  4618.                 'name' => $agent->getName(),
  4619.                 'lastname' => $agent->getLastname(),
  4620.                 'picture' => $agent->getPicture(),
  4621.             );
  4622.         }
  4623.         $parametersNew = array(
  4624.             'proposalId' => $proposal->getId(),
  4625.             'recommended' => '0',
  4626.             'priority' => '0',
  4627.         );
  4628.         $dqlNew = 'SELECT p
  4629.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  4630.                     WHERE p.proposalId = :proposalId 
  4631.                     AND p.recommended = :recommended
  4632.                     AND p.priority != :priority
  4633.                     ORDER BY p.priority ASC';
  4634.         $queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
  4635.         $controlbudgetsNew = $queryNew->getResult();
  4636.         $sidebarData = $this->sidebarAction($token, "", "");
  4637.         return $this->render(
  4638.             'MDS/EventsPresentationBundle/presentation/budgetview-save-client.html.twig',
  4639.             array(
  4640.                 'token' => $token,
  4641.                 'company' => $company,
  4642.                 'proposal' => $proposal,
  4643.                 'client' => $client,
  4644.                 'selectType' => $selectType,
  4645.                 'destination' => $data_destionation,
  4646.                 'budgetcontrol' => $data_controlbudgets,
  4647.                 'agent' => $agentMaster,
  4648.                 'countDestino' => $cont_destino,
  4649.                 'budgets' => $controlbudget,
  4650.                 'budgetNew' => $controlbudgetsNew,
  4651.                 'data' => $data,
  4652.                 'totales_neto' => $totales_neto,
  4653.                 'ivas' => $totales_iva,
  4654.                 'totales' => $totales_total,
  4655.                 'confirm' => $controlbudgetBoton,
  4656.                 'sidebar' => $sidebarData,
  4657.                 'idp' => $idp,
  4658.                 //                'agendas' => $showAgenda,
  4659.             )
  4660.         );
  4661.     }
  4662.     /**
  4663.      * @Route("/mybudgetsconfirmed/{idp}/{token}", name="presentation_mybudgets_confirmed_token")
  4664.      */
  4665.     public function mybudgetsConfirmedAction($token, $idp, Request $request)
  4666.     {
  4667.         $em = $this->getDoctrine()->getManager();
  4668.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4669.         if ($proposal->getStatus() == "Cancel") {
  4670.             return $this->redirectToRoute(
  4671.                 'presentation_error_cancel',
  4672.                 array(
  4673.                     'token' => $token
  4674.                 )
  4675.             );
  4676.         }
  4677.         $selectType = explode(",", $proposal->getSelectType());
  4678.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4679.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  4680.             array(
  4681.                 'proposalId' => $proposal->getId(),
  4682.                 'disabled' => '0',
  4683.             )
  4684.         );
  4685.         $data_destionation = array();
  4686.         $cont_destino = 0;
  4687.         foreach ($proposal_Control as $proposalControl) {
  4688.             $cont_destino += 1;
  4689.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4690.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4691.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  4692.                 array(
  4693.                     'destinationId' => $proposalControl->getDestinationId(),
  4694.                     'language' => $proposal->getLanguage()
  4695.                 )
  4696.             );
  4697.             $data_destionation[$destino->getTitle()] = array(
  4698.                 'destino' => $destino,
  4699.                 'gallery' => $gallery,
  4700.                 'description' => $description,
  4701.             );
  4702.         }
  4703.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  4704.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4705.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4706.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4707.         if (($proposal->getStatus() != "Invoiced") and ($proposal->getStatus() != "Unblocked")) {
  4708.             $proposal->setStatus('Confirmed');
  4709.         }
  4710.         $controlbudget = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  4711.         $controlbudget->setStatus('Confirmed');
  4712.         $budgets = $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($idp);
  4713.         foreach ($budgets as $budget) {
  4714.             $services = $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getItemsserviceId());
  4715.             if (!empty($services)) {
  4716.                 $services->setStatus('Confirmed');
  4717.                 $em->persist($services);
  4718.             }
  4719.         }
  4720.         $em->persist($controlbudget);
  4721.         $em->persist($proposal);
  4722.         $em->flush();
  4723.         $event = 'The item has ben saved Successfully';
  4724.         $successMessage = $this->translator->trans($event);
  4725.         $this->addFlash('mensajebudgetclient', $successMessage);
  4726.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4727.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  4728.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4729.         return $this->redirectToRoute(
  4730.             'presentation_mybudgets_view_token',
  4731.             array(
  4732.                 'idp' => $idp,
  4733.                 'token' => $token,
  4734.             )
  4735.         );
  4736.     }
  4737.     /**
  4738.      * @Route("/destinationAjax/{idd}/{token}", name="presentation_destination_ajax")
  4739.      */
  4740.     public function destinationAjaxViewAction($token, $idd, Request $request)
  4741.     {
  4742.         $em = $this->getDoctrine()->getManager();
  4743.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4744.         if ($proposal->getStatus() == "Cancel") {
  4745.             return $this->redirectToRoute(
  4746.                 'presentation_error_cancel',
  4747.                 array(
  4748.                     'token' => $token
  4749.                 )
  4750.             );
  4751.         }
  4752.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  4753.         // Usuario Anonimo es = "anon."
  4754.         if ($user_logueado == "anon.") {
  4755.             $proposal->setViewedAt(new \DateTime("now"));
  4756.             $em->persist($proposal);
  4757.             $em->flush();
  4758.         }
  4759.         $selectType = explode(",", $proposal->getSelectType());
  4760.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4761.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  4762.             array(
  4763.                 'proposalId' => $proposal->getId(),
  4764.                 'disabled' => '0',
  4765.             )
  4766.         );
  4767.         $data_destionation = array();
  4768.         $cont_destino = 0;
  4769.         foreach ($proposal_Control as $proposalControl) {
  4770.             $cont_destino += 1;
  4771.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4772.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4773.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  4774.                 array(
  4775.                     'destinationId' => $proposalControl->getDestinationId(),
  4776.                     'language' => $proposal->getLanguage()
  4777.                 )
  4778.             );
  4779.             $data_destionation[$destino->getTitle()] = array(
  4780.                 'destino' => $destino,
  4781.                 'gallery' => $gallery,
  4782.                 'description' => $description,
  4783.             );
  4784.         }
  4785.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  4786.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4787.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4788.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4789.         $destino_details = $em->getRepository(Destination::class)->findOneById($idd);
  4790.         $gallery_details = $em->getRepository(DestinationGallery::class)->findByDestinationId($idd);
  4791.         $description_details = $em->getRepository(DestinationDescription::class)->findOneBy(
  4792.             array(
  4793.                 'destinationId' => $idd,
  4794.                 'language' => $proposal->getLanguage()
  4795.             )
  4796.         );
  4797.         $response_body =
  4798.             array(
  4799.                 'token' => $token,
  4800.                 'countDestino' => $cont_destino,
  4801.                 //                'agent'=>$agentMaster,
  4802.                 'destino' => $destino_details,
  4803.                 'gallerys' => $gallery_details,
  4804.                 'description' => $description_details,
  4805.                 //                'sidebar' => $sidebarData
  4806.             );
  4807.         //        d($response_body);
  4808.         //
  4809.         //        d($response);
  4810.         $serializer = SerializerBuilder::create()->build();
  4811.         $array = $serializer->toArray($response_body);
  4812.         $response = new JsonResponse($array);
  4813.         return $response;
  4814.     }
  4815.     /**
  4816.      * @Route("/download/{token}", name="presentation_document_list")
  4817.      */
  4818.     public function downloadAction($token, Request $request)
  4819.     {
  4820.         $em = $this->getDoctrine()->getManager();
  4821.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4822.         if ($proposal->getStatus() == "Cancel") {
  4823.             return $this->redirectToRoute(
  4824.                 'presentation_error_cancel',
  4825.                 array(
  4826.                     'token' => $token
  4827.                 )
  4828.             );
  4829.         }
  4830.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  4831.         // Usuario Anonimo es = "anon."
  4832.         if ($user_logueado == "anon.") {
  4833.             $proposal->setViewedAt(new \DateTime("now"));
  4834.             $em->persist($proposal);
  4835.             $em->flush();
  4836.         }
  4837.         $selectType = explode(",", $proposal->getSelectType());
  4838.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4839.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  4840.             array(
  4841.                 'proposalId' => $proposal->getId(),
  4842.                 'disabled' => '0',
  4843.             )
  4844.         );
  4845.         $data_destionation = array();
  4846.         $cont_destino = 0;
  4847.         foreach ($proposal_Control as $proposalControl) {
  4848.             $cont_destino += 1;
  4849.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4850.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4851.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  4852.                 array(
  4853.                     'destinationId' => $proposalControl->getDestinationId(),
  4854.                     'language' => $proposal->getLanguage()
  4855.                 )
  4856.             );
  4857.             $data_destionation[$destino->getTitle()] = array(
  4858.                 'destino' => $destino,
  4859.                 'gallery' => $gallery,
  4860.                 'description' => $description,
  4861.             );
  4862.         }
  4863.         $document = $em->getRepository(ProposalDocument::class)->findBy(
  4864.             array('proposalId' => $proposal->getId())
  4865.         );
  4866.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  4867.         $agentMaster = array();
  4868.         if (!empty($proposal->getAgentId())) {
  4869.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  4870.             $agentMaster = array(
  4871.                 'name' => $agent->getName(),
  4872.                 'lastname' => $agent->getLastname(),
  4873.                 'picture' => $agent->getPicture(),
  4874.             );
  4875.         }
  4876.         $parametersNew = array(
  4877.             'proposalId' => $proposal->getId(),
  4878.             'recommended' => '0',
  4879.             'priority' => '0',
  4880.         );
  4881.         $dqlNew = 'SELECT p
  4882.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  4883.                     WHERE p.proposalId = :proposalId 
  4884.                     AND p.recommended = :recommended
  4885.                     AND p.priority != :priority
  4886.                     ORDER BY p.priority ASC';
  4887.         $queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
  4888.         $controlbudgetsNew = $queryNew->getResult();
  4889.         //d($proposal, $client, $company, $data_destionation);
  4890.         $sidebarData = $this->sidebarAction($token, "", "");
  4891.         return $this->render(
  4892.             'MDS/EventsPresentationBundle/presentation/document.html.twig',
  4893.             array(
  4894.                 'token' => $token,
  4895.                 'company' => $company,
  4896.                 'proposal' => $proposal,
  4897.                 'client' => $client,
  4898.                 'selectType' => $selectType,
  4899.                 'destination' => $data_destionation,
  4900.                 'budgetNew' => $controlbudgetsNew,
  4901.                 'document' => $document,
  4902.                 'countDestino' => $cont_destino,
  4903.                 'sidebar' => $sidebarData,
  4904.                 'agent' => $agentMaster,
  4905.                 //                'agendas' => $showAgenda,
  4906.             )
  4907.         );
  4908.     }
  4909.     /**
  4910.      * @Route("/esp-detail/{type}/{idd}/{idi}/{token}", name="presentation_idea_view_detail_token")
  4911.      */
  4912.     public function ideaViewDetailAction($type, $token, $idd, $idi, Request $request)
  4913.     {
  4914.         //        $type='idea';
  4915.         $em = $this->getDoctrine()->getManager();
  4916.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4917.         if ($proposal->getStatus() == "Cancel") {
  4918.             return $this->redirectToRoute(
  4919.                 'presentation_error_cancel',
  4920.                 array(
  4921.                     'token' => $token
  4922.                 )
  4923.             );
  4924.         }
  4925.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  4926.         // Usuario Anonimo es = "anon."
  4927.         if ($user_logueado == "anon.") {
  4928.             $proposal->setViewedAt(new \DateTime("now"));
  4929.             $em->persist($proposal);
  4930.             $em->flush();
  4931.         }
  4932.         if (is_null($proposal->getSelectType())) {
  4933.             $selectType = array();
  4934.         } else {
  4935.             $selectType = explode(",", $proposal->getSelectType());
  4936.         }
  4937.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4938.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  4939.             array(
  4940.                 'proposalId' => $proposal->getId(),
  4941.                 'disabled' => '0',
  4942.             )
  4943.         );
  4944.         $data_destionation = array();
  4945.         $cont_destino = 0;
  4946.         foreach ($proposal_Control as $proposalControl) {
  4947.             $cont_destino += 1;
  4948.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4949.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4950.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  4951.                 array(
  4952.                     'destinationId' => $proposalControl->getDestinationId(),
  4953.                     'language' => $proposal->getLanguage()
  4954.                 )
  4955.             );
  4956.             $data_destionation[$destino->getTitle()] = array(
  4957.                 'destino' => $destino,
  4958.                 'gallery' => $gallery,
  4959.                 'description' => $description,
  4960.             );
  4961.         }
  4962.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  4963.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4964.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4965.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4966.         $typeM = strtoupper($type);
  4967.         $ideas_services = array();
  4968.         $activities_services = array();
  4969.         $supplier_services = array();
  4970.         if ($type == "idea") {
  4971.             $ideas = $em->getRepository(Ideas::class)->findOneBy(
  4972.                 array(
  4973.                     'id' => $idi
  4974.                 )
  4975.             );
  4976.             if (!is_null($ideas)) {
  4977.                 $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($idi);
  4978.                 $id = $controlgeneral->getId();
  4979.                 $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  4980.                     array(
  4981.                         'supplierId' => $id,
  4982.                         'servicesCatId' => '0',
  4983.                         'servicesId' => '0',
  4984.                     )
  4985.                 );
  4986.                 $descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
  4987.                     array(
  4988.                         'supplierId' => $id,
  4989.                         'language' => $proposal->getLanguage()
  4990.                     )
  4991.                 );
  4992.                 $data_idea = array(
  4993.                     'datos' => $ideas,
  4994.                     'gallery' => $gallerySupplier,
  4995.                     'description' => $descriptionSupplier,
  4996.                 );
  4997.                 $ideas_services = array(
  4998.                     'ideas' => $data_idea,
  4999.                 );
  5000.             }
  5001.         }
  5002.         if ($type == "activity") {
  5003.             $activities = $em->getRepository(Activities::class)->findOneBy(
  5004.                 array(
  5005.                     'id' => $idi
  5006.                 )
  5007.             );
  5008.             if (!is_null($activities)) {
  5009.                 $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($idi);
  5010.                 $id = $controlgeneral->getId();
  5011.                 $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5012.                     array(
  5013.                         'supplierId' => $id,
  5014.                         'servicesCatId' => '0',
  5015.                         'servicesId' => '0',
  5016.                     )
  5017.                 );
  5018.                 $descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
  5019.                     array(
  5020.                         'supplierId' => $id,
  5021.                         'language' => $proposal->getLanguage()
  5022.                     )
  5023.                 );
  5024.                 $data_activity = array(
  5025.                     'datos' => $activities,
  5026.                     'gallery' => $gallerySupplier,
  5027.                     'description' => $descriptionSupplier,
  5028.                 );
  5029.                 $activities_services = array(
  5030.                     'activities' => $data_activity,
  5031.                 );
  5032.             }
  5033.         }
  5034.         $data = array(
  5035.             'type' => $typeM,
  5036.             'ideas' => $ideas_services,
  5037.             'activities' => $activities_services,
  5038.             'supplier' => $supplier_services
  5039.         );
  5040.         ////////////////////////////////////////////////////////////////////////////////////////////////
  5041.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  5042.         ////////////////////////////////////////////////////////////////////////////////////////////////
  5043.         //////////////////////////////////////////////
  5044.         /* CODIGO PARA TRAER A LOS AGENTES         */
  5045.         ////////////////////////////////////////////
  5046.         $agentMaster = array();
  5047.         if (!empty($proposal->getAgentId())) {
  5048.             $agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  5049.             $agentMaster = array(
  5050.                 'name' => $agent->getName(),
  5051.                 'lastname' => $agent->getLastname(),
  5052.                 'picture' => $agent->getPicture(),
  5053.             );
  5054.         }
  5055.         ////////////////////////////////////////////
  5056.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  5057.         //////////////////////////////////////////
  5058.         $sidebarData = $this->sidebarAction($token, $typeM, $idd);
  5059.         //d($data,$selectType);
  5060.         return $this->render(
  5061.             'MDS/EventsPresentationBundle/presentation/service-detail-client.html.twig',
  5062.             array(
  5063.                 'token' => $token,
  5064.                 'company' => $company,
  5065.                 'proposal' => $proposal,
  5066.                 'client' => $client,
  5067.                 'selectType' => $selectType,
  5068.                 'destination' => $data_destionation,
  5069.                 'countDestino' => $cont_destino,
  5070.                 'agent' => $agentMaster,
  5071.                 'data' => $data,
  5072.                 'activity' => $activities_services,
  5073.                 'idea' => $ideas_services,
  5074.                 'sidebar' => $sidebarData,
  5075.                 //                'agendas' => $showAgenda,
  5076.             )
  5077.         );
  5078.     }
  5079.     /**
  5080.      * @Route("/service-detail-ajax/{type}/{idd}/{ids}/{token}", name="presentation_services_detail_ajax")
  5081.      */
  5082.     public function ajaxServicesDetailAction($token, $type, $idd, $ids, Request $request)
  5083.     {
  5084.         $em = $this->getDoctrine()->getManager();
  5085.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  5086.         if ($proposal->getStatus() == "Cancel") {
  5087.             return $this->redirectToRoute(
  5088.                 'presentation_error_cancel',
  5089.                 array(
  5090.                     'token' => $token
  5091.                 )
  5092.             );
  5093.         }
  5094.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  5095.         // Usuario Anonimo es = "anon."
  5096.         if ($user_logueado == "anon.") {
  5097.             $proposal->setViewedAt(new \DateTime("now"));
  5098.             $em->persist($proposal);
  5099.             $em->flush();
  5100.         }
  5101.         if (is_null($proposal->getSelectType())) {
  5102.             $selectType = array();
  5103.         } else {
  5104.             $selectType = explode(",", $proposal->getSelectType());
  5105.         }
  5106.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  5107.             array(
  5108.                 'proposalId' => $proposal->getId(),
  5109.                 'disabled' => '0',
  5110.             )
  5111.         );
  5112.         $data_destionation = array();
  5113.         $cont_destino = 0;
  5114.         foreach ($proposal_Control as $proposalControl) {
  5115.             $cont_destino += 1;
  5116.             $destino = $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  5117.             $gallery = $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  5118.             $description = $em->getRepository(DestinationDescription::class)->findOneBy(
  5119.                 array(
  5120.                     'destinationId' => $proposalControl->getDestinationId(),
  5121.                     'language' => $proposal->getLanguage()
  5122.                 )
  5123.             );
  5124.             $data_destionation[$destino->getTitle()] = array(
  5125.                 'destino' => $destino,
  5126.                 'gallery' => $gallery,
  5127.                 'description' => $description,
  5128.             );
  5129.         }
  5130.         $typeStr = str_replace("-", " ", $type);
  5131.         $typeM = strtoupper($typeStr);
  5132.         $controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
  5133.             array(
  5134.                 'destinoId' => $idd,
  5135.                 'proposalId' => $proposal->getId(),
  5136.                 'disabled' => '0',
  5137.             )
  5138.         );
  5139.         $ideas_services = array();
  5140.         $supplier_services = array();
  5141.         $data_supplier = array();
  5142.         $data = array();
  5143.         foreach ($controlservices as $controlServicesProposal) {
  5144.             if (is_null($controlServicesProposal->getIdeaId()) && $type != "idea" && $controlServicesProposal->getSupplierId() != "0") {
  5145.                 //                d($controlServicesProposal);
  5146.                 /*consulta Proveedor*/
  5147.                 $supplier = $em->getRepository(Supplier::class)->findOneBy(
  5148.                     array(
  5149.                         'id' => $controlServicesProposal->getSupplierId(),
  5150.                         'type' => $typeM,
  5151.                     )
  5152.                 );
  5153.                 //d($supplier);
  5154.                 if (!is_null($supplier)) {
  5155.                     //d($typeM);
  5156.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
  5157.                     $id = $controlgeneral->getId();
  5158.                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5159.                         array(
  5160.                             'supplierId' => $id,
  5161.                             'servicesCatId' => '0',
  5162.                             'servicesId' => '0',
  5163.                         )
  5164.                     );
  5165.                     $descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
  5166.                         array(
  5167.                             'supplierId' => $id,
  5168.                             'language' => $proposal->getLanguage()
  5169.                         )
  5170.                     );
  5171.                     $data_supplier = array(
  5172.                         'datos' => $supplier,
  5173.                         'gallery' => $gallerySupplier,
  5174.                         'description' => $descriptionSupplier,
  5175.                     );
  5176.                     //                    d($data_supplier);
  5177.                     /*consulta Hoteles para salones*/
  5178.                     //
  5179.                     $services = $em->getRepository(ProposalSupplierServices::class)->findBy(
  5180.                         array(
  5181.                             'controlId' => $controlServicesProposal->getId(),
  5182.                             'supplierId' => $controlServicesProposal->getSupplierId(),
  5183.                             //                            'serviceCatId' => $idcat,
  5184.                         )
  5185.                     );
  5186.                     //d($services);
  5187.                     $servicesArray = array();
  5188.                     foreach ($services as $servicesSupplier) {
  5189.                         /*consulta Lounge*/
  5190.                         // d($typeM);
  5191.                         if (
  5192.                             $servicesSupplier->getServiceId() != "0" &&
  5193.                             (
  5194.                                 $typeM == "RESTAURANTE" or
  5195.                                 $typeM == "HOTEL" or
  5196.                                 $typeM == "HOTEL URBANO PERIFERIA" or
  5197.                                 $typeM == "HOTEL DE COSTA" or
  5198.                                 $typeM == "HOTEL URBANO DENTRO DE LA CIUDAD" or
  5199.                                 $typeM == "HOTEL URBANO CÉNTRICO" or
  5200.                                 $typeM == "SALON" or
  5201.                                 $typeM == "LUGARES DE EVENTOS"
  5202.                             )
  5203.                         ) {
  5204.                             $idcat = '10'; // Lounge
  5205.                             $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  5206.                             if (!is_null($servicesSup)) {
  5207.                                 $controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
  5208.                                     array(
  5209.                                         'servicesId' => $servicesSup->getId(),
  5210.                                         'servicesCat' => $idcat,
  5211.                                     )
  5212.                                 );
  5213.                                 $servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  5214.                                 $servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
  5215.                                     array(
  5216.                                         'servicesId' => $servicesSup->getId(),
  5217.                                         'controlId' => $servicesSupplier->getServiceId(),
  5218.                                         'language' => $proposal->getLanguage()
  5219.                                     )
  5220.                                 );
  5221.                                 //paquete de tipo
  5222.                                 $serviceCapacity = $em->getRepository('App:SupplierLoungeCapacity')->findBy(array('serviceId' => $servicesSup->getId()));
  5223.                                 if (!empty($serviceCapacity)) {
  5224.                                     foreach ($serviceCapacity as $item) {
  5225.                                         switch ($item->getType()) {
  5226.                                             case 1:
  5227.                                                 $item->setType("Teatro");
  5228.                                                 break;
  5229.                                             case 2:
  5230.                                                 $item->setType("Cocktail");
  5231.                                                 break;
  5232.                                             case 3:
  5233.                                                 $item->setType("Banquete");
  5234.                                                 break;
  5235.                                             case 4:
  5236.                                                 $item->setType("Imperial");
  5237.                                                 break;
  5238.                                             case 5:
  5239.                                                 $item->setType("Montaje en U");
  5240.                                                 break;
  5241.                                             case 6:
  5242.                                                 $item->setType("Cabaret");
  5243.                                                 break;
  5244.                                             case 0:
  5245.                                                 $item->setType("Escuela");
  5246.                                                 break;
  5247.                                         }
  5248.                                         //
  5249.                                     }
  5250.                                 } else {
  5251.                                     $serviceCapacity = array();
  5252.                                 }
  5253.                                 /* ARMO EL CONTENIDO GLOBAL */
  5254.                                 $servicesArray[$servicesSup->getId()] = array(
  5255.                                     'services' => $servicesSup,
  5256.                                     'gallery' => $servicesGallery,
  5257.                                     'descripcion' => $servicesDescription,
  5258.                                     'capacity' => $serviceCapacity,
  5259.                                 );
  5260.                                 //d($typeM);
  5261.                             }
  5262.                         }
  5263.                     }
  5264.                     // d($data_supplier);
  5265.                     if ($data_supplier['datos']->getId() == $ids) {
  5266.                         $supplier_services[] = array(
  5267.                             'supplier' => $data_supplier,
  5268.                             'services' => $servicesArray,
  5269.                         );
  5270.                     }
  5271.                 }
  5272.             }
  5273.             $data = array(
  5274.                 'type' => $typeM,
  5275.                 'ideas' => $ideas_services,
  5276.                 'supplier' => $supplier_services
  5277.             );
  5278.         }
  5279.         //d($data);
  5280.         $response_body = array(
  5281.             'token' => $token,
  5282.             'selectType' => $selectType,
  5283.             'countDestino' => $cont_destino,
  5284.             'data' => $data,
  5285.             'idd' => $idd,
  5286.             'idea' => '',
  5287.             'activity' => '',
  5288.         );
  5289.         $serializer = SerializerBuilder::create()->build();
  5290.         $array = $serializer->toArray($response_body);
  5291.         $response = new JsonResponse($array);
  5292.         return $response;
  5293.     }
  5294.     /**
  5295.      * @Route("/type-ajax/{idd}/{token}", name="presentation_type_ajax")
  5296.      */
  5297.     public function ServicesViewAjaxDetailAction($token, $idd, Request $request)
  5298.     {
  5299.         $em = $this->getDoctrine()->getManager();
  5300.         $type = '';
  5301.         $sidebarData = $this->sidebarAction($token, $type, $idd);
  5302.         ////////////////////////////////////////////
  5303.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  5304.         //////////////////////////////////////////
  5305.         //d($data);
  5306.         $response_body = array(
  5307.             'token' => $token,
  5308.             'selectType' => $type,
  5309.             'idd' => $idd,
  5310.             'sidebar' => $sidebarData,
  5311.         );
  5312.         $serializer = SerializerBuilder::create()->build();
  5313.         $array = $serializer->toArray($response_body);
  5314.         $response = new JsonResponse($array);
  5315.         return $response;
  5316.     }
  5317.     /**
  5318.      * @Route("/services/{type}/{token}", name="presentation_services_view_token")
  5319.      */
  5320.     public function ServicesViewAction($token, $type, Request $request)
  5321.     {
  5322.         //Services
  5323.         $em = $this->getDoctrine()->getManager();
  5324.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  5325.         if ($proposal->getStatus() == "Cancel") {
  5326.             return $this->redirectToRoute(
  5327.                 'presentation_error_cancel',
  5328.                 array(
  5329.                     'token' => $token
  5330.                 )
  5331.             );
  5332.         }
  5333.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  5334.         // Usuario Anonimo es = "anon."
  5335.         if ($user_logueado == "anon.") {
  5336.             $proposal->setViewedAt(new \DateTime("now"));
  5337.             $em->persist($proposal);
  5338.             $em->flush();
  5339.         }
  5340.         if (is_null($proposal->getSelectType())) {
  5341.             $selectType = array();
  5342.         } else {
  5343.             $selectType = explode(",", $proposal->getSelectType());
  5344.         }
  5345.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  5346.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  5347.             array(
  5348.                 'proposalId' => $proposal->getId(),
  5349.                 'disabled' => '0',
  5350.             )
  5351.         );
  5352.         switch ($type) {
  5353.             case 1:
  5354.                 $nameType = "hotel";
  5355.                 $transType = strtoupper($this->translator->trans("Hotel"));
  5356.                 $varType = "1";
  5357.                 $viewGroupService = "1";
  5358.                 break;
  5359.             case 2:
  5360.                 $nameType = "restaurante";
  5361.                 $transType = strtoupper($this->translator->trans("Restaurant"));
  5362.                 $varType = "2";
  5363.                 $viewGroupService = "1";
  5364.                 break;
  5365.             case 3:
  5366.                 $nameType = "actividad";
  5367.                 $transType = strtoupper($this->translator->trans("Activities"));
  5368.                 $varType = "3";
  5369.                 $viewGroupService = "0";
  5370.                 break;
  5371.             case 4:
  5372.                 $nameType = "idea";
  5373.                 $transType = strtoupper($this->translator->trans("Ideas"));
  5374.                 $varType = "4";
  5375.                 $viewGroupService = "0";
  5376.                 break;
  5377.             case 5:
  5378.                 $nameType = "audiovisual";
  5379.                 $transType = strtoupper($this->translator->trans("Audiovisual"));
  5380.                 $varType = "5";
  5381.                 $viewGroupService = "1";
  5382.                 break;
  5383.             case 6:
  5384.                 $nameType = "tecnologia";
  5385.                 $transType = strtoupper($this->translator->trans("Technology Services"));
  5386.                 $varType = "6";
  5387.                 $viewGroupService = "1";
  5388.                 break;
  5389.             case 7:
  5390.                 $nameType = "lugares de eventos";
  5391.                 $transType = strtoupper($this->translator->trans("Places of Events"));
  5392.                 $varType = "7";
  5393.                 $viewGroupService = "1";
  5394.                 break;
  5395.             case 8:
  5396.                 $nameType = "otros";
  5397.                 $transType = strtoupper($this->translator->trans("Others"));
  5398.                 $varType = "8";
  5399.                 $viewGroupService = "0";
  5400.                 break;
  5401.             case 9:
  5402.                 $nameType = "catering";
  5403.                 $transType = strtoupper($this->translator->trans("Catering"));
  5404.                 $varType = "9";
  5405.                 $viewGroupService = "0";
  5406.                 break;
  5407.             case 10:
  5408.                 $nameType = "excursiones";
  5409.                 $transType = strtoupper($this->translator->trans("Excursions"));
  5410.                 $varType = "10";
  5411.                 $viewGroupService = "0";
  5412.                 break;
  5413.             case 11:
  5414.                 $nameType = "musica";
  5415.                 $transType = strtoupper($this->translator->trans("Music"));
  5416.                 $varType = "11";
  5417.                 $viewGroupService = "0";
  5418.                 break;
  5419.             case 12:
  5420.                 $nameType = "actividades";
  5421.                 $transType = strtoupper($this->translator->trans("Activities"));
  5422.                 $varType = "12";
  5423.                 $viewGroupService = "0";
  5424.                 break;
  5425.             case 13:
  5426.                 $nameType = "cruceros";
  5427.                 $transType = strtoupper($this->translator->trans("Cruise ships"));
  5428.                 $varType = "13";
  5429.                 $viewGroupService = "0";
  5430.                 break;
  5431.             case 14:
  5432.                 $nameType = "guias";
  5433.                 $transType = strtoupper($this->translator->trans("Guides"));
  5434.                 $varType = "14";
  5435.                 $viewGroupService = "0";
  5436.                 break;
  5437.             case 15:
  5438.                 $nameType = "entretenimiento ";
  5439.                 $transType = strtoupper($this->translator->trans("Entertainment"));
  5440.                 $varType = "15";
  5441.                 $viewGroupService = "0";
  5442.                 break;
  5443.             case 16:
  5444.                 $nameType = "salon ";
  5445.                 $transType = strtoupper($this->translator->trans("Lounge"));
  5446.                 $varType = "16";
  5447.                 $viewGroupService = "0";
  5448.                 break;
  5449.             case 17:
  5450.                 $nameType = "transporte ";
  5451.                 $transType = strtoupper($this->translator->trans("Transport"));
  5452.                 $varType = "17";
  5453.                 $viewGroupService = "0";
  5454.                 break;
  5455.             case 18:
  5456.                 $nameType = "regalos ";
  5457.                 $transType = strtoupper($this->translator->trans("Gifts"));
  5458.                 $varType = "18";
  5459.                 $viewGroupService = "0";
  5460.                 break;
  5461.             case 19:
  5462.                 $nameType = "itinerarios ";
  5463.                 $transType = strtoupper($this->translator->trans("Itineraries"));
  5464.                 $varType = "19";
  5465.                 $viewGroupService = "0";
  5466.                 break;
  5467.             default:
  5468.                 break;
  5469.                 //crear los demas numero por servicos
  5470.         }
  5471.         $typeM = strtoupper($nameType);
  5472.         //        $typeM = strtoupper($type);
  5473.         //        $transType = $type;
  5474.         $controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
  5475.             array(
  5476.                 //                'destinoId' => $idd,
  5477.                 'proposalId' => $proposal->getId(),
  5478.                 'disabled' => '0',
  5479.             )
  5480.         );
  5481.         $data_idea = array();
  5482.         $data_supplier = array();
  5483.         $data_all = array();
  5484.         $data = array();
  5485.         $servicesArray = array();
  5486.         foreach ($controlservices as $controlServicesProposal) {
  5487.             if (!is_null($controlServicesProposal->getIdeaId()) && $nameType == "idea") {
  5488.                 //                d('idea');
  5489.                 /* IDEA  */
  5490.                 /*consulta Proveedor*/
  5491.                 $ideas = $em->getRepository(Ideas::class)->findOneBy(
  5492.                     array(
  5493.                         'id' => $controlServicesProposal->getIdeaId()
  5494.                     )
  5495.                 );
  5496.                 //                d($ideas);
  5497.                 if (!is_null($ideas)) {
  5498.                     if ($ideas->getDestinationId() != 0) {
  5499.                         $ideasDestination = $em->getRepository(Destination::class)->findOneById($ideas->getDestinationId());
  5500.                         $citiesData = $em->getRepository(Cities::class)->findOneById($ideasDestination->getPopulation());
  5501.                         $cities = $citiesData->getCity();
  5502.                     } else {
  5503.                         $cities = null;
  5504.                     }
  5505.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($controlServicesProposal->getIdeaId());
  5506.                     $id = $controlgeneral->getId();
  5507.                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5508.                         array(
  5509.                             'supplierId' => $id,
  5510.                             'servicesCatId' => '0',
  5511.                             'servicesId' => '0',
  5512.                         )
  5513.                     );
  5514.                     $descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
  5515.                         array(
  5516.                             'supplierId' => $id,
  5517.                             'language' => $proposal->getLanguage()
  5518.                         )
  5519.                     );
  5520.                     $data_all[] = array(
  5521.                         'id' => $ideas->getId(),
  5522.                         'name' => $ideas->getName(),
  5523.                         'img' => $gallerySupplier['0'],
  5524.                         'cities' => $cities,
  5525.                         'type' => $typeM,
  5526.                         'typeajax' => "idea",
  5527.                         'gallery' => $gallerySupplier,
  5528.                         'description' => $descriptionSupplier,
  5529.                         'services' => null,
  5530.                         'ids' => $varType,
  5531.                         //                        'idd' => $ideasDestination,
  5532.                         'viewGroupService' => $viewGroupService,
  5533.                     );
  5534.                 }
  5535.             }
  5536.             //Actividades
  5537.             if (!is_null($controlServicesProposal->getActivityId()) && $nameType == "actividad") {
  5538.                 //                d('idea');
  5539.                 /* IDEA  */
  5540.                 /*consulta Proveedor*/
  5541.                 $activities = $em->getRepository(Activities::class)->findOneBy(
  5542.                     array(
  5543.                         'id' => $controlServicesProposal->getActivityId()
  5544.                     )
  5545.                 );
  5546.                 if (!is_null($activities)) {
  5547.                     //                    $activitiesDestination = $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
  5548.                     //                    $cities = $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
  5549.                     if ($activities->getDestinationId() != 0) {
  5550.                         $activitiesDestination = $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
  5551.                         $citiesData = $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
  5552.                         $cities = $citiesData->getCity();
  5553.                     } else {
  5554.                         $cities = null;
  5555.                     }
  5556.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($controlServicesProposal->getActivityId());
  5557.                     $id = $controlgeneral->getId();
  5558.                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5559.                         array(
  5560.                             'supplierId' => $id,
  5561.                             'servicesCatId' => '0',
  5562.                             'servicesId' => '0',
  5563.                         )
  5564.                     );
  5565.                     $descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
  5566.                         array(
  5567.                             'supplierId' => $id,
  5568.                             'language' => $proposal->getLanguage()
  5569.                         )
  5570.                     );
  5571.                     $data_all[] = array(
  5572.                         'id' => $activities->getId(),
  5573.                         'name' => $activities->getName(),
  5574.                         'img' => $gallerySupplier['0'],
  5575.                         'cities' => $cities,
  5576.                         'type' => $typeM,
  5577.                         'typeajax' => "actividad",
  5578.                         'gallery' => $gallerySupplier,
  5579.                         'description' => $descriptionSupplier,
  5580.                         'services' => null,
  5581.                         'ids' => $varType,
  5582.                         //                        'idd' => $activitiesDestination,
  5583.                         'viewGroupService' => $viewGroupService,
  5584.                     );
  5585.                 }
  5586.             }
  5587.             if (is_null($controlServicesProposal->getIdeaId()) && $nameType != "idea" && is_null($controlServicesProposal->getActivityId()) && $nameType != "actividad" && $controlServicesProposal->getSupplierId() != "0") {
  5588.                 //                d($controlServicesProposal);
  5589.                 /*consulta Proveedor*/
  5590.                 $supplier = $em->getRepository(Supplier::class)->findOneBy(
  5591.                     array(
  5592.                         'id' => $controlServicesProposal->getSupplierId(),
  5593.                         'type' => $typeM,
  5594.                     )
  5595.                 );
  5596.                 if (!is_null($supplier)) {
  5597.                     /* OJO AQUI */
  5598.                     $cities = $em->getRepository(Cities::class)->findOneById($supplier->getPopulation());
  5599.                     //d($typeM);
  5600.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
  5601.                     $id = $controlgeneral->getId();
  5602.                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5603.                         array(
  5604.                             'supplierId' => $id,
  5605.                             'servicesCatId' => '0',
  5606.                             'servicesId' => '0',
  5607.                         )
  5608.                     );
  5609.                     $descriptionSupplier = $em->getRepository(SupplierDescription::class)->findOneBy(
  5610.                         array(
  5611.                             'supplierId' => $id,
  5612.                             'language' => $proposal->getLanguage()
  5613.                         )
  5614.                     );
  5615.                     if ($varType == "5") {
  5616.                         $idcat = '3';
  5617.                         /*consulta de los servicios del supplier*/
  5618.                         $services = $em->getRepository(ProposalSupplierServices::class)->findBy(
  5619.                             array(
  5620.                                 'controlId' => $controlServicesProposal->getId(),
  5621.                                 'supplierId' => $controlServicesProposal->getSupplierId(),
  5622.                                 'serviceCatId' => $idcat,
  5623.                             )
  5624.                         );
  5625.                         foreach ($services as $servicesSupplier) {
  5626.                             $destino = $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
  5627.                             /*consulta Lounge*/
  5628.                             //                             d($servicesSupplier);
  5629.                             if ($servicesSupplier->getServiceId() != "0") {
  5630.                                 //                            $idcat = '10'; // Lounge
  5631.                                 $servicesSup = $em->getRepository(SupplierAv::class)->findOneBy(
  5632.                                     array(
  5633.                                         'id' => $servicesSupplier->getServiceId(),
  5634.                                         'responsible' => "RENDERS 3D",
  5635.                                     )
  5636.                                 );
  5637.                                 if (!empty($servicesSup)) {
  5638.                                     $controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
  5639.                                         array(
  5640.                                             'servicesId' => $servicesSup->getId(),
  5641.                                             'servicesCat' => $idcat,
  5642.                                         )
  5643.                                     );
  5644.                                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  5645.                                     $servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
  5646.                                         array(
  5647.                                             'servicesId' => $servicesSup->getId(),
  5648.                                             'controlId' => $servicesSupplier->getServiceId(),
  5649.                                             'language' => $proposal->getLanguage()
  5650.                                         )
  5651.                                     );
  5652.                                 } else {
  5653.                                     $controlSup = array();
  5654.                                     $gallerySupplier = array();
  5655.                                     $servicesDescription = array();
  5656.                                 }
  5657.                                 //paquete de tipo
  5658.                                 $serviceCapacity = array();
  5659.                                 /* ARMO EL CONTENIDO GLOBAL */
  5660.                                 $servicesArray[] = array(
  5661.                                     'services' => $servicesSup,
  5662.                                     'gallery' => $gallerySupplier,
  5663.                                     'descripcion' => $servicesDescription,
  5664.                                     'capacity' => $serviceCapacity,
  5665.                                 );
  5666.                                 //d($typeM);
  5667.                                 //                                array_push($galleryNuevaSupplier, $servicesGallery);
  5668.                                 //                                d($servicesGallery);
  5669.                             }
  5670.                         }
  5671.                         //
  5672.                         $data_all[$supplier->getId()] = array(
  5673.                             'id' => $supplier->getId(),
  5674.                             'name' => $viewGroupService == "0" ? '' : $supplier->getName(),
  5675.                             //                        'nameav' => $nameav,
  5676.                             'img' => empty($gallerySupplier) ? null : $gallerySupplier['0'],
  5677.                             'cities' => $cities->getCity(),
  5678.                             'type' => $transType,
  5679.                             'typeajax' => "supplier",
  5680.                             'gallery' => $gallerySupplier,
  5681.                             'description' => null,
  5682.                             'services' => $servicesArray,
  5683.                             'ids' => $varType,
  5684.                             //                        'idd' => $destino,
  5685.                             'viewGroupService' => $viewGroupService,
  5686.                         );
  5687.                         //
  5688.                     } else {
  5689.                         $idcat = '10';
  5690.                         /*consulta de los servicios del supplier*/
  5691.                         $services = $em->getRepository(ProposalSupplierServices::class)->findBy(
  5692.                             array(
  5693.                                 'controlId' => $controlServicesProposal->getId(),
  5694.                                 'supplierId' => $controlServicesProposal->getSupplierId(),
  5695.                                 'serviceCatId' => $idcat,
  5696.                             )
  5697.                         );
  5698.                         $servicesArray = array();
  5699.                         foreach ($services as $servicesSupplier) {
  5700.                             $destino = $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
  5701.                             /*consulta Lounge*/
  5702.                             // d($typeM);
  5703.                             if ($servicesSupplier->getServiceId() != "0") {
  5704.                                 //                            $idcat = '10'; // Lounge
  5705.                                 $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  5706.                                 $controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
  5707.                                     array(
  5708.                                         'servicesId' => $servicesSup->getId(),
  5709.                                         'servicesCat' => $idcat,
  5710.                                     )
  5711.                                 );
  5712.                                 //                                d($servicesSup,$idcat,$controlSup);
  5713.                                 $servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  5714.                                 $servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
  5715.                                     array(
  5716.                                         'servicesId' => $servicesSup->getId(),
  5717.                                         'controlId' => $servicesSupplier->getServiceId(),
  5718.                                         'language' => $proposal->getLanguage()
  5719.                                     )
  5720.                                 );
  5721.                                 //                                d($servicesSup,$servicesGallery);
  5722.                                 //paquete de tipo
  5723.                                 $serviceCapacity = $em->getRepository('App:SupplierLoungeCapacity')->findByServiceId($servicesSup->getId());
  5724.                                 foreach ($serviceCapacity as $item) {
  5725.                                     switch ($item->getType()) {
  5726.                                         case 1:
  5727.                                             $item->setType("Teatro");
  5728.                                             break;
  5729.                                         case 2:
  5730.                                             $item->setType("Cocktail");
  5731.                                             break;
  5732.                                         case 3:
  5733.                                             $item->setType("Banquete");
  5734.                                             break;
  5735.                                         case 4:
  5736.                                             $item->setType("Imperial");
  5737.                                             break;
  5738.                                         case 5:
  5739.                                             $item->setType("Montaje en U");
  5740.                                             break;
  5741.                                         case 6:
  5742.                                             $item->setType("Cabaret");
  5743.                                             break;
  5744.                                         case 0:
  5745.                                             $item->setType("Escuela");
  5746.                                             break;
  5747.                                     }
  5748.                                     //
  5749.                                 }
  5750.                                 /* ARMO EL CONTENIDO GLOBAL */
  5751.                                 $servicesArray[] = array(
  5752.                                     'services' => $servicesSup,
  5753.                                     'gallery' => $servicesGallery,
  5754.                                     'descripcion' => $servicesDescription,
  5755.                                     'capacity' => $serviceCapacity,
  5756.                                 );
  5757.                                 //d($typeM);
  5758.                             }
  5759.                         }
  5760.                         $data_all[$supplier->getId()] = array(
  5761.                             'id' => $supplier->getId(),
  5762.                             'name' => $viewGroupService == "0" ? '' : $supplier->getName(),
  5763.                             //                        'nameav' => $nameav,
  5764.                             'img' => empty($gallerySupplier) ? null : $gallerySupplier['0'],
  5765.                             'cities' => $cities->getCity(),
  5766.                             'type' => $transType,
  5767.                             'typeajax' => "supplier",
  5768.                             'gallery' => $gallerySupplier,
  5769.                             'description' => $descriptionSupplier,
  5770.                             'services' => $servicesArray,
  5771.                             'ids' => $varType,
  5772.                             //                        'idd' => $destino,
  5773.                             'viewGroupService' => $viewGroupService,
  5774.                         );
  5775.                         //                        $descriptionSupplierexter[] = $descriptionSupplier->getDescription();
  5776.                     }
  5777.                 }
  5778.             }
  5779.         }
  5780.         //d($descriptionSupplierexter);
  5781.         //        d($data_all);
  5782.         //        exit();
  5783.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  5784.         return $this->render(
  5785.             'MDS/EventsPresentationBundle/presentation/services.html.twig',
  5786.             array(
  5787.                 'token' => $token,
  5788.                 'type' => $transType,
  5789.                 'company' => $company,
  5790.                 'proposal' => $proposal,
  5791.                 'client' => $client,
  5792.                 'selectType' => $selectType,
  5793.                 'data' => $data_all,
  5794.             )
  5795.         );
  5796.     }
  5797.     /**
  5798.      * @Route("/services-ajax/{id}/{type}/{ssi}/{token}", name="presentation_services_view_token_ajax")
  5799.      */
  5800.     public function ServicesAjaxViewAction($token, $type, $id, $ssi, Request $request)
  5801.     {
  5802.         //  var_dump($token, "",  $type,"",  $id, "", $ssi);die();
  5803.         $em = $this->getDoctrine()->getManager();
  5804.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  5805.         if ($proposal->getStatus() == "Cancel") {
  5806.             return $this->redirectToRoute(
  5807.                 'presentation_error_cancel',
  5808.                 array(
  5809.                     'token' => $token
  5810.                 )
  5811.             );
  5812.         }
  5813.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  5814.         // Usuario Anonimo es = "anon."
  5815.         if ($user_logueado == "anon.") {
  5816.             $proposal->setViewedAt(new \DateTime("now"));
  5817.             $em->persist($proposal);
  5818.             $em->flush();
  5819.         }
  5820.         if (is_null($proposal->getSelectType())) {
  5821.             $selectType = array();
  5822.         } else {
  5823.             $selectType = explode(",", $proposal->getSelectType());
  5824.         }
  5825.         if ($type == "idea") {
  5826.             $controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
  5827.                 array(
  5828.                     'proposalId' => $proposal->getId(),
  5829.                     'ideaId' => $id,
  5830.                 )
  5831.             );
  5832.         }
  5833.         if ($type == "actividad") {
  5834.             $controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
  5835.                 array(
  5836.                     'proposalId' => $proposal->getId(),
  5837.                     'activityId' => $id,
  5838.                 )
  5839.             );
  5840.         }
  5841.         if ($type == "supplier") {
  5842.             $controlservices = $em->getRepository(ProposalSupplierControl::class)->findBy(
  5843.                 array(
  5844.                     'proposalId' => $proposal->getId(),
  5845.                     'supplierId' => $id,
  5846.                 )
  5847.             );
  5848.         }
  5849.         $data_idea = array();
  5850.         $data_supplier = array();
  5851.         $data_all = array();
  5852.         $data = array();
  5853.         foreach ($controlservices as $controlServicesProposal) {
  5854.             if (!is_null($controlServicesProposal->getIdeaId()) && $type == "idea") {
  5855.                 //                d('idea');
  5856.                 /* IDEA  */
  5857.                 /*consulta Proveedor*/
  5858.                 $ideas = $em->getRepository(Ideas::class)->findOneBy(
  5859.                     array(
  5860.                         'id' => $controlServicesProposal->getIdeaId()
  5861.                     )
  5862.                 );
  5863.                 if (!is_null($ideas)) {
  5864.                     $ideasDestination = $em->getRepository(Destination::class)->findOneById($ideas->getDestinationId());
  5865.                     $cities = $em->getRepository(Cities::class)->findOneById($ideasDestination->getPopulation());
  5866.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($controlServicesProposal->getIdeaId());
  5867.                     $id = $controlgeneral->getId();
  5868.                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5869.                         array(
  5870.                             'supplierId' => $id,
  5871.                             'servicesCatId' => '0',
  5872.                             'servicesId' => '0',
  5873.                         )
  5874.                     );
  5875.                     $descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
  5876.                         array(
  5877.                             'supplierId' => $id,
  5878.                             'language' => $proposal->getLanguage()
  5879.                         )
  5880.                     );
  5881.                     $data_all = array(
  5882.                         'id' => $ideas->getId(),
  5883.                         'name' => $ideas->getName(),
  5884.                         'gallery' => $gallerySupplier,
  5885.                         'description' => $descriptionSupplier,
  5886.                         'services' => null,
  5887.                     );
  5888.                 }
  5889.             }
  5890.             //Actividades
  5891.             if (!is_null($controlServicesProposal->getActivityId()) && $type == "actividad") {
  5892.                 //                d('idea');
  5893.                 /* IDEA  */
  5894.                 /*consulta Proveedor*/
  5895.                 $activities = $em->getRepository(Activities::class)->findOneBy(
  5896.                     array(
  5897.                         'id' => $controlServicesProposal->getActivityId()
  5898.                     )
  5899.                 );
  5900.                 if (!is_null($activities)) {
  5901.                     $activitiesDestination = $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
  5902.                     $cities = $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
  5903.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($controlServicesProposal->getActivityId());
  5904.                     $id = $controlgeneral->getId();
  5905.                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5906.                         array(
  5907.                             'supplierId' => $id,
  5908.                             'servicesCatId' => '0',
  5909.                             'servicesId' => '0',
  5910.                         )
  5911.                     );
  5912.                     $descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
  5913.                         array(
  5914.                             'supplierId' => $id,
  5915.                             'language' => $proposal->getLanguage()
  5916.                         )
  5917.                     );
  5918.                     $data_all = array(
  5919.                         'id' => $activities->getId(),
  5920.                         'name' => $activities->getName(),
  5921.                         'gallery' => $gallerySupplier,
  5922.                         'description' => $descriptionSupplier,
  5923.                         'services' => null,
  5924.                     );
  5925.                 }
  5926.             }
  5927.             if (is_null($controlServicesProposal->getIdeaId()) && $type != "idea" && is_null($controlServicesProposal->getActivityId()) && $type != "actividad" && $controlServicesProposal->getSupplierId() != "0") {
  5928.                 //                d($controlServicesProposal);
  5929.                 /*consulta Proveedor*/
  5930.                 $supplier = $em->getRepository(Supplier::class)->findOneBy(
  5931.                     array(
  5932.                         'id' => $controlServicesProposal->getSupplierId(),
  5933.                     )
  5934.                 );
  5935.                 if (!is_null($supplier)) {
  5936.                     /* OJO AQUI */
  5937.                     $cities = $em->getRepository(Cities::class)->findOneById($supplier->getPopulation());
  5938.                     //                    d($supplier);
  5939.                     //d($typeM);
  5940.                     $controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
  5941.                     $id = $controlgeneral->getId();
  5942.                     $gallerySupplier = $em->getRepository(SupplierGallery::class)->findBy(
  5943.                         array(
  5944.                             'supplierId' => $id,
  5945.                             'servicesCatId' => '0',
  5946.                             'servicesId' => '0',
  5947.                         )
  5948.                     );
  5949.                     $descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
  5950.                         array(
  5951.                             'supplierId' => $id,
  5952.                             'language' => $proposal->getLanguage()
  5953.                         )
  5954.                     );
  5955.                     //                    $idcat = '10';
  5956.                     /*consulta de los servicios del supplier*/
  5957.                     $services = $em->getRepository(ProposalSupplierServices::class)->findBy(
  5958.                         array(
  5959.                             'controlId' => $controlServicesProposal->getId(),
  5960.                             'supplierId' => $controlServicesProposal->getSupplierId(),
  5961.                             //                            'serviceCatId' => $idcat,
  5962.                         )
  5963.                     );
  5964.                     $servicesArray = array();
  5965.                     if ($ssi == 1) {
  5966.                         foreach ($services as $servicesSupplier) {
  5967.                             ///////////////////////////////////////////
  5968.                             /// estoy aqui
  5969.                             /// /////////////
  5970.                             //                        d($servicesSupplier, $servicesSupplier->getServiceCatId() );
  5971.                             $destino = $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
  5972.                             /*consulta Lounge*/
  5973.                             // d($typeM);
  5974.                             if ($servicesSupplier->getServiceId() != "0") {
  5975.                                 //$idcat = '10'; // Lounge
  5976.                                 ///
  5977.                                 //                                $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  5978.                                 switch ($servicesSupplier->getServiceCatId()) {
  5979.                                     case 1:
  5980.                                         $servicesSup = $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
  5981.                                         break;
  5982.                                     case 2:
  5983.                                         $servicesSup = $em->getRepository(SupplierActivities::class)->findOneById($servicesSupplier->getServiceId());
  5984.                                         break;
  5985.                                     case 3:
  5986.                                         $servicesSup = $em->getRepository(SupplierAv::class)->findOneById($servicesSupplier->getServiceId());
  5987.                                         break;
  5988.                                     case 4:
  5989.                                         $servicesSup = $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
  5990.                                         break;
  5991.                                     case 5:
  5992.                                         $servicesSup = $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
  5993.                                         break;
  5994.                                     case 6:
  5995.                                         $servicesSup = $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
  5996.                                         break;
  5997.                                     case 7:
  5998.                                         $servicesSup = $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
  5999.                                         break;
  6000.                                     case 8:
  6001.                                         $servicesSup = $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
  6002.                                         break;
  6003.                                     case 9:
  6004.                                         $servicesSup = $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
  6005.                                         break;
  6006.                                     case 10:
  6007.                                         $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  6008.                                         break;
  6009.                                     case 11:
  6010.                                         $servicesSup = $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
  6011.                                         break;
  6012.                                     case 12:
  6013.                                         $servicesSup = $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
  6014.                                         break;
  6015.                                     case 13:
  6016.                                         $servicesSup = $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
  6017.                                         break;
  6018.                                     case 14:
  6019.                                         $servicesSup = $em->getRepository(SupplierTechnology::class)->findOneById($servicesSupplier->getServiceId());
  6020.                                         break;
  6021.                                 }
  6022.                                 if (!empty($servicesSup)) {
  6023.                                     $controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
  6024.                                         array(
  6025.                                             'servicesId' => $servicesSup->getId(),
  6026.                                             'servicesCat' => $servicesSupplier->getServiceCatId(),
  6027.                                             //                                            'servicesCat' => $idcat,
  6028.                                         )
  6029.                                     );
  6030.                                     $servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  6031.                                     foreach ($servicesGallery as $servicesga) {
  6032.                                         array_push($gallerySupplier, $servicesga);
  6033.                                     }
  6034.                                     $servicesDescription[] = $em->getRepository(SupplierServicesDescription::class)->findOneBy(
  6035.                                         array(
  6036.                                             'servicesId' => $servicesSup->getId(),
  6037.                                             'controlId' => $controlSup->getId(),
  6038.                                             'language' => $proposal->getLanguage()
  6039.                                         )
  6040.                                     );
  6041.                                     $serviceCapacity = array();
  6042.                                     if ($servicesSupplier->getServiceCatId() == 10) {
  6043.                                         //paquete de tipo
  6044.                                         $serviceCapacityBase = $em->getRepository('App:SupplierLoungeCapacity')->findByServiceId($servicesSup->getId());
  6045.                                         $serviceCapacity = array();
  6046.                                         if (!empty($serviceCapacityBase)) {
  6047.                                             foreach ($serviceCapacityBase as $item) {
  6048.                                                 switch ($item->getType()) {
  6049.                                                     case 1:
  6050.                                                         $item->setType("teatro");
  6051.                                                         break;
  6052.                                                     case 2:
  6053.                                                         $item->setType("cocktail");
  6054.                                                         break;
  6055.                                                     case 3:
  6056.                                                         $item->setType("banquete");
  6057.                                                         break;
  6058.                                                     case 4:
  6059.                                                         $item->setType("imperial");
  6060.                                                         break;
  6061.                                                     case 5:
  6062.                                                         $item->setType("montaje en U");
  6063.                                                         break;
  6064.                                                     case 6:
  6065.                                                         $item->setType("cabaret");
  6066.                                                         break;
  6067.                                                     case 0:
  6068.                                                         $item->setType("escuela");
  6069.                                                         break;
  6070.                                                 }
  6071.                                                 $serviceCapacity[] = $item;
  6072.                                             }
  6073.                                         }
  6074.                                         /* ARMO EL CONTENIDO GLOBAL */
  6075.                                         $servicesArray[] = array(
  6076.                                             'services' => $servicesSup,
  6077.                                             'gallery' => $servicesGallery,
  6078.                                             'descripcion' => $servicesDescription,
  6079.                                             'capacity' => $serviceCapacity,
  6080.                                         );
  6081.                                         //d($typeM);
  6082.                                     }
  6083.                                 }
  6084.                             }
  6085.                         }
  6086.                     }
  6087.                     $data_all = array(
  6088.                         'id' => $supplier->getId(),
  6089.                         'name' => $ssi == "0" ? '' : $supplier->getName(),
  6090.                         'gallery' => $gallerySupplier,
  6091.                         'description' => is_null($descriptionSupplier['0']) ? $servicesDescription : $descriptionSupplier,
  6092.                         'services' => $servicesArray,
  6093.                     );
  6094.                 }
  6095.             }
  6096.         }
  6097.         //        d($data_all);
  6098.         //        exit();
  6099.         $serializer = SerializerBuilder::create()->build();
  6100.         $array = $serializer->toArray($data_all);
  6101.         $response = new JsonResponse($array);
  6102.         return $response;
  6103.     }
  6104.     /**
  6105.      * @Route("/servicesview/{idcat}/{token}", name="presentation_services_view_all_token")
  6106.      */
  6107.     public function ServicesViewAllAction($token, $idcat, Request $request)
  6108.     {
  6109.         //Suppliers
  6110.         $em = $this->getDoctrine()->getManager();
  6111.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  6112.         if ($proposal->getStatus() == "Cancel") {
  6113.             return $this->redirectToRoute(
  6114.                 'presentation_error_cancel',
  6115.                 array(
  6116.                     'token' => $token
  6117.                 )
  6118.             );
  6119.         }
  6120.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  6121.         // Usuario Anonimo es = "anon."
  6122.         if ($user_logueado == "anon.") {
  6123.             $proposal->setViewedAt(new \DateTime("now"));
  6124.             $em->persist($proposal);
  6125.             $em->flush();
  6126.         }
  6127.         if (is_null($proposal->getSelectType())) {
  6128.             $selectType = array();
  6129.         } else {
  6130.             $selectType = explode(",", $proposal->getSelectType());
  6131.         }
  6132.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  6133.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  6134.             array(
  6135.                 'proposalId' => $proposal->getId(),
  6136.                 'disabled' => '0',
  6137.             )
  6138.         );
  6139.         /*consulta de los servicios del supplier*/
  6140.         $services = $em->getRepository(ProposalSupplierServices::class)->findBy(
  6141.             array(
  6142.                 'proposalId' => $proposal->getId(),
  6143.                 'serviceCatId' => $idcat,
  6144.             )
  6145.         );
  6146.         $servicesArray = array();
  6147.         $transType = "Not Available";
  6148.         if (!empty($services)) {
  6149.             foreach ($services as $servicesSupplier) {
  6150.                 $transType = $this->translator->trans($servicesSupplier->getServiceCatName());
  6151.                 /*consulta Lounge*/
  6152.                 // d($typeM);
  6153.                 if ($servicesSupplier->getServiceId() != "0") {
  6154.                     //                            $idcat = '10'; // Lounge
  6155.                     //                            $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  6156.                     $nameServices = "";
  6157.                     switch ($idcat) {
  6158.                         case 11:
  6159.                             $servicesSup = $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
  6160.                             $nameServices = $servicesSup->getTitle();
  6161.                             $transType = $this->translator->trans("Menu");
  6162.                             $varCat = "11";
  6163.                             break;
  6164.                         case 5:
  6165.                             $servicesSup = $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
  6166.                             $nameServices = $servicesSup->getTitle();
  6167.                             $transType = $this->translator->trans("Cruise");
  6168.                             $varCat = "5";
  6169.                             break;
  6170.                         case 6:
  6171.                             $servicesSup = $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
  6172.                             $nameServices = $servicesSup->getName();
  6173.                             $transType = $this->translator->trans("Entertainment");
  6174.                             $varCat = "6";
  6175.                             break;
  6176.                         case 4:
  6177.                             $servicesSup = $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
  6178.                             $nameServices = $servicesSup->getTitle();
  6179.                             $transType = $this->translator->trans("Comunicación");
  6180.                             $varCat = "4";
  6181.                             break;
  6182.                         case 7:
  6183.                             $servicesSup = $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
  6184.                             $nameServices = $servicesSup->getName();
  6185.                             $transType = $this->translator->trans("Gifts");
  6186.                             $varCat = "7";
  6187.                             break;
  6188.                         case 8:
  6189.                             $servicesSup = $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
  6190.                             $nameServices = $servicesSup->getName();
  6191.                             $transType = $this->translator->trans("Guide");
  6192.                             $varCat = "8";
  6193.                             break;
  6194.                         case 9:
  6195.                             $servicesSup = $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
  6196.                             $nameServices = $servicesSup->getTitle();
  6197.                             $transType = $this->translator->trans("Itineraries");
  6198.                             $varCat = "9";
  6199.                             break;
  6200.                         case 13:
  6201.                             $servicesSup = $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
  6202.                             $nameServices = $servicesSup->getName();
  6203.                             $transType = $this->translator->trans("Transport");
  6204.                             $varCat = "13";
  6205.                             break;
  6206.                         case 12:
  6207.                             $servicesSup = $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
  6208.                             $nameServices = $servicesSup->getName();
  6209.                             $transType = $this->translator->trans("Others");
  6210.                             $varCat = "12";
  6211.                             break;
  6212.                         case 1:
  6213.                             $servicesSup = $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
  6214.                             $nameServices = $servicesSup->getName();
  6215.                             $transType = $this->translator->trans("Accommodation");
  6216.                             $varCat = "1";
  6217.                             break;
  6218.                     }
  6219.                     $controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
  6220.                         array(
  6221.                             'servicesId' => $servicesSup->getId(),
  6222.                             'servicesCat' => $idcat,
  6223.                         )
  6224.                     );
  6225.                     $servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  6226.                     $servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
  6227.                         array(
  6228.                             'servicesId' => $servicesSup->getId(),
  6229.                             'controlId' => $servicesSupplier->getServiceId(),
  6230.                             'language' => $proposal->getLanguage()
  6231.                         )
  6232.                     );
  6233.                     /* ARMO EL CONTENIDO GLOBAL */
  6234.                     $servicesArray[] = array(
  6235.                         'services' => $servicesSup,
  6236.                         'name' => strtoupper($nameServices),
  6237.                         'img' => isset($servicesGallery['0']) ? $servicesGallery['0'] : null,
  6238.                         'cities' => null,
  6239.                         'type' => $transType,
  6240.                         'ids' => $varCat,
  6241.                         'gallery' => $servicesGallery,
  6242.                         'descripcion' => $servicesDescription,
  6243.                         //                        'capacity' =>$serviceCapacity,
  6244.                     );
  6245.                     //                    d($servicesArray);
  6246.                 }
  6247.             }
  6248.         }
  6249.         return $this->render(
  6250.             'MDS/EventsPresentationBundle/presentation/services-view.html.twig',
  6251.             array(
  6252.                 'token' => $token,
  6253.                 'type' => $transType,
  6254.                 //                'company' => $company,
  6255.                 'proposal' => $proposal,
  6256.                 'client' => $client,
  6257.                 'selectType' => $selectType,
  6258.                 //                'destination' => $data_destionation,
  6259.                 //                'countDestino' => $cont_destino,
  6260.                 //                'agent'=>$agentMaster,
  6261.                 'data' => $servicesArray,
  6262.                 //                'idd'=>$idd,
  6263.                 //                'sidebar' => $sidebarData,
  6264.             )
  6265.         );
  6266.     }
  6267.     /**
  6268.      * @Route("/servicesview-Ajax/{ids}/{idcat}/{token}", name="presentation_services_view_all_token_ajax")
  6269.      */
  6270.     public function ServicesViewAjaxAllAction($token, $ids, $idcat, Request $request)
  6271.     {
  6272.         //        d($token);
  6273.         $em = $this->getDoctrine()->getManager();
  6274.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  6275.         if ($proposal->getStatus() == "Cancel") {
  6276.             return $this->redirectToRoute(
  6277.                 'presentation_error_cancel',
  6278.                 array(
  6279.                     'token' => $token
  6280.                 )
  6281.             );
  6282.         }
  6283.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  6284.         // Usuario Anonimo es = "anon."
  6285.         if ($user_logueado == "anon.") {
  6286.             $proposal->setViewedAt(new \DateTime("now"));
  6287.             $em->persist($proposal);
  6288.             $em->flush();
  6289.         }
  6290.         if (is_null($proposal->getSelectType())) {
  6291.             $selectType = array();
  6292.         } else {
  6293.             $selectType = explode(",", $proposal->getSelectType());
  6294.         }
  6295.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  6296.         $proposal_Control = $em->getRepository(ProposalControl::class)->findBy(
  6297.             array(
  6298.                 'proposalId' => $proposal->getId(),
  6299.                 'disabled' => '0',
  6300.             )
  6301.         );
  6302.         /*consulta de los servicios del supplier*/
  6303.         $services = $em->getRepository(ProposalSupplierServices::class)->findBy(
  6304.             array(
  6305.                 'proposalId' => $proposal->getId(),
  6306.                 'serviceCatId' => $idcat,
  6307.             )
  6308.         );
  6309.         $servicesArray = array();
  6310.         //        d($services);
  6311.         $transType = "Not Available";
  6312.         if (!empty($services)) {
  6313.             foreach ($services as $servicesSupplier) {
  6314.                 $transType = $this->translator->trans($servicesSupplier->getServiceCatName());
  6315.                 /*consulta Lounge*/
  6316.                 // d($typeM);
  6317.                 if ($servicesSupplier->getServiceId() != "0") {
  6318.                     $nameServices = "";
  6319.                     switch ($idcat) {
  6320.                         case 11:
  6321.                             $servicesSup = $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
  6322.                             $nameServices = $servicesSup->getTitle();
  6323.                             break;
  6324.                         case 5:
  6325.                             $servicesSup = $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
  6326.                             $nameServices = $servicesSup->getTitle();
  6327.                             break;
  6328.                         case 6:
  6329.                             $servicesSup = $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
  6330.                             $nameServices = $servicesSup->getName();
  6331.                             break;
  6332.                         case 4:
  6333.                             $servicesSup = $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
  6334.                             $nameServices = $servicesSup->getTitle();
  6335.                             break;
  6336.                         case 7:
  6337.                             $servicesSup = $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
  6338.                             $nameServices = $servicesSup->getName();
  6339.                             break;
  6340.                         case 8:
  6341.                             $servicesSup = $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
  6342.                             $nameServices = $servicesSup->getName();
  6343.                             break;
  6344.                         case 9:
  6345.                             $servicesSup = $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
  6346.                             $nameServices = $servicesSup->getTitle();
  6347.                             break;
  6348.                         case 13:
  6349.                             $servicesSup = $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
  6350.                             $nameServices = $servicesSup->getName();
  6351.                             break;
  6352.                         case 12:
  6353.                             $servicesSup = $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
  6354.                             $nameServices = $servicesSup->getName();
  6355.                             break;
  6356.                         case 2:
  6357.                             $servicesSup = $em->getRepository(SupplierActivities::class)->findOneById($servicesSupplier->getServiceId());
  6358.                             $nameServices = $servicesSup->getTitle();
  6359.                             break;
  6360.                         case 1:
  6361.                             $servicesSup = $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
  6362.                             $nameServices = $servicesSup->getName();
  6363.                             break;
  6364.                     }
  6365.                     $controlSup = $em->getRepository(SupplierServicesControl::class)->findOneBy(
  6366.                         array(
  6367.                             'servicesId' => $ids,
  6368.                             'servicesCat' => $idcat,
  6369.                         )
  6370.                     );
  6371.                     $servicesGallery = $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  6372.                     $servicesDescription = $em->getRepository(SupplierServicesDescription::class)->findBy(
  6373.                         array(
  6374.                             'servicesId' => $ids,
  6375.                             'controlId' => $servicesSupplier->getServiceId(),
  6376.                             'language' => $proposal->getLanguage()
  6377.                         )
  6378.                     );
  6379.                     /* ARMO EL CONTENIDO GLOBAL */
  6380.                     $servicesArray = array(
  6381.                         'services' => $servicesSupplier->getServiceId(),
  6382.                         'name' => $nameServices,
  6383.                         'gallery' => $servicesGallery,
  6384.                         'descripcion' => $servicesDescription,
  6385.                         //                        'capacity' =>$serviceCapacity,
  6386.                     );
  6387.                     //                    d($servicesArray);
  6388.                 }
  6389.             }
  6390.         }
  6391.         $serializer = SerializerBuilder::create()->build();
  6392.         $array = $serializer->toArray($servicesArray);
  6393.         $response = new JsonResponse($array);
  6394.         return $response;
  6395.     }
  6396.     protected function sidebarAction($token, $typeSide, $idd)
  6397.     {
  6398.         $em = $this->getDoctrine()->getManager();
  6399.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  6400.         if ($proposal->getStatus() == "Cancel") {
  6401.             return $this->redirectToRoute(
  6402.                 'presentation_error_cancel',
  6403.                 array(
  6404.                     'token' => $token
  6405.                 )
  6406.             );
  6407.         }
  6408.         /* inicio array con los agentes */
  6409.         $dataAgents = array();
  6410.         if (!is_null($proposal->getAgentId())) {
  6411.             $agenteTwo = array();
  6412.             if (!empty($proposal->getAgentTwoId())) {
  6413.                 $agenteTwo = explode(",", $proposal->getAgentTwoId());
  6414.             } else {
  6415.                 $agenteTwo[0] = $proposal->getAgentId();
  6416.             }
  6417.             $agentProposal = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  6418.             $teamLeader = $em->getRepository(User::class)->findOneBy(
  6419.                 array(
  6420.                     'team' => $agentProposal->getTeam(),
  6421.                     'teamleader' => 1,
  6422.                 )
  6423.             );
  6424.             if (!empty($teamLeader)) {
  6425.                 $leader = $teamLeader->getId();
  6426.             } else {
  6427.                 $leader = $proposal->getAgentId();
  6428.             }
  6429.             $agentArray = array();
  6430.             array_push($agentArray, $proposal->getAgentId());
  6431.             array_push($agentArray, $agenteTwo[0]);
  6432.             array_push($agentArray, $leader);
  6433.             array_push($agentArray, 6);
  6434.             array_push($agentArray, 14);
  6435.             //            array_push($agentArray, 1);
  6436.             //            array_push($agentArray, 1);
  6437.             //            $dataAgents=array();
  6438.             //d($agentArray);
  6439.             foreach ($agentArray as $agent) {
  6440.                 //d($agent);
  6441.                 $users = $em->getRepository(User::class)->findOneById($agent);
  6442.                 $dataAgents[] = array(
  6443.                     'id' => $agent,
  6444.                     'fullname' => $users->getName() . ' ' . $users->getLastName(),
  6445.                     'picture' => $users->getPicture()
  6446.                 );
  6447.             }
  6448.             /* fin array con los agentes */
  6449.         }
  6450.         /* inicio array con los supplier */
  6451.         $parameters = array(
  6452.             'proposalId' => $proposal->getId(),
  6453.             'serviceIdFather' => '0',
  6454.         );
  6455.         $dql = 'SELECT p
  6456.                 FROM EventsBundle:ProposalSupplierServices p
  6457.                 WHERE p.proposalId = :proposalId AND p.serviceIdFather = :serviceIdFather 
  6458.                 ORDER BY p.supplierId ASC ';
  6459.         $query = $em->createQuery($dql)->setParameters($parameters);
  6460.         $data_service_supplier = $query->getResult();
  6461.         $supplier_Id = array();
  6462.         $idea_Id = array();
  6463.         $activity_Id = array();
  6464.         foreach ($data_service_supplier as $dataservicesupplier) {
  6465.             $controlservices_supplier = $em->getRepository(ProposalSupplierControl::class)->findOneBy(
  6466.                 array(
  6467.                     'proposalId' => $proposal->getId(),
  6468.                     'disabled' => '0',
  6469.                     'id' => $dataservicesupplier->getControlId(),
  6470.                 )
  6471.             );
  6472.             if (!empty($controlservices_supplier)) {
  6473.                 $proposal_Control = $em->getRepository(ProposalControl::class)->findOneBy(
  6474.                     array(
  6475.                         'proposalId' => $proposal->getId(),
  6476.                         'disabled' => '0',
  6477.                         'id' => $controlservices_supplier->getControlDestinationId(),
  6478.                     )
  6479.                 );
  6480.                 if (!empty($proposal_Control)) {
  6481.                     if ($dataservicesupplier->getSupplierId() != "0") {
  6482.                         if (!is_null($controlservices_supplier->getIdeaId())) {
  6483.                             $idea_Id[$controlservices_supplier->getIdeaId()] = array(
  6484.                                 'ideaid' => $controlservices_supplier->getIdeaId(),
  6485.                                 'destinoid' => $controlservices_supplier->getDestinoId(),
  6486.                             );
  6487.                         }
  6488.                         if (!is_null($controlservices_supplier->getActivityId())) {
  6489.                             $activity_Id[$controlservices_supplier->getActivityId()] = array(
  6490.                                 'activityid' => $controlservices_supplier->getActivityId(),
  6491.                                 'destinoid' => $controlservices_supplier->getDestinoId(),
  6492.                             );
  6493.                         }
  6494.                         if (!is_null($dataservicesupplier->getSupplierId())) {
  6495.                             $supplier_Id[$dataservicesupplier->getSupplierId()] = array(
  6496.                                 'supplierid' => $dataservicesupplier->getSupplierId(),
  6497.                                 'destinoid' => $controlservices_supplier->getDestinoId(),
  6498.                             );
  6499.                         }
  6500.                         $destination_Id[$controlservices_supplier->getDestinoId()] = $controlservices_supplier->getDestinoId();
  6501.                     }
  6502.                 }
  6503.             }
  6504.         }
  6505.         $all_Idea_control = $em->getRepository(ProposalSupplierControl::class)->findBy(
  6506.             array(
  6507.                 'proposalId' => $proposal->getId(),
  6508.                 'disabled' => '0',
  6509.             )
  6510.         );
  6511.         foreach ($all_Idea_control as $allIdea) {
  6512.             if (!is_null($allIdea->getIdeaId())) {
  6513.                 $idea_Id[$allIdea->getIdeaId()] = array(
  6514.                     'ideaid' => $allIdea->getIdeaId(),
  6515.                     'destinoid' => $allIdea->getDestinoId(),
  6516.                 );
  6517.             }
  6518.             if (!is_null($allIdea->getActivityId())) {
  6519.                 $activity_Id[$allIdea->getActivityId()] = array(
  6520.                     'activityid' => $allIdea->getActivityId(),
  6521.                     'destinoid' => $allIdea->getDestinoId(),
  6522.                 );
  6523.             }
  6524.         }
  6525.         //        d($supplier_Id, $idea_Id, $activity_Id);
  6526.         /* Fin array con los supplier */
  6527.         if (is_null($proposal->getSelectType())) {
  6528.             $select_Type = array();
  6529.         } else {
  6530.             $select_Type = explode(",", $proposal->getSelectType());
  6531.         }
  6532.         $type = array();
  6533.         if (!empty($destination_Id)) {
  6534.             foreach ($select_Type as $selectType) {
  6535.                 //                d($selectType);
  6536.                 $destination = array();
  6537.                 if ($selectType == "IDEA") {
  6538.                     foreach ($destination_Id as $destinationId) {
  6539.                         $ideas = array();
  6540.                         foreach ($idea_Id as $ideaId) {
  6541.                             if ($destinationId == $ideaId['destinoid']) {
  6542.                                 $ideas_query = $em->getRepository(Ideas::class)->findOneBy(
  6543.                                     array(
  6544.                                         'id' => $ideaId['ideaid'],
  6545.                                     )
  6546.                                 );
  6547.                                 if (!empty($ideas_query)) {
  6548.                                     $ideas[] = $ideas_query;
  6549.                                 }
  6550.                             }
  6551.                         }
  6552.                         $destino = $em->getRepository(Destination::class)->findOneById($destinationId);
  6553.                         if (count($ideas) != 0) {
  6554.                             $destination[$destino->getId()] = array(
  6555.                                 'destination' => $destino,
  6556.                                 'data' => $ideas,
  6557.                             );
  6558.                         }
  6559.                     }
  6560.                 }
  6561.                 if (($selectType == "ACTIVITY") or ($selectType == "ACTIVIDADES")) {
  6562.                     foreach ($destination_Id as $destinationId) {
  6563.                         $activity = array();
  6564.                         foreach ($activity_Id as $activityId) {
  6565.                             if ($destinationId == $activityId['destinoid']) {
  6566.                                 $activities_query = $em->getRepository(Activities::class)->findOneBy(
  6567.                                     array(
  6568.                                         'id' => $activityId['activityid'],
  6569.                                     )
  6570.                                 );
  6571.                                 if (!empty($activities_query)) {
  6572.                                     $activity[] = $activities_query;
  6573.                                 }
  6574.                             }
  6575.                         }
  6576.                         $destino = $em->getRepository(Destination::class)->findOneById($destinationId);
  6577.                         if (count($activity) != 0) {
  6578.                             $destination[$destino->getId()] = array(
  6579.                                 'destination' => $destino,
  6580.                                 'data' => $activity,
  6581.                             );
  6582.                         }
  6583.                     }
  6584.                 }
  6585.                 foreach ($destination_Id as $destinationId) {
  6586.                     $supplier = array();
  6587.                     foreach ($supplier_Id as $supplierId) {
  6588.                         if ($destinationId == $supplierId['destinoid']) {
  6589.                             $supplier_query = $em->getRepository("App:Supplier")->findOneBy(
  6590.                                 array(
  6591.                                     'id' => $supplierId['supplierid'],
  6592.                                     'type' => $selectType,                              // Funcion conversora
  6593.                                 )
  6594.                             );
  6595.                             if (!empty($supplier_query)) {
  6596.                                 $supplier[] = $supplier_query;
  6597.                             }
  6598.                         }
  6599.                     }
  6600.                     $destino = $em->getRepository(Destination::class)->findOneById($destinationId);
  6601.                     if (count($supplier) != 0) {
  6602.                         $destination[$destino->getId()] = array(
  6603.                             'destination' => $destino,
  6604.                             'data' => $supplier,
  6605.                         );
  6606.                     }
  6607.                 }
  6608.                 if (count($destination) != 0) {
  6609.                     $type[] = array(
  6610.                         'type' => $selectType,
  6611.                         'destination' => $destination,
  6612.                     );
  6613.                 }
  6614.             }
  6615.         }
  6616.         $budgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findBy(
  6617.             array(
  6618.                 'proposalId' => $proposal->getId(),
  6619.                 'recommended' => 1,
  6620.             )
  6621.         );
  6622.         $agendas =  $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
  6623.             array(
  6624.                 'proposalId' => $proposal->getId()
  6625.             ),
  6626.             array(
  6627.                 'priority' => 'ASC',
  6628.                 'recommended' => 'ASC',
  6629.             )
  6630.         );
  6631.         $showAgenda = array();
  6632.         foreach ($agendas as $item) {
  6633.             $showAgenda[] = $item;
  6634.         }
  6635.         $data[] = array(
  6636.             'agent' => $dataAgents,
  6637.             'type' => $type,
  6638.             'typeSide' => $typeSide,
  6639.             'idd' => $idd,
  6640.             'budgetslist' => $budgets,
  6641.             'agendas' => $showAgenda,
  6642.         );
  6643.         //        d($data);
  6644.         //        exit();
  6645.         return $data;
  6646.     }
  6647.     /**
  6648.      * @Route("/proposal/invoice/print/{id}",  name="proposal_invoice_detector_print_externo")
  6649.      */
  6650.     public function detectorInvoicePrintAction($id, Request $request)
  6651.     {
  6652.         $em = $this->getDoctrine()->getManager();
  6653.         $invoiceconsulta = array();
  6654.         $typeconsulta = '';
  6655.         $invoice = $em->getRepository(ProposalInvoice::class)->findOneByProposalId($id);
  6656.         if (!empty($invoice)) {
  6657.             $invoiceconsulta = $invoice;
  6658.             $typeconsulta = $invoice->getType();
  6659.         }
  6660.         if (!empty($invoiceconsulta)) {
  6661.             $type = $typeconsulta;
  6662.             //            $number = $invoiceconsulta->getId();
  6663.             $number = $invoiceconsulta->getNumber();
  6664.             $date = $invoiceconsulta->getDateAt();
  6665.             $prefix = $invoiceconsulta->getPrefix();
  6666.             $data = $this->baseInvoiceProposal($id, $type, $number, $prefix, $date, $request);
  6667.             $token = $data['token'];
  6668.         } else {
  6669.             return $this->redirectToRoute(
  6670.                 'proposal_invoice_proforma_print_externo',
  6671.                 array(
  6672.                     'id' => $id
  6673.                 )
  6674.             );
  6675.         }
  6676.         $fees = $em->getRepository(ProposalFeeInvoice::class)->findByProposalId($id);
  6677.         if (!empty($fees)) {
  6678.             $fees[0]->setAmount($fees[0]->getFeeNet());
  6679.             if (!($fees[0]->getToInvoice())) {
  6680.                 $fees = null;
  6681.             }
  6682.         } // Si no se debe mostrar en factura se pone a null
  6683.         $summary = $em->getRepository(ProposalsInvoiceSummary::class)->findOneByProposalId($id);
  6684.         $summaryInvoice = !empty($summary);
  6685.         $summaryInvoiceText = !empty($summary) ? $summary->getDescription() : null;
  6686.         return $this->render(
  6687.             'MDS/EventsBundle/services/services-invoice-print-proposal.html.twig',
  6688.             array(
  6689.                 'id' => $id,
  6690.                 'type' => $data['type'],
  6691.                 'number' => $data['number'],
  6692.                 'prefix' => $data['prefix'],
  6693.                 'date' => $data['date'],
  6694.                 'token' => $token,
  6695.                 'proposal' => $data['proposal'],
  6696.                 'company' => $data['company'],
  6697.                 'clients' => $data['clients'],
  6698.                 'datasupplier' => $data['datasupplier'],
  6699.                 'totales_neto_antes' => $data['totales_neto_antes'],
  6700.                 'totales_neto' => $data['totales_neto'],
  6701.                 'bases_imponibles' => $data['bases_imponibles'],
  6702.                 'totales_antes' => $data['totales_antes'],
  6703.                 'totales' => $data['totales'],
  6704.                 'balance' => $data['balance'],
  6705.                 'totales_generales' => $data['totales_generales'],
  6706.                 'currency' => $data['currency'],
  6707.                 'detail_iva' => 'no',
  6708.                 'discounts' => $data['discounts'],
  6709.                 'fees' => $fees,
  6710.                 'paymentInvoice' => $data['paymentInvoice'],
  6711.                 'invoiceDesposit' => $data['invoiceDesposit'],
  6712.                 'summaryInvoice' => $summaryInvoice,
  6713.                 'summaryInvoiceText' => $summaryInvoiceText,
  6714.             )
  6715.         );
  6716.     }
  6717.     /**
  6718.      * @Route("/proposal/invoice/proforma/print/{id}",  name="proposal_invoice_proforma_print_externo")
  6719.      */
  6720.     public function detailsProformaPrintAction($id, Request $request)
  6721.     {
  6722. //        dd($id);
  6723.         $data = array();
  6724.         //        $token = "";
  6725.         $em = $this->getDoctrine()->getManager();
  6726.         $proforma = $em->getRepository(ProposalProforma::class)->findOneByProposalId($id);
  6727.         if (!empty($proforma)) {
  6728.             $type = 'Proforma';
  6729.             $number = $proforma->getId();
  6730.             $date = $proforma->getDateAt();
  6731.             $prefix = $proforma->getPrefix();
  6732.             $data = $this->baseInvoiceProposal($id, $type, $number, $prefix, $date, $request);
  6733.             $token = $data['token'];
  6734.         } else {
  6735.                         return $this->redirectToRoute('proposal_generate_proforma',
  6736.                             array(
  6737.                                 'id' => $id
  6738.                             )
  6739.                         );
  6740.         }
  6741.         $fees = $em->getRepository(ProposalFee::class)->findByProposalId($id);
  6742.         if (!empty($fees)) {
  6743.             if (!($fees[0]->getToInvoice())) {
  6744.                 $fees = null;
  6745.             }
  6746.         } // Si no se debe mostrar en factura se pone a null
  6747.         $summaryInvoice = $em->getRepository(ProposalsInvoiceSummary::class)->findOneByProposalId($id);
  6748.         return $this->render(
  6749.             'MDS/EventsBundle/services/services-invoice-print-proposal.html.twig',
  6750.             array(
  6751.                 'id' => $id,
  6752.                 'type' => $data['type'],
  6753.                 'number' => $data['number'],
  6754.                 'prefix' => $data['prefix'],
  6755.                 'date' => $data['date'],
  6756.                 'token' => $token,
  6757.                 'proposal' => $data['proposal'],
  6758.                 'company' => $data['company'],
  6759.                 'clients' => $data['clients'],
  6760.                 'datasupplier' => $data['datasupplier'],
  6761.                 'totales_neto_antes' => $data['totales_neto_antes'],
  6762.                 'totales_neto' => $data['totales_neto'],
  6763.                 'bases_imponibles' => $data['bases_imponibles'],
  6764.                 'totales_antes' => $data['totales_antes'],
  6765.                 'totales' => $data['totales'],
  6766.                 'balance' => $data['balance'],
  6767.                 'totales_generales' => $data['totales_generales'],
  6768.                 'currency' => $data['currency'],
  6769.                 'detail_iva' => 'yes',
  6770.                 'discounts' => $data['discounts'],
  6771.                 'fees' => $fees,
  6772.                 'paymentInvoice' => $data['paymentInvoice'],
  6773.                 'invoiceDesposit' => $data['invoiceDesposit'],
  6774.                 'summaryInvoice' => $summaryInvoice,
  6775.             )
  6776.         );
  6777.     }
  6778.     private function baseInvoiceProposal($id, $type, $number, $prefix, $date, Request $request)
  6779.     {
  6780.         $em = $this->getDoctrine()->getManager();
  6781.         $proposal = $em->getRepository(Proposal::class)->findOneById($id);
  6782.         $services_supplier = $em->getRepository(ProposalSupplierServicesCostsClient::class)->findBy(
  6783.             array(
  6784.                 'proposalId' => $id,
  6785.                 'serviceIdFather' => '0'
  6786.             ),
  6787.             array(
  6788.                 'id' => 'ASC'
  6789.             )
  6790.         );
  6791.         $data_iva = array();
  6792.         $supplier_control = array();
  6793.         foreach ($services_supplier as $servicessupplier) {
  6794.             if (!is_null($servicessupplier->getActivityId())) {
  6795.                 $supplier_control[$servicessupplier->getActivityId()] = array(
  6796.                     'master' => 'activity',
  6797.                     'id' => $servicessupplier->getActivityId(),
  6798.                     'destinoId' => $servicessupplier->getDestinationId(),
  6799.                 );
  6800.             }
  6801.             if (!is_null($servicessupplier->getIdeaId())) {
  6802.                 $supplier_control[$servicessupplier->getIdeaId()] = array(
  6803.                     'master' => 'idea',
  6804.                     'id' => $servicessupplier->getIdeaId(),
  6805.                     'destinoId' => $servicessupplier->getDestinationId(),
  6806.                 );
  6807.             }
  6808.             if ((!is_null($servicessupplier->getSupplierId())) && ($servicessupplier->getIdeaId() == null) and ($servicessupplier->getActivityId() == null)) {
  6809.                 $supplier_control[$servicessupplier->getSupplierId()] = array(
  6810.                     'master' => 'supplier',
  6811.                     'id' => $servicessupplier->getSupplierId(),
  6812.                     'destinoId' => $servicessupplier->getDestinationId(),
  6813.                 );
  6814.             }
  6815.         }
  6816.         $data_serviceCat = array();
  6817.         $data_supplier = array();
  6818.         $totales_neto_all = 0;
  6819.         $totales_all = 0;
  6820.         $currency = 0;
  6821.         $data_service_supplier = array();
  6822.         foreach ($supplier_control as $suppliercontrol) {
  6823.             //            $destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol['destinoId']);
  6824.             $destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol['destinoId']);
  6825.             $colorlabel = "bg-success-300";
  6826.             $sqlactivities = "";
  6827.             if ($suppliercontrol['master'] == 'activity') {
  6828.                 $master = "activity";
  6829.                 $sqlactivities = $em->getRepository(Activities::class)->findOneById($suppliercontrol['id']);
  6830.                 // ORDEN DESCENDENTE Y POR SERVICES
  6831.                 $parameters = array(
  6832.                     'proposalId' => $id,
  6833.                     'serviceIdFather' => '0',
  6834.                     'activityId' => $suppliercontrol['id']
  6835.                 );
  6836.                 $dql = 'SELECT p
  6837.                         FROM EventsBundle:ProposalSupplierServicesCostsClient p
  6838.                         WHERE p.proposalId = :proposalId AND p.activityId = :activityId AND p.serviceIdFather = :serviceIdFather
  6839.                         ORDER BY p.serviceCatId, p.rank ASC ';
  6840.                 $query = $em->createQuery($dql)->setParameters($parameters);
  6841.                 $data_service_supplier = $query->getResult();
  6842.             }
  6843.             $sqlideas = "";
  6844.             if ($suppliercontrol['master'] == 'idea') {
  6845.                 $master = "idea";
  6846.                 $sqlideas = $em->getRepository(Ideas::class)->findOneById($suppliercontrol['id']);
  6847.                 // ORDEN DESCENDENTE Y POR SERVICES
  6848.                 $parameters = array(
  6849.                     'proposalId' => $id,
  6850.                     'serviceIdFather' => '0',
  6851.                     'ideaId' => $suppliercontrol['id']
  6852.                 );
  6853.                 $dql = 'SELECT p
  6854.                         FROM EventsBundle:ProposalSupplierServicesCostsClient p
  6855.                         WHERE p.proposalId = :proposalId AND p.ideaId = :ideaId AND p.serviceIdFather = :serviceIdFather
  6856.                         ORDER BY p.serviceCatId, p.rank ASC ';
  6857.                 $query = $em->createQuery($dql)->setParameters($parameters);
  6858.                 $data_service_supplier = $query->getResult();
  6859.             }
  6860.             $sqlsuppliers = "";
  6861.             if ($suppliercontrol['master'] == 'supplier') {
  6862.                 $master = "supplier";
  6863.                 $sqlsuppliers = $em->getRepository(Supplier::class)->findOneById($suppliercontrol['id']);
  6864.                 if (!is_null($sqlsuppliers)) {
  6865.                     switch ($sqlsuppliers->getStar()) {
  6866.                         case 1:
  6867.                             $sqlsuppliers->setStar('<i class="icon-star-full2"></i>');
  6868.                             break;
  6869.                         case 2:
  6870.                             $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  6871.                             break;
  6872.                         case 3:
  6873.                             $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  6874.                             break;
  6875.                         case 4:
  6876.                             $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>');
  6877.                             break;
  6878.                         case 5:
  6879.                             $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');
  6880.                             break;
  6881.                         case 6:
  6882.                             $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>');
  6883.                             break;
  6884.                         case 7:
  6885.                             $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');
  6886.                             break;
  6887.                         case 8:
  6888.                             $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');
  6889.                             break;
  6890.                     }
  6891.                 }
  6892.                 // ORDEN DESCENDENTE Y POR SERVICES
  6893.                 $parameters = array(
  6894.                     'proposalId' => $id,
  6895.                     'serviceIdFather' => '0',
  6896.                     'supplierId' => $suppliercontrol['id']
  6897.                 );
  6898.                 $dql = 'SELECT p
  6899.                         FROM EventsBundle:ProposalSupplierServicesCostsClient p
  6900.                         WHERE p.proposalId = :proposalId AND p.supplierId = :supplierId AND p.ideaId is null AND p.activityId is null AND p.serviceIdFather = :serviceIdFather
  6901.                         ORDER BY p.serviceCatId, p.rank ASC ';
  6902.                 $query = $em->createQuery($dql)->setParameters($parameters);
  6903.                 $data_service_supplier = $query->getResult();
  6904.                 // Agrupamos asistencias de In-Out por ID de Agente
  6905.                 $new_data_service_supplier = array();
  6906.                 $arregloAcumulador = array();
  6907.                 $acumulador = array();
  6908.                 // Procesamos servicios de In Out (Líneas independientes para cálculo correcto y PDF)
  6909.                 $new_data_service_supplier = array();
  6910.                 if ($sqlsuppliers->getCompany() == 'IN OUT TRAVEL & EVENTS') {
  6911.                     foreach ($data_service_supplier as $dtsp) {
  6912.                         // 1. Buscamos nombre personalizado
  6913.                         $zNameSrvOrNameUsr = $em->getRepository(ProposalsSupplierServicesAssistantName::class)
  6914.                             ->findOneByPrpSupSrvId($dtsp->getServiceIdProposal());
  6915.                         if ($dtsp->getServiceCatId() != 15) {
  6916.                             $new_data_service_supplier[] = $dtsp;
  6917.                         } else {
  6918.                             // 2. Lógica de nombres para Staff
  6919.                             if (!is_null($dtsp->getAssistantId())) {
  6920.                                 $zAg = $em->getRepository(User::class)->findOneById($dtsp->getAssistantId());
  6921.                                 if (empty($zNameSrvOrNameUsr) && !empty($zAg)) {
  6922.                                     $dtsp->setName('Staff In Out Events: ' . $zAg->getName() . ' ' . $zAg->getLastName());
  6923.                                 }
  6924.                             } else {
  6925.                                 // Agente externo
  6926.                                 if (empty($zNameSrvOrNameUsr)) {
  6927.                                     $dtsp->setName('Staff In Out Events: ' . $dtsp->getName());
  6928.                                 }
  6929.                             }
  6930.                             // 3. SEPARACIÓN REAL: Forzamos 1 unidad y no acumulamos en ningún array
  6931.                             $dtsp->setUnits(1);
  6932.                             $new_data_service_supplier[] = $dtsp;
  6933.                         }
  6934.                     }
  6935.                     // Reemplazamos los datos originales por los procesados sin agrupar
  6936.                     $data_service_supplier = $new_data_service_supplier;
  6937.                 }
  6938.                 // FIN - Procesamos servicios de In Out
  6939.                 // FIN  -  Agrupamos asistencias de In-Out por ID de Agente
  6940.             }
  6941.             $imagenSmall = null;
  6942.             $service_supplier_data = array();
  6943.             $totales_neto = '0';
  6944.             $totales_iva = '0';
  6945.             $totales_con_iva = '0';
  6946.             $totales_paying = '0';
  6947.             $totales_pago = '0';
  6948.             $totales_benefit_moneda = '0';
  6949.             $totales_benefit_porsentaje = '0';
  6950.             foreach ($data_service_supplier as $data_service) {
  6951.                 //                d($data_service->getId());
  6952.                 //Currency
  6953.                 $currency = $data_service->getCurrency();
  6954.                 if (isset($currency)) {
  6955.                     $currency = "Euro";
  6956.                 }
  6957.                 if ($currency == "Euro") {
  6958.                     $currency = "€";
  6959.                 }
  6960.                 if ($currency == "Dolar") {
  6961.                     $currency = " $";
  6962.                 }
  6963.                 if ($currency == "MXN") {
  6964.                     $currency = " MXN";
  6965.                 }
  6966.                 $data_service->setCurrency($currency);
  6967.                 $idcat = $data_service->getServiceCatId();
  6968.                 $price = $data_service->getPrice();
  6969.                 $units = $data_service->getUnits();
  6970.                 $pax = $data_service->getPax();
  6971.                 $opcommission = $data_service->getOpCommission();
  6972.                 $commission = $data_service->getCommission();
  6973.                 $opover = $data_service->getOpOver();
  6974.                 $over = $data_service->getOver();
  6975.                 $opiva = $data_service->getOpIva();
  6976.                 $iva = $data_service->getIva();
  6977.                 $dateInAt = $data_service->getDateInAt();
  6978.                 $dateOutAt = $data_service->getDateOutAt();
  6979.                 if (!is_null($dateInAt) and !is_null($dateOutAt)) {
  6980.                     $days = $dateInAt->diff($dateOutAt);
  6981.                     $day = $days->days;
  6982.                     //                    if (($data_service->getSupplierId() == '4') and ($data_service->getServiceCatId() == '15')){
  6983.                     //                        $day ="0";
  6984.                     //                    }
  6985.                 } else {
  6986.                     $day = "0";
  6987.                     //                    if (($data_service->getSupplierId() == '4') and ($data_service->getServiceCatId() == '15')){
  6988.                     //                        $day ="0";
  6989.                     //                    }
  6990.                 }
  6991.                 if (!is_null($data_service->getIdeaId())) {
  6992.                     $name_supplier = $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
  6993.                     if (empty($name_supplier)) {
  6994.                         $namesupplier = '';
  6995.                     } else {
  6996.                         $namesupplier = $name_supplier->getName();
  6997.                     }
  6998.                 }
  6999.                 if (!is_null($data_service->getSupplierId()) and $data_service->getIdeaId() == null) {
  7000.                     $name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  7001.                     if (empty($name_supplier)) {
  7002.                         $namesupplier = '';
  7003.                     } else {
  7004.                         $namesupplier = $name_supplier->getName();
  7005.                     }
  7006.                 }
  7007.                 //                $name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  7008.                 //                $namesupplier = $name_supplier->getName();
  7009.                 if ($type == 'No Vat Invoice') {
  7010.                     $iva = "0";
  7011.                     $data_service->setIva($iva);
  7012.                 }
  7013.                 $calculos = $this->CalculoTotalesservicesDos($price, $units, $pax, $day, $opcommission, $commission, $opover, $over, $opiva, $iva, $idcat);
  7014.                 $data_service->setPrice($calculos['precio']); //ojo aqui
  7015.                 $service_supplier_data[] = array(
  7016.                     'calculos' => $calculos,
  7017.                     'services_data' => $data_service,
  7018.                     'namesupplier' => $namesupplier
  7019.                 );
  7020.                 $totales_neto += $calculos['total_neto'];
  7021.                 $totales_iva += $calculos['sub_total_iva'];
  7022.                 $totales_con_iva += $calculos['total'];
  7023.                 $totales_paying += $calculos['total_paying'];
  7024.                 $totales_pago += $calculos['total_pago'];
  7025.                 $totales_benefit_moneda += $calculos['benefit_moneda'];
  7026.                 /* base imponible por servicios */
  7027.                 if (empty($base_imponible_service[$idcat])) {
  7028.                     $base_imponible_service[$idcat] = 0;
  7029.                 }
  7030.                 $base_imponible_service[$idcat] += $calculos['total_neto'];
  7031.                 $data_serviceCat[$idcat] = array(
  7032.                     'idcat' => $idcat,
  7033.                     'total_neto' => $base_imponible_service[$idcat],
  7034.                 );
  7035.                 /* base impobnible detalles por diferentes Ivas */
  7036.                 if (empty($base_imponible_iva[$iva])) {
  7037.                     $base_imponible_iva[$iva] = 0;
  7038.                 }
  7039.                 $base_imponible_iva[$iva] += $calculos['total_neto'];
  7040.                 if (empty($totales_ivas_all[$iva])) {
  7041.                     $totales_ivas_all[$iva] = 0;
  7042.                 }
  7043.                 $totales_ivas_all[$iva] += $calculos['sub_total_iva'];
  7044.                 $totales_neto_all += $calculos['total_neto'];
  7045.                 $totales_all += $calculos['total'];
  7046.                 $data_iva[$iva] = array(
  7047.                     'iva' => $iva,
  7048.                     'ivas' => $totales_ivas_all[$iva],
  7049.                     'total_iva' => $base_imponible_iva[$iva]
  7050.                 );
  7051.                 if ($totales_benefit_moneda == '0') {
  7052.                     $totales_benefit_porsentaje =  '0';
  7053.                 } else {
  7054.                     if ($totales_neto != 0) {
  7055.                         $totales_benefit_porsentaje = $totales_benefit_moneda / $totales_neto * 100; // arreglado or esteban
  7056.                     } else {
  7057.                         $totales_benefit_porsentaje = 0;
  7058.                     }
  7059.                 }
  7060.             }
  7061.             $calculos_totatales = array(
  7062.                 'totales_neto' => $totales_neto,
  7063.                 'totales_iva' => $totales_iva,
  7064.                 'totales_con_iva' => $totales_con_iva,
  7065.                 'totales_paying' => $totales_paying,
  7066.                 'totales_benefit_moneda' => $totales_benefit_moneda,
  7067.                 'totales_benefit_porsentaje' => $totales_benefit_porsentaje
  7068.             );
  7069.             $data_supplier[$destination->getTitle()][] = array(
  7070.                 'master' => $master,
  7071.                 'colorlabel' => $colorlabel,
  7072.                 'control' => "1",
  7073.                 'supplier' => $sqlsuppliers,
  7074.                 'idea' => $sqlideas,
  7075.                 'activity' => $sqlactivities,
  7076.                 'image' => $imagenSmall,
  7077.                 'services' => $service_supplier_data,
  7078.                 'totales_services' => $calculos_totatales
  7079.             );
  7080.         }
  7081.         $totales_neto_antes = $totales_neto_all;
  7082.         $totales_antes = $totales_all;
  7083.         /*Group Everything*/
  7084.         if ($type == 'Group Everything') {
  7085.             $data_supplier = array();
  7086.             $service_supplier_data = array();
  7087.             $messageitems = $this->translator->trans('Grouped Services');
  7088.             $data_service = array(
  7089.                 "price" => $totales_neto_antes,
  7090.                 "name" => $messageitems,
  7091.                 "units" => 1,
  7092.                 "iva" => $iva,
  7093.                 "dateInAt" => "2018-4-4",
  7094.                 "dateOutAt" => "2018-4-4",
  7095.             );
  7096.             $calculos = array(
  7097.                 "precio" => $totales_neto_antes,
  7098.                 "total_days" => 1,
  7099.                 "sub_total" => $totales_neto_antes,
  7100.                 "sub_total_iva" => 0,
  7101.                 "total_neto" => $totales_neto_antes,
  7102.                 "total_iva" => 0,
  7103.                 "total_paying" => 0,
  7104.                 "total_pago" => 0,
  7105.                 "total_comision" => "0",
  7106.                 "total" => $totales_antes,
  7107.                 "benefit_moneda" => 0,
  7108.             );
  7109.             $service_supplier_data[] = array(
  7110.                 'calculos' => $calculos,
  7111.                 'services_data' => $data_service,
  7112.                 'namesupplier' => ""
  7113.             );
  7114.             $calculos_totatales = array(
  7115.                 'totales_neto' => $totales_neto_antes,
  7116.                 'totales_iva' => "",
  7117.                 'totales_con_iva' => $totales_antes,
  7118.                 'totales_paying' => "",
  7119.                 'totales_benefit_moneda' => "",
  7120.                 'totales_benefit_porsentaje' => ""
  7121.             );
  7122.             $data_supplier[$messageitems][] = array(
  7123.                 'master' => '',
  7124.                 'colorlabel' => '',
  7125.                 'control' => "1",
  7126.                 'supplier' => '',
  7127.                 'idea' => '',
  7128.                 'activity' => '',
  7129.                 'image' => '',
  7130.                 'services' => $service_supplier_data,
  7131.                 'totales_services' => $calculos_totatales
  7132.             );
  7133.         }
  7134.         $data_serviceOut = array(
  7135.             'idcat' => null,
  7136.             'total_neto' => $totales_neto_all,
  7137.         );
  7138.         array_push($data_serviceCat, $data_serviceOut);
  7139.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  7140.         $parameters = array(
  7141.             'id' => $proposal->getclientId(),
  7142.         );
  7143.         $dql = 'SELECT cl,  c.country, re.region, p.name, r.city
  7144.                 FROM App:Client cl
  7145.                 INNER JOIN App:Country c WITH c.id = cl.country
  7146.                 INNER JOIN App:Regions re WITH re.id = cl.region
  7147.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  7148.                 INNER JOIN App:Cities r WITH r.id = cl.population
  7149.                 WHERE cl.id = :id';
  7150.         $query = $em->createQuery($dql)->setParameters($parameters);
  7151.         $client = $query->getResult();
  7152.         $data_invoice = array();
  7153.         $inv_neto_total = 0;
  7154.         $inv_total = 0;
  7155.         $invoice_deposit_control = $em->getRepository(ProposalInvoiceDepositControl::class)->findByProposalId($proposal->getId());
  7156.         if (!empty($invoice_deposit_control)) {
  7157.             foreach ($invoice_deposit_control as $invoicedepositcontrol) {
  7158.                 $data_items_inv = array();
  7159.                 $invoice_deposit_items = $em->getRepository(ProposalInvoiceDepositItems::class)->findByControlId($invoicedepositcontrol->getId());
  7160.                 foreach ($invoice_deposit_items as $invoicedeposititems) {
  7161.                     $invamount = $invoicedeposititems->getAmount();
  7162.                     $invamount_iva = $invoicedeposititems->getIva();
  7163.                     $invamount_el_iva = $invamount * ($invamount_iva / 100);
  7164.                     $invamount_con_iva = $invamount * (($invamount_iva / 100) + 1);
  7165.                     $inv_neto_total += $invamount;
  7166.                     $inv_total += $invamount_con_iva;
  7167.                     if (is_null($invoicedepositcontrol->getNumber())) {
  7168.                         $numInvoice = $invoicedepositcontrol->getId();
  7169.                     } else {
  7170.                         $numInvoice = $invoicedepositcontrol->getNumber();
  7171.                     }
  7172.                     $data_items_inv[] = array(
  7173.                         'numInvoice' => $numInvoice,
  7174.                         'name' => $invoicedeposititems->getName(),
  7175.                         'amount' => $invoicedeposititems->getAmount(),
  7176.                         'iva' => $invoicedeposititems->getIva(),
  7177.                         'ivaamount' => $invamount_el_iva,
  7178.                         'total' => $invamount_con_iva,
  7179.                     );
  7180.                     foreach ($data_iva as $items_iva) {
  7181.                         if ($items_iva['iva'] == $invoicedeposititems->getIva()) {
  7182.                             $new_iva = $items_iva['iva'];
  7183.                             $new_ivas = $items_iva['ivas'] - $invamount_el_iva;
  7184.                             $new_total_iva = $items_iva['total_iva'] - $invoicedeposititems->getAmount();
  7185.                             $new_data_iva = array(
  7186.                                 'iva' => $new_iva,
  7187.                                 'ivas' => $new_ivas,
  7188.                                 'total_iva' => $new_total_iva
  7189.                             );
  7190.                             $data_iva = array_replace($data_iva, array($new_iva => $new_data_iva));
  7191.                         }
  7192.                     }
  7193.                 }
  7194.                 $data_invoice[] = array(
  7195.                     'itemsInvoice' => $data_items_inv,
  7196.                 );
  7197.             }
  7198.             //            d($inv_neto_total, $inv_total);
  7199.             $totales_neto_all = $totales_neto_all - $inv_neto_total;
  7200.             $totales_all = $totales_all - $inv_total;
  7201.             //            d($totales_neto_all, $totales_all);
  7202.         }
  7203.         $consulta_discount = $em->getRepository(ProposalDiscount::class)->findByProposalId($id);
  7204.         $cuantosdiscount = count($consulta_discount);
  7205.         $totales_generales = "";
  7206.         $descuento = array();
  7207.         if (!empty($consulta_discount)) {
  7208.             //            d($data_serviceCat);
  7209.             $quitar_en_todos = 0.00;
  7210.             $datos_total_neto_suma = 0.00;
  7211.             foreach ($data_serviceCat as $dataserviceat) {
  7212.                 $name = "";
  7213.                 $amount = "";
  7214.                 $type_des = "";
  7215.                 $iva_discount = "";
  7216.                 $datos_idcat = $dataserviceat['idcat'];
  7217.                 $datos_total_neto = $dataserviceat['total_neto'];
  7218.                 $totales_neto_des = $datos_total_neto;
  7219.                 $datosiva_neto_des = $datos_total_neto;
  7220.                 $calculo_net_negativo = "";
  7221.                 $total_con_iva_desc = "";
  7222.                 $contarveces = 1;
  7223.                 foreach ($consulta_discount as $consultadiscount) {
  7224.                     if ($dataserviceat['idcat'] == null) {
  7225.                         if ($contarveces > 1) {
  7226.                             $totales_neto_des = $datos_total_neto_suma;
  7227.                             $datosiva_neto_des = $datos_total_neto_suma;
  7228.                             $datos_total_neto = $datos_total_neto_suma;
  7229.                         } else {
  7230.                             if ($cuantosdiscount > 1) {
  7231.                                 $totales_neto_des = $dataserviceat['total_neto'] - $quitar_en_todos;
  7232.                                 $datosiva_neto_des = $dataserviceat['total_neto'] - $quitar_en_todos;
  7233.                                 $datos_total_neto = $dataserviceat['total_neto'] - $quitar_en_todos;
  7234.                             }
  7235.                         }
  7236.                         $contarveces += 1;
  7237.                     }
  7238.                     if ($dataserviceat['idcat'] == $consultadiscount->getServiceId()) {
  7239.                         $iva = $consultadiscount->getIva() / 100;
  7240.                         if ($consultadiscount->getType() == "0") {
  7241.                             $por = $consultadiscount->getAmount() / 100;
  7242.                             //                            $datosiva_neto_des = $datosiva_neto_des / ($por + 1) ;
  7243.                             $datosiva_neto_des = $datosiva_neto_des - ($datosiva_neto_des * $por);
  7244.                             $name = $consultadiscount->getName();
  7245.                             $type_des = $consultadiscount->getType();
  7246.                             $amount = $consultadiscount->getAmount();
  7247.                         }
  7248.                         if ($consultadiscount->getType() == "1") {
  7249.                             $datosiva_neto_des = $datosiva_neto_des - $consultadiscount->getAmount();
  7250.                             $name = $consultadiscount->getName();
  7251.                             $type_des = $consultadiscount->getType();
  7252.                             $amount = $consultadiscount->getAmount();
  7253.                         }
  7254.                         //                        d($dataserviceat['idcat'], $datos_total_neto);
  7255.                         // resultados en negativo
  7256.                         $calculo_net_negativo =  $datosiva_neto_des - $datos_total_neto;
  7257.                         //                        d($calculo_net_negativo);
  7258.                         $total_desc = "0";
  7259.                         // resultados para calculos
  7260.                         $calculo_net = $datos_total_neto - $datosiva_neto_des;
  7261.                         if ($consultadiscount->getOpIva() == '0') {
  7262.                             $iva_discount = $calculo_net - ($calculo_net / ($iva + 1));
  7263.                             $calculo_net_negativo = $calculo_net_negativo + $iva_discount;
  7264.                             $totales_neto_des = $totales_neto_des + $iva_discount;
  7265.                             $total_desc = $iva_discount;
  7266.                         }
  7267.                         if ($consultadiscount->getOpIva() == '1') {
  7268.                             $iva_discount = $calculo_net * $iva;
  7269.                             $total_desc = $iva_discount;
  7270.                         }
  7271.                         if ($type == 'No Vat Invoice') {
  7272.                             $iva_discount = "0";
  7273.                         }
  7274.                         //                        if($dataserviceat['idcat'] == null){
  7275.                         $datos_total_neto_suma = $datos_total_neto - abs((float)$calculo_net_negativo);
  7276.                         //                        }
  7277.                         $quitar_en_todos = $quitar_en_todos + abs((float)$calculo_net_negativo);
  7278.                         $total_con_iva_desc = $calculo_net_negativo - $iva_discount;
  7279.                         $totales_neto_all = $totales_neto_all - abs((float)$calculo_net_negativo);
  7280.                         $totales_all = $totales_all - abs($total_con_iva_desc);
  7281.                         $descuento[] = array(
  7282.                             'name' => $name,
  7283.                             'type' => $type_des,
  7284.                             'amount' => $amount,
  7285.                             'iva' => $consultadiscount->getIva(),
  7286.                             'iva_amount' => $iva_discount,
  7287.                             'totales_neto_des' => $calculo_net_negativo,
  7288.                             'total' => $total_con_iva_desc,
  7289.                         );
  7290.                         // Nueva actualizacion 17-07-2019 Recalcular Ivas
  7291.                         foreach ($data_iva as $items_iva) {
  7292.                             if ($items_iva['iva'] == $consultadiscount->getIva()) {
  7293.                                 $new_iva = $items_iva['iva'];
  7294.                                 $new_ivas = $items_iva['ivas'] - $iva_discount;
  7295.                                 $new_total_iva = $items_iva['total_iva'] - $iva_discount;
  7296.                                 $new_data_iva = array(
  7297.                                     'iva' => $new_iva,
  7298.                                     'ivas' => $new_ivas,
  7299.                                     'total_iva' => $new_total_iva
  7300.                                 );
  7301.                                 $data_iva = array_replace($data_iva, array($new_iva => $new_data_iva));
  7302.                             }
  7303.                         }
  7304.                     }
  7305.                 }
  7306.             }
  7307.         }
  7308.         $payments = $em->getRepository(ProposalPaymentsClient::class)->findByProposalId($id);
  7309.         $amount_pay = 0;
  7310.         foreach ($payments as $payment) {
  7311.             $amount_pay = $amount_pay + $payment->getAmount();
  7312.         }
  7313.         $totales_all = round($totales_all, 2);
  7314.         $totales_total = $totales_all;
  7315.         if (!empty($payments)) {
  7316.             $totales_all = $totales_all - $amount_pay;
  7317.         }
  7318.         $data = array(
  7319.             'id' => $id,
  7320.             'type' => $type,
  7321.             'number' => $number,
  7322.             'prefix' => $prefix,
  7323.             'date' => $date,
  7324.             'token' => $proposal->getAccessKey(),
  7325.             'proposal' => $proposal,
  7326.             'company' => $company,
  7327.             'clients' => $client,
  7328.             'datasupplier' => $data_supplier,
  7329.             'totales_neto_antes' => $totales_neto_antes,
  7330.             'totales_neto' => $totales_neto_all,
  7331.             'totales_generales' => $totales_generales,
  7332.             'bases_imponibles' => $data_iva,
  7333.             'totales_antes' => $totales_antes,
  7334.             'totales' => $totales_total,
  7335.             'balance' => $totales_all,
  7336.             'currency' => $currency,
  7337.             'paymentInvoice' => $amount_pay,
  7338.             'discounts' => $descuento,
  7339.             'invoiceDesposit' => $data_invoice,
  7340.         );
  7341.         // ************************************************  FEE    ************************************************************
  7342.         $fees = $em->getRepository(ProposalFee::class)->findByProposalId($id);
  7343.         $feesInvoice = $em->getRepository(ProposalFeeInvoice::class)->findByProposalId($id);
  7344.         if (!empty($feesInvoice)) {
  7345.             // Fee en factura
  7346.             // 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
  7347.             if ($feesInvoice[0]->getToinvoice() == true) {
  7348.                 foreach ($feesInvoice as $feeInv) {
  7349.                     if ($feeInv->getType() == 0) {
  7350.                         // Tenemos un porcentaje en el Fee de la factura, debe calcularse
  7351.                         $feeNet = ($data['totales_neto_antes'] * $feeInv->getAmount()) / 100;
  7352.                     } else {
  7353.                         $feeNet = $feeInv->getAmount();
  7354.                     }
  7355.                     $feeTotal = $feeNet * 1.21;                     //El fee siempre será al 21%, Esteban Rincón
  7356.                     if ($feeInv->getToInvoice() == true) {
  7357.                         $data['totales_neto'] += $feeNet;
  7358.                         $data['totales'] += $feeTotal;
  7359.                         $data['balance'] += $feeTotal;
  7360.                         if (array_key_exists('21', $data['bases_imponibles'])) {
  7361.                             $data['bases_imponibles']['21']['ivas'] += $feeNet * 0.21;
  7362.                             $data['bases_imponibles']['21']['total_iva'] += $feeNet;
  7363.                         } else {
  7364.                             $data['bases_imponibles']['21']['iva'] = '21';
  7365.                             $data['bases_imponibles']['21']['ivas'] = $feeNet * 0.21;
  7366.                             $data['bases_imponibles']['21']['total_iva'] = $feeNet;
  7367.                         }
  7368.                     }
  7369.                     if ($feeInv->getFeeNet() == 0 or empty($feeInv->getFeeNet())) {
  7370.                         // La asignación solo se hace la primera vez
  7371.                         $feeInv->setFeeNet($feeNet);
  7372.                         $feeInv->setFeeTotal($feeTotal);
  7373.                         $em->persist($feeInv);
  7374.                         $em->flush();
  7375.                     }
  7376.                 }
  7377.             }
  7378.         } else {
  7379.             // Fee en proforma
  7380.             if (!empty($fees)) {
  7381.                 // 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
  7382.                 if ($fees[0]->getToinvoice() == true) {
  7383.                     foreach ($fees as $fee) {
  7384.                         if ($fee->getType() == 0) {
  7385.                             // Tenemos un porcentaje, debe calcularse
  7386.                             $amount = ($data['totales_neto_antes'] * $fee->getAmount()) / 100;
  7387.                             $fee->setAmount($amount);
  7388.                         }
  7389.                         $fee->setFeeTotal($fee->getAmount() * 1.21);        //El fee siempre será al 21%, Esteban Rincón
  7390.                         if ($fee->getToInvoice() == true) {
  7391.                             $data['totales_neto'] += $fee->getAmount();
  7392.                             $data['totales'] += $fee->getFeeTotal();
  7393.                             $data['balance'] += $fee->getFeeTotal();
  7394.                             if (array_key_exists('21', $data['bases_imponibles'])) {
  7395.                                 $data['bases_imponibles']['21']['ivas'] += $fee->getAmount() * 0.21;
  7396.                                 $data['bases_imponibles']['21']['total_iva'] += $fee->getAmount();
  7397.                             } else {
  7398.                                 $data['bases_imponibles']['21']['iva'] = '21';
  7399.                                 $data['bases_imponibles']['21']['ivas'] = $fee->getAmount() * 0.21;
  7400.                                 $data['bases_imponibles']['21']['total_iva'] = $fee->getAmount();
  7401.                             }
  7402.                         }
  7403.                     }
  7404.                 }
  7405.             }
  7406.         }
  7407.         // ************************************************  FEE    ************************************************************
  7408.         return $data;
  7409.     }
  7410.     /**
  7411.      * @Route("/proposal/invoicedeposit/print/proforma/{id}",  name="proposal_invoice_deposit_proforma_print_externo")
  7412.      */
  7413.     public function printdetailsProformadepositAction($id, Request $request)
  7414.     {
  7415.         $data = array();
  7416.         $controlId = null;
  7417.         $type = "Proforma";
  7418.         $prefix = "PFD-";
  7419.         $date = new \DateTime('now');
  7420.         $data = $this->baseInvoiceDepositProposal($id, $controlId, $type, $id, $prefix, $date, $request);
  7421.         return $this->render(
  7422.             'MDS/EventsBundle/invoice/print-invoice-deposit-proforma.html.twig',
  7423.             array(
  7424.                 'id' => $id,
  7425.                 'type' => $data['type'],
  7426.                 'number' => $data['number'],
  7427.                 'numberadmin' => $data['numberadmin'],
  7428.                 'prefix' => $data['prefix'],
  7429.                 'date' => $data['date'],
  7430.                 'token' =>  $data['token'],
  7431.                 'proposal' => $data['proposal'],
  7432.                 'company' => $data['company'],
  7433.                 'clients' => $data['clients'],
  7434.                 'invoicedeposititems' => $data['invoicedeposititems'],
  7435.                 'totales_neto' => $data['totales_neto'],
  7436.                 'totales_iva' => $data['totales_iva'],
  7437.                 'totales' => $data['totales'],
  7438.                 'bases_imponibles' => $data['ivas'],
  7439.                 'currency' => $data['currency'],
  7440.             )
  7441.         );
  7442.     }
  7443.     /**
  7444.      * @Route("/proposal/invoicedeposit/print/invoice/{id}/{fid}",  name="proposal_invoice_deposit_invoice_print_externo")
  7445.      */
  7446.     public function printdetailsInvoicedepositAction($id, $fid, Request $request)
  7447.     {
  7448.         $data = array();
  7449.         $em = $this->getDoctrine()->getManager();
  7450.         $invoicedepositcontrolconsulta = $em->getRepository(ProposalInvoiceDepositControl::class)->findOneBy(
  7451.             array(
  7452.                 'proposalId' => $id,
  7453.                 'id' => $fid
  7454.             )
  7455.         );
  7456.         $type = "Invoice";
  7457.         $controlId = $invoicedepositcontrolconsulta->getId();
  7458.         $date = $invoicedepositcontrolconsulta->getDateAt();
  7459.         $prefix = $invoicedepositcontrolconsulta->getPrefix();
  7460.         $data = $this->baseInvoiceDepositProposal($id, $controlId, $type, $id, $prefix, $date, $request);
  7461.         return $this->render(
  7462.             'MDS/EventsBundle/invoice/print-invoice-deposit-proforma.html.twig',
  7463.             array(
  7464.                 'id' => $id,
  7465.                 'type' => $data['type'],
  7466.                 'number' => $data['number'],
  7467.                 'prefix' => $data['prefix'],
  7468.                 'numberadmin' => $data['numberadmin'],
  7469.                 'date' => $data['date'],
  7470.                 'token' =>  $data['token'],
  7471.                 'proposal' => $data['proposal'],
  7472.                 'company' => $data['company'],
  7473.                 'clients' => $data['clients'],
  7474.                 'invoicedeposititems' => $data['invoicedeposititems'],
  7475.                 'totales_neto' => $data['totales_neto'],
  7476.                 'totales_iva' => $data['totales_iva'],
  7477.                 'totales' => $data['totales'],
  7478.                 'bases_imponibles' => $data['ivas'],
  7479.                 'currency' => $data['currency'],
  7480.             )
  7481.         );
  7482.     }
  7483.     private function baseInvoiceDepositProposal($id, $controlId, $type, $number, $prefix, $date, Request $request)
  7484.     {
  7485.         $em = $this->getDoctrine()->getManager();
  7486.         $proposal = $em->getRepository(Proposal::class)->findOneById($id);
  7487.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  7488.         $parameters = array(
  7489.             'id' => $proposal->getclientId(),
  7490.         );
  7491.         $dql = 'SELECT cl,  c.country, re.region, p.name, r.city 
  7492.                 FROM App:Client cl
  7493.                 INNER JOIN App:Country c WITH c.id = cl.country
  7494.                 INNER JOIN App:Regions re WITH re.id = cl.region
  7495.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  7496.                 INNER JOIN App:Cities r WITH r.id = cl.population
  7497.                 WHERE cl.id = :id';
  7498.         $query = $em->createQuery($dql)->setParameters($parameters);
  7499.         $client = $query->getResult();
  7500.         if (!is_null($controlId)) {
  7501.             $invoicecontrol = $em->getRepository(ProposalInvoiceDepositControl::class)->findOneById($controlId);
  7502.             if (!is_null($invoicecontrol->getNumber())) {
  7503.                 $numberadmin = $invoicecontrol->getNumber();
  7504.             } else {
  7505.                 $numberadmin = null;
  7506.             }
  7507.         } else {
  7508.             $numberadmin = null;
  7509.         }
  7510.         $invoicedeposititems = $em->getRepository(ProposalInvoiceDepositItems::class)->findBy(
  7511.             array(
  7512.                 'proposalId' => $id,
  7513.                 'controlId' => $controlId,
  7514.             )
  7515.         );
  7516.         $totales_neto_all = "0";
  7517.         $totales_iva_all = "0";
  7518.         $totales_con_iva_all = "0";
  7519.         $data_iva = array();
  7520.         foreach ($invoicedeposititems as $deposititems) {
  7521.             $amount = $deposititems->getAmount();
  7522.             $iva_base = $deposititems->getIva();
  7523.             $iva = $iva_base / 100;
  7524.             $amount_iva = ($iva_base != '0') ? ($amount * $iva) : 0;
  7525. //            if ($iva_base != '0') {
  7526. //                $amount_iva = $amount * $iva;
  7527. //            }
  7528.             $amount_con_iva = $amount + $amount_iva;
  7529.             $totales_neto_all += $amount;
  7530.             $totales_iva_all += $amount_iva;
  7531.             $totales_con_iva_all += $amount_con_iva;
  7532.             if (empty($totales_ivas_all[$iva_base])) {
  7533.                 $totales_ivas_all[$iva_base] = 0;
  7534.             }
  7535.             $totales_ivas_all[$iva_base] += $amount_iva;
  7536.             $data_iva[$iva_base] = array(
  7537.                 'iva' => $iva_base,
  7538.                 'ivas' => $totales_ivas_all[$iva_base],
  7539.             );
  7540.             $data_deposititems[] = array(
  7541.                 'name' => $deposititems->getName(),
  7542.                 'amount' => $amount,
  7543.                 'iva' => $iva_base,
  7544.                 'total' => $amount_con_iva
  7545.             );
  7546.         }
  7547.         $currency = "€";
  7548.         $data = array(
  7549.             'id' => $id,
  7550.             'type' => $type,
  7551.             'number' => $number,
  7552.             'prefix' => $prefix,
  7553.             'numberadmin' => $numberadmin,
  7554.             'date' => $date,
  7555.             'token' => $proposal->getAccessKey(),
  7556.             'proposal' => $proposal,
  7557.             'company' => $company,
  7558.             'clients' => $client,
  7559.             'invoicedeposititems' => $data_deposititems,
  7560.             'totales_neto' => $totales_neto_all,
  7561.             'totales_iva' => $totales_iva_all,
  7562.             'totales' => $totales_con_iva_all,
  7563.             'ivas' => $data_iva,
  7564.             'currency' => $currency,
  7565.         );
  7566.         return $data;
  7567.     }
  7568.     public function CalculoTotalesservicesDos($price, $units, $pax, $days, $opcommission, $commission, $opover, $over, $opiva, $iva, $idcat)
  7569.     {
  7570.         $commission = (float)$commission;
  7571.         $price = (float)trim($price);
  7572.         $over = (float)trim($over);
  7573.         //$price = str_replace(",", ".", $price);
  7574.         //$over = str_replace(",", ".", $over);
  7575.         $iva = $iva / 100;
  7576.         if ($opiva == '0') {
  7577.             $price = (float)$price / ($iva + 1);
  7578.         }
  7579.         if ($opcommission == '0') {
  7580.             $commission = (100 - $commission) / 100;
  7581.             $precio_units = $price;
  7582.             $price = $price * $commission;
  7583.         }
  7584.         if ($opcommission == '1') {
  7585.             $commission = ($commission / 100) + 1;
  7586.             $precio_units = $price * $commission;
  7587.         }
  7588.         //Units
  7589.         if (empty($units) or $units == "0") {
  7590.             //            d('entre');
  7591.             $units = "1";
  7592.         }
  7593.         // Calculo Especial por categoria
  7594.         //Alojamientos
  7595.         if ($idcat == "1") {
  7596.             $informativo_days = "si";
  7597.             $pax = "1";
  7598.         }
  7599.         //Transporte
  7600.         elseif ($idcat == "13") {
  7601.             $informativo_days = "no";
  7602.             $pax = "1";
  7603.             //            if($days > "1"){
  7604.             //                $days = "2";
  7605.             //            }else{
  7606.             //                $days = "1";
  7607.             //            }
  7608.         }
  7609.         //Lounge
  7610.         elseif ($idcat == "10") {
  7611.             $informativo_days = "no";
  7612.             $pax = "1";
  7613.         }
  7614.         //Guia
  7615.         elseif ($idcat == "8") {
  7616.             $informativo_days = "no";
  7617.             $pax = "1";
  7618.         }
  7619.         //Asistencia
  7620.         elseif ($idcat == "15") {
  7621.             $informativo_days = "no";
  7622.             $days = '0';
  7623.         } else {
  7624.             $informativo_days = "no";
  7625.         }
  7626.         //Pax
  7627.         if (empty($pax) or $pax == "0") {
  7628.             $pax = "1";
  7629.         }
  7630.         if ($informativo_days == "no") {
  7631.             //Days
  7632.             if (empty($days) or $days == "0") {
  7633.                 $days = "1";
  7634.             } else {
  7635.                 $days = $days + 1;
  7636.             }
  7637.         }
  7638.         $total_items = $price * $units * $pax * $days;
  7639.         //        $total_pdirect = $price * $units * $pax * $days;
  7640.         $total_over = (float)$over * (float)$units * (float)$pax * (float)$days;
  7641.         if ($opcommission == '0') {
  7642.             $total_neto = $total_items / $commission;
  7643.         }
  7644.         if ($opcommission == '1') {
  7645.             $total_neto = $total_items * $commission;
  7646.         }
  7647.         if ($opover == '0') {
  7648.             $total_neto = $total_neto - $total_over;
  7649.             $precio_units = (float)$precio_units - (float)$over;
  7650.         }
  7651.         if ($opover == '1') {
  7652.             $total_neto = $total_neto +  $total_over;
  7653.             $precio_units = (float)$precio_units + (float)$over;
  7654.         }
  7655.         $total_paying = $total_items * ($iva + 1);
  7656.         $total_comision = "0";
  7657.         $total_pago = $total_items;
  7658.         $total_iva = $total_items * $iva;
  7659.         $sub_total_iva = $total_neto * $iva;
  7660.         $total = $total_neto + $sub_total_iva;
  7661.         $benefit_moneda = $total_neto - $total_items;
  7662.         $data_calculos = array(
  7663.             'precio' => $precio_units,
  7664.             'total_days' => $days,
  7665.             'sub_total' => $total_items,
  7666.             'sub_total_iva' => $sub_total_iva,
  7667.             'total_neto' => $total_neto,
  7668.             'total_iva' => $total_iva,
  7669.             'total_paying' => $total_paying,
  7670.             'total_pago' => $total_pago,
  7671.             'total_comision' => $total_comision,
  7672.             'total' => $total,
  7673.             'benefit_moneda' => $benefit_moneda
  7674.         );
  7675.         return $data_calculos;
  7676.     }
  7677.     /**
  7678.      * Añadido el 11/06/2018 por Miguel Aguire
  7679.      */
  7680.     /**
  7681.      * @Route("/invoice/{token}",  name="proposal_presentation_invoice")
  7682.      */
  7683.     public function detectorPresentationInvoiceAction($token, Request $request)
  7684.     {
  7685.         $em = $this->getDoctrine()->getManager();
  7686.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7687.         if ($proposal->getStatus() == "Cancel") {
  7688.             return $this->redirectToRoute(
  7689.                 'presentation_error_cancel',
  7690.                 array(
  7691.                     'proposal' => $proposal,
  7692.                     'token' => $token
  7693.                 )
  7694.             );
  7695.         }
  7696.         if (is_null($proposal->getSelectType())) {
  7697.             $selectType = array();
  7698.         } else {
  7699.             $selectType = explode(",", $proposal->getSelectType());
  7700.         }
  7701.         $invoiceconsulta = array();
  7702.         $typeconsulta = '';
  7703.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7704.         $invoice = $em->getRepository(ProposalInvoice::class)->findOneByProposalId($proposal->getId());
  7705.         if (!empty($invoice)) {
  7706.             $invoiceconsulta = $invoice;
  7707.             $typeconsulta = $invoice->getType();
  7708.         }
  7709.         $parametersNew = array(
  7710.             'proposalId' => $proposal->getId(),
  7711.             'recommended' => '0',
  7712.             'priority' => '0',
  7713.         );
  7714.         $dqlNew = 'SELECT p
  7715.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  7716.                     WHERE p.proposalId = :proposalId 
  7717.                     AND p.recommended = :recommended
  7718.                     AND p.priority != :priority
  7719.                     ORDER BY p.priority ASC';
  7720.         $queryNew = $em->createQuery($dqlNew)->setParameters($parametersNew);
  7721.         $controlbudgetsNew = $queryNew->getResult();
  7722.         $sidebarData = $this->sidebarAction($token, "", "");
  7723.         $noinvoice = false;
  7724.         if (!empty($invoiceconsulta)) {
  7725.             $type = $invoiceconsulta->getType();
  7726.             $number = $invoiceconsulta->getNumber();
  7727.             $date = $invoiceconsulta->getDateAt();
  7728.             $prefix = $invoiceconsulta->getPrefix();
  7729.             $data = $this->baseInvoiceProposal($proposal->getId(), $type, $number, $prefix, $date, $request);
  7730.             $token = $data['token'];
  7731.             return $this->render(
  7732.                 'MDS/EventsPresentationBundle/presentation/invoice.html.twig',
  7733.                 array(
  7734.                     'id' => $proposal->getId(),
  7735.                     'type' => $data['type'],
  7736.                     'number' => $data['number'],
  7737.                     'prefix' => $data['prefix'],
  7738.                     'date' => $data['date'],
  7739.                     'token' => $token,
  7740.                     'proposal' => $data['proposal'],
  7741.                     'company' => $data['company'],
  7742.                     'clients' => $data['clients'],
  7743.                     'datasupplier' => $data['datasupplier'],
  7744.                     'totales_neto_antes' => $data['totales_neto_antes'],
  7745.                     'totales_neto' => $data['totales_neto'], // totales neto
  7746.                     'bases_imponibles' => $data['bases_imponibles'],
  7747.                     'totales_antes' => $data['totales_antes'],
  7748.                     'totales' => $data['totales'], // totales generales
  7749.                     'balance' => $data['balance'],
  7750.                     'totales_generales' => $data['totales_generales'],
  7751.                     'currency' => $data['currency'],
  7752.                     'detail_iva' => 'no',
  7753.                     'discounts' => $data['discounts'],
  7754.                     'paymentInvoice' => $data['paymentInvoice'],
  7755.                     'invoiceDesposit' => $data['invoiceDesposit'],
  7756.                     'mcp' => $data['proposal']->getMcp(),
  7757.                     'noinvoice' => $noinvoice,
  7758.                     'sidebar' => $sidebarData,
  7759.                     'client' => $client,
  7760.                     'budgetNew' => $controlbudgetsNew,
  7761.                     //                    'agendas' => $showAgenda,
  7762.                 )
  7763.             );
  7764.         } else {
  7765.             $noinvoice = true;
  7766.             $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  7767.             return $this->render(
  7768.                 'MDS/EventsPresentationBundle/presentation/invoice.html.twig',
  7769.                 array(
  7770.                     'id' => $proposal->getId(),
  7771.                     'proposal' => $proposal,
  7772.                     'noinvoice' => $noinvoice,
  7773.                     'sidebar' => $sidebarData,
  7774.                     'client' => $client,
  7775.                     'token' => $token,
  7776.                     'budgetNew' => $controlbudgetsNew,
  7777.                     'selectType' => $selectType,
  7778.                     //                    'agendas' => $showAgenda,
  7779.                     'company' => $company,
  7780.                 )
  7781.             );
  7782.         }
  7783.     }
  7784.     /**
  7785.      * @Route("/cancelled/{token}",  name="presentation_error_cancel")
  7786.      */
  7787.     public function canceledInvoiceAction($token, Request $request)
  7788.     {
  7789.         $em = $this->getDoctrine()->getManager();
  7790.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7791.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7792.         $sidebarData = $this->sidebarAction($token, "", "");
  7793.         return $this->render(
  7794.             'MDS/EventsPresentationBundle/presentation/canceled_invoice.html.twig',
  7795.             array(
  7796.                 'proposal' => $proposal,
  7797.                 'sidebar' => $sidebarData,
  7798.                 'client' => $client,
  7799.                 'token' => $token,
  7800.             )
  7801.         );
  7802.     }
  7803.     /**
  7804.      * @Route("/disclaimer/",  name="disclaimer")
  7805.      */
  7806.     public function disclaimer($token, Request $request)
  7807.     {
  7808.         return $this->render(
  7809.             'MDS/EventsPresentationBundle/presentation/disclaimer.html.twig'
  7810.         );
  7811.     }
  7812.     /**
  7813.      * @Route("/showDiary/{token}/{controlId}",  name="presentation_show_diary")
  7814.      */
  7815.     public function showDiaryAction($token, $controlId, Request $request)
  7816.     {
  7817.         $em = $this->getDoctrine()->getManager();
  7818.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7819.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7820.         $sidebarData = $this->sidebarAction($token, "", "");
  7821.         $diary = $em->getRepository(ProposalAgendaPresupuesto::class)->findBy(
  7822.             array(
  7823.                 'proposalId' => $proposal->getId(),
  7824.                 'controlId' => $controlId,
  7825.             ),
  7826.             array(
  7827.                 'dateInAt' => 'ASC',
  7828.             )
  7829.         );
  7830.         $generalDiaryData = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findOneBy(
  7831.             array(
  7832.                 'proposalId' => $proposal->getId(),
  7833.                 'controlId' => $controlId,
  7834.             )
  7835.         );
  7836.         $diaryData = array();
  7837.         $dateAux = null;
  7838.         foreach ($diary as $data) {
  7839.             $diaryData[$data->getDateInAt()->format('Y/m/d')]['services'][] = $data;
  7840.             if ($dateAux != $data->getDateInAt()->format('Y/m/d')) {
  7841.                 $dateAux = $data->getDateInAt()->format('Y/m/d');
  7842.                 $diaryData[$data->getDateInAt()->format('Y/m/d')]['date'] = $dateAux;
  7843.             }
  7844.             //            $diaryData[] = $data;
  7845.         }
  7846.         return $this->render(
  7847.             'MDS/EventsPresentationBundle/presentation/agenda-presupuesto.html.twig',
  7848.             array(
  7849.                 'proposal' => $proposal,
  7850.                 'sidebar' => $sidebarData,
  7851.                 'client' => $client,
  7852.                 'token' => $token,
  7853.                 'diary' => $diaryData,
  7854.                 'general' => $generalDiaryData,
  7855.                 //                'agendas' => $showAgenda,
  7856.             )
  7857.         );
  7858.     }
  7859.     /**
  7860.      * @Route("/aboutUs/{token}",  name="presentation_about_us")
  7861.      */
  7862.     public function aboutUsAction($token, Request $request)
  7863.     {
  7864.         $em = $this->getDoctrine()->getManager();
  7865.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7866.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7867.         $sidebarData = $this->sidebarAction($token, "", "");
  7868.         return $this->render(
  7869.             'MDS/EventsPresentationBundle/presentation/aboutUs.html.twig',
  7870.             array(
  7871.                 'proposal' => $proposal,
  7872.                 'sidebar' => $sidebarData,
  7873.                 'client' => $client,
  7874.                 'token' => $token,
  7875.                 //                'agendas' => $showAgenda,
  7876.             )
  7877.         );
  7878.     }
  7879.     // Funcion para insertar historico de seguimiento
  7880.     private function TracingHistoryOperations($id, $text)
  7881.     {
  7882.         $em = $this->getDoctrine()->getManager();
  7883.         /* Obtengo usuario logueado */
  7884.         $user_id = "0";
  7885.         $history = new ProposalTracing();
  7886.         $history->setDateAt(new \DateTime('now'));
  7887.         $history->setText($text);
  7888.         $history->setAgentId($user_id);
  7889.         $history->setProposalId($id);
  7890.         $history->setViewed('no');
  7891.         $history->setCreatedId($user_id);
  7892.         $history->setUpdatedId($user_id);
  7893.         $em->persist($history);
  7894.         $em->flush();
  7895.         $success = 'success';
  7896.         return $success;
  7897.     }
  7898.     /**
  7899.      * @Route("/menu/{token}", name="presentation_menu_view_token")
  7900.      */
  7901.     public function MenuAction($token, Request $request)
  7902.     {
  7903.         $em = $this->getDoctrine()->getManager();
  7904.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7905.         if ($proposal->getStatus() == "Cancel") {
  7906.             return $this->redirectToRoute(
  7907.                 'presentation_error_cancel',
  7908.                 array(
  7909.                     'token' => $token
  7910.                 )
  7911.             );
  7912.         }
  7913.         if (is_null($proposal->getSelectType())) {
  7914.             $selectTypearray = array();
  7915.         } else {
  7916.             $selectTypearray = explode(",", $proposal->getSelectType());
  7917.         }
  7918.         //        d($selectTypearray);
  7919.         $selectType = array();
  7920.         foreach ($selectTypearray as $selectTypedata) {
  7921.             $agrupacionetiquetas = $em->getRepository(SupplierSettingsType::class)->findOneByBase($selectTypedata);
  7922.             if (empty($agrupacionetiquetas)) {
  7923.                 $selectType['NoHay'][] = $selectTypedata;
  7924.             } else {
  7925.                 if (is_null($agrupacionetiquetas->getGroupBase())) {
  7926.                     $selectType['NoHay'][] = $selectTypedata;
  7927.                 } else {
  7928.                     $selectType[$agrupacionetiquetas->getGroupBase()][] = $selectTypedata;
  7929.                 }
  7930.             }
  7931.         }
  7932.         //        d($selectType);
  7933.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  7934.         // Usuario Anonimo es = "anon."
  7935.         if ($user_logueado == "anon.") {
  7936.             $proposal->setViewedAt(new \DateTime("now"));
  7937.             $em->persist($proposal);
  7938.             $em->flush();
  7939.         }
  7940.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  7941.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7942.         $musica =  $em->getRepository(PresentationMusic::class)->findOneBy(
  7943.             array(
  7944.                 'id' => $proposal->getIdMusic()
  7945.             )
  7946.         );
  7947.         return $this->render(
  7948.             'MDS/EventsPresentationBundle/presentation/menu.html.twig',
  7949.             array(
  7950.                 'token' => $token,
  7951.                 'proposal' => $proposal,
  7952.                 'selectType' => $selectType,
  7953.                 'company' => $company,
  7954.                 'client' => $client,
  7955.                 'music' => $musica,
  7956.             )
  7957.         );
  7958.     }
  7959.     /**
  7960.      * @Route("/submenu/{idg}/{token}", name="presentation_submenu_view_token")
  7961.      */
  7962.     public function SubmenuViewAction($idg, $token, Request $request)
  7963.     {
  7964.         $em = $this->getDoctrine()->getManager();
  7965.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7966.         if ($proposal->getStatus() == "Cancel") {
  7967.             return $this->redirectToRoute(
  7968.                 'presentation_error_cancel',
  7969.                 array(
  7970.                     'token' => $token
  7971.                 )
  7972.             );
  7973.         }
  7974.         switch ($idg) {
  7975.             case 1:
  7976.                 $namerGroup = "LOGÍSTICA";
  7977.                 break;
  7978.             case 2:
  7979.                 $namerGroup = "PRODUCCIÓN";
  7980.                 break;
  7981.             case 3:
  7982.                 $namerGroup = "TECNOLOGÍA";
  7983.                 break;
  7984.         }
  7985.         if (is_null($proposal->getSelectType())) {
  7986.             $selectTypearray = array();
  7987.         } else {
  7988.             $selectTypearray = explode(",", $proposal->getSelectType());
  7989.         }
  7990.         //        d($selectTypearray);
  7991.         $selectType = array();
  7992.         foreach ($selectTypearray as $selectTypedata) {
  7993.             $agrupacionetiquetas = $em->getRepository(SupplierSettingsType::class)->findOneByBase($selectTypedata);
  7994.             if (empty($agrupacionetiquetas)) {
  7995.                 $selectType['NoHay'][] = $selectTypedata;
  7996.             } else {
  7997.                 if (is_null($agrupacionetiquetas->getGroupBase())) {
  7998.                     $selectType['NoHay'][] = $selectTypedata;
  7999.                 } else {
  8000.                     if ($namerGroup == $agrupacionetiquetas->getGroupBase()) {
  8001.                         $selectType[$agrupacionetiquetas->getGroupBase()][] = $selectTypedata;
  8002.                     }
  8003.                 }
  8004.             }
  8005.         }
  8006.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  8007.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  8008.         //        d($selectType);
  8009.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  8010.         // Usuario Anonimo es = "anon."
  8011.         if ($user_logueado == "anon.") {
  8012.             $proposal->setViewedAt(new \DateTime("now"));
  8013.             $em->persist($proposal);
  8014.             $em->flush();
  8015.         }
  8016.         //
  8017.         return $this->render(
  8018.             'MDS/EventsPresentationBundle/presentation/submenu.html.twig',
  8019.             array(
  8020.                 'token' => $token,
  8021.                 'proposal' => $proposal,
  8022.                 'selectType' => $selectType,
  8023.                 'client' => $client,
  8024.                 'company' => $company,
  8025.             )
  8026.         );
  8027.     }
  8028.     /**
  8029.      * @Route("/presupuesto/{token}", name="presentation_presupuesto_view_token")
  8030.      */
  8031.     public function PresupuestoViewAction($token, Request $request)
  8032.     {
  8033.         $em = $this->getDoctrine()->getManager();
  8034.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  8035.         if ($proposal->getStatus() == "Cancel") {
  8036.             return $this->redirectToRoute(
  8037.                 'presentation_error_cancel',
  8038.                 array(
  8039.                     'token' => $token
  8040.                 )
  8041.             );
  8042.         }
  8043.         if (is_null($proposal->getSelectType())) {
  8044.             $selectTypearray = array();
  8045.         } else {
  8046.             $selectTypearray = explode(",", $proposal->getSelectType());
  8047.         }
  8048.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  8049.         // Usuario Anonimo es = "anon."
  8050.         if ($user_logueado == "anon.") {
  8051.             $proposal->setViewedAt(new \DateTime("now"));
  8052.             $em->persist($proposal);
  8053.             $em->flush();
  8054.         }
  8055.         $controlbudget = array(
  8056.             '0' => array(),
  8057.             '1' => array(),
  8058.             '0a' => array()
  8059.         );
  8060.         $controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  8061.         foreach ($controlbudgets as $controlbudge) {
  8062.             if (is_null($controlbudge->getByClient())) {
  8063.                 $byclient = "";
  8064.             } else {
  8065.                 $byclient = "a";
  8066.             }
  8067.             $controlbudget[$controlbudge->getRecommended() . $byclient][] = $controlbudge;
  8068.         }
  8069.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  8070.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  8071.         return $this->render(
  8072.             'MDS/EventsPresentationBundle/presentation/presupuesto.html.twig',
  8073.             array(
  8074.                 'token' => $token,
  8075.                 'proposal' => $proposal,
  8076.                 'budgets' => $controlbudget,
  8077.                 'client' => $client,
  8078.                 'company' => $company,
  8079.             )
  8080.         );
  8081.     }
  8082.     /**
  8083.      * @Route("/idea/{token}",  name="presentation_ideaview")
  8084.      */
  8085.     public function IdeaViewAction($token, Request $request)
  8086.     {
  8087.         $em = $this->getDoctrine()->getManager();
  8088.         $proposal = $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  8089.         $client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  8090.         $company = $em->getRepository(SettingsCompany::class)->findOneById('1');
  8091.         $galeria = $em->getRepository(PresentationGallery::class)->findByProposalId($proposal->getId());
  8092.         $description = $em->getRepository(ProposalDescription::class)->findOneBy(
  8093.             array('proposalId' => $proposal->getId(), 'language' => $proposal->getLanguage())
  8094.         );
  8095.         //        d($description);exit();
  8096.         $musica =  $em->getRepository(PresentationMusic::class)->findOneBy(
  8097.             array(
  8098.                 'id' => $proposal->getIdMusic()
  8099.             )
  8100.         );
  8101.         $video_sinservices = $em->getRepository(PresentationVideo::class)->findByProposalId($proposal->getId());
  8102.         $datos_videos = array();
  8103.         if (!empty($video_sinservices)) {
  8104.             foreach ($video_sinservices as $videoview) {
  8105.                 $urlvideo = $videoview->getVideo();
  8106.                 $esyoutube = strpos($urlvideo, 'youtube');
  8107.                 if ($esyoutube !== false) {
  8108.                     $urvideo_final = '<iframe class="embed-responsive-item" src="' . $urlvideo . '"></iframe>';
  8109.                 }
  8110.                 $esvimeo = strpos($urlvideo, 'vimeo');
  8111.                 if ($esvimeo !== false) {
  8112.                     $urvideo_final = '<iframe allowfullscreen="" frameborder="0" mozallowfullscreen="" src="' . $urlvideo . '?title=0&amp;byline=0&amp;portrait=0" webkitallowfullscreen=""></iframe>';
  8113.                 }
  8114.                 $datos_videos[] = array(
  8115.                     'id' => $videoview->getId(),
  8116.                     'urlvideo' => $urvideo_final
  8117.                 );
  8118.             }
  8119.         }
  8120.         $bg = '/assets/img/presentation-two/02hero.jpg';
  8121.         //            d($galeria); exit();
  8122.         return $this->render(
  8123.             'MDS/EventsPresentationBundle/presentation/idea.html.twig',
  8124.             array(
  8125.                 'proposal' => $proposal,
  8126.                 'client' => $client,
  8127.                 'bg' => $bg,
  8128.                 'token' => $token,
  8129.                 'galeria' => $galeria,
  8130.                 'video' => $datos_videos,
  8131.                 'description' => $description,
  8132.                 'company' => $company,
  8133.                 'music' => $musica,
  8134.             )
  8135.         );
  8136.     }
  8137. }