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

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($tokenRequest $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($tokenRequest $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($tokenRequest $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($tokenRequest $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($tokenRequest $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($tokenRequest $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() == null array_push($agentArray$agentes_data->getAgOne());
  574.             $agentes_data->getAgTwo() == null array_push($agentArray$agentes_data->getAgTwo());
  575.             $agentes_data->getAgThree() == null array_push($agentArray$agentes_data->getAgThree());
  576.             $agentes_data->getAgFour() == 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() == null array_push($agentArray$proposal->getAgencommercialId());
  589.             array_push($agentArray6);
  590.             array_push($agentArray14);
  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$idpRequest $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() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1043.                                     $celdaServicioNeto '=(D' $k '*E' $k '*G' $k ')';
  1044.                                 } else {
  1045.                                     if ($valueService['service']->getPax() == 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 == $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() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1162.                                     $celdaServicioNeto '=(D' $k '*E' $k '*G' $k ')';
  1163.                                 } else {
  1164.                                     if ($valueService['service']->getPax() == 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 == $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() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1281.                                     $celdaServicioNeto '=(D' $k '*E' $k '*G' $k ')';
  1282.                                 } else {
  1283.                                     if ($valueService['service']->getPax() == 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 == $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() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1400.                                     $celdaServicioNeto '=(D' $k '*E' $k '*G' $k ')';
  1401.                                 } else {
  1402.                                     if ($valueService['service']->getPax() == 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 == $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($valueTotalUnit2);
  1542.                                 $celdaServicioPax $valueService['service']->getPax();
  1543.                                 if ($valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1544.                                     $celdaServicioNeto '=(D' $k '*F' $k '*H' $k ')';
  1545.                                 } else {
  1546.                                     if ($valueService['service']->getPax() == 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 == $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($valueTotalUnit2);
  1675.                                 $celdaServicioPax $valueService['service']->getPax();
  1676.                                 if ($valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1677.                                     $celdaServicioNeto '=(D' $k '*F' $k '*H' $k ')';
  1678.                                 } else {
  1679.                                     if ($valueService['service']->getPax() == 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 == $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($valueTotalUnit2);
  1808.                                 $celdaServicioPax $valueService['service']->getPax();
  1809.                                 if ($valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1810.                                     $celdaServicioNeto '=(D' $k '*F' $k '*H' $k ')';
  1811.                                 } else {
  1812.                                     if ($valueService['service']->getPax() == 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 == $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($valueTotalUnit2);
  1941.                                 $celdaServicioPax $valueService['service']->getPax();
  1942.                                 if ($valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 10 or $valueService['service']->getServiceCatId() == or $valueService['service']->getServiceCatId() == 13) {
  1943.                                     $celdaServicioNeto '=(D' $k '*F' $k '*H' $k ')';
  1944.                                 } else {
  1945.                                     if ($valueService['service']->getPax() == 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 == $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) {
  2088.                 $phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
  2089.             }
  2090.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot 2))->applyFromArray($estilo);
  2091.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot 3))->applyFromArray($estilo);
  2092.             $phpExcelObject->getActiveSheet()->getStyle("L" . ($tot 4))->applyFromArray($estilo);
  2093.             $phpExcelObject->setActiveSheetIndex(0)
  2094.                 ->setCellValue('L' . ($tot 2), 'INOUT TRAVEL')
  2095.                 ->setCellValue('L' . ($tot 3), 'events@inout-travel.com')
  2096.                 ->setCellValue('L' . ($tot 4), '+34 911 878 393');
  2097.             $phpExcelObject
  2098.                 ->getActiveSheet()
  2099.                 ->getStyle('k' . ($tot 2) . ':' 'L' . ($tot 4))
  2100.                 ->getFill()
  2101.                 ->setFillType($fill::FILL_SOLID)
  2102.                 ->getStartColor()
  2103.                 ->setRGB('F18E0D');
  2104.         } else { // Caso Internacional (pie de pagina)
  2105.             $phpExcelObject
  2106.                 ->getActiveSheet()
  2107.                 ->getStyle('J' $tot)
  2108.                 ->getFill()
  2109.                 ->setFillType($fill::FILL_SOLID)
  2110.                 ->getStartColor()
  2111.                 ->setRGB('7ec8e0');
  2112.             $phpExcelObject
  2113.                 ->getActiveSheet()
  2114.                 ->getStyle('L' $tot)
  2115.                 ->getFill()
  2116.                 ->setFillType($fill::FILL_SOLID)
  2117.                 ->getStartColor()
  2118.                 ->setRGB('7ec8e0');
  2119.             $phpExcelObject
  2120.                 ->getActiveSheet()
  2121.                 ->getStyle('K' $tot)
  2122.                 ->getFill()
  2123.                 ->setFillType($fill::FILL_SOLID)
  2124.                 ->getStartColor()
  2125.                 //            ->setRGB('57A639')
  2126.                 ->setRGB('7ec8e0');
  2127.             $phpExcelObject
  2128.                 ->getActiveSheet()
  2129.                 ->getStyle('M' $tot)
  2130.                 ->getFill()
  2131.                 ->setFillType($fill::FILL_SOLID)
  2132.                 ->getStartColor()
  2133.                 //            ->setRGB('57A639')
  2134.                 ->setRGB('7ec8e0');
  2135.             $phpExcelObject->setActiveSheetIndex(0)
  2136.                 ->setCellValue('J' $tot$transnet ': ')
  2137.                 ->setCellValue('L' $tot$transtotal ': ')
  2138.                 ->setCellValue('K' $tot$celdaNeto)
  2139.                 ->setCellValue('M' $tot$celdaTotal);
  2140.             $phpExcelObject
  2141.                 ->getActiveSheet()
  2142.                 ->getStyle('K' $tot)
  2143.                 ->getNumberFormat()
  2144.                 ->setFormatCode('#,##0.00 €');
  2145. //                ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  2146. //                ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  2147.             $phpExcelObject
  2148.                 ->getActiveSheet()
  2149.                 ->getStyle('M' $tot)
  2150.                 ->getNumberFormat()
  2151.                 ->setFormatCode('#,##0.00 €');
  2152. //                ->setFormatCode($numberFormat::FORMAT_NUMBER_00)
  2153. //                ->setFormatCode($numberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
  2154.             foreach (range('I' $tot'M' $tot) as $columnID) {
  2155.                 $phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
  2156.             }
  2157.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot 2))->applyFromArray($estilo);
  2158.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot 3))->applyFromArray($estilo);
  2159.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot 4))->applyFromArray($estilo);
  2160.             $phpExcelObject->setActiveSheetIndex(0)
  2161.                 ->setCellValue('M' . ($tot 2), 'INOUT TRAVEL')
  2162.                 ->setCellValue('M' . ($tot 3), 'events@inout-travel.com')
  2163.                 ->setCellValue('M' . ($tot 4), '+34 911 878 393');
  2164.             $phpExcelObject
  2165.                 ->getActiveSheet()
  2166.                 ->getStyle('L' . ($tot 2) . ':' 'M' . ($tot 4))
  2167.                 ->getFill()
  2168.                 ->setFillType($fill::FILL_SOLID)
  2169.                 ->getStartColor()
  2170.                 ->setRGB('F18E0D');
  2171.         }
  2172.         $phpExcelObject->getActiveSheet()->setTitle('Simple');
  2173.         // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  2174.         $phpExcelObject->setActiveSheetIndex(0);
  2175.         // Crea el writer
  2176.         $writer = new Xlsx($phpExcelObject);
  2177.         // Envia la respuesta del controlador
  2178.         $response = new StreamedResponse(
  2179.             function () use ($writer) {
  2180.                 $writer->save('php://output');
  2181.             }
  2182.         );
  2183.         // Agrega los headers requeridos
  2184.         $dispositionHeader $response->headers->makeDisposition(
  2185.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  2186.             //            $company->getCompany().' proposal - '.$proposal->getId().'.xlsx'
  2187.             'In_Out_Travel_presupuesto-' $idp '_proposal-' $proposal->getId() . '.xlsx'
  2188.         );
  2189.         $response->headers->set('Content-Type''application/vnd.ms-excel; charset=utf-8');
  2190.         $response->headers->set('Pragma''public');
  2191.         $response->headers->set('Cache-Control''maxage=1');
  2192.         $response->headers->set('Content-Disposition'$dispositionHeader);
  2193.         return $response;
  2194.     }
  2195.     /**
  2196.      * @Route("/budget/xls/{token}",  name="proposal_xls_budget")
  2197.      *
  2198.      */
  2199.     public function xlsAction($tokenEntityManagerInterface $emRequest $request)
  2200.     {
  2201.         $totales_neto_sub $totales_iva_sub  $totales_con_iva_sub $totales_paying_sub $totales_pago_sub $totales_benefit_moneda_sub 0;
  2202.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  2203.         if ($proposal->getStatus() == "Cancel") {
  2204.             return $this->redirectToRoute'presentation_error_cancel', array( 'token' => $token ) );
  2205.         }
  2206.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2207.         // Usuario Anonimo es = "anon."
  2208.         if ($user_logueado == "anon.") {
  2209.             $proposal->setViewedAt(new \DateTime("now"));
  2210.             $em->persist($proposal);
  2211.             $em->flush();
  2212.         }
  2213.         $selectType explode(","$proposal->getSelectType());
  2214.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  2215.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  2216.             array(
  2217.                 'proposalId' => $proposal->getId(),
  2218.                 'disabled' => '0',
  2219.             )
  2220.         );
  2221.         $data_destionation = array();
  2222.         $cont_destino 0;
  2223.         foreach ($proposal_Control as $proposalControl) {
  2224.             $cont_destino += 1;
  2225.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  2226.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  2227.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  2228.                 array(
  2229.                     'destinationId' => $proposalControl->getDestinationId(),
  2230.                     'language' => $proposal->getLanguage()
  2231.                 )
  2232.             );
  2233.             $data_destionation[$destino->getTitle()] = array(
  2234.                 'destino' => $destino,
  2235.                 'gallery' => $gallery,
  2236.                 'description' => $description,
  2237.             );
  2238.         }
  2239.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  2240.         ////////////////////////////////////////////////////////////////////////////////////////////////
  2241.         /* INICIO CONTENIDO DEL PRESUPUESTO                                                           */
  2242.         ////////////////////////////////////////////////////////////////////////////////////////////////
  2243.         $available_destination $em->getRepository(ProposalControl::class)->findBy(
  2244.             array(
  2245.                 'proposalId' => $proposal->getId(),
  2246.                 'disabled' => "0"
  2247.             )
  2248.         );
  2249.         $data_supplier = array();
  2250.         foreach ($available_destination as $availabledestination) {
  2251.             /* Data Supplier agregados */
  2252.             $service_supplier $em->getRepository(ProposalSupplierControl::class)->findBy(
  2253.                 array(
  2254.                     'controlDestinationId' => $availabledestination->getId(),
  2255.                     'disabled' => "0"
  2256.                 ),
  2257.                 array(
  2258.                     'rank' => 'ASC'
  2259.                 )
  2260.             );
  2261.             $controlgeneral = array(); $master null;
  2262.             foreach ($service_supplier as $suppliercontrol) {
  2263.                 $destination $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
  2264.                 //cambiar el estatus de colores
  2265.                 $colorlabel "";
  2266.                 switch ($suppliercontrol->getStatus()) {
  2267.                     case 'Pending'$colorlabel "bg-danger"; break;
  2268.                     case 'Confirmed'$colorlabel "bg-success"; break;
  2269.                 }
  2270.                 $sqlactivities "";
  2271.                 if (!is_null($suppliercontrol->getActivityId())) {
  2272.                     $master "activity";
  2273.                     $sqlactivities $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
  2274.                     /*CONTROL GENERAL*/
  2275.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
  2276.                 }
  2277.                 $sqlideas "";
  2278.                 if (!is_null($suppliercontrol->getIdeaId())) {
  2279.                     $master "idea";
  2280.                     $sqlideas $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
  2281.                     /*CONTROL GENERAL*/
  2282.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
  2283.                 }
  2284.                 $sqlsuppliers "";
  2285.                 if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
  2286.                     $master "supplier";
  2287.                     $sqlsuppliers $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
  2288.                     if (!is_null($sqlsuppliers)) {
  2289.                         switch ($sqlsuppliers->getStar()) {
  2290.                             case 1$sqlsuppliers->setStar('<i class="icon-star-full2"></i>'); break;
  2291.                             case 2$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  2292.                             case 3$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  2293.                             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;
  2294.                             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;
  2295.                             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;
  2296.                             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;
  2297.                         }
  2298.                     }
  2299.                     /*CONTROL GENERAL*/
  2300.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
  2301.                 }
  2302.                 $sqlcompany "";
  2303.                 if ($suppliercontrol->getSupplierId() == "0") {
  2304.                     $master "company";
  2305.                     $sqlcompany $em->getRepository(SettingsCompany::class)->findOneById('1');
  2306.                     if (!is_null($sqlcompany)) {
  2307.                         $imagenSmall $sqlcompany->getPicture();
  2308.                     } else {
  2309.                         //Imagen no disponible (poner una generica)
  2310.                         $imagenSmall null;
  2311.                     }
  2312.                 } else {
  2313.                     $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  2314.                         array(
  2315.                             'supplierId' => $controlgeneral->getId(),
  2316.                             'servicesCatId' => '0',
  2317.                             'servicesCategory' => 'General',
  2318.                             'servicesId' => '0',
  2319.                             'controlId' => '0'
  2320.                         )
  2321.                     );
  2322.                     if (!is_null($sqlsuppliers_gallery)) {
  2323.                         $imagenSmall $sqlsuppliers_gallery->getImageSmall();
  2324.                     } else {
  2325.                         //Imagen no disponible (poner una generica)
  2326.                         $imagenSmall null;
  2327.                     }
  2328.                 }
  2329.                 // ORDEN DESCENDENTE Y POR SERVICES
  2330.                 $parameters = array(
  2331.                     'controlId' => $suppliercontrol->getId(),
  2332.                     'serviceIdFather' => '0',
  2333.                     'directPayment' => '0',
  2334.                 );
  2335.                 $dql 'SELECT p
  2336.                         FROM EventsBundle:ProposalSupplierServices p
  2337.                         WHERE p.controlId = :controlId 
  2338.                         AND p.serviceIdFather = :serviceIdFather
  2339.                         AND p.directPayment = :directPayment
  2340.                         ORDER BY p.serviceCatId, p.rank ASC ';
  2341.                 $query $em->createQuery($dql)->setParameters($parameters);
  2342.                 $data_service_supplier $query->getResult();
  2343.                 $service_supplier_data = array();
  2344.                 $calculos_totatales = array();
  2345.                 $totales_neto '0';
  2346.                 $totales_iva '0';
  2347.                 $totales_con_iva '0';
  2348.                 $totales_paying '0';
  2349.                 $totales_pago '0';
  2350.                 $totales_benefit_moneda '0';
  2351.                 $totales_benefit_porsentaje '0';
  2352.                 foreach ($data_service_supplier as $data_service) {
  2353.                     //COLOR POR SERVICIO
  2354.                     $contcolor "";
  2355.                     switch ($data_service->getServiceCatName()) {
  2356.                         case "Accommodation"$contcolor 'teal'; break;
  2357.                         case "Menu"$contcolor 'purple'; break;
  2358.                         case "Lounge"$contcolor 'warning'; break;
  2359.                         case "Activities"$contcolor 'blue'; break;
  2360.                         case "Itineraries"$contcolor 'indigo'; break;
  2361.                         case "Cruise"$contcolor 'brown'; break;
  2362.                         case "Transport"$contcolor 'grey'; break;
  2363.                         case "Av"$contcolor 'slate'; break;
  2364.                         case "Creative"$contcolor 'orange'; break;
  2365.                         case "Gifts"$contcolor 'pink'; break;
  2366.                         case "Entertainment"$contcolor 'green'; break;
  2367.                         case "Guide"$contcolor 'orange'; break;
  2368.                         case "Others"$contcolor 'danger'; break;
  2369.                         case "Technology"$contcolor 'grey-800'; break;
  2370.                         case "Assistant"$contcolor 'indigo-800'; break;
  2371.                         case "DDR"$contcolor 'green-300'; break;
  2372.                     }
  2373.                     $idcat $data_service->getServiceCatId();
  2374.                     $price $data_service->getPrice();
  2375.                     $units $data_service->getUnits();
  2376.                     $pax $data_service->getPax();
  2377.                     $opcommission $data_service->getOpCommission();
  2378.                     $commission $data_service->getCommission();
  2379.                     $opover $data_service->getOpOver();
  2380.                     $over $data_service->getOver();
  2381.                     $opiva $data_service->getOpIva();
  2382.                     $iva $data_service->getIva();
  2383.                     $dateInAt $data_service->getDateInAt();
  2384.                     $dateOutAt $data_service->getDateOutAt();
  2385.                     if (!is_null($dateInAt) and !is_null($dateOutAt)) {
  2386.                         $days $dateInAt->diff($dateOutAt);
  2387.                         $day $days->days;
  2388.                     } else {
  2389.                         $day "0";
  2390.                     }
  2391.                     $directPayment $data_service->getDirectPayment();
  2392.                     if ($data_service->getSupplierId() == "0") {
  2393.                         $name_company $em->getRepository(SettingsCompany::class)->findOneById('1');
  2394.                         $namesupplier $name_company->getCompany();
  2395.                     }
  2396.                     if (!is_null($data_service->getSupplierId()) && $data_service->getSupplierId() != "0") {
  2397.                         $name_supplier $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  2398.                         $namesupplier $name_supplier->getName();
  2399.                     }
  2400.                     if (!is_null($data_service->getActivityId())) {
  2401.                         $name_supplier $em->getRepository(Activities::class)->findOneById($data_service->getActivityId());
  2402.                         $namesupplier $name_supplier->getName();
  2403.                     }
  2404.                     if (!is_null($data_service->getIdeaId())) {
  2405.                         $name_supplier $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
  2406.                         $namesupplier $name_supplier->getName();
  2407.                     }
  2408.                     $calculos $this->CalculoTotalesservices($price$units$pax$day$opcommission$commission$opover$over$opiva$iva$directPayment$idcat);
  2409.                     $data_service->setPrice($calculos['precio']); //ojo aqui
  2410.                     /*CONTROL GENERAL*/
  2411.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
  2412.                     $data_service->setPrice($calculos['precio']); //ojo aqui
  2413.                     $service_supplier_data[$data_service->getServiceCatName()][] = array(
  2414.                         'calculos' => $calculos,
  2415.                         'services_data' => $data_service,
  2416.                         'contcolor' => $contcolor,
  2417.                     );
  2418.                     if ($data_service->getBreakdown() == false) {
  2419.                         $totales_neto += $calculos['total_neto'];
  2420.                         $totales_iva += $calculos['sub_total_iva'];
  2421.                         $totales_con_iva += $calculos['total'];
  2422.                         $totales_paying += $calculos['total_paying'];
  2423.                         $totales_pago += $calculos['total_pago'];
  2424.                         $totales_benefit_moneda += $calculos['benefit_moneda'];
  2425.                     } else {
  2426.                         $totales_neto += $totales_neto_sub;
  2427.                         $totales_iva += $totales_iva_sub;
  2428.                         $totales_con_iva += $totales_con_iva_sub;
  2429.                         $totales_paying += $totales_paying_sub;
  2430.                         $totales_pago += $totales_pago_sub;
  2431.                         $totales_benefit_moneda += $totales_benefit_moneda_sub;
  2432.                     }
  2433.                     if ($totales_benefit_moneda == '0') {
  2434.                         $totales_benefit_porsentaje =  '0';
  2435.                     } else {
  2436.                         if ($totales_pago == or is_null($totales_pago)) {
  2437.                             $totales_benefit_porsentaje 0;
  2438.                         } else {
  2439.                             $totales_benefit_porsentaje =  $totales_benefit_moneda 100 $totales_pago;
  2440.                         }
  2441.                     }
  2442.                 }
  2443.                 $calculos_totatales = array(
  2444.                     'totales_neto' => $totales_neto,
  2445.                     'totales_iva' => $totales_iva,
  2446.                     'totales_con_iva' => $totales_con_iva,
  2447.                     'totales_paying' => $totales_paying,
  2448.                     'totales_benefit_moneda' => $totales_benefit_moneda,
  2449.                     'totales_benefit_porsentaje' => $totales_benefit_porsentaje
  2450.                 );
  2451.                 if ($master == "company") { $typeMaster $sqlcompany->getCompany(); }
  2452.                 if ($master == "supplier") { $typeMaster $sqlsuppliers->getType(); }
  2453.                 if ($master == "activity") { $typeMaster "Activity"; }
  2454.                 if ($master == "idea") { $typeMaster "IDEA"; }
  2455.                 $data_supplier[$destination->getTitle()][$typeMaster][] = array(
  2456.                     'colorlabel' => $colorlabel,
  2457.                     'control' => $suppliercontrol,
  2458.                     'master' => $master,
  2459.                     'supplier' => $sqlsuppliers,
  2460.                     'idea' => $sqlideas,
  2461.                     'company' => $sqlcompany,
  2462.                     'activity' => $sqlactivities,
  2463.                     'image' => $imagenSmall,
  2464.                     'services' => $service_supplier_data,
  2465.                     'totales_services' => $calculos_totatales
  2466.                 );
  2467.             }
  2468.         }
  2469.         $fees $em->getRepository(ProposalFee::class)->findByProposalId($proposal->getId()); $theFee = [];
  2470.         if (!empty($fees)) {
  2471.             // 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
  2472.             if ($fees[0]->getToinvoice() == true) {
  2473.                 foreach ($fees as $fee) {
  2474.                     $xFeeAmount = empty($fee->getAmount()) ? $fee->getAmount();
  2475.                     if ($fee->getType() == 0) {
  2476.                         $theFee = array(
  2477.                             'valorDirecto' => null,
  2478.                             'montoPorcentaje' => $xFeeAmount,
  2479.                         );
  2480.                     } else {
  2481.                         $theFee = array(
  2482.                             'valorDirecto' => $xFeeAmount,
  2483.                             'montoPorcentaje' => null,
  2484.                         );
  2485.                     }
  2486.                 }
  2487.             }
  2488.         } else {
  2489.             $theFee null;
  2490.         }
  2491.         $total 0;
  2492.         $neto 0;
  2493.         // Solicita el servicio de excel
  2494.         $phpExcelObject = new Spreadsheet;;
  2495.         $phpExcelObject->getProperties()->setCreator("InOut Travel")
  2496.             ->setLastModifiedBy("InOut Travel")
  2497.             ->setTitle("InOut Travel")
  2498.             ->setSubject("InOut Travel")
  2499.             ->setDescription("InOut Travel, generado usando clases de PHP")
  2500.             ->setKeywords("office 2005 openxml php")
  2501.             ->setCategory("Archivo de ejemplo");
  2502.         $fill = new Fill();
  2503.         $numberFormat = new NumberFormat();
  2504.         $alignment = new Alignment();
  2505.         $i 5;
  2506.         $tot 0;
  2507.         $activesheet $phpExcelObject->getActiveSheet();
  2508.         $drawingobject = new Drawing;
  2509.         $drawingobject->setName('Image name');
  2510.         $drawingobject->setDescription('Image description');
  2511.         $drawingobject->setPath(getcwd() . '/assets/images/logo/logo2022.png');
  2512.         $drawingobject->setHeight(60);
  2513.         $drawingobject->setOffsetY(20);
  2514.         $drawingobject->setCoordinates('K1');
  2515.         $drawingobject->setWorksheet($activesheet);
  2516.         $phpExcelObject
  2517.             ->getActiveSheet()
  2518.             ->getStyle('B3:H3')
  2519.             ->getFill()
  2520.             ->setFillType($fill::FILL_SOLID)
  2521.             ->getStartColor()
  2522.             ->setRGB('FFA420');
  2523.         $phpExcelObject->setActiveSheetIndex(0)
  2524.             ->setCellValue('C3''PRESUPUESTO: ' $proposal->getTitle());
  2525.         if (empty($proposal->getCommission()) or $proposal->getCommission() == 'National') {
  2526.             // *****************************************************************************************************
  2527.             //                                      Caso Nacional
  2528.             // *****************************************************************************************************
  2529.             $celdaNeto '';
  2530.             $celdaTotal '';
  2531.             foreach ($data_supplier as $key => $value) {
  2532.                 $phpExcelObject
  2533.                     ->getActiveSheet()
  2534.                     ->getStyle('A' $i ':L' $i)
  2535.                     ->getFill()
  2536.                     ->setFillType($fill::FILL_SOLID)
  2537.                     ->getStartColor()
  2538.                     ->setRGB('FFA420');
  2539.                 $keytrans strtoupper($this->translator->trans($key));
  2540.                 $phpExcelObject->setActiveSheetIndex(0)
  2541.                     ->setCellValue('E' $i$keytrans);
  2542.                 //          d($phpExcelObject);
  2543.                 $j $i 1;
  2544.                 foreach ($value as $keySup => $valueSup) {
  2545.                     $phpExcelObject
  2546.                         ->getActiveSheet()
  2547.                         ->getStyle('A' $j ':L' $j)
  2548.                         ->getFill()
  2549.                         ->setFillType($fill::FILL_SOLID)
  2550.                         ->getStartColor()
  2551.                         ->setRGB('B5B8B1');
  2552.                     $keySuptrans strtoupper($this->translator->trans($keySup));
  2553.                     $phpExcelObject->setActiveSheetIndex(0)
  2554.                         ->setCellValue('E' $j$keySuptrans);
  2555.                     $drawingobject = new Drawing;
  2556.                     $service $j 1;
  2557.                     foreach ($valueSup as $keySupAll => $valueSupAll) {
  2558.                         $totalSub 0;
  2559.                         $netoSub 0;
  2560.                         if (!is_null($valueSupAll['master'])) {
  2561.                             $type $valueSupAll['master'];
  2562.                             if ($type == 'idea' or $type == 'activity') {
  2563.                                 $name $valueSupAll[$type]->getName();
  2564.                             } else {
  2565.                                 $name "";
  2566.                                 if (!empty($valueSupAll['supplier'])) {
  2567.                                     //                                d($valueSupAll['supplier']->getType());
  2568.                                     if (
  2569.                                         $valueSupAll['supplier']->getType() == "ENTRETENIMIENTO" or
  2570.                                         $valueSupAll['supplier']->getType() == "TRANSPORTE" or
  2571.                                         $valueSupAll['supplier']->getType() == "GUÍAS" or
  2572.                                         $valueSupAll['supplier']->getType() == "OTROS" or
  2573.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUAL" or
  2574.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUALES" or
  2575.                                         $valueSupAll['supplier']->getType() == "MÚSICA" or
  2576.                                         $valueSupAll['supplier']->getType() == "ASISTENCIA"
  2577.                                     ) {
  2578.                                         $name "";
  2579.                                         $valueSupAll[$type]->setCompany('');
  2580.                                         $valueSupAll[$type]->setName('');
  2581.                                     } else {
  2582.                                         $name $valueSupAll[$type]->getCompany();
  2583.                                     }
  2584.                                 }
  2585.                             }
  2586.                             if ($name != '') {
  2587.                                 $phpExcelObject
  2588.                                     ->getActiveSheet()
  2589.                                     ->getStyle('A' $service ':C' $service)
  2590.                                     ->getFill()
  2591.                                     ->setFillType($fill::FILL_SOLID)
  2592.                                     ->getStartColor()
  2593.                                     ->setRGB('DA9694');
  2594.                                 $phpExcelObject->setActiveSheetIndex(0)
  2595.                                     ->setCellValue('A' $service$name);
  2596.                             }
  2597.                         }
  2598.                         $estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ) );
  2599.                         $k $service 1;
  2600.                         if (!empty($valueSupAll[$type])) {
  2601.                             foreach ($valueSupAll['services'] as $keyService => $valueService) {
  2602.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  2603.                                     // Por defecto para todos los idiomas sera un presupuesto en castellano
  2604.                                     $keyServiceTrad $this->translator->trans($keyService);
  2605.                                 } else {
  2606.                                     // El otro idioma es ingles
  2607.                                     $keyServiceTrad $keyService;
  2608.                                 }
  2609.                                 $phpExcelObject
  2610.                                     ->getActiveSheet()
  2611.                                     ->getStyle('A' $k ':L' $k)
  2612.                                     ->applyFromArray($estilo)
  2613.                                     ->getFill()
  2614.                                     ->setFillType($fill::FILL_SOLID)
  2615.                                     ->getStartColor()
  2616.                                     ->setRGB('497E76');
  2617.                                 $estiloL = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_LEFT, ) );
  2618.                                 $phpExcelObject
  2619.                                     ->getActiveSheet()
  2620.                                     ->getStyle('A' $k)
  2621.                                     ->applyFromArray($estiloL);
  2622.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  2623.                                     $phpExcelObject->setActiveSheetIndex(0)
  2624.                                         ->setCellValue('A' $k$keyServiceTrad)
  2625.                                         ->setCellValue('D' $k'Precio Unitario')
  2626.                                         ->setCellValue('E' $k'Cantidad')
  2627.                                         ->setCellValue('F' $k'Personas')
  2628.                                         ->setCellValue('G' $k'Días')
  2629.                                         ->setCellValue('H' $k'Inicio')
  2630.                                         ->setCellValue('I' $k'Fin')
  2631.                                         ->setCellValue('J' $k'Neto')
  2632.                                         ->setCellValue('K' $k'Iva')
  2633.                                         ->setCellValue('L' $k'Total');
  2634.                                 } else {
  2635.                                     $phpExcelObject->setActiveSheetIndex(0)
  2636.                                         ->setCellValue('A' $k$keyServiceTrad)
  2637.                                         ->setCellValue('D' $k'Price')
  2638.                                         ->setCellValue('E' $k'Qty')
  2639.                                         ->setCellValue('F' $k'People')
  2640.                                         ->setCellValue('G' $k'Days')
  2641.                                         ->setCellValue('H' $k'Start')
  2642.                                         ->setCellValue('I' $k'End')
  2643.                                         ->setCellValue('J' $k'Net')
  2644.                                         ->setCellValue('K' $k'Vat')
  2645.                                         ->setCellValue('L' $k'Total');
  2646.                                 }
  2647.                                 $l $k 1;
  2648.                                 foreach ($valueService as $keyServiceDetail => $valueServiceDetail) {
  2649.                                     //                                    d($valueServiceDetail['services_data']->getServiceCatId());
  2650.                                     $idServiceCategory $valueServiceDetail['services_data']->getServiceCatId();
  2651.                                     $inDate date_format($valueServiceDetail['services_data']->getDateInAt(), 'd/m/Y');
  2652.                                     $outDate date_format($valueServiceDetail['services_data']->getDateOutAt(), 'd/m/Y');
  2653.                                     $valueTotalUnit $valueServiceDetail['calculos']['total'] / $valueServiceDetail['calculos']['total_days'];
  2654.                                     if (!empty($valueServiceDetail['services_data']->getUnits()) and ($valueServiceDetail['services_data']->getUnits() > 1)) {
  2655.                                         $valueTotalUnit $valueTotalUnit $valueServiceDetail['services_data']->getUnits();
  2656.                                     }
  2657.                                     if (!empty($valueServiceDetail['services_data']->getPax()) and ($valueServiceDetail['services_data']->getPax() > 1)) {
  2658.                                         $valueTotalUnit $valueTotalUnit $valueServiceDetail['services_data']->getPax();
  2659.                                     }
  2660.                                     $phpExcelObject->setActiveSheetIndex(0)
  2661.                                         ->setCellValue('A' $l$valueServiceDetail['services_data']->getName())
  2662.                                         ->setCellValue('D' $l$valueServiceDetail['calculos']['precio'])
  2663.                                         ->setCellValue('E' $l$valueServiceDetail['services_data']->getUnits())
  2664.                                         ->setCellValue('F' $l$valueServiceDetail['services_data']->getPax())
  2665.                                         ->setCellValue('G' $l$valueServiceDetail['calculos']['total_days'])
  2666.                                         ->setCellValue('H' $l$inDate)
  2667.                                         ->setCellValue('I' $l$outDate)
  2668.                                         ->setCellValue('K' $l$valueServiceDetail['services_data']->getIva());
  2669.                                     if ($idServiceCategory == or $idServiceCategory == 10 or $idServiceCategory == or $idServiceCategory == 13) {
  2670.                                         $phpExcelObject->getActiveSheet()
  2671.                                             ->setCellValue(
  2672.                                                 'J' $l,
  2673.                                                 '=(D' $l '*E' $l '*G' $l ')'
  2674.                                             );
  2675.                                     } else {
  2676.                                         if ($valueServiceDetail['services_data']->getPax() == or is_null($valueServiceDetail['services_data']->getPax())) {
  2677.                                             $phpExcelObject->setActiveSheetIndex(0)
  2678.                                                 ->setCellValue('F' $l1);
  2679.                                         }
  2680.                                         $phpExcelObject->getActiveSheet()
  2681.                                             ->setCellValue(
  2682.                                                 'J' $l,
  2683.                                                 '=(D' $l '*E' $l '*F' $l '*G' $l ')'
  2684.                                             );
  2685.                                     }
  2686.                                     $phpExcelObject->getActiveSheet()
  2687.                                         ->setCellValue(
  2688.                                             'L' $l,
  2689.                                             '=J' $l '+(K' $l '*J' $l '/100)'
  2690.                                         );
  2691.                                     $phpExcelObject
  2692.                                         ->getActiveSheet()
  2693.                                         ->getStyle('J' $l)
  2694.                                         ->getNumberFormat()
  2695.                                         ->setFormatCode('#,##0.00 €');
  2696.                                     $phpExcelObject
  2697.                                         ->getActiveSheet()
  2698.                                         ->getStyle('L' $l)
  2699.                                         ->getNumberFormat()
  2700.                                         ->setFormatCode('#,##0.00 €');
  2701.                                     $netoSub $netoSub $valueServiceDetail['calculos']['total_neto'];
  2702.                                     $totalSub $totalSub $valueServiceDetail['calculos']['total'];
  2703.                                     $neto $neto $valueServiceDetail['calculos']['total_neto'];
  2704.                                     $total $total $valueServiceDetail['calculos']['total'];
  2705.                                     $l++;
  2706.                                 }
  2707.                                 $k $l 1;
  2708.                             }
  2709.                             $phpExcelObject->setActiveSheetIndex(0)
  2710.                                 ->setCellValue('I' . ($k 1), 'SUBTOTAL')
  2711.                                 ->setCellValue('J' . ($k 1), $netoSub)
  2712.                                 ->setCellValue('L' . ($k 1), $totalSub);
  2713.                             $phpExcelObject
  2714.                                 ->getActiveSheet()
  2715.                                 ->getStyle('I' . ($k 1) . ':L' . ($k 1))
  2716.                                 ->getNumberFormat()
  2717.                                 ->setFormatCode('#,##0.00 €');
  2718.                             $phpExcelObject
  2719.                                 ->getActiveSheet()
  2720.                                 ->getStyle('I' . ($k 1) . ':L' . ($k 1))
  2721.                                 ->getFill()
  2722.                                 ->setFillType($fill::FILL_SOLID)
  2723.                                 ->getStartColor()
  2724.                                 ->setRGB('DF3A01');
  2725.                         }
  2726.                         if ($k == $service) {
  2727.                             //                        d($k,$k);
  2728.                         } else {
  2729.                             $phpExcelObject->getActiveSheet()
  2730.                                 ->setCellValue(
  2731.                                     'L' . ($k 1),
  2732.                                     '=SUM(L' $service ':L' . ($k 2) . ')'
  2733.                                 );
  2734.                             $phpExcelObject->getActiveSheet()
  2735.                                 ->setCellValue(
  2736.                                     'J' . ($k 1),
  2737.                                     '=SUM(J' $service ':J' . ($k 2) . ')'
  2738.                                 );
  2739.                             if (empty($celdaNeto)) {
  2740.                                 $celdaNeto '=';
  2741.                             } else {
  2742.                                 $celdaNeto $celdaNeto ' + ';
  2743.                             }
  2744.                             $celdaNeto $celdaNeto 'SUM(J' $service ':J' . ($k 2) . ')';
  2745.                             if (empty($celdaTotal)) {
  2746.                                 $celdaTotal '=';
  2747.                             } else {
  2748.                                 $celdaTotal $celdaTotal ' + ';
  2749.                             }
  2750.                             $celdaTotal $celdaTotal 'SUM(L' $service ':L' . ($k 2) . ')';
  2751.                         }
  2752.                         $service $k 1;
  2753.                     }
  2754.                     $j $service 1;
  2755.                 }
  2756.                 $i $j 1;
  2757.                 $tot $j 1;
  2758.             }
  2759.             if (!empty($theFee)){
  2760.                 $phpExcelObject
  2761.                     ->getActiveSheet()
  2762.                     ->getStyle('I' $tot)
  2763.                     ->getFill()
  2764.                     ->setFillType($fill::FILL_SOLID)
  2765.                     ->getStartColor()
  2766.                     ->setRGB('7ec8e0');
  2767.                 $phpExcelObject
  2768.                     ->getActiveSheet()
  2769.                     ->getStyle('J' $tot)
  2770.                     ->getFill()
  2771.                     ->setFillType($fill::FILL_SOLID)
  2772.                     ->getStartColor()
  2773.                     ->setRGB('7ec8e0');
  2774.                 $phpExcelObject
  2775.                     ->getActiveSheet()
  2776.                     ->getStyle('K' $tot)
  2777.                     ->getFill()
  2778.                     ->setFillType($fill::FILL_SOLID)
  2779.                     ->getStartColor()
  2780.                     ->setRGB('7ec8e0');
  2781.                 $phpExcelObject
  2782.                     ->getActiveSheet()
  2783.                     ->getStyle('L' $tot)
  2784.                     ->getFill()
  2785.                     ->setFillType($fill::FILL_SOLID)
  2786.                     ->getStartColor()
  2787.                     ->setRGB('7ec8e0');
  2788.                 if (empty($theFee['valorDirecto'])){
  2789.                     // Fee de porcentaje
  2790.                     $phpExcelObject->getActiveSheet()
  2791.                         ->setCellValue(
  2792.                             'I' $tot,
  2793.                             'FEE '.$theFee['montoPorcentaje'].'%'
  2794.                         );
  2795.                     $phpExcelObject->getActiveSheet()
  2796.                         ->setCellValue(
  2797.                             'J' $tot,
  2798.                              '=('.substr($celdaNeto1).') * ('.$theFee['montoPorcentaje'].'/100 )'
  2799.                         );
  2800.                     $celdaNeto $celdaNeto '+ (('.substr($celdaNeto1).') * ('.$theFee['montoPorcentaje'].'/100 ))';
  2801.                     $phpExcelObject
  2802.                         ->getActiveSheet()
  2803.                         ->getStyle('J' $tot)
  2804.                         ->getNumberFormat()
  2805.                         ->setFormatCode('#,##0.00 €');
  2806.                     $phpExcelObject->getActiveSheet()
  2807.                         ->setCellValue(
  2808.                             'L' $tot,
  2809.                              '=J'.$tot.' * (1.21)'
  2810.                         );
  2811.                     $celdaTotal $celdaTotal '+ L'.$tot;
  2812.                     $phpExcelObject
  2813.                         ->getActiveSheet()
  2814.                         ->getStyle('L' $tot)
  2815.                         ->getNumberFormat()
  2816.                         ->setFormatCode('#,##0.00 €');
  2817.                 } else {
  2818.                     // Fee de valor directo
  2819.                     $phpExcelObject->getActiveSheet()
  2820.                         ->setCellValue(
  2821.                             'I' $tot,
  2822.                             'FEE'
  2823.                         );
  2824.                     $phpExcelObject->getActiveSheet()
  2825.                         ->setCellValue(
  2826.                             'J' $tot,
  2827.                             $theFee['valorDirecto']
  2828.                         );
  2829.                     $celdaNeto $celdaNeto ' + '.$theFee['valorDirecto'];
  2830.                     $phpExcelObject
  2831.                         ->getActiveSheet()
  2832.                         ->getStyle('J' $tot)
  2833.                         ->getNumberFormat()
  2834.                         ->setFormatCode('#,##0.00 €');
  2835.                     $phpExcelObject
  2836.                         ->getActiveSheet()
  2837.                         ->getStyle('L' $tot)
  2838.                         ->getNumberFormat()
  2839.                         ->setFormatCode('#,##0.00 €');
  2840.                     $phpExcelObject->getActiveSheet()
  2841.                         ->setCellValue(
  2842.                             'L' $tot,
  2843.                             '=J'.$tot.' * (1.21)'
  2844.                         );
  2845.                     $celdaTotal $celdaTotal ' +  L'.$tot;
  2846.                 }
  2847.                 $tot $tot 2;
  2848.             }
  2849.             #####################################################
  2850.             # TOTAL Y NETO                                      #
  2851.             #####################################################
  2852.             $phpExcelObject
  2853.                 ->getActiveSheet()
  2854.                 ->getStyle('I' $tot)
  2855.                 ->getFill()
  2856.                 ->setFillType($fill::FILL_SOLID)
  2857.                 ->getStartColor()
  2858.                 ->setRGB('7ec8e0');
  2859.             $phpExcelObject
  2860.                 ->getActiveSheet()
  2861.                 ->getStyle('J' $tot)
  2862.                 ->getFill()
  2863.                 ->setFillType($fill::FILL_SOLID)
  2864.                 ->getStartColor()
  2865.                 ->setRGB('7ec8e0');
  2866.             $phpExcelObject
  2867.                 ->getActiveSheet()
  2868.                 ->getStyle('K' $tot)
  2869.                 ->getFill()
  2870.                 ->setFillType($fill::FILL_SOLID)
  2871.                 ->getStartColor()
  2872.                 ->setRGB('7ec8e0');
  2873.             $phpExcelObject
  2874.                 ->getActiveSheet()
  2875.                 ->getStyle('L' $tot)
  2876.                 ->getFill()
  2877.                 ->setFillType($fill::FILL_SOLID)
  2878.                 ->getStartColor()
  2879.                 ->setRGB('7ec8e0');
  2880.             $phpExcelObject->setActiveSheetIndex(0)
  2881.                 ->setCellValue('I' $tot'NETO: ')
  2882.                 ->setCellValue('K' $tot'TOTAL: ')
  2883.                 ->setCellValue('J' $tot$celdaNeto)
  2884.                 ->setCellValue('L' $tot$celdaTotal);
  2885.             $phpExcelObject
  2886.                 ->getActiveSheet()
  2887.                 ->getStyle('J' $tot)
  2888.                 ->getNumberFormat()
  2889.                 ->setFormatCode('#,##0.00 €');
  2890.             $phpExcelObject
  2891.                 ->getActiveSheet()
  2892.                 ->getStyle('L' $tot)
  2893.                 ->getNumberFormat()
  2894.                 ->setFormatCode('#,##0.00 €');
  2895.             #####################################################
  2896.             # FIN TOTAL Y NETO                                  #
  2897.             #####################################################
  2898.             foreach (range('H' $tot'L' $tot) 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.                 //          d($phpExcelObject);
  2934.                 $j $i 1;
  2935.                 foreach ($value as $keySup => $valueSup) {
  2936.                     $phpExcelObject
  2937.                         ->getActiveSheet()
  2938.                         ->getStyle('A' $j ':M' $j)
  2939.                         ->getFill()
  2940.                         ->setFillType($fill::FILL_SOLID)
  2941.                         ->getStartColor()
  2942.                         ->setRGB('B5B8B1');
  2943.                     $keySuptrans strtoupper($this->translator->trans($keySup));
  2944.                     $phpExcelObject->setActiveSheetIndex(0)
  2945.                         ->setCellValue('E' $j$keySuptrans);
  2946.                     $drawingobject = new Drawing;
  2947.                     $service $j 1;
  2948.                     foreach ($valueSup as $keySupAll => $valueSupAll) {
  2949.                         $totalSub 0;
  2950.                         $netoSub 0;
  2951.                         if (!is_null($valueSupAll['master'])) {
  2952.                             $type $valueSupAll['master'];
  2953.                             if ($type == 'idea' or $type == 'activity') {
  2954.                                 $name $valueSupAll[$type]->getName();
  2955.                             } else {
  2956.                                 $name "";
  2957.                                 if (!empty($valueSupAll['supplier'])) {
  2958.                                     //                                d($valueSupAll['supplier']->getType());
  2959.                                     if (
  2960.                                         $valueSupAll['supplier']->getType() == "ENTRETENIMIENTO" or
  2961.                                         $valueSupAll['supplier']->getType() == "TRANSPORTE" or
  2962.                                         $valueSupAll['supplier']->getType() == "GUÍAS" or
  2963.                                         $valueSupAll['supplier']->getType() == "OTROS" or
  2964.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUAL" or
  2965.                                         $valueSupAll['supplier']->getType() == "AUDIOVISUALES" or
  2966.                                         $valueSupAll['supplier']->getType() == "MÚSICA" or
  2967.                                         $valueSupAll['supplier']->getType() == "ASISTENCIA"
  2968.                                     ) {
  2969.                                         $name "";
  2970.                                         $valueSupAll[$type]->setCompany('');
  2971.                                         $valueSupAll[$type]->setName('');
  2972.                                     } else {
  2973.                                         $name $valueSupAll[$type]->getCompany();
  2974.                                     }
  2975.                                 }
  2976.                             }
  2977.                             if ($name != '') {
  2978.                                 $phpExcelObject
  2979.                                     ->getActiveSheet()
  2980.                                     ->getStyle('A' $service ':C' $service)
  2981.                                     ->getFill()
  2982.                                     ->setFillType($fill::FILL_SOLID)
  2983.                                     ->getStartColor()
  2984.                                     ->setRGB('DA9694');
  2985.                                 $phpExcelObject->setActiveSheetIndex(0)
  2986.                                     ->setCellValue('A' $service$name);
  2987.                             }
  2988.                         }
  2989.                         $estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ) );
  2990.                         $k $service 1;
  2991.                         if (!empty($valueSupAll[$type])) {
  2992.                             foreach ($valueSupAll['services'] as $keyService => $valueService) {
  2993.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  2994.                                     // Por defecto para todos los idiomas sera un presupuesto en castellano
  2995.                                     $keyServiceTrad $this->translator->trans($keyService);
  2996.                                 } else {
  2997.                                     // El otro idioma es ingles
  2998.                                     $keyServiceTrad $keyService;
  2999.                                 }
  3000.                                 $phpExcelObject
  3001.                                     ->getActiveSheet()
  3002.                                     ->getStyle('A' $k ':M' $k)
  3003.                                     ->applyFromArray($estilo)
  3004.                                     ->getFill()
  3005.                                     ->setFillType($fill::FILL_SOLID)
  3006.                                     ->getStartColor()
  3007.                                     ->setRGB('497E76');
  3008.                                 $estiloL = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_LEFT, ) );
  3009.                                 $phpExcelObject
  3010.                                     ->getActiveSheet()
  3011.                                     ->getStyle('A' $k)
  3012.                                     ->applyFromArray($estiloL);
  3013.                                 if (!($proposal->getLanguage() == 'ENGLISH')) {
  3014.                                     $phpExcelObject->setActiveSheetIndex(0)
  3015.                                         ->setCellValue('A' $k$keyServiceTrad)
  3016.                                         ->setCellValue('D' $k'Precio Unitario')
  3017.                                         ->setCellValue('E' $k'Precio con Iva')
  3018.                                         ->setCellValue('F' $k'Cantidad')
  3019.                                         ->setCellValue('G' $k'Personas')
  3020.                                         ->setCellValue('H' $k'Días')
  3021.                                         ->setCellValue('I' $k'Inicio')
  3022.                                         ->setCellValue('J' $k'Fin')
  3023.                                         ->setCellValue('K' $k'Neto')
  3024.                                         ->setCellValue('L' $k'Iva')
  3025.                                         ->setCellValue('M' $k'Total');
  3026.                                 } else {
  3027.                                     $phpExcelObject->setActiveSheetIndex(0)
  3028.                                         ->setCellValue('A' $k$keyServiceTrad)
  3029.                                         ->setCellValue('D' $k'Price')
  3030.                                         ->setCellValue('E' $k'Price with Vat')
  3031.                                         ->setCellValue('F' $k'Qty')
  3032.                                         ->setCellValue('G' $k'People')
  3033.                                         ->setCellValue('H' $k'Days')
  3034.                                         ->setCellValue('I' $k'Start')
  3035.                                         ->setCellValue('J' $k'End')
  3036.                                         ->setCellValue('K' $k'Net')
  3037.                                         ->setCellValue('L' $k'Vat')
  3038.                                         ->setCellValue('M' $k'Total');
  3039.                                 }
  3040.                                 $l $k 1;
  3041.                                 foreach ($valueService as $keyServiceDetail => $valueServiceDetail) {
  3042.                                     $idServiceCategory $valueServiceDetail['services_data']->getServiceCatId();
  3043.                                     $inDate date_format($valueServiceDetail['services_data']->getDateInAt(), 'd/m/Y');
  3044.                                     $outDate date_format($valueServiceDetail['services_data']->getDateOutAt(), 'd/m/Y');
  3045.                                     $valueTotalUnit $valueServiceDetail['calculos']['total'] / $valueServiceDetail['calculos']['total_days'];
  3046.                                     $celdaValueTotalUnit '=(M' $l '/ H' $l ')';
  3047.                                     if (!empty($valueServiceDetail['services_data']->getUnits()) and ($valueServiceDetail['services_data']->getUnits() > 1)) {
  3048.                                         $valueTotalUnit $valueTotalUnit $valueServiceDetail['services_data']->getUnits();
  3049.                                         $celdaValueTotalUnit '=((M' $l '/ H' $l ')/ F' $l ')';
  3050.                                     }
  3051.                                     if (!empty($valueServiceDetail['services_data']->getPax()) and ($valueServiceDetail['services_data']->getPax() > 1)) {
  3052.                                         $valueTotalUnit $valueTotalUnit $valueServiceDetail['services_data']->getPax();
  3053.                                         $celdaValueTotalUnit '=(((M' $l '/ H' $l ')/ F' $l ')/ G' $l ')';
  3054.                                     }
  3055.                                     $valueTotalUnit round($valueTotalUnit2);
  3056.                                     $phpExcelObject->setActiveSheetIndex(0)
  3057.                                         ->setCellValue('A' $l$valueServiceDetail['services_data']->getName())
  3058.                                         ->setCellValue('D' $l$valueServiceDetail['calculos']['precio'])
  3059.                                         ->setCellValue('E' $l$celdaValueTotalUnit)
  3060.                                         ->setCellValue('F' $l$valueServiceDetail['services_data']->getUnits())
  3061.                                         ->setCellValue('G' $l$valueServiceDetail['services_data']->getPax())
  3062.                                         ->setCellValue('H' $l$valueServiceDetail['calculos']['total_days'])
  3063.                                         ->setCellValue('I' $l$inDate)
  3064.                                         ->setCellValue('J' $l$outDate)
  3065.                                         ->setCellValue('L' $l$valueServiceDetail['services_data']->getIva());
  3066.                                     if ($idServiceCategory == or $idServiceCategory == 10 or $idServiceCategory == or $idServiceCategory == 13) {
  3067.                                         $phpExcelObject->getActiveSheet()
  3068.                                             ->setCellValue(
  3069.                                                 'K' $l,
  3070.                                                 '=(D' $l '*F' $l '*H' $l ')'
  3071.                                             );
  3072.                                     } else {
  3073.                                         if ($valueServiceDetail['services_data']->getPax() == or is_null($valueServiceDetail['services_data']->getPax())) {
  3074.                                             $phpExcelObject->setActiveSheetIndex(0)
  3075.                                                 ->setCellValue('G' $l1);
  3076.                                         }
  3077.                                         $phpExcelObject->getActiveSheet()
  3078.                                             ->setCellValue(
  3079.                                                 'K' $l,
  3080.                                                 '=(D' $l '*F' $l '*G' $l '*H' $l ')'
  3081.                                             );
  3082.                                     }
  3083.                                     $phpExcelObject->getActiveSheet()
  3084.                                         ->setCellValue(
  3085.                                             'M' $l,
  3086.                                             '=K' $l '+(L' $l '*K' $l '/100)'
  3087.                                         );
  3088.                                     $phpExcelObject
  3089.                                         ->getActiveSheet()
  3090.                                         ->getStyle('K' $l)
  3091.                                         ->getNumberFormat()
  3092.                                         ->setFormatCode('#,##0.00 €');
  3093.                                     $phpExcelObject
  3094.                                         ->getActiveSheet()
  3095.                                         ->getStyle('M' $l)
  3096.                                         ->getNumberFormat()
  3097.                                         ->setFormatCode('#,##0.00 €');
  3098.                                     $netoSub $netoSub $valueServiceDetail['calculos']['total_neto'];
  3099.                                     $totalSub $totalSub $valueServiceDetail['calculos']['total'];
  3100.                                     $neto $neto $valueServiceDetail['calculos']['total_neto'];
  3101.                                     $total $total $valueServiceDetail['calculos']['total'];
  3102.                                     $l++;
  3103.                                 }
  3104.                                 $k $l 1;
  3105.                             }
  3106.                             $phpExcelObject->setActiveSheetIndex(0)
  3107.                                 ->setCellValue('J' . ($k 1), 'SUBTOTAL')
  3108.                                 ->setCellValue('K' . ($k 1), $netoSub)
  3109.                                 ->setCellValue('M' . ($k 1), $totalSub);
  3110.                             $phpExcelObject
  3111.                                 ->getActiveSheet()
  3112.                                 ->getStyle('J' . ($k 1) . ':M' . ($k 1))
  3113.                                 ->getNumberFormat()
  3114.                                 ->setFormatCode('#,##0.00 €');
  3115.                             $phpExcelObject
  3116.                                 ->getActiveSheet()
  3117.                                 ->getStyle('J' . ($k 1) . ':M' . ($k 1))
  3118.                                 ->getFill()
  3119.                                 ->setFillType($fill::FILL_SOLID)
  3120.                                 ->getStartColor()
  3121.                                 ->setRGB('DF3A01');
  3122.                         }
  3123.                         if ($k == $service) {
  3124.                             //                        d($k,$k);
  3125.                         } else {
  3126.                             $phpExcelObject->getActiveSheet()
  3127.                                 ->setCellValue(
  3128.                                     'M' . ($k 1),
  3129.                                     '=SUM(M' $service ':M' . ($k 2) . ')'
  3130.                                 );
  3131.                             $phpExcelObject->getActiveSheet()
  3132.                                 ->setCellValue(
  3133.                                     'K' . ($k 1),
  3134.                                     '=SUM(K' $service ':K' . ($k 2) . ')'
  3135.                                 );
  3136.                             if (empty($celdaNeto)) { $celdaNeto '='; } else { $celdaNeto $celdaNeto ' + '; }
  3137.                             $celdaNeto $celdaNeto 'SUM(K' $service ':K' . ($k 2) . ')';
  3138.                             if (empty($celdaTotal)) { $celdaTotal '='; } else { $celdaTotal $celdaTotal ' + '; }
  3139.                             $celdaTotal $celdaTotal 'SUM(M' $service ':M' . ($k 2) . ')';
  3140.                         }
  3141.                         $service $k 1;
  3142.                     }
  3143.                     $j $service 1;
  3144.                 }
  3145.                 $i $j 1;
  3146.                 $tot $j 1;
  3147.             }
  3148.             #####################################################
  3149.             # TOTAL Y NETO                                      #
  3150.             #####################################################
  3151.             $phpExcelObject
  3152.                 ->getActiveSheet()
  3153.                 ->getStyle('J' $tot)
  3154.                 ->getFill()
  3155.                 ->setFillType($fill::FILL_SOLID)
  3156.                 ->getStartColor()
  3157.                 ->setRGB('7ec8e0');
  3158.             $phpExcelObject
  3159.                 ->getActiveSheet()
  3160.                 ->getStyle('K' $tot)
  3161.                 ->getFill()
  3162.                 ->setFillType($fill::FILL_SOLID)
  3163.                 ->getStartColor()
  3164.                 //            ->setRGB('57A639')
  3165.                 ->setRGB('7ec8e0');
  3166.             $phpExcelObject
  3167.                 ->getActiveSheet()
  3168.                 ->getStyle('L' $tot)
  3169.                 ->getFill()
  3170.                 ->setFillType($fill::FILL_SOLID)
  3171.                 ->getStartColor()
  3172.                 ->setRGB('7ec8e0');
  3173.             $phpExcelObject
  3174.                 ->getActiveSheet()
  3175.                 ->getStyle('M' $tot)
  3176.                 ->getFill()
  3177.                 ->setFillType($fill::FILL_SOLID)
  3178.                 ->getStartColor()
  3179.                 //            ->setRGB('57A639')
  3180.                 ->setRGB('7ec8e0');
  3181.             if (!($proposal->getLanguage() == 'ENGLISH')) {
  3182.                 $phpExcelObject->setActiveSheetIndex(0)
  3183.                     ->setCellValue('J' $tot'NETO: ')
  3184.                     ->setCellValue('L' $tot'TOTAL: ')
  3185.                     ->setCellValue('K' $tot$celdaNeto)
  3186.                     ->setCellValue('M' $tot$celdaTotal);
  3187.             } else {
  3188.                 $phpExcelObject->setActiveSheetIndex(0)
  3189.                     ->setCellValue('J' $tot'NET: ')
  3190.                     ->setCellValue('L' $tot'TOTAL: ')
  3191.                     ->setCellValue('K' $tot$celdaNeto)
  3192.                     ->setCellValue('M' $tot$celdaTotal);
  3193.             }
  3194.             $phpExcelObject
  3195.                 ->getActiveSheet()
  3196.                 ->getStyle('K' $tot)
  3197.                 ->getNumberFormat()
  3198.                 ->setFormatCode('#,##0.00 €');
  3199.             $phpExcelObject
  3200.                 ->getActiveSheet()
  3201.                 ->getStyle('M' $tot)
  3202.                 ->getNumberFormat()
  3203.                 ->setFormatCode('#,##0.00 €');
  3204.             #####################################################
  3205.             # FIN TOTAL Y NETO                                  #
  3206.             #####################################################
  3207.             foreach (range('I' $tot'M' $tot) as $columnID) {
  3208.                 $phpExcelObject->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
  3209.             }
  3210.             $estilo = array( 'alignment' => array( 'horizontal' => $alignment::HORIZONTAL_RIGHT, ));
  3211.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot 2))->applyFromArray($estilo);
  3212.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot 3))->applyFromArray($estilo);
  3213.             $phpExcelObject->getActiveSheet()->getStyle("M" . ($tot 4))->applyFromArray($estilo);
  3214.             $phpExcelObject->setActiveSheetIndex(0)
  3215.                 ->setCellValue('M' . ($tot 2), 'INOUT TRAVEL')
  3216.                 ->setCellValue('M' . ($tot 3), 'events@inout-travel.com')
  3217.                 ->setCellValue('M' . ($tot 4), '+34 911 878 393');
  3218.             $phpExcelObject
  3219.                 ->getActiveSheet()
  3220.                 ->getStyle('L' . ($tot 2) . ':' 'M' . ($tot 4))
  3221.                 ->getFill()
  3222.                 ->setFillType($fill::FILL_SOLID)
  3223.                 ->getStartColor()
  3224.                 ->setRGB('F18E0D');
  3225.         } //FIN DEL IF DE LA COMMISSION
  3226.         $phpExcelObject->getActiveSheet()->setTitle('Simple');
  3227.         // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  3228.         $phpExcelObject->setActiveSheetIndex(0);
  3229.         // Crea el writer
  3230.         $writer = new Xlsx($phpExcelObject);
  3231.         // Envia la respuesta del controlador
  3232.         $response = new StreamedResponse(
  3233.             function () use ($writer) {
  3234.                 $writer->save('php://output');
  3235.             }
  3236.         );
  3237.         // Agrega los headers requeridos
  3238.         $dispositionHeader $response->headers->makeDisposition(
  3239.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  3240.             //            $company->getCompany().' proposal - '.$proposal->getId().'.xlsx'
  3241.             'In Out Travel proposal - ' $proposal->getId() . '.xlsx'
  3242.         );
  3243.         $response->headers->set('Content-Type''application/vnd.ms-excel; charset=utf-8');
  3244.         $response->headers->set('Pragma''public');
  3245.         $response->headers->set('Cache-Control''maxage=1');
  3246.         $response->headers->set('Content-Disposition'$dispositionHeader);
  3247.         return $response;
  3248.     }
  3249.     /**
  3250.      * @Route("/budget/{token}", name="presentation_budget_token")
  3251.      */
  3252.     public function budgetAction($tokenEntityManagerInterface $emRequest $request)
  3253.     {
  3254.         $totales_neto_sub $totales_iva_sub  $totales_con_iva_sub $totales_paying_sub $totales_pago_sub $totales_benefit_moneda_sub 0;
  3255.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  3256.         if ($proposal->getStatus() == "Cancel") {
  3257.             return $this->redirectToRoute'presentation_error_cancel', array( 'token' => $token ) );
  3258.         }
  3259.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3260.         // Usuario Anonimo es = "anon."
  3261.         if ($user_logueado == "anon.") {
  3262.             $proposal->setViewedAt(new \DateTime("now"));
  3263.             $em->persist($proposal);
  3264.             $em->flush();
  3265.         }
  3266.         $selectType explode(","$proposal->getSelectType());
  3267.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  3268.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  3269.             array(
  3270.                 'proposalId' => $proposal->getId(),
  3271.                 'disabled' => '0',
  3272.             )
  3273.         );
  3274.         $data_destionation = array();
  3275.         $cont_destino 0;
  3276.         foreach ($proposal_Control as $proposalControl) {
  3277.             $cont_destino += 1;
  3278.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  3279.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  3280.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  3281.                 array(
  3282.                     'destinationId' => $proposalControl->getDestinationId(),
  3283.                     'language' => $proposal->getLanguage()
  3284.                 )
  3285.             );
  3286.             $data_destionation[$destino->getTitle()] = array(
  3287.                 'destino' => $destino,
  3288.                 'gallery' => $gallery,
  3289.                 'description' => $description,
  3290.             );
  3291.         }
  3292.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  3293.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3294.         /* INICIO CONTENIDO DEL PRESUPUESTO                                                           */
  3295.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3296.         //        $available_destination = $em->getRepository(ProposalControl::class)->findByProposalId($proposal->getId());
  3297.         $available_destination $em->getRepository(ProposalControl::class)->findBy(
  3298.             array(
  3299.                 'proposalId' => $proposal->getId(),
  3300.                 'disabled' => "0"
  3301.             )
  3302.         );
  3303.         $data_supplier = array();
  3304.         foreach ($available_destination as $availabledestination) {
  3305.             /* Data Supplier agregados */
  3306.             $service_supplier $em->getRepository(ProposalSupplierControl::class)->findBy(
  3307.                 array(
  3308.                     'controlDestinationId' => $availabledestination->getId(),
  3309.                     'disabled' => "0"
  3310.                 ),
  3311.                 array(
  3312.                     'rank' => 'ASC'
  3313.                 )
  3314.             );
  3315.             $controlgeneral = array();
  3316.             foreach ($service_supplier as $suppliercontrol) {
  3317.                 $destination $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
  3318.                 //cambiar el estatus de colores
  3319.                 $colorlabel "";
  3320.                 switch ($suppliercontrol->getStatus()) {
  3321.                     case 'Pending'$colorlabel "bg-danger"; break;
  3322.                     case 'Confirmed'$colorlabel "bg-success"; break;
  3323.                 }
  3324.                 $sqlactivities "";
  3325.                 if (!is_null($suppliercontrol->getActivityId())) {
  3326.                     $master "activity";
  3327.                     $sqlactivities $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
  3328.                     /*CONTROL GENERAL*/
  3329.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
  3330.                 }
  3331.                 $sqlideas "";
  3332.                 if (!is_null($suppliercontrol->getIdeaId())) {
  3333.                     $master "idea";
  3334.                     $sqlideas $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
  3335.                     /*CONTROL GENERAL*/
  3336.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
  3337.                 }
  3338.                 $sqlsuppliers "";
  3339.                 if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
  3340.                     $master "supplier";
  3341.                     $sqlsuppliers $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
  3342.                     if (!is_null($sqlsuppliers)) {
  3343.                         switch ($sqlsuppliers->getStar()) {
  3344.                             case 1$sqlsuppliers->setStar('<i class="icon-star-full2"></i>'); break;
  3345.                             case 2$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  3346.                             case 3$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>'); break;
  3347.                             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;
  3348.                             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;
  3349.                             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;
  3350.                             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;
  3351.                             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;
  3352.                         }
  3353.                     }
  3354.                     /*CONTROL GENERAL*/
  3355.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
  3356.                 }
  3357.                 $sqlcompany "";
  3358.                 if ($suppliercontrol->getSupplierId() == "0") {
  3359.                     $master "company";
  3360.                     $sqlcompany $em->getRepository(SettingsCompany::class)->findOneById('1');
  3361.                     if (!is_null($sqlcompany)) {
  3362.                         $imagenSmall $sqlcompany->getPicture();
  3363.                     } else {
  3364.                         //Imagen no disponible (poner una generica)
  3365.                         $imagenSmall null;
  3366.                     }
  3367.                 } else {
  3368.                     $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  3369.                         array(
  3370.                             'supplierId' => $controlgeneral->getId(),
  3371.                             'servicesCatId' => '0',
  3372.                             'servicesCategory' => 'General',
  3373.                             'servicesId' => '0',
  3374.                             'controlId' => '0'
  3375.                         )
  3376.                     );
  3377.                     if (!is_null($sqlsuppliers_gallery)) {
  3378.                         $imagenSmall $sqlsuppliers_gallery->getImageSmall();
  3379.                     } else {
  3380.                         //Imagen no disponible (poner una generica)
  3381.                         $imagenSmall null;
  3382.                     }
  3383.                 }
  3384.                 // ORDEN DESCENDENTE Y POR SERVICES
  3385.                 $parameters = array(
  3386.                     'controlId' => $suppliercontrol->getId(),
  3387.                     'serviceIdFather' => '0',
  3388.                     'directPayment' => '0',
  3389.                 );
  3390.                 $dql 'SELECT p
  3391.                         FROM EventsBundle:ProposalSupplierServices p
  3392.                         WHERE p.controlId = :controlId 
  3393.                         AND p.serviceIdFather = :serviceIdFather
  3394.                         AND p.directPayment = :directPayment
  3395.                         ORDER BY p.serviceCatId, p.rank ASC ';
  3396.                 $query $em->createQuery($dql)->setParameters($parameters);
  3397.                 $data_service_supplier $query->getResult();
  3398.                 $service_supplier_data = array();
  3399.                 $calculos_totatales = array();
  3400.                 $totales_neto '0';
  3401.                 $totales_iva '0';
  3402.                 $totales_con_iva '0';
  3403.                 $totales_paying '0';
  3404.                 $totales_pago '0';
  3405.                 $totales_benefit_moneda '0';
  3406.                 $totales_benefit_porsentaje '0';
  3407.                 foreach ($data_service_supplier as $data_service) {
  3408.                     //COLOR POR SERVICIO
  3409.                     $contcolor "";
  3410.                     switch ($data_service->getServiceCatName()) {
  3411.                         case "Accommodation"$contcolor 'teal'; break;
  3412.                         case "Menu"$contcolor 'purple'; break;
  3413.                         case "Lounge"$contcolor 'warning'; break;
  3414.                         case "Activities"$contcolor 'blue'; break;
  3415.                         case "Itineraries"$contcolor 'indigo'; break;
  3416.                         case "Cruise"$contcolor 'brown'; break;
  3417.                         case "Transport"$contcolor 'grey'; break;
  3418.                         case "Av"$contcolor 'slate'; break;
  3419.                         case "Creative"$contcolor 'orange'; break;
  3420.                         case "Gifts"$contcolor 'pink'; break;
  3421.                         case "Entertainment"$contcolor 'green'; break;
  3422.                         case "Guide"$contcolor 'orange'; break;
  3423.                         case "Others"$contcolor 'danger'; break;
  3424.                         case "Technology"$contcolor 'grey-800'; break;
  3425.                         case "Assistant"$contcolor 'indigo-800'; break;
  3426.                         case "DDR"$contcolor 'green-300'; break;
  3427.                     }
  3428.                     $idcat $data_service->getServiceCatId();
  3429.                     $price $data_service->getPrice();
  3430.                     $units $data_service->getUnits();
  3431.                     $pax $data_service->getPax();
  3432.                     $opcommission $data_service->getOpCommission();
  3433.                     $commission $data_service->getCommission();
  3434.                     $opover $data_service->getOpOver();
  3435.                     $over $data_service->getOver();
  3436.                     $opiva $data_service->getOpIva();
  3437.                     $iva $data_service->getIva();
  3438.                     $dateInAt $data_service->getDateInAt();
  3439.                     $dateOutAt $data_service->getDateOutAt();
  3440.                     if (!is_null($dateInAt) and !is_null($dateOutAt)) {
  3441.                         $days $dateInAt->diff($dateOutAt);
  3442.                         $day $days->days;
  3443.                     } else {
  3444.                         $day "0";
  3445.                     }
  3446.                     $directPayment $data_service->getDirectPayment();
  3447.                     if ($data_service->getSupplierId() == "0") {
  3448.                         $name_company $em->getRepository(Configuration::class)->findOneById('1');
  3449.                         $namesupplier $name_company->getCompany();
  3450.                     }
  3451.                     if (!is_null($data_service->getSupplierId()) && $data_service->getSupplierId() != "0") {
  3452.                         $name_supplier $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  3453.                         $namesupplier $name_supplier->getName();
  3454.                     }
  3455.                     if (!is_null($data_service->getActivityId())) {
  3456.                         $name_supplier $em->getRepository(Activities::class)->findOneById($data_service->getActivityId());
  3457.                         $namesupplier $name_supplier->getName();
  3458.                     }
  3459.                     if (!is_null($data_service->getIdeaId())) {
  3460.                         $name_supplier $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
  3461.                         $namesupplier $name_supplier->getName();
  3462.                     }
  3463.                     $calculos $this->CalculoTotalesservices($price$units$pax$day$opcommission$commission$opover$over$opiva$iva$directPayment$idcat);
  3464.                     $data_service->setPrice($calculos['precio']); //ojo aqui
  3465.                     /*CONTROL GENERAL*/
  3466.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
  3467.                     $service_supplier_data[$data_service->getServiceCatName()][] = array(
  3468.                         'calculos' => $calculos,
  3469.                         'services_data' => $data_service,
  3470.                         'contcolor' => $contcolor,
  3471.                     );
  3472.                     if ($data_service->getBreakdown() == false) {
  3473.                         $totales_neto += $calculos['total_neto'];
  3474.                         $totales_iva += $calculos['sub_total_iva'];
  3475.                         $totales_con_iva += $calculos['total'];
  3476.                         $totales_paying += $calculos['total_paying'];
  3477.                         $totales_pago += $calculos['total_pago'];
  3478.                         $totales_benefit_moneda += $calculos['benefit_moneda'];
  3479.                     } else {
  3480.                         $totales_neto += $totales_neto_sub;
  3481.                         $totales_iva += $totales_iva_sub;
  3482.                         $totales_con_iva += $totales_con_iva_sub;
  3483.                         $totales_paying += $totales_paying_sub;
  3484.                         $totales_pago += $totales_pago_sub;
  3485.                         $totales_benefit_moneda += $totales_benefit_moneda_sub;
  3486.                     }
  3487.                     if ($totales_benefit_moneda == '0') {
  3488.                         $totales_benefit_porsentaje =  '0';
  3489.                     } else {
  3490.                         if ($totales_pago == '0') {
  3491.                             $totales_benefit_porsentaje =  '0';
  3492.                         } else {
  3493.                             //                        $totales_benefit_porsentaje =  $totales_benefit_moneda * 100 / $totales_neto;
  3494.                             $totales_benefit_porsentaje =  $totales_benefit_moneda 100 $totales_pago;
  3495.                         }
  3496.                     }
  3497.                 }
  3498.                 $calculos_totatales = array(
  3499.                     'totales_neto' => $totales_neto,
  3500.                     'totales_iva' => $totales_iva,
  3501.                     'totales_con_iva' => $totales_con_iva,
  3502.                     'totales_paying' => $totales_paying,
  3503.                     'totales_benefit_moneda' => $totales_benefit_moneda,
  3504.                     'totales_benefit_porsentaje' => $totales_benefit_porsentaje
  3505.                 );
  3506.                 if ($master == "company") { $typeMaster $sqlcompany->getCompany(); }
  3507.                 if ($master == "supplier") { $typeMaster $sqlsuppliers->getType(); }
  3508.                 if ($master == "activity") { $typeMaster "Activity"; }
  3509.                 if ($master == "idea") { $typeMaster "Idea"; }
  3510.                 $data_supplier[$destination->getTitle()][$typeMaster][] = array(
  3511.                     'colorlabel' => $colorlabel,
  3512.                     'control' => $suppliercontrol,
  3513.                     'master' => $master,
  3514.                     'supplier' => $sqlsuppliers,
  3515.                     'idea' => $sqlideas,
  3516.                     'activity' => $sqlactivities,
  3517.                     'company' => $sqlcompany,
  3518.                     'image' => $imagenSmall,
  3519.                     'services' => $service_supplier_data,
  3520.                     'totales_services' => $calculos_totatales
  3521.                 );
  3522.             }
  3523.         }
  3524.         $controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  3525.         foreach ($controlbudgets as $controlbudge) {
  3526.             $controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
  3527.         }
  3528.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3529.         /* FIN CONTENIDO DEL PRESUPUESTO                                                              */
  3530.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3531.         //////////////////////////////////////////////
  3532.         /* CODIGO PARA TRAER A LOS AGENTES         */
  3533.         ////////////////////////////////////////////
  3534.         $agentMaster = array();
  3535.         if (!empty($proposal->getAgentId())) {
  3536.             $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  3537.             $agentMaster = array(
  3538.                 'name' => $agent->getName(),
  3539.                 'lastname' => $agent->getLastname(),
  3540.                 'picture' => $agent->getPicture(),
  3541.             );
  3542.         }
  3543.         ////////////////////////////////////////////
  3544.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  3545.         //////////////////////////////////////////
  3546.         $sidebarData $this->sidebarAction($token"""");
  3547.         $parametersNew = array(
  3548.             'proposalId' => $proposal->getId(),
  3549.             'recommended' => '0',
  3550.             'priority' => '0',
  3551.         );
  3552.         $dqlNew 'SELECT p
  3553.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  3554.                     WHERE p.proposalId = :proposalId 
  3555.                     AND p.recommended = :recommended
  3556.                     AND p.priority != :priority
  3557.                     ORDER BY p.priority ASC';
  3558.         $queryNew $em->createQuery($dqlNew)->setParameters($parametersNew);
  3559.         $controlbudgetsNew $queryNew->getResult();
  3560.         $today = new \DateTime("now");
  3561.         //        d($controlbudget);
  3562.         return $this->render(
  3563.             'MDS/EventsPresentationBundle/presentation/budget-client.html.twig',
  3564.             array(
  3565.                 'token' => $token,
  3566.                 'today' => $today,
  3567.                 'company' => $company,
  3568.                 'proposal' => $proposal,
  3569.                 'client' => $client,
  3570.                 'selectType' => $selectType,
  3571.                 'destination' => $data_destionation,
  3572.                 'agent' => $agentMaster,
  3573.                 'countDestino' => $cont_destino,
  3574.                 'datasupplier' => $data_supplier,
  3575.                 'budgets' => $controlbudget,
  3576.                 'sidebar' => $sidebarData,
  3577.                 'budgetNew' => $controlbudgetsNew,
  3578.                 //                'agendas' => $showAgenda,
  3579.             )
  3580.         );
  3581.     }
  3582.     public function CalculoTotalesservices($price$units$pax$days$opcommission$commission$opover$over$opiva$iva$directPayment$idcat)
  3583.     {
  3584.         $price trim($price);
  3585.         $over trim($over);
  3586.         $price str_replace(",""."$price);
  3587.         $over str_replace(",""."$over);
  3588.         if (empty($iva)) {
  3589.             $iva 0;
  3590.         }
  3591.         if (empty($price)) {
  3592.             $price 0;
  3593.         }
  3594.         if (empty($commission)) {
  3595.             $commission 0;
  3596.         }
  3597.         $iva $iva 100;
  3598.         if ($opiva == '0') {
  3599.             $price $price / ($iva 1);
  3600.         }
  3601.         if (!empty($commission)) {
  3602.             if ($opcommission == '0') {
  3603.                 $commission = (100 $commission) / 100;
  3604.                 $precio_units $price;
  3605.                 $price $price $commission;
  3606.             }
  3607.             if ($opcommission == '1') {
  3608.                 $commission = ($commission 100) + 1;
  3609.                 $precio_units $price $commission;
  3610.             }
  3611.         } else {
  3612.             $precio_units $price;
  3613.         }
  3614.         //Units
  3615.         if (empty($units) or $units == "0") {
  3616.             $units "1";
  3617.         }
  3618.         // Calculo Especial por categoria
  3619.         //Alojamientos
  3620.         if ($idcat == "1") {
  3621.             $informativo_days "si";
  3622.             $pax "1";
  3623.         }
  3624.         //Transporte
  3625.         elseif ($idcat == "13") {
  3626.             $informativo_days "no";
  3627.             $pax "1";
  3628.             //            if($days > "1"){
  3629.             //                $days = "2";
  3630.             //            }else{
  3631.             //                $days = "1";
  3632.             //            }
  3633.         }
  3634.         //Lounge
  3635.         elseif ($idcat == "10") {
  3636.             $informativo_days "no";
  3637.             $pax "1";
  3638.         }
  3639.         //Guia
  3640.         elseif ($idcat == "8") {
  3641.             $informativo_days "no";
  3642.             $pax "1";
  3643.         } else {
  3644.             $informativo_days "no";
  3645.         }
  3646.         //Pax
  3647.         if (empty($pax) or $pax == "0") {
  3648.             $pax "1";
  3649.         }
  3650.         //Over
  3651.         if (empty($over)) {
  3652.             $over "0";
  3653.         }
  3654.         if ($informativo_days == "no") {
  3655.             //Days
  3656.             if (empty($days) or $days == "0") {
  3657.                 $days "1";
  3658.             } else {
  3659.                 $days $days 1;
  3660.             }
  3661.         }
  3662.         if(empty($days) or $days == "0"){
  3663.             $days "1";
  3664.         }
  3665.         $total_items $price $units $pax $days;
  3666.         //        $total_pdirect = $price * $units * $pax * $days;
  3667.         $total_over $over $units $pax $days;
  3668.         if (!empty($commission)) {
  3669.             if ($opcommission == '0') {
  3670.                 $total_neto $total_items $commission;
  3671.             }
  3672.             if ($opcommission == '1') {
  3673.                 $total_neto $total_items $commission;
  3674.             }
  3675.         } else {
  3676.             $total_neto $total_items;
  3677.         }
  3678.         if ($opover == '0') {
  3679.             $total_neto $total_neto $total_over;
  3680.             $precio_units $precio_units $over;
  3681.         }
  3682.         if ($opover == '1') {
  3683.             $total_neto $total_neto +  $total_over;
  3684.             $precio_units $precio_units $over;
  3685.         }
  3686.         $total_paying $total_items * ($iva 1);
  3687.         if ($directPayment == true) {
  3688.             $total_neto $total_neto $total_paying;
  3689.         }
  3690.         $total_comision "0";
  3691.         $total_pago $total_items;
  3692.         $total_iva $total_items $iva;
  3693.         $sub_total_iva $total_neto $iva;
  3694.         $total $total_neto $sub_total_iva;
  3695.         if ($directPayment == true) {
  3696.             $benefit_moneda $total_neto;
  3697.             $total_paying "0";
  3698.         } else {
  3699.             $benefit_moneda $total_neto $total_items;
  3700.         }
  3701.         $data_calculos = array(
  3702.             'precio' => $precio_units,
  3703.             'total_days' => $days,
  3704.             'sub_total' => $total_items,
  3705.             'sub_total_iva' => $sub_total_iva,
  3706.             'total_neto' => $total_neto,
  3707.             'total_iva' => $total_iva,
  3708.             'total_paying' => $total_paying,
  3709.             'total_pago' => $total_pago,
  3710.             'total_comision' => $total_comision,
  3711.             'total' => $total,
  3712.             'benefit_moneda' => $benefit_moneda,
  3713.             'commission' => $commission,
  3714.             //            'commission_1' => $commission_1,
  3715.             'units' => $units,
  3716.             'pax' => $pax,
  3717.             'over' => $over,
  3718.         );
  3719.         //        d($data_calculos);
  3720.         return $data_calculos;
  3721.     }
  3722.     /**
  3723.      * @Route("/mybudgetsadd/{token}", name="presentation_mybudgets_add_token")
  3724.      */
  3725.     public function mybudgetsAddAction($tokenRequest $request)
  3726.     {
  3727.         $em $this->getDoctrine()->getManager();
  3728.         //        d($request);
  3729.         //        exit();
  3730.         $incluir "";
  3731.         $proposalid $request->request->get('proposalid');
  3732.         $incluir $request->request->get('incluir');
  3733.         //        $incluir_sub = $request->request->get('incluir_sub');
  3734.         $services $request->request->get('services');
  3735.         $name $request->request->get('name');
  3736.         $byclient "1";
  3737.         $status "Pending";
  3738.         //        $proposal = $em->getRepository(Proposal::class)->findOneById($proposalid);
  3739.         /* Obtengo usuario logueado */
  3740.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3741.         // Usuario Anonimo es = "anon."
  3742.         if ($user_logueado == "anon.") {
  3743.             $user_id '0';
  3744.         } else {
  3745.             $user_id $user_logueado->getId();
  3746.         }
  3747.         if (!empty($incluir)) {
  3748.             $control = new ProposalSupplierServicesBudgetControl();
  3749.             $control->setProposalId($proposalid);
  3750.             $control->setStatus($status);
  3751.             $control->setName($name);
  3752.             $control->setByClient($byclient);
  3753.             $em->persist($control);
  3754.             $em->flush();
  3755.             $controlid $control->getId();
  3756.             //            d($controlid);
  3757.             foreach ($incluir as $padentro) {
  3758.                 $id $padentro['id'];
  3759.                 if (array_key_exists($id$services)) {
  3760.                     $services_proposal $em->getRepository(ProposalSupplierServices::class)->findOneById($id);
  3761.                     //COLOR POR SERVICIO
  3762.                     $contcolor "";
  3763.                     switch ($services_proposal->getServiceCatName()) {
  3764.                         case "Accommodation":
  3765.                             $contcolor 'teal';
  3766.                             break;
  3767.                         case "Menu":
  3768.                             $contcolor 'purple';
  3769.                             break;
  3770.                         case "Lounge":
  3771.                             $contcolor 'warning';
  3772.                             break;
  3773.                         case "Activities":
  3774.                             $contcolor 'blue';
  3775.                             break;
  3776.                         case "Itineraries":
  3777.                             $contcolor 'indigo';
  3778.                             break;
  3779.                         case "Cruise":
  3780.                             $contcolor 'brown';
  3781.                             break;
  3782.                         case "Transport":
  3783.                             $contcolor 'grey';
  3784.                             break;
  3785.                         case "Av":
  3786.                             $contcolor 'slate';
  3787.                             break;
  3788.                         case "Creative":
  3789.                             $contcolor 'orange';
  3790.                             break;
  3791.                         case "Gifts":
  3792.                             $contcolor 'pink';
  3793.                             break;
  3794.                         case "Entertainment":
  3795.                             $contcolor 'green';
  3796.                             break;
  3797.                         case "Guide":
  3798.                             $contcolor 'orange';
  3799.                             break;
  3800.                         case "Others":
  3801.                             $contcolor 'danger';
  3802.                             break;
  3803.                         case "Technology":
  3804.                             $contcolor 'grey-800';
  3805.                             break;
  3806.                         case "Assistant":
  3807.                             $contcolor 'indigo-800';
  3808.                             break;
  3809.                         case "DDR":
  3810.                             $contcolor 'green-300';
  3811.                             break;
  3812.                     }
  3813.                     $var $services[$id];
  3814.                     // UNITS
  3815.                     if (empty($var['units']) or $var['units'] == 0) {
  3816.                         $units "1";
  3817.                     } else {
  3818.                         $units $var['units'];
  3819.                     }
  3820.                     // PAX
  3821.                     if (empty($var['pax']) or $var['pax'] == 0) {
  3822.                         $pax "1";
  3823.                     } else {
  3824.                         $pax $var['pax'];
  3825.                     }
  3826.                     // Calculo Especial por categoria
  3827.                     //Alojamientos
  3828.                     if ($services_proposal->getServiceCatId() == "1") {
  3829.                         $pax "1";
  3830.                     }
  3831.                     //Transporte
  3832.                     elseif ($services_proposal->getServiceCatId() == "13") {
  3833.                         $pax "1";
  3834.                     }
  3835.                     //Lounge
  3836.                     elseif ($services_proposal->getServiceCatId() == "10") {
  3837.                         $pax "1";
  3838.                     }
  3839.                     //Guia
  3840.                     elseif ($services_proposal->getServiceCatId() == "8") {
  3841.                         $pax "1";
  3842.                     }
  3843.                     // CALCULO DEL NETO
  3844.                     $netamount $var['price'] * $units $pax $var['days'];
  3845.                     // CALCULO DEL TOTAL
  3846.                     $iva = ($var['iva'] / 100) + 1;
  3847.                     $total $netamount $iva;
  3848.                     $servicesBudget = new ProposalSupplierServicesBudget();
  3849.                     $servicesBudget->setControlId($controlid);
  3850.                     $servicesBudget->setItemsServiceId($id);
  3851.                     $servicesBudget->setItemsserviceIdFather('0');
  3852.                     $servicesBudget->setProposalId($proposalid);
  3853.                     $servicesBudget->setDestinationId($services_proposal->getDestinationId());
  3854.                     $servicesBudget->setSupplierId($services_proposal->getSupplierId());
  3855.                     $servicesBudget->setIdeaId($services_proposal->getIdeaId());
  3856.                     $servicesBudget->setActivityId($services_proposal->getActivityId());
  3857.                     $servicesBudget->setServiceId($services_proposal->getServiceId());
  3858.                     $servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
  3859.                     $servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
  3860.                     $servicesBudget->setContColor($contcolor);
  3861.                     $servicesBudget->setName($services_proposal->getName());
  3862.                     $servicesBudget->setPrice($var['price']);
  3863.                     $servicesBudget->setCurrency($services_proposal->getCurrency());
  3864.                     $servicesBudget->setUnits($var['units']);
  3865.                     $servicesBudget->setPax($var['pax']);
  3866.                     $servicesBudget->setDays($var['days']);
  3867.                     $servicesBudget->setDateInAt($services_proposal->getDateInAt());
  3868.                     $servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
  3869.                     $servicesBudget->setNetAmount($netamount);
  3870.                     $servicesBudget->setIva($var['iva']);
  3871.                     $servicesBudget->setTotal($total);
  3872.                     $servicesBudget->setStatus($status);
  3873.                     $servicesBudget->setRank($var['rank']);
  3874.                     $servicesBudget->setCreatedId($user_id);
  3875.                     $servicesBudget->setUpdatedId($user_id);
  3876.                     $em->persist($servicesBudget);
  3877.                     $em->flush();
  3878.                 }
  3879.             }
  3880.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3881.             // Usuario Anonimo es = "anon."
  3882.             if ($user_logueado == "anon.") {
  3883.                 $time = new \DateTime("now");
  3884.                 $ipclient $request->getClientIp();
  3885.                 $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  3886.                 $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  3887.                 $mailAgent[] = $agent->getEmail();
  3888.                 $agentMail $agent->getEmail();
  3889.                 $passGmail $agent->getPassGmail();
  3890.                 $firmGmail $agent->getFirmGmail();
  3891.                 $mailAgentSent = array(
  3892.                     $agent->getEmail() => $agent->getName() . ' ' $agent->getLastName()
  3893.                 );
  3894.                 $data = array(
  3895.                     '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>',
  3896.                     'firm' => $firmGmail,
  3897.                 );
  3898.                 $mailTodos array_merge($mailAgent);
  3899.                 // EJECUTAR ENVIO DE ALERTA DE VISTO POR CLIENTE
  3900.                 $transporter = new Swift_SmtpTransport();
  3901.                 $transporter->setHost('smtp.gmail.com')
  3902.                     ->setEncryption('ssl'//ssl / tls
  3903.                     ->setPort(465// 465 / 587
  3904.                     ->setUsername('desarrollo@develup.solutions')
  3905.                     ->setPassword('utvh hzoi wfdo ztjs');
  3906.                 $mailer = new Swift_Mailer($transporter);
  3907.                 $message = new Swift_Message();
  3908.                 $message->setSubject('P#' $proposal->getId() . ', Alerta De Presupuesto Creado por el cliente')
  3909.                     ->setSender($agentMail)
  3910.                     ->setFrom($mailAgentSent)
  3911.                     ->setReplyTo($mailAgentSent)
  3912.                     ->setTo($mailTodos)
  3913.                     ->setBody(
  3914.                         $this->renderView(
  3915.                             'mail/structure-mail.html.twig',
  3916.                             array('data' => $data)
  3917.                         ),
  3918.                         'text/html'
  3919.                     );
  3920.                 $mailer->send($message);
  3921.             }
  3922.         }
  3923.         return $this->redirectToRoute(
  3924.             'presentation_mybudgets_view_token',
  3925.             array(
  3926.                 'idp' => $controlid,
  3927.                 'token' => $token,
  3928.             )
  3929.         );
  3930.     }
  3931.     /**
  3932.      * @Route("/mybudgetsview/{idp}/{token}", name="presentation_mybudgets_view_token")
  3933.      */
  3934.     public function mybudgetsViewAction($token$idpRequest $request)
  3935.     {
  3936.         $em $this->getDoctrine()->getManager();
  3937.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  3938.         if ($proposal->getStatus() == "Cancel") {
  3939.             return $this->redirectToRoute(
  3940.                 'presentation_error_cancel',
  3941.                 array(
  3942.                     'token' => $token
  3943.                 )
  3944.             );
  3945.         }
  3946.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3947.         // Usuario Anonimo es = "anon."
  3948.         if ($user_logueado == "anon.") {
  3949.             $proposal->setViewedAt(new \DateTime("now"));
  3950.             $em->persist($proposal);
  3951.             $em->flush();
  3952.         }
  3953.         $selectType explode(","$proposal->getSelectType());
  3954.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  3955.         $country $em->getRepository(Country::class)->findOneById($client->getCountry());
  3956.         $client->setCountry($country->getCountry());
  3957.         $regions $em->getRepository(Regions::class)->findOneById($client->getRegion());
  3958.         $client->setRegion($regions->getRegion());
  3959.         $province $em->getRepository(Provinces::class)->findOneById($client->getProvince());
  3960.         $client->setProvince($province->getName());
  3961.         $cities $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  3962.         $client->setPopulation($cities->getCity());
  3963.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  3964.             array(
  3965.                 'proposalId' => $proposal->getId(),
  3966.                 'disabled' => '0',
  3967.             )
  3968.         );
  3969.         $data_destionation = array();
  3970.         $cont_destino 0;
  3971.         foreach ($proposal_Control as $proposalControl) {
  3972.             $cont_destino += 1;
  3973.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  3974.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  3975.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  3976.                 array(
  3977.                     'destinationId' => $proposalControl->getDestinationId(),
  3978.                     'language' => $proposal->getLanguage()
  3979.                 )
  3980.             );
  3981.             $data_destionation[$destino->getTitle()] = array(
  3982.                 'destino' => $destino,
  3983.                 'gallery' => $gallery,
  3984.                 'description' => $description,
  3985.             );
  3986.         }
  3987.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  3988.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3989.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  3990.         ////////////////////////////////////////////////////////////////////////////////////////////////
  3991.         $controlproposal $em->getRepository(ProposalControl::class)->findBy(
  3992.             array(
  3993.                 'proposalId' => $proposal->getId(),
  3994.                 'disabled' => '0',
  3995.             )
  3996.         );
  3997.         $data_controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  3998.         $controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  3999.         foreach ($controlbudgets as $controlbudge) {
  4000.             $controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
  4001.         }
  4002.         $controlbudgetBoton $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  4003.         $filtro2 = array();
  4004.         foreach ($controlproposal as $consultabudget2) {
  4005.             $filtro2[] = $consultabudget2->getDestinationId();
  4006.         }
  4007.         $services_supplier = array();
  4008.         $services_ideas = array();
  4009.         $budget = array();
  4010.         $content_data = array();
  4011.         $destination = array();
  4012.         //        $totales_neto="";
  4013.         //        $totales_total="";
  4014.         $totales_neto 0;
  4015.         $totales_total 0;
  4016.         $totales_iva = array();
  4017.         $data = array();
  4018.         foreach ($filtro2 as $destinobudget) {
  4019.             $destination $em->getRepository(Destination::class)->findOneById($destinobudget);
  4020.             $destino $destination->getTitle();
  4021.             $consulta_budget $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  4022.                 array(
  4023.                     'controlId' => $idp,
  4024.                     'destinationId' => $destinobudget,
  4025.                     'itemsserviceIdFather' => '0'
  4026.                 ),
  4027.                 array(
  4028.                     'rank' => 'DESC'
  4029.                 )
  4030.             );
  4031.             $filtro = array();
  4032.             foreach ($consulta_budget as $consultabudget) {
  4033.                 if (!is_null($consultabudget->getActivityId())) {
  4034.                     $filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
  4035.                 }
  4036.                 if (!is_null($consultabudget->getIdeaId())) {
  4037.                     $filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
  4038.                 }
  4039.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
  4040.                     $filtro['whiteservice']['0'][] = $consultabudget;
  4041.                 }
  4042.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
  4043.                     $filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
  4044.                 }
  4045.                 //                $filtro[$consultabudget->getSupplierId()] = $consultabudget;
  4046.             }
  4047.             //            d($filtro);
  4048.             //
  4049.             $master "";
  4050.             $services = array();
  4051.             $whiteservice = array();
  4052.             $idea = array();
  4053.             $activity = array();
  4054.             $supplier = array();
  4055.             foreach ($filtro as $key => $ideaOsupplier) {
  4056.                 //                d("·········································", $ideaOsupplier);
  4057.                 foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
  4058.                     //                    d($ideaOsupplierAdentro);
  4059.                     $services = array();
  4060.                     //                    $total_neto="";
  4061.                     //                    $total_total="";
  4062.                     $total_neto 0;
  4063.                     $total_total 0;
  4064.                     foreach ($ideaOsupplierAdentro as $servicesbudget) {
  4065.                         if ($key == "whiteservice") {
  4066.                             $services_white $em->getRepository(Configuration::class)->findOneById('1');
  4067.                             $master "whiteservice";
  4068.                             $services[] = array(
  4069.                                 'service' => $servicesbudget
  4070.                             );
  4071.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4072.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  4073.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  4074.                             }
  4075.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4076.                             $totales_neto += $servicesbudget->getNetAmount();
  4077.                             $total_total += $servicesbudget->getTotal();
  4078.                             $totales_total += $servicesbudget->getTotal();
  4079.                             $whiteservice[$services_white->getId()]  = array(
  4080.                                 'datos' => $services_white,
  4081.                                 'services' => $services,
  4082.                                 'master' => $master,
  4083.                                 'neto' => $total_neto,
  4084.                                 'total' => $total_total
  4085.                             );
  4086.                         }
  4087.                         if ($key == "activity") {
  4088.                             $services_activities $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
  4089.                             $master "activity";
  4090.                             $services[] = array(
  4091.                                 'service' => $servicesbudget
  4092.                             );
  4093.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4094.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  4095.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  4096.                             }
  4097.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4098.                             $total_neto += $servicesbudget->getNetAmount();
  4099.                             $totales_neto += $servicesbudget->getNetAmount();
  4100.                             $total_total += $servicesbudget->getTotal();
  4101.                             $totales_total += $servicesbudget->getTotal();
  4102.                             /*CONTROL GENERAL*/
  4103.                             $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($servicesbudget->getActivityId());
  4104.                             $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  4105.                                 array(
  4106.                                     'supplierId' => $controlgeneral->getId(),
  4107.                                     'servicesCatId' => '0',
  4108.                                     'servicesCategory' => 'General',
  4109.                                     'servicesId' => '0',
  4110.                                     'controlId' => '0'
  4111.                                 )
  4112.                             );
  4113.                             if (!is_null($sqlsuppliers_gallery)) {
  4114.                                 $imagenSmall "/assets/images/suppliers/gallery/" $sqlsuppliers_gallery->getImageSmall();
  4115.                             } else {
  4116.                                 //Imagen no disponible (poner una generica)
  4117.                                 $imagenSmall null;
  4118.                             }
  4119.                             $activity[$services_activities->getId()] = array(
  4120.                                 'datos' => $services_activities,
  4121.                                 'services' => $services,
  4122.                                 'master' => $master,
  4123.                                 'neto' => $total_neto,
  4124.                                 'total' => $total_total,
  4125.                                 'image' => $imagenSmall,
  4126.                             );
  4127.                         }
  4128.                         if ($key == "idea") {
  4129.                             $services_ideas $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
  4130.                             $master "idea";
  4131.                             $services[] = array(
  4132.                                 'service' => $servicesbudget
  4133.                             );
  4134.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4135.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  4136.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  4137.                             }
  4138.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4139.                             $total_neto += $servicesbudget->getNetAmount();
  4140.                             $totales_neto += $servicesbudget->getNetAmount();
  4141.                             $total_total += $servicesbudget->getTotal();
  4142.                             $totales_total += $servicesbudget->getTotal();
  4143.                             /*CONTROL GENERAL*/
  4144.                             $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($servicesbudget->getIdeaId());
  4145.                             $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  4146.                                 array(
  4147.                                     'supplierId' => $controlgeneral->getId(),
  4148.                                     'servicesCatId' => '0',
  4149.                                     'servicesCategory' => 'General',
  4150.                                     'servicesId' => '0',
  4151.                                     'controlId' => '0'
  4152.                                 )
  4153.                             );
  4154.                             if (!is_null($sqlsuppliers_gallery)) {
  4155.                                 $imagenSmall "/assets/images/suppliers/gallery/" $sqlsuppliers_gallery->getImageSmall();
  4156.                             } else {
  4157.                                 //Imagen no disponible (poner una generica)
  4158.                                 $imagenSmall null;
  4159.                             }
  4160.                             $idea[$services_ideas->getId()] = array(
  4161.                                 'datos' => $services_ideas,
  4162.                                 'services' => $services,
  4163.                                 'master' => $master,
  4164.                                 'neto' => $total_neto,
  4165.                                 'total' => $total_total,
  4166.                                 'image' => $imagenSmall,
  4167.                             );
  4168.                         }
  4169.                         if ($key == "supplier") {
  4170.                             if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
  4171.                                 $servicessupplier $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
  4172.                                 $master "supplier";
  4173.                                 //                            foreach($services_supplier as $servicessupplier){
  4174.                                 if (!is_null($servicessupplier)) {
  4175.                                     switch ($servicessupplier->getStar()) {
  4176.                                         case 1:
  4177.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i>');
  4178.                                             break;
  4179.                                         case 2:
  4180.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4181.                                             break;
  4182.                                         case 3:
  4183.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4184.                                             break;
  4185.                                         case 4:
  4186.                                             $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>');
  4187.                                             break;
  4188.                                         case 5:
  4189.                                             $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');
  4190.                                             break;
  4191.                                         case 6:
  4192.                                             $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>');
  4193.                                             break;
  4194.                                         case 7:
  4195.                                             $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');
  4196.                                             break;
  4197.                                         case 8:
  4198.                                             $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');
  4199.                                             break;
  4200.                                     }
  4201.                                     $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4202.                                     if (empty($totales_iva[$servicesbudget->getIva()])) {
  4203.                                         $totales_iva[$servicesbudget->getIva()] = 0;
  4204.                                     }
  4205.                                     //                                d($servicesbudget); exit();
  4206.                                     $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4207.                                     $total_neto += $servicesbudget->getNetAmount();
  4208.                                     $totales_neto += $servicesbudget->getNetAmount();
  4209.                                     $total_total += $servicesbudget->getTotal();
  4210.                                     $totales_total += $servicesbudget->getTotal();
  4211.                                     /*CONTROL GENERAL*/
  4212.                                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($servicesbudget->getSupplierId());
  4213.                                     $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  4214.                                         array(
  4215.                                             'supplierId' => $controlgeneral->getId(),
  4216.                                             'servicesCatId' => '0',
  4217.                                             'servicesCategory' => 'General',
  4218.                                             'servicesId' => '0',
  4219.                                             'controlId' => '0'
  4220.                                         )
  4221.                                     );
  4222.                                     if (!is_null($sqlsuppliers_gallery)) {
  4223.                                         $imagenSmall "/assets/images/suppliers/gallery/" $sqlsuppliers_gallery->getImageSmall();
  4224.                                     } else {
  4225.                                         //Imagen no disponible (poner una generica)
  4226.                                         $imagenSmall null;
  4227.                                     }
  4228.                                 }
  4229.                                 $services[] = array(
  4230.                                     'service' => $servicesbudget
  4231.                                 );
  4232.                                 $supplier[$servicessupplier->getId()] = array(
  4233.                                     'datos' => $servicessupplier,
  4234.                                     'services' => $services,
  4235.                                     'master' => $master,
  4236.                                     'neto' => $total_neto,
  4237.                                     'total' => $total_total,
  4238.                                     'image' => $imagenSmall,
  4239.                                 );
  4240.                             }
  4241.                         }
  4242.                     }
  4243.                 }
  4244.             }
  4245.             $content_data = array(
  4246.                 'supplier' => $supplier,
  4247.                 'idea' => $idea,
  4248.                 'activity' => $activity,
  4249.                 'whiteservice' => $whiteservice,
  4250.             );
  4251.             $data[] = array(
  4252.                 'destination' => $destination,
  4253.                 'container' => $content_data
  4254.             );
  4255.         }
  4256.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4257.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  4258.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4259.         //////////////////////////////////////////////
  4260.         /* CODIGO PARA TRAER A LOS AGENTES         */
  4261.         ////////////////////////////////////////////
  4262.         $agentMaster = array();
  4263.         if (!empty($proposal->getAgentId())) {
  4264.             $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  4265.             $agentMaster = array(
  4266.                 'name' => $agent->getName(),
  4267.                 'lastname' => $agent->getLastname(),
  4268.                 'picture' => $agent->getPicture(),
  4269.             );
  4270.         }
  4271.         $parametersNew = array(
  4272.             'proposalId' => $proposal->getId(),
  4273.             'recommended' => '0',
  4274.             'priority' => '0',
  4275.         );
  4276.         $dqlNew 'SELECT p
  4277.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  4278.                     WHERE p.proposalId = :proposalId 
  4279.                     AND p.recommended = :recommended
  4280.                     AND p.priority != :priority
  4281.                     ORDER BY p.priority ASC';
  4282.         $queryNew $em->createQuery($dqlNew)->setParameters($parametersNew);
  4283.         $controlbudgetsNew $queryNew->getResult();
  4284.         $sidebarData $this->sidebarAction($token"""");
  4285.         return $this->render(
  4286.             'MDS/EventsPresentationBundle/presentation/budgetview-client.html.twig',
  4287.             array(
  4288.                 'token' => $token,
  4289.                 'company' => $company,
  4290.                 'proposal' => $proposal,
  4291.                 'client' => $client,
  4292.                 'selectType' => $selectType,
  4293.                 'destination' => $data_destionation,
  4294.                 'budgetcontrol' => $data_controlbudgets,
  4295.                 'agent' => $agentMaster,
  4296.                 'countDestino' => $cont_destino,
  4297.                 'budgets' => $controlbudget,
  4298.                 'budgetNew' => $controlbudgetsNew,
  4299.                 'data' => $data,
  4300.                 'totales_neto' => $totales_neto,
  4301.                 'ivas' => $totales_iva,
  4302.                 'totales' => $totales_total,
  4303.                 'confirm' => $controlbudgetBoton,
  4304.                 'sidebar' => $sidebarData,
  4305.                 //                'agendas' => $showAgenda,
  4306.             )
  4307.         );
  4308.     }
  4309.     /**
  4310.      * @Route("/mybudgetssave/{idp}/{token}", name="presentation_mybudgets_save_token")
  4311.      */
  4312.     public function mybudgetsSaveAction($token$idpRequest $request)
  4313.     {
  4314.         $em $this->getDoctrine()->getManager();
  4315.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4316.         if ($proposal->getStatus() == "Cancel") {
  4317.             return $this->redirectToRoute(
  4318.                 'presentation_error_cancel',
  4319.                 array(
  4320.                     'token' => $token
  4321.                 )
  4322.             );
  4323.         }
  4324.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4325.         // Usuario Anonimo es = "anon."
  4326.         if ($user_logueado == "anon.") {
  4327.             $proposal->setViewedAt(new \DateTime("now"));
  4328.             $em->persist($proposal);
  4329.             $em->flush();
  4330.         }
  4331.         $selectType explode(","$proposal->getSelectType());
  4332.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4333.         $country $em->getRepository(Country::class)->findOneById($client->getCountry());
  4334.         $client->setCountry($country->getCountry());
  4335.         $regions $em->getRepository(Regions::class)->findOneById($client->getRegion());
  4336.         $client->setRegion($regions->getRegion());
  4337.         $province $em->getRepository(Provinces::class)->findOneById($client->getProvince());
  4338.         $client->setProvince($province->getName());
  4339.         $cities $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  4340.         $client->setPopulation($cities->getCity());
  4341.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  4342.             array(
  4343.                 'proposalId' => $proposal->getId(),
  4344.                 'disabled' => '0',
  4345.             )
  4346.         );
  4347.         $data_destionation = array();
  4348.         $cont_destino 0;
  4349.         foreach ($proposal_Control as $proposalControl) {
  4350.             $cont_destino += 1;
  4351.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4352.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4353.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  4354.                 array(
  4355.                     'destinationId' => $proposalControl->getDestinationId(),
  4356.                     'language' => $proposal->getLanguage()
  4357.                 )
  4358.             );
  4359.             $data_destionation[$destino->getTitle()] = array(
  4360.                 'destino' => $destino,
  4361.                 'gallery' => $gallery,
  4362.                 'description' => $description,
  4363.             );
  4364.         }
  4365.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  4366.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4367.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4368.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4369.         $controlproposal $em->getRepository(ProposalControl::class)->findBy(
  4370.             array(
  4371.                 'proposalId' => $proposal->getId(),
  4372.                 'disabled' => '0',
  4373.             )
  4374.         );
  4375.         $data_controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  4376.         $controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  4377.         foreach ($controlbudgets as $controlbudge) {
  4378.             if (is_null($controlbudge->getByClient())) {
  4379.                 $byclient "";
  4380.             } else {
  4381.                 $byclient "a";
  4382.             }
  4383.             $controlbudget[$controlbudge->getRecommended() . $byclient][] = $controlbudge;
  4384.         }
  4385.         $controlbudgetBoton $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  4386.         $filtro2 = array();
  4387.         foreach ($controlproposal as $consultabudget2) {
  4388.             $filtro2[] = $consultabudget2->getDestinationId();
  4389.         }
  4390.         $services_supplier = array();
  4391.         $services_ideas = array();
  4392.         $budget = array();
  4393.         $content_data = array();
  4394.         $destination = array();
  4395.         //        $totales_neto="";
  4396.         //        $totales_total="";
  4397.         $totales_neto 0;
  4398.         $totales_total 0;
  4399.         $totales_iva = array();
  4400.         $data = array();
  4401.         foreach ($filtro2 as $destinobudget) {
  4402.             $destination $em->getRepository(Destination::class)->findOneById($destinobudget);
  4403.             $destino $destination->getTitle();
  4404.             $consulta_budget $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  4405.                 array(
  4406.                     'controlId' => $idp,
  4407.                     'destinationId' => $destinobudget,
  4408.                     'itemsserviceIdFather' => '0'
  4409.                 ),
  4410.                 array(
  4411.                     'rank' => 'DESC'
  4412.                 )
  4413.             );
  4414.             $filtro = array();
  4415.             foreach ($consulta_budget as $consultabudget) {
  4416.                 if (!is_null($consultabudget->getActivityId())) {
  4417.                     $filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
  4418.                 }
  4419.                 if (!is_null($consultabudget->getIdeaId())) {
  4420.                     $filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
  4421.                 }
  4422.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
  4423.                     $filtro['whiteservice']['0'][] = $consultabudget;
  4424.                 }
  4425.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
  4426.                     $filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
  4427.                 }
  4428.                 //                $filtro[$consultabudget->getSupplierId()] = $consultabudget;
  4429.             }
  4430.             //            d($filtro);
  4431.             //
  4432.             $master "";
  4433.             $services = array();
  4434.             $whiteservice = array();
  4435.             $idea = array();
  4436.             $activity = array();
  4437.             $supplier = array();
  4438.             foreach ($filtro as $key => $ideaOsupplier) {
  4439.                 //                d("·········································", $ideaOsupplier);
  4440.                 foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
  4441.                     //                    d($ideaOsupplierAdentro);
  4442.                     $services = array();
  4443.                     //                    $total_neto="";
  4444.                     //                    $total_total="";
  4445.                     $total_neto 0;
  4446.                     $total_total 0;
  4447.                     foreach ($ideaOsupplierAdentro as $servicesbudget) {
  4448.                         //                        d($servicesbudget);
  4449.                         $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  4450.                         if (empty($totales_iva[$servicesbudget->getIva()])) {
  4451.                             $totales_iva[$servicesbudget->getIva()] = 0;
  4452.                         }
  4453.                         $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  4454.                         $total_neto += $servicesbudget->getNetAmount();
  4455.                         $totales_neto += $servicesbudget->getNetAmount();
  4456.                         $total_total += $servicesbudget->getTotal();
  4457.                         $totales_total += $servicesbudget->getTotal();
  4458.                         if ($key == "whiteservice") {
  4459.                             $services_white $em->getRepository(Configuration::class)->findOneById('1');
  4460.                             $master "whiteservice";
  4461.                             $imagenSmall $services_white->getPicture();
  4462.                             $services[] = array(
  4463.                                 'service' => $servicesbudget
  4464.                             );
  4465.                             $whiteservice[$services_white->getId()]  = array(
  4466.                                 'datos' => $services_white,
  4467.                                 'services' => $services,
  4468.                                 'master' => $master,
  4469.                                 'neto' => $total_neto,
  4470.                                 'total' => $total_total,
  4471.                                 'image' => $imagenSmall,
  4472.                             );
  4473.                         }
  4474.                         if ($key == "activity") {
  4475.                             $services_activities $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
  4476.                             $master "activity";
  4477.                             $services[] = array(
  4478.                                 'service' => $servicesbudget
  4479.                             );
  4480.                             /*CONTROL GENERAL*/
  4481.                             $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($servicesbudget->getActivityId());
  4482.                             $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  4483.                                 array(
  4484.                                     'supplierId' => $controlgeneral->getId(),
  4485.                                     'servicesCatId' => '0',
  4486.                                     'servicesCategory' => 'General',
  4487.                                     'servicesId' => '0',
  4488.                                     'controlId' => '0'
  4489.                                 )
  4490.                             );
  4491.                             if (!is_null($sqlsuppliers_gallery)) {
  4492.                                 $imagenSmall "/assets/images/suppliers/gallery/" $sqlsuppliers_gallery->getImageSmall();
  4493.                             } else {
  4494.                                 //Imagen no disponible (poner una generica)
  4495.                                 $imagenSmall null;
  4496.                             }
  4497.                             $activity[$services_activities->getId()] = array(
  4498.                                 'datos' => $services_activities,
  4499.                                 'services' => $services,
  4500.                                 'master' => $master,
  4501.                                 'neto' => $total_neto,
  4502.                                 'total' => $total_total,
  4503.                                 'image' => $imagenSmall,
  4504.                             );
  4505.                         }
  4506.                         if ($key == "idea") {
  4507.                             $services_ideas $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
  4508.                             $master "idea";
  4509.                             $services[] = array(
  4510.                                 'service' => $servicesbudget
  4511.                             );
  4512.                             /*CONTROL GENERAL*/
  4513.                             $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($servicesbudget->getIdeaId());
  4514.                             $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  4515.                                 array(
  4516.                                     'supplierId' => $controlgeneral->getId(),
  4517.                                     'servicesCatId' => '0',
  4518.                                     'servicesCategory' => 'General',
  4519.                                     'servicesId' => '0',
  4520.                                     'controlId' => '0'
  4521.                                 )
  4522.                             );
  4523.                             if (!is_null($sqlsuppliers_gallery)) {
  4524.                                 $imagenSmall "/assets/images/suppliers/gallery/" $sqlsuppliers_gallery->getImageSmall();
  4525.                             } else {
  4526.                                 //Imagen no disponible (poner una generica)
  4527.                                 $imagenSmall null;
  4528.                             }
  4529.                             $idea[$services_ideas->getId()] = array(
  4530.                                 'datos' => $services_ideas,
  4531.                                 'services' => $services,
  4532.                                 'master' => $master,
  4533.                                 'neto' => $total_neto,
  4534.                                 'total' => $total_total,
  4535.                                 'image' => $imagenSmall,
  4536.                             );
  4537.                         }
  4538.                         if ($key == "supplier") {
  4539.                             if (is_null($servicesbudget->getIdeaId())) {
  4540.                                 $servicessupplier $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
  4541.                                 $master "supplier";
  4542.                                 //                            foreach($services_supplier as $servicessupplier){
  4543.                                 if (!is_null($servicessupplier)) {
  4544.                                     switch ($servicessupplier->getStar()) {
  4545.                                         case 1:
  4546.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i>');
  4547.                                             break;
  4548.                                         case 2:
  4549.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4550.                                             break;
  4551.                                         case 3:
  4552.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  4553.                                             break;
  4554.                                         case 4:
  4555.                                             $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>');
  4556.                                             break;
  4557.                                         case 5:
  4558.                                             $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');
  4559.                                             break;
  4560.                                         case 6:
  4561.                                             $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>');
  4562.                                             break;
  4563.                                         case 7:
  4564.                                             $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');
  4565.                                             break;
  4566.                                         case 8:
  4567.                                             $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');
  4568.                                             break;
  4569.                                     }
  4570.                                     /*CONTROL GENERAL*/
  4571.                                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($servicesbudget->getSupplierId());
  4572.                                     $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  4573.                                         array(
  4574.                                             'supplierId' => $controlgeneral->getId(),
  4575.                                             'servicesCatId' => '0',
  4576.                                             'servicesCategory' => 'General',
  4577.                                             'servicesId' => '0',
  4578.                                             'controlId' => '0'
  4579.                                         )
  4580.                                     );
  4581.                                     if (!is_null($sqlsuppliers_gallery)) {
  4582.                                         $imagenSmall "/assets/images/suppliers/gallery/" $sqlsuppliers_gallery->getImageSmall();
  4583.                                     } else {
  4584.                                         //Imagen no disponible (poner una generica)
  4585.                                         $imagenSmall null;
  4586.                                     }
  4587.                                 }
  4588.                                 $services[] = array(
  4589.                                     'service' => $servicesbudget
  4590.                                 );
  4591.                                 $supplier[$servicessupplier->getId()] = array(
  4592.                                     'datos' => $servicessupplier,
  4593.                                     'services' => $services,
  4594.                                     'master' => $master,
  4595.                                     'neto' => $total_neto,
  4596.                                     'total' => $total_total,
  4597.                                     'image' => $imagenSmall,
  4598.                                 );
  4599.                             }
  4600.                         }
  4601.                     }
  4602.                 }
  4603.             }
  4604.             $content_data = array(
  4605.                 'supplier' => $supplier,
  4606.                 'idea' => $idea,
  4607.                 'activity' => $activity,
  4608.                 'whiteservice' => $whiteservice,
  4609.             );
  4610.             $data[] = array(
  4611.                 'destination' => $destination,
  4612.                 'container' => $content_data
  4613.             );
  4614.         }
  4615.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4616.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  4617.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4618.         //////////////////////////////////////////////
  4619.         /* CODIGO PARA TRAER A LOS AGENTES         */
  4620.         ////////////////////////////////////////////
  4621.         $agentMaster = array();
  4622.         if (!empty($proposal->getAgentId())) {
  4623.             $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  4624.             $agentMaster = array(
  4625.                 'name' => $agent->getName(),
  4626.                 'lastname' => $agent->getLastname(),
  4627.                 'picture' => $agent->getPicture(),
  4628.             );
  4629.         }
  4630.         $parametersNew = array(
  4631.             'proposalId' => $proposal->getId(),
  4632.             'recommended' => '0',
  4633.             'priority' => '0',
  4634.         );
  4635.         $dqlNew 'SELECT p
  4636.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  4637.                     WHERE p.proposalId = :proposalId 
  4638.                     AND p.recommended = :recommended
  4639.                     AND p.priority != :priority
  4640.                     ORDER BY p.priority ASC';
  4641.         $queryNew $em->createQuery($dqlNew)->setParameters($parametersNew);
  4642.         $controlbudgetsNew $queryNew->getResult();
  4643.         $sidebarData $this->sidebarAction($token"""");
  4644.         return $this->render(
  4645.             'MDS/EventsPresentationBundle/presentation/budgetview-save-client.html.twig',
  4646.             array(
  4647.                 'token' => $token,
  4648.                 'company' => $company,
  4649.                 'proposal' => $proposal,
  4650.                 'client' => $client,
  4651.                 'selectType' => $selectType,
  4652.                 'destination' => $data_destionation,
  4653.                 'budgetcontrol' => $data_controlbudgets,
  4654.                 'agent' => $agentMaster,
  4655.                 'countDestino' => $cont_destino,
  4656.                 'budgets' => $controlbudget,
  4657.                 'budgetNew' => $controlbudgetsNew,
  4658.                 'data' => $data,
  4659.                 'totales_neto' => $totales_neto,
  4660.                 'ivas' => $totales_iva,
  4661.                 'totales' => $totales_total,
  4662.                 'confirm' => $controlbudgetBoton,
  4663.                 'sidebar' => $sidebarData,
  4664.                 'idp' => $idp,
  4665.                 //                'agendas' => $showAgenda,
  4666.             )
  4667.         );
  4668.     }
  4669.     /**
  4670.      * @Route("/mybudgetsconfirmed/{idp}/{token}", name="presentation_mybudgets_confirmed_token")
  4671.      */
  4672.     public function mybudgetsConfirmedAction($token$idpRequest $request)
  4673.     {
  4674.         $em $this->getDoctrine()->getManager();
  4675.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4676.         if ($proposal->getStatus() == "Cancel") {
  4677.             return $this->redirectToRoute(
  4678.                 'presentation_error_cancel',
  4679.                 array(
  4680.                     'token' => $token
  4681.                 )
  4682.             );
  4683.         }
  4684.         $selectType explode(","$proposal->getSelectType());
  4685.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4686.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  4687.             array(
  4688.                 'proposalId' => $proposal->getId(),
  4689.                 'disabled' => '0',
  4690.             )
  4691.         );
  4692.         $data_destionation = array();
  4693.         $cont_destino 0;
  4694.         foreach ($proposal_Control as $proposalControl) {
  4695.             $cont_destino += 1;
  4696.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4697.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4698.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  4699.                 array(
  4700.                     'destinationId' => $proposalControl->getDestinationId(),
  4701.                     'language' => $proposal->getLanguage()
  4702.                 )
  4703.             );
  4704.             $data_destionation[$destino->getTitle()] = array(
  4705.                 'destino' => $destino,
  4706.                 'gallery' => $gallery,
  4707.                 'description' => $description,
  4708.             );
  4709.         }
  4710.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  4711.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4712.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4713.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4714.         if (($proposal->getStatus() != "Invoiced") and ($proposal->getStatus() != "Unblocked")) {
  4715.             $proposal->setStatus('Confirmed');
  4716.         }
  4717.         $controlbudget $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idp);
  4718.         $controlbudget->setStatus('Confirmed');
  4719.         $budgets $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($idp);
  4720.         foreach ($budgets as $budget) {
  4721.             $services $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getItemsserviceId());
  4722.             if (!empty($services)) {
  4723.                 $services->setStatus('Confirmed');
  4724.                 $em->persist($services);
  4725.             }
  4726.         }
  4727.         $em->persist($controlbudget);
  4728.         $em->persist($proposal);
  4729.         $em->flush();
  4730.         $event 'The item has ben saved Successfully';
  4731.         $successMessage $this->translator->trans($event);
  4732.         $this->addFlash('mensajebudgetclient'$successMessage);
  4733.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4734.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  4735.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4736.         return $this->redirectToRoute(
  4737.             'presentation_mybudgets_view_token',
  4738.             array(
  4739.                 'idp' => $idp,
  4740.                 'token' => $token,
  4741.             )
  4742.         );
  4743.     }
  4744.     /**
  4745.      * @Route("/destinationAjax/{idd}/{token}", name="presentation_destination_ajax")
  4746.      */
  4747.     public function destinationAjaxViewAction($token$iddRequest $request)
  4748.     {
  4749.         $em $this->getDoctrine()->getManager();
  4750.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4751.         if ($proposal->getStatus() == "Cancel") {
  4752.             return $this->redirectToRoute(
  4753.                 'presentation_error_cancel',
  4754.                 array(
  4755.                     'token' => $token
  4756.                 )
  4757.             );
  4758.         }
  4759.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4760.         // Usuario Anonimo es = "anon."
  4761.         if ($user_logueado == "anon.") {
  4762.             $proposal->setViewedAt(new \DateTime("now"));
  4763.             $em->persist($proposal);
  4764.             $em->flush();
  4765.         }
  4766.         $selectType explode(","$proposal->getSelectType());
  4767.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4768.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  4769.             array(
  4770.                 'proposalId' => $proposal->getId(),
  4771.                 'disabled' => '0',
  4772.             )
  4773.         );
  4774.         $data_destionation = array();
  4775.         $cont_destino 0;
  4776.         foreach ($proposal_Control as $proposalControl) {
  4777.             $cont_destino += 1;
  4778.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4779.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4780.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  4781.                 array(
  4782.                     'destinationId' => $proposalControl->getDestinationId(),
  4783.                     'language' => $proposal->getLanguage()
  4784.                 )
  4785.             );
  4786.             $data_destionation[$destino->getTitle()] = array(
  4787.                 'destino' => $destino,
  4788.                 'gallery' => $gallery,
  4789.                 'description' => $description,
  4790.             );
  4791.         }
  4792.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  4793.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4794.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4795.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4796.         $destino_details $em->getRepository(Destination::class)->findOneById($idd);
  4797.         $gallery_details $em->getRepository(DestinationGallery::class)->findByDestinationId($idd);
  4798.         $description_details $em->getRepository(DestinationDescription::class)->findOneBy(
  4799.             array(
  4800.                 'destinationId' => $idd,
  4801.                 'language' => $proposal->getLanguage()
  4802.             )
  4803.         );
  4804.         $response_body =
  4805.             array(
  4806.                 'token' => $token,
  4807.                 'countDestino' => $cont_destino,
  4808.                 //                'agent'=>$agentMaster,
  4809.                 'destino' => $destino_details,
  4810.                 'gallerys' => $gallery_details,
  4811.                 'description' => $description_details,
  4812.                 //                'sidebar' => $sidebarData
  4813.             );
  4814.         //        d($response_body);
  4815.         //
  4816.         //        d($response);
  4817.         $serializer SerializerBuilder::create()->build();
  4818.         $array $serializer->toArray($response_body);
  4819.         $response = new JsonResponse($array);
  4820.         return $response;
  4821.     }
  4822.     /**
  4823.      * @Route("/download/{token}", name="presentation_document_list")
  4824.      */
  4825.     public function downloadAction($tokenRequest $request)
  4826.     {
  4827.         $em $this->getDoctrine()->getManager();
  4828.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4829.         if ($proposal->getStatus() == "Cancel") {
  4830.             return $this->redirectToRoute(
  4831.                 'presentation_error_cancel',
  4832.                 array(
  4833.                     'token' => $token
  4834.                 )
  4835.             );
  4836.         }
  4837.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4838.         // Usuario Anonimo es = "anon."
  4839.         if ($user_logueado == "anon.") {
  4840.             $proposal->setViewedAt(new \DateTime("now"));
  4841.             $em->persist($proposal);
  4842.             $em->flush();
  4843.         }
  4844.         $selectType explode(","$proposal->getSelectType());
  4845.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4846.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  4847.             array(
  4848.                 'proposalId' => $proposal->getId(),
  4849.                 'disabled' => '0',
  4850.             )
  4851.         );
  4852.         $data_destionation = array();
  4853.         $cont_destino 0;
  4854.         foreach ($proposal_Control as $proposalControl) {
  4855.             $cont_destino += 1;
  4856.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4857.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4858.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  4859.                 array(
  4860.                     'destinationId' => $proposalControl->getDestinationId(),
  4861.                     'language' => $proposal->getLanguage()
  4862.                 )
  4863.             );
  4864.             $data_destionation[$destino->getTitle()] = array(
  4865.                 'destino' => $destino,
  4866.                 'gallery' => $gallery,
  4867.                 'description' => $description,
  4868.             );
  4869.         }
  4870.         $document $em->getRepository(ProposalDocument::class)->findBy(
  4871.             array('proposalId' => $proposal->getId())
  4872.         );
  4873.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  4874.         $agentMaster = array();
  4875.         if (!empty($proposal->getAgentId())) {
  4876.             $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  4877.             $agentMaster = array(
  4878.                 'name' => $agent->getName(),
  4879.                 'lastname' => $agent->getLastname(),
  4880.                 'picture' => $agent->getPicture(),
  4881.             );
  4882.         }
  4883.         $parametersNew = array(
  4884.             'proposalId' => $proposal->getId(),
  4885.             'recommended' => '0',
  4886.             'priority' => '0',
  4887.         );
  4888.         $dqlNew 'SELECT p
  4889.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  4890.                     WHERE p.proposalId = :proposalId 
  4891.                     AND p.recommended = :recommended
  4892.                     AND p.priority != :priority
  4893.                     ORDER BY p.priority ASC';
  4894.         $queryNew $em->createQuery($dqlNew)->setParameters($parametersNew);
  4895.         $controlbudgetsNew $queryNew->getResult();
  4896.         //d($proposal, $client, $company, $data_destionation);
  4897.         $sidebarData $this->sidebarAction($token"""");
  4898.         return $this->render(
  4899.             'MDS/EventsPresentationBundle/presentation/document.html.twig',
  4900.             array(
  4901.                 'token' => $token,
  4902.                 'company' => $company,
  4903.                 'proposal' => $proposal,
  4904.                 'client' => $client,
  4905.                 'selectType' => $selectType,
  4906.                 'destination' => $data_destionation,
  4907.                 'budgetNew' => $controlbudgetsNew,
  4908.                 'document' => $document,
  4909.                 'countDestino' => $cont_destino,
  4910.                 'sidebar' => $sidebarData,
  4911.                 'agent' => $agentMaster,
  4912.                 //                'agendas' => $showAgenda,
  4913.             )
  4914.         );
  4915.     }
  4916.     /**
  4917.      * @Route("/esp-detail/{type}/{idd}/{idi}/{token}", name="presentation_idea_view_detail_token")
  4918.      */
  4919.     public function ideaViewDetailAction($type$token$idd$idiRequest $request)
  4920.     {
  4921.         //        $type='idea';
  4922.         $em $this->getDoctrine()->getManager();
  4923.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  4924.         if ($proposal->getStatus() == "Cancel") {
  4925.             return $this->redirectToRoute(
  4926.                 'presentation_error_cancel',
  4927.                 array(
  4928.                     'token' => $token
  4929.                 )
  4930.             );
  4931.         }
  4932.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4933.         // Usuario Anonimo es = "anon."
  4934.         if ($user_logueado == "anon.") {
  4935.             $proposal->setViewedAt(new \DateTime("now"));
  4936.             $em->persist($proposal);
  4937.             $em->flush();
  4938.         }
  4939.         if (is_null($proposal->getSelectType())) {
  4940.             $selectType = array();
  4941.         } else {
  4942.             $selectType explode(","$proposal->getSelectType());
  4943.         }
  4944.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  4945.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  4946.             array(
  4947.                 'proposalId' => $proposal->getId(),
  4948.                 'disabled' => '0',
  4949.             )
  4950.         );
  4951.         $data_destionation = array();
  4952.         $cont_destino 0;
  4953.         foreach ($proposal_Control as $proposalControl) {
  4954.             $cont_destino += 1;
  4955.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  4956.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  4957.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  4958.                 array(
  4959.                     'destinationId' => $proposalControl->getDestinationId(),
  4960.                     'language' => $proposal->getLanguage()
  4961.                 )
  4962.             );
  4963.             $data_destionation[$destino->getTitle()] = array(
  4964.                 'destino' => $destino,
  4965.                 'gallery' => $gallery,
  4966.                 'description' => $description,
  4967.             );
  4968.         }
  4969.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  4970.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4971.         /* INICIO CONTENIDO DEL MI PRESUPUESTO                                                           */
  4972.         ////////////////////////////////////////////////////////////////////////////////////////////////
  4973.         $typeM strtoupper($type);
  4974.         $ideas_services = array();
  4975.         $activities_services = array();
  4976.         $supplier_services = array();
  4977.         if ($type == "idea") {
  4978.             $ideas $em->getRepository(Ideas::class)->findOneBy(
  4979.                 array(
  4980.                     'id' => $idi
  4981.                 )
  4982.             );
  4983.             if (!is_null($ideas)) {
  4984.                 $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($idi);
  4985.                 $id $controlgeneral->getId();
  4986.                 $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  4987.                     array(
  4988.                         'supplierId' => $id,
  4989.                         'servicesCatId' => '0',
  4990.                         'servicesId' => '0',
  4991.                     )
  4992.                 );
  4993.                 $descriptionSupplier $em->getRepository(SupplierDescription::class)->findOneBy(
  4994.                     array(
  4995.                         'supplierId' => $id,
  4996.                         'language' => $proposal->getLanguage()
  4997.                     )
  4998.                 );
  4999.                 $data_idea = array(
  5000.                     'datos' => $ideas,
  5001.                     'gallery' => $gallerySupplier,
  5002.                     'description' => $descriptionSupplier,
  5003.                 );
  5004.                 $ideas_services = array(
  5005.                     'ideas' => $data_idea,
  5006.                 );
  5007.             }
  5008.         }
  5009.         if ($type == "activity") {
  5010.             $activities $em->getRepository(Activities::class)->findOneBy(
  5011.                 array(
  5012.                     'id' => $idi
  5013.                 )
  5014.             );
  5015.             if (!is_null($activities)) {
  5016.                 $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($idi);
  5017.                 $id $controlgeneral->getId();
  5018.                 $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5019.                     array(
  5020.                         'supplierId' => $id,
  5021.                         'servicesCatId' => '0',
  5022.                         'servicesId' => '0',
  5023.                     )
  5024.                 );
  5025.                 $descriptionSupplier $em->getRepository(SupplierDescription::class)->findOneBy(
  5026.                     array(
  5027.                         'supplierId' => $id,
  5028.                         'language' => $proposal->getLanguage()
  5029.                     )
  5030.                 );
  5031.                 $data_activity = array(
  5032.                     'datos' => $activities,
  5033.                     'gallery' => $gallerySupplier,
  5034.                     'description' => $descriptionSupplier,
  5035.                 );
  5036.                 $activities_services = array(
  5037.                     'activities' => $data_activity,
  5038.                 );
  5039.             }
  5040.         }
  5041.         $data = array(
  5042.             'type' => $typeM,
  5043.             'ideas' => $ideas_services,
  5044.             'activities' => $activities_services,
  5045.             'supplier' => $supplier_services
  5046.         );
  5047.         ////////////////////////////////////////////////////////////////////////////////////////////////
  5048.         /* FIN CONTENIDO DEL MI PRESUPUESTO                                                              */
  5049.         ////////////////////////////////////////////////////////////////////////////////////////////////
  5050.         //////////////////////////////////////////////
  5051.         /* CODIGO PARA TRAER A LOS AGENTES         */
  5052.         ////////////////////////////////////////////
  5053.         $agentMaster = array();
  5054.         if (!empty($proposal->getAgentId())) {
  5055.             $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  5056.             $agentMaster = array(
  5057.                 'name' => $agent->getName(),
  5058.                 'lastname' => $agent->getLastname(),
  5059.                 'picture' => $agent->getPicture(),
  5060.             );
  5061.         }
  5062.         ////////////////////////////////////////////
  5063.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  5064.         //////////////////////////////////////////
  5065.         $sidebarData $this->sidebarAction($token$typeM$idd);
  5066.         //d($data,$selectType);
  5067.         return $this->render(
  5068.             'MDS/EventsPresentationBundle/presentation/service-detail-client.html.twig',
  5069.             array(
  5070.                 'token' => $token,
  5071.                 'company' => $company,
  5072.                 'proposal' => $proposal,
  5073.                 'client' => $client,
  5074.                 'selectType' => $selectType,
  5075.                 'destination' => $data_destionation,
  5076.                 'countDestino' => $cont_destino,
  5077.                 'agent' => $agentMaster,
  5078.                 'data' => $data,
  5079.                 'activity' => $activities_services,
  5080.                 'idea' => $ideas_services,
  5081.                 'sidebar' => $sidebarData,
  5082.                 //                'agendas' => $showAgenda,
  5083.             )
  5084.         );
  5085.     }
  5086.     /**
  5087.      * @Route("/service-detail-ajax/{type}/{idd}/{ids}/{token}", name="presentation_services_detail_ajax")
  5088.      */
  5089.     public function ajaxServicesDetailAction($token$type$idd$idsRequest $request)
  5090.     {
  5091.         $em $this->getDoctrine()->getManager();
  5092.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  5093.         if ($proposal->getStatus() == "Cancel") {
  5094.             return $this->redirectToRoute(
  5095.                 'presentation_error_cancel',
  5096.                 array(
  5097.                     'token' => $token
  5098.                 )
  5099.             );
  5100.         }
  5101.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5102.         // Usuario Anonimo es = "anon."
  5103.         if ($user_logueado == "anon.") {
  5104.             $proposal->setViewedAt(new \DateTime("now"));
  5105.             $em->persist($proposal);
  5106.             $em->flush();
  5107.         }
  5108.         if (is_null($proposal->getSelectType())) {
  5109.             $selectType = array();
  5110.         } else {
  5111.             $selectType explode(","$proposal->getSelectType());
  5112.         }
  5113.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  5114.             array(
  5115.                 'proposalId' => $proposal->getId(),
  5116.                 'disabled' => '0',
  5117.             )
  5118.         );
  5119.         $data_destionation = array();
  5120.         $cont_destino 0;
  5121.         foreach ($proposal_Control as $proposalControl) {
  5122.             $cont_destino += 1;
  5123.             $destino $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  5124.             $gallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  5125.             $description $em->getRepository(DestinationDescription::class)->findOneBy(
  5126.                 array(
  5127.                     'destinationId' => $proposalControl->getDestinationId(),
  5128.                     'language' => $proposal->getLanguage()
  5129.                 )
  5130.             );
  5131.             $data_destionation[$destino->getTitle()] = array(
  5132.                 'destino' => $destino,
  5133.                 'gallery' => $gallery,
  5134.                 'description' => $description,
  5135.             );
  5136.         }
  5137.         $typeStr str_replace("-"" "$type);
  5138.         $typeM strtoupper($typeStr);
  5139.         $controlservices $em->getRepository(ProposalSupplierControl::class)->findBy(
  5140.             array(
  5141.                 'destinoId' => $idd,
  5142.                 'proposalId' => $proposal->getId(),
  5143.                 'disabled' => '0',
  5144.             )
  5145.         );
  5146.         $ideas_services = array();
  5147.         $supplier_services = array();
  5148.         $data_supplier = array();
  5149.         $data = array();
  5150.         foreach ($controlservices as $controlServicesProposal) {
  5151.             if (is_null($controlServicesProposal->getIdeaId()) && $type != "idea" && $controlServicesProposal->getSupplierId() != "0") {
  5152.                 //                d($controlServicesProposal);
  5153.                 /*consulta Proveedor*/
  5154.                 $supplier $em->getRepository(Supplier::class)->findOneBy(
  5155.                     array(
  5156.                         'id' => $controlServicesProposal->getSupplierId(),
  5157.                         'type' => $typeM,
  5158.                     )
  5159.                 );
  5160.                 //d($supplier);
  5161.                 if (!is_null($supplier)) {
  5162.                     //d($typeM);
  5163.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
  5164.                     $id $controlgeneral->getId();
  5165.                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5166.                         array(
  5167.                             'supplierId' => $id,
  5168.                             'servicesCatId' => '0',
  5169.                             'servicesId' => '0',
  5170.                         )
  5171.                     );
  5172.                     $descriptionSupplier $em->getRepository(SupplierDescription::class)->findOneBy(
  5173.                         array(
  5174.                             'supplierId' => $id,
  5175.                             'language' => $proposal->getLanguage()
  5176.                         )
  5177.                     );
  5178.                     $data_supplier = array(
  5179.                         'datos' => $supplier,
  5180.                         'gallery' => $gallerySupplier,
  5181.                         'description' => $descriptionSupplier,
  5182.                     );
  5183.                     //                    d($data_supplier);
  5184.                     /*consulta Hoteles para salones*/
  5185.                     //
  5186.                     $services $em->getRepository(ProposalSupplierServices::class)->findBy(
  5187.                         array(
  5188.                             'controlId' => $controlServicesProposal->getId(),
  5189.                             'supplierId' => $controlServicesProposal->getSupplierId(),
  5190.                             //                            'serviceCatId' => $idcat,
  5191.                         )
  5192.                     );
  5193.                     //d($services);
  5194.                     $servicesArray = array();
  5195.                     foreach ($services as $servicesSupplier) {
  5196.                         /*consulta Lounge*/
  5197.                         // d($typeM);
  5198.                         if (
  5199.                             $servicesSupplier->getServiceId() != "0" &&
  5200.                             (
  5201.                                 $typeM == "RESTAURANTE" or
  5202.                                 $typeM == "HOTEL" or
  5203.                                 $typeM == "HOTEL URBANO PERIFERIA" or
  5204.                                 $typeM == "HOTEL DE COSTA" or
  5205.                                 $typeM == "HOTEL URBANO DENTRO DE LA CIUDAD" or
  5206.                                 $typeM == "HOTEL URBANO CÉNTRICO" or
  5207.                                 $typeM == "SALON" or
  5208.                                 $typeM == "LUGARES DE EVENTOS"
  5209.                             )
  5210.                         ) {
  5211.                             $idcat '10'// Lounge
  5212.                             $servicesSup $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  5213.                             if (!is_null($servicesSup)) {
  5214.                                 $controlSup $em->getRepository(SupplierServicesControl::class)->findOneBy(
  5215.                                     array(
  5216.                                         'servicesId' => $servicesSup->getId(),
  5217.                                         'servicesCat' => $idcat,
  5218.                                     )
  5219.                                 );
  5220.                                 $servicesGallery $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  5221.                                 $servicesDescription $em->getRepository(SupplierServicesDescription::class)->findBy(
  5222.                                     array(
  5223.                                         'servicesId' => $servicesSup->getId(),
  5224.                                         'controlId' => $servicesSupplier->getServiceId(),
  5225.                                         'language' => $proposal->getLanguage()
  5226.                                     )
  5227.                                 );
  5228.                                 //paquete de tipo
  5229.                                 $serviceCapacity $em->getRepository('App:SupplierLoungeCapacity')->findBy(array('serviceId' => $servicesSup->getId()));
  5230.                                 if (!empty($serviceCapacity)) {
  5231.                                     foreach ($serviceCapacity as $item) {
  5232.                                         switch ($item->getType()) {
  5233.                                             case 1:
  5234.                                                 $item->setType("Teatro");
  5235.                                                 break;
  5236.                                             case 2:
  5237.                                                 $item->setType("Cocktail");
  5238.                                                 break;
  5239.                                             case 3:
  5240.                                                 $item->setType("Banquete");
  5241.                                                 break;
  5242.                                             case 4:
  5243.                                                 $item->setType("Imperial");
  5244.                                                 break;
  5245.                                             case 5:
  5246.                                                 $item->setType("Montaje en U");
  5247.                                                 break;
  5248.                                             case 6:
  5249.                                                 $item->setType("Cabaret");
  5250.                                                 break;
  5251.                                             case 0:
  5252.                                                 $item->setType("Escuela");
  5253.                                                 break;
  5254.                                         }
  5255.                                         //
  5256.                                     }
  5257.                                 } else {
  5258.                                     $serviceCapacity = array();
  5259.                                 }
  5260.                                 /* ARMO EL CONTENIDO GLOBAL */
  5261.                                 $servicesArray[$servicesSup->getId()] = array(
  5262.                                     'services' => $servicesSup,
  5263.                                     'gallery' => $servicesGallery,
  5264.                                     'descripcion' => $servicesDescription,
  5265.                                     'capacity' => $serviceCapacity,
  5266.                                 );
  5267.                                 //d($typeM);
  5268.                             }
  5269.                         }
  5270.                     }
  5271.                     // d($data_supplier);
  5272.                     if ($data_supplier['datos']->getId() == $ids) {
  5273.                         $supplier_services[] = array(
  5274.                             'supplier' => $data_supplier,
  5275.                             'services' => $servicesArray,
  5276.                         );
  5277.                     }
  5278.                 }
  5279.             }
  5280.             $data = array(
  5281.                 'type' => $typeM,
  5282.                 'ideas' => $ideas_services,
  5283.                 'supplier' => $supplier_services
  5284.             );
  5285.         }
  5286.         //d($data);
  5287.         $response_body = array(
  5288.             'token' => $token,
  5289.             'selectType' => $selectType,
  5290.             'countDestino' => $cont_destino,
  5291.             'data' => $data,
  5292.             'idd' => $idd,
  5293.             'idea' => '',
  5294.             'activity' => '',
  5295.         );
  5296.         $serializer SerializerBuilder::create()->build();
  5297.         $array $serializer->toArray($response_body);
  5298.         $response = new JsonResponse($array);
  5299.         return $response;
  5300.     }
  5301.     /**
  5302.      * @Route("/type-ajax/{idd}/{token}", name="presentation_type_ajax")
  5303.      */
  5304.     public function ServicesViewAjaxDetailAction($token$iddRequest $request)
  5305.     {
  5306.         $em $this->getDoctrine()->getManager();
  5307.         $type '';
  5308.         $sidebarData $this->sidebarAction($token$type$idd);
  5309.         ////////////////////////////////////////////
  5310.         /* FIN CODIGO PARA TRAER A LOS AGENTES   */
  5311.         //////////////////////////////////////////
  5312.         //d($data);
  5313.         $response_body = array(
  5314.             'token' => $token,
  5315.             'selectType' => $type,
  5316.             'idd' => $idd,
  5317.             'sidebar' => $sidebarData,
  5318.         );
  5319.         $serializer SerializerBuilder::create()->build();
  5320.         $array $serializer->toArray($response_body);
  5321.         $response = new JsonResponse($array);
  5322.         return $response;
  5323.     }
  5324.     /**
  5325.      * @Route("/services/{type}/{token}", name="presentation_services_view_token")
  5326.      */
  5327.     public function ServicesViewAction($token$typeRequest $request)
  5328.     {
  5329.         //Services
  5330.         $em $this->getDoctrine()->getManager();
  5331.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  5332.         if ($proposal->getStatus() == "Cancel") {
  5333.             return $this->redirectToRoute(
  5334.                 'presentation_error_cancel',
  5335.                 array(
  5336.                     'token' => $token
  5337.                 )
  5338.             );
  5339.         }
  5340.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5341.         // Usuario Anonimo es = "anon."
  5342.         if ($user_logueado == "anon.") {
  5343.             $proposal->setViewedAt(new \DateTime("now"));
  5344.             $em->persist($proposal);
  5345.             $em->flush();
  5346.         }
  5347.         if (is_null($proposal->getSelectType())) {
  5348.             $selectType = array();
  5349.         } else {
  5350.             $selectType explode(","$proposal->getSelectType());
  5351.         }
  5352.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  5353.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  5354.             array(
  5355.                 'proposalId' => $proposal->getId(),
  5356.                 'disabled' => '0',
  5357.             )
  5358.         );
  5359.         switch ($type) {
  5360.             case 1:
  5361.                 $nameType "hotel";
  5362.                 $transType strtoupper($this->translator->trans("Hotel"));
  5363.                 $varType "1";
  5364.                 $viewGroupService "1";
  5365.                 break;
  5366.             case 2:
  5367.                 $nameType "restaurante";
  5368.                 $transType strtoupper($this->translator->trans("Restaurant"));
  5369.                 $varType "2";
  5370.                 $viewGroupService "1";
  5371.                 break;
  5372.             case 3:
  5373.                 $nameType "actividad";
  5374.                 $transType strtoupper($this->translator->trans("Activities"));
  5375.                 $varType "3";
  5376.                 $viewGroupService "0";
  5377.                 break;
  5378.             case 4:
  5379.                 $nameType "idea";
  5380.                 $transType strtoupper($this->translator->trans("Ideas"));
  5381.                 $varType "4";
  5382.                 $viewGroupService "0";
  5383.                 break;
  5384.             case 5:
  5385.                 $nameType "audiovisual";
  5386.                 $transType strtoupper($this->translator->trans("Audiovisual"));
  5387.                 $varType "5";
  5388.                 $viewGroupService "1";
  5389.                 break;
  5390.             case 6:
  5391.                 $nameType "tecnologia";
  5392.                 $transType strtoupper($this->translator->trans("Technology Services"));
  5393.                 $varType "6";
  5394.                 $viewGroupService "1";
  5395.                 break;
  5396.             case 7:
  5397.                 $nameType "lugares de eventos";
  5398.                 $transType strtoupper($this->translator->trans("Places of Events"));
  5399.                 $varType "7";
  5400.                 $viewGroupService "1";
  5401.                 break;
  5402.             case 8:
  5403.                 $nameType "otros";
  5404.                 $transType strtoupper($this->translator->trans("Others"));
  5405.                 $varType "8";
  5406.                 $viewGroupService "0";
  5407.                 break;
  5408.             case 9:
  5409.                 $nameType "catering";
  5410.                 $transType strtoupper($this->translator->trans("Catering"));
  5411.                 $varType "9";
  5412.                 $viewGroupService "0";
  5413.                 break;
  5414.             case 10:
  5415.                 $nameType "excursiones";
  5416.                 $transType strtoupper($this->translator->trans("Excursions"));
  5417.                 $varType "10";
  5418.                 $viewGroupService "0";
  5419.                 break;
  5420.             case 11:
  5421.                 $nameType "musica";
  5422.                 $transType strtoupper($this->translator->trans("Music"));
  5423.                 $varType "11";
  5424.                 $viewGroupService "0";
  5425.                 break;
  5426.             case 12:
  5427.                 $nameType "actividades";
  5428.                 $transType strtoupper($this->translator->trans("Activities"));
  5429.                 $varType "12";
  5430.                 $viewGroupService "0";
  5431.                 break;
  5432.             case 13:
  5433.                 $nameType "cruceros";
  5434.                 $transType strtoupper($this->translator->trans("Cruise ships"));
  5435.                 $varType "13";
  5436.                 $viewGroupService "0";
  5437.                 break;
  5438.             case 14:
  5439.                 $nameType "guias";
  5440.                 $transType strtoupper($this->translator->trans("Guides"));
  5441.                 $varType "14";
  5442.                 $viewGroupService "0";
  5443.                 break;
  5444.             case 15:
  5445.                 $nameType "entretenimiento ";
  5446.                 $transType strtoupper($this->translator->trans("Entertainment"));
  5447.                 $varType "15";
  5448.                 $viewGroupService "0";
  5449.                 break;
  5450.             case 16:
  5451.                 $nameType "salon ";
  5452.                 $transType strtoupper($this->translator->trans("Lounge"));
  5453.                 $varType "16";
  5454.                 $viewGroupService "0";
  5455.                 break;
  5456.             case 17:
  5457.                 $nameType "transporte ";
  5458.                 $transType strtoupper($this->translator->trans("Transport"));
  5459.                 $varType "17";
  5460.                 $viewGroupService "0";
  5461.                 break;
  5462.             case 18:
  5463.                 $nameType "regalos ";
  5464.                 $transType strtoupper($this->translator->trans("Gifts"));
  5465.                 $varType "18";
  5466.                 $viewGroupService "0";
  5467.                 break;
  5468.             case 19:
  5469.                 $nameType "itinerarios ";
  5470.                 $transType strtoupper($this->translator->trans("Itineraries"));
  5471.                 $varType "19";
  5472.                 $viewGroupService "0";
  5473.                 break;
  5474.             default:
  5475.                 break;
  5476.                 //crear los demas numero por servicos
  5477.         }
  5478.         $typeM strtoupper($nameType);
  5479.         //        $typeM = strtoupper($type);
  5480.         //        $transType = $type;
  5481.         $controlservices $em->getRepository(ProposalSupplierControl::class)->findBy(
  5482.             array(
  5483.                 //                'destinoId' => $idd,
  5484.                 'proposalId' => $proposal->getId(),
  5485.                 'disabled' => '0',
  5486.             )
  5487.         );
  5488.         $data_idea = array();
  5489.         $data_supplier = array();
  5490.         $data_all = array();
  5491.         $data = array();
  5492.         $servicesArray = array();
  5493.         foreach ($controlservices as $controlServicesProposal) {
  5494.             if (!is_null($controlServicesProposal->getIdeaId()) && $nameType == "idea") {
  5495.                 //                d('idea');
  5496.                 /* IDEA  */
  5497.                 /*consulta Proveedor*/
  5498.                 $ideas $em->getRepository(Ideas::class)->findOneBy(
  5499.                     array(
  5500.                         'id' => $controlServicesProposal->getIdeaId()
  5501.                     )
  5502.                 );
  5503.                 //                d($ideas);
  5504.                 if (!is_null($ideas)) {
  5505.                     if ($ideas->getDestinationId() != 0) {
  5506.                         $ideasDestination $em->getRepository(Destination::class)->findOneById($ideas->getDestinationId());
  5507.                         $citiesData $em->getRepository(Cities::class)->findOneById($ideasDestination->getPopulation());
  5508.                         $cities $citiesData->getCity();
  5509.                     } else {
  5510.                         $cities null;
  5511.                     }
  5512.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($controlServicesProposal->getIdeaId());
  5513.                     $id $controlgeneral->getId();
  5514.                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5515.                         array(
  5516.                             'supplierId' => $id,
  5517.                             'servicesCatId' => '0',
  5518.                             'servicesId' => '0',
  5519.                         )
  5520.                     );
  5521.                     $descriptionSupplier $em->getRepository(SupplierDescription::class)->findOneBy(
  5522.                         array(
  5523.                             'supplierId' => $id,
  5524.                             'language' => $proposal->getLanguage()
  5525.                         )
  5526.                     );
  5527.                     $data_all[] = array(
  5528.                         'id' => $ideas->getId(),
  5529.                         'name' => $ideas->getName(),
  5530.                         'img' => $gallerySupplier['0'],
  5531.                         'cities' => $cities,
  5532.                         'type' => $typeM,
  5533.                         'typeajax' => "idea",
  5534.                         'gallery' => $gallerySupplier,
  5535.                         'description' => $descriptionSupplier,
  5536.                         'services' => null,
  5537.                         'ids' => $varType,
  5538.                         //                        'idd' => $ideasDestination,
  5539.                         'viewGroupService' => $viewGroupService,
  5540.                     );
  5541.                 }
  5542.             }
  5543.             //Actividades
  5544.             if (!is_null($controlServicesProposal->getActivityId()) && $nameType == "actividad") {
  5545.                 //                d('idea');
  5546.                 /* IDEA  */
  5547.                 /*consulta Proveedor*/
  5548.                 $activities $em->getRepository(Activities::class)->findOneBy(
  5549.                     array(
  5550.                         'id' => $controlServicesProposal->getActivityId()
  5551.                     )
  5552.                 );
  5553.                 if (!is_null($activities)) {
  5554.                     //                    $activitiesDestination = $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
  5555.                     //                    $cities = $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
  5556.                     if ($activities->getDestinationId() != 0) {
  5557.                         $activitiesDestination $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
  5558.                         $citiesData $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
  5559.                         $cities $citiesData->getCity();
  5560.                     } else {
  5561.                         $cities null;
  5562.                     }
  5563.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($controlServicesProposal->getActivityId());
  5564.                     $id $controlgeneral->getId();
  5565.                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5566.                         array(
  5567.                             'supplierId' => $id,
  5568.                             'servicesCatId' => '0',
  5569.                             'servicesId' => '0',
  5570.                         )
  5571.                     );
  5572.                     $descriptionSupplier $em->getRepository(SupplierDescription::class)->findOneBy(
  5573.                         array(
  5574.                             'supplierId' => $id,
  5575.                             'language' => $proposal->getLanguage()
  5576.                         )
  5577.                     );
  5578.                     $data_all[] = array(
  5579.                         'id' => $activities->getId(),
  5580.                         'name' => $activities->getName(),
  5581.                         'img' => $gallerySupplier['0'],
  5582.                         'cities' => $cities,
  5583.                         'type' => $typeM,
  5584.                         'typeajax' => "actividad",
  5585.                         'gallery' => $gallerySupplier,
  5586.                         'description' => $descriptionSupplier,
  5587.                         'services' => null,
  5588.                         'ids' => $varType,
  5589.                         //                        'idd' => $activitiesDestination,
  5590.                         'viewGroupService' => $viewGroupService,
  5591.                     );
  5592.                 }
  5593.             }
  5594.             if (is_null($controlServicesProposal->getIdeaId()) && $nameType != "idea" && is_null($controlServicesProposal->getActivityId()) && $nameType != "actividad" && $controlServicesProposal->getSupplierId() != "0") {
  5595.                 //                d($controlServicesProposal);
  5596.                 /*consulta Proveedor*/
  5597.                 $supplier $em->getRepository(Supplier::class)->findOneBy(
  5598.                     array(
  5599.                         'id' => $controlServicesProposal->getSupplierId(),
  5600.                         'type' => $typeM,
  5601.                     )
  5602.                 );
  5603.                 if (!is_null($supplier)) {
  5604.                     /* OJO AQUI */
  5605.                     $cities $em->getRepository(Cities::class)->findOneById($supplier->getPopulation());
  5606.                     //d($typeM);
  5607.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
  5608.                     $id $controlgeneral->getId();
  5609.                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5610.                         array(
  5611.                             'supplierId' => $id,
  5612.                             'servicesCatId' => '0',
  5613.                             'servicesId' => '0',
  5614.                         )
  5615.                     );
  5616.                     $descriptionSupplier $em->getRepository(SupplierDescription::class)->findOneBy(
  5617.                         array(
  5618.                             'supplierId' => $id,
  5619.                             'language' => $proposal->getLanguage()
  5620.                         )
  5621.                     );
  5622.                     if ($varType == "5") {
  5623.                         $idcat '3';
  5624.                         /*consulta de los servicios del supplier*/
  5625.                         $services $em->getRepository(ProposalSupplierServices::class)->findBy(
  5626.                             array(
  5627.                                 'controlId' => $controlServicesProposal->getId(),
  5628.                                 'supplierId' => $controlServicesProposal->getSupplierId(),
  5629.                                 'serviceCatId' => $idcat,
  5630.                             )
  5631.                         );
  5632.                         foreach ($services as $servicesSupplier) {
  5633.                             $destino $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
  5634.                             /*consulta Lounge*/
  5635.                             //                             d($servicesSupplier);
  5636.                             if ($servicesSupplier->getServiceId() != "0") {
  5637.                                 //                            $idcat = '10'; // Lounge
  5638.                                 $servicesSup $em->getRepository(SupplierAv::class)->findOneBy(
  5639.                                     array(
  5640.                                         'id' => $servicesSupplier->getServiceId(),
  5641.                                         'responsible' => "RENDERS 3D",
  5642.                                     )
  5643.                                 );
  5644.                                 if (!empty($servicesSup)) {
  5645.                                     $controlSup $em->getRepository(SupplierServicesControl::class)->findOneBy(
  5646.                                         array(
  5647.                                             'servicesId' => $servicesSup->getId(),
  5648.                                             'servicesCat' => $idcat,
  5649.                                         )
  5650.                                     );
  5651.                                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  5652.                                     $servicesDescription $em->getRepository(SupplierServicesDescription::class)->findBy(
  5653.                                         array(
  5654.                                             'servicesId' => $servicesSup->getId(),
  5655.                                             'controlId' => $servicesSupplier->getServiceId(),
  5656.                                             'language' => $proposal->getLanguage()
  5657.                                         )
  5658.                                     );
  5659.                                 } else {
  5660.                                     $controlSup = array();
  5661.                                     $gallerySupplier = array();
  5662.                                     $servicesDescription = array();
  5663.                                 }
  5664.                                 //paquete de tipo
  5665.                                 $serviceCapacity = array();
  5666.                                 /* ARMO EL CONTENIDO GLOBAL */
  5667.                                 $servicesArray[] = array(
  5668.                                     'services' => $servicesSup,
  5669.                                     'gallery' => $gallerySupplier,
  5670.                                     'descripcion' => $servicesDescription,
  5671.                                     'capacity' => $serviceCapacity,
  5672.                                 );
  5673.                                 //d($typeM);
  5674.                                 //                                array_push($galleryNuevaSupplier, $servicesGallery);
  5675.                                 //                                d($servicesGallery);
  5676.                             }
  5677.                         }
  5678.                         //
  5679.                         $data_all[$supplier->getId()] = array(
  5680.                             'id' => $supplier->getId(),
  5681.                             'name' => $viewGroupService == "0" '' $supplier->getName(),
  5682.                             //                        'nameav' => $nameav,
  5683.                             'img' => empty($gallerySupplier) ? null $gallerySupplier['0'],
  5684.                             'cities' => $cities->getCity(),
  5685.                             'type' => $transType,
  5686.                             'typeajax' => "supplier",
  5687.                             'gallery' => $gallerySupplier,
  5688.                             'description' => null,
  5689.                             'services' => $servicesArray,
  5690.                             'ids' => $varType,
  5691.                             //                        'idd' => $destino,
  5692.                             'viewGroupService' => $viewGroupService,
  5693.                         );
  5694.                         //
  5695.                     } else {
  5696.                         $idcat '10';
  5697.                         /*consulta de los servicios del supplier*/
  5698.                         $services $em->getRepository(ProposalSupplierServices::class)->findBy(
  5699.                             array(
  5700.                                 'controlId' => $controlServicesProposal->getId(),
  5701.                                 'supplierId' => $controlServicesProposal->getSupplierId(),
  5702.                                 'serviceCatId' => $idcat,
  5703.                             )
  5704.                         );
  5705.                         $servicesArray = array();
  5706.                         foreach ($services as $servicesSupplier) {
  5707.                             $destino $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
  5708.                             /*consulta Lounge*/
  5709.                             // d($typeM);
  5710.                             if ($servicesSupplier->getServiceId() != "0") {
  5711.                                 //                            $idcat = '10'; // Lounge
  5712.                                 $servicesSup $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  5713.                                 $controlSup $em->getRepository(SupplierServicesControl::class)->findOneBy(
  5714.                                     array(
  5715.                                         'servicesId' => $servicesSup->getId(),
  5716.                                         'servicesCat' => $idcat,
  5717.                                     )
  5718.                                 );
  5719.                                 //                                d($servicesSup,$idcat,$controlSup);
  5720.                                 $servicesGallery $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  5721.                                 $servicesDescription $em->getRepository(SupplierServicesDescription::class)->findBy(
  5722.                                     array(
  5723.                                         'servicesId' => $servicesSup->getId(),
  5724.                                         'controlId' => $servicesSupplier->getServiceId(),
  5725.                                         'language' => $proposal->getLanguage()
  5726.                                     )
  5727.                                 );
  5728.                                 //                                d($servicesSup,$servicesGallery);
  5729.                                 //paquete de tipo
  5730.                                 $serviceCapacity $em->getRepository('App:SupplierLoungeCapacity')->findByServiceId($servicesSup->getId());
  5731.                                 foreach ($serviceCapacity as $item) {
  5732.                                     switch ($item->getType()) {
  5733.                                         case 1:
  5734.                                             $item->setType("Teatro");
  5735.                                             break;
  5736.                                         case 2:
  5737.                                             $item->setType("Cocktail");
  5738.                                             break;
  5739.                                         case 3:
  5740.                                             $item->setType("Banquete");
  5741.                                             break;
  5742.                                         case 4:
  5743.                                             $item->setType("Imperial");
  5744.                                             break;
  5745.                                         case 5:
  5746.                                             $item->setType("Montaje en U");
  5747.                                             break;
  5748.                                         case 6:
  5749.                                             $item->setType("Cabaret");
  5750.                                             break;
  5751.                                         case 0:
  5752.                                             $item->setType("Escuela");
  5753.                                             break;
  5754.                                     }
  5755.                                     //
  5756.                                 }
  5757.                                 /* ARMO EL CONTENIDO GLOBAL */
  5758.                                 $servicesArray[] = array(
  5759.                                     'services' => $servicesSup,
  5760.                                     'gallery' => $servicesGallery,
  5761.                                     'descripcion' => $servicesDescription,
  5762.                                     'capacity' => $serviceCapacity,
  5763.                                 );
  5764.                                 //d($typeM);
  5765.                             }
  5766.                         }
  5767.                         $data_all[$supplier->getId()] = array(
  5768.                             'id' => $supplier->getId(),
  5769.                             'name' => $viewGroupService == "0" '' $supplier->getName(),
  5770.                             //                        'nameav' => $nameav,
  5771.                             'img' => empty($gallerySupplier) ? null $gallerySupplier['0'],
  5772.                             'cities' => $cities->getCity(),
  5773.                             'type' => $transType,
  5774.                             'typeajax' => "supplier",
  5775.                             'gallery' => $gallerySupplier,
  5776.                             'description' => $descriptionSupplier,
  5777.                             'services' => $servicesArray,
  5778.                             'ids' => $varType,
  5779.                             //                        'idd' => $destino,
  5780.                             'viewGroupService' => $viewGroupService,
  5781.                         );
  5782.                         //                        $descriptionSupplierexter[] = $descriptionSupplier->getDescription();
  5783.                     }
  5784.                 }
  5785.             }
  5786.         }
  5787.         //d($descriptionSupplierexter);
  5788.         //        d($data_all);
  5789.         //        exit();
  5790.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  5791.         return $this->render(
  5792.             'MDS/EventsPresentationBundle/presentation/services.html.twig',
  5793.             array(
  5794.                 'token' => $token,
  5795.                 'type' => $transType,
  5796.                 'company' => $company,
  5797.                 'proposal' => $proposal,
  5798.                 'client' => $client,
  5799.                 'selectType' => $selectType,
  5800.                 'data' => $data_all,
  5801.             )
  5802.         );
  5803.     }
  5804.     /**
  5805.      * @Route("/services-ajax/{id}/{type}/{ssi}/{token}", name="presentation_services_view_token_ajax")
  5806.      */
  5807.     public function ServicesAjaxViewAction($token$type$id$ssiRequest $request)
  5808.     {
  5809.         //  var_dump($token, "",  $type,"",  $id, "", $ssi);die();
  5810.         $em $this->getDoctrine()->getManager();
  5811.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  5812.         if ($proposal->getStatus() == "Cancel") {
  5813.             return $this->redirectToRoute(
  5814.                 'presentation_error_cancel',
  5815.                 array(
  5816.                     'token' => $token
  5817.                 )
  5818.             );
  5819.         }
  5820.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5821.         // Usuario Anonimo es = "anon."
  5822.         if ($user_logueado == "anon.") {
  5823.             $proposal->setViewedAt(new \DateTime("now"));
  5824.             $em->persist($proposal);
  5825.             $em->flush();
  5826.         }
  5827.         if (is_null($proposal->getSelectType())) {
  5828.             $selectType = array();
  5829.         } else {
  5830.             $selectType explode(","$proposal->getSelectType());
  5831.         }
  5832.         if ($type == "idea") {
  5833.             $controlservices $em->getRepository(ProposalSupplierControl::class)->findBy(
  5834.                 array(
  5835.                     'proposalId' => $proposal->getId(),
  5836.                     'ideaId' => $id,
  5837.                 )
  5838.             );
  5839.         }
  5840.         if ($type == "actividad") {
  5841.             $controlservices $em->getRepository(ProposalSupplierControl::class)->findBy(
  5842.                 array(
  5843.                     'proposalId' => $proposal->getId(),
  5844.                     'activityId' => $id,
  5845.                 )
  5846.             );
  5847.         }
  5848.         if ($type == "supplier") {
  5849.             $controlservices $em->getRepository(ProposalSupplierControl::class)->findBy(
  5850.                 array(
  5851.                     'proposalId' => $proposal->getId(),
  5852.                     'supplierId' => $id,
  5853.                 )
  5854.             );
  5855.         }
  5856.         $data_idea = array();
  5857.         $data_supplier = array();
  5858.         $data_all = array();
  5859.         $data = array();
  5860.         foreach ($controlservices as $controlServicesProposal) {
  5861.             if (!is_null($controlServicesProposal->getIdeaId()) && $type == "idea") {
  5862.                 //                d('idea');
  5863.                 /* IDEA  */
  5864.                 /*consulta Proveedor*/
  5865.                 $ideas $em->getRepository(Ideas::class)->findOneBy(
  5866.                     array(
  5867.                         'id' => $controlServicesProposal->getIdeaId()
  5868.                     )
  5869.                 );
  5870.                 if (!is_null($ideas)) {
  5871.                     $ideasDestination $em->getRepository(Destination::class)->findOneById($ideas->getDestinationId());
  5872.                     $cities $em->getRepository(Cities::class)->findOneById($ideasDestination->getPopulation());
  5873.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($controlServicesProposal->getIdeaId());
  5874.                     $id $controlgeneral->getId();
  5875.                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5876.                         array(
  5877.                             'supplierId' => $id,
  5878.                             'servicesCatId' => '0',
  5879.                             'servicesId' => '0',
  5880.                         )
  5881.                     );
  5882.                     $descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
  5883.                         array(
  5884.                             'supplierId' => $id,
  5885.                             'language' => $proposal->getLanguage()
  5886.                         )
  5887.                     );
  5888.                     $data_all = array(
  5889.                         'id' => $ideas->getId(),
  5890.                         'name' => $ideas->getName(),
  5891.                         'gallery' => $gallerySupplier,
  5892.                         'description' => $descriptionSupplier,
  5893.                         'services' => null,
  5894.                     );
  5895.                 }
  5896.             }
  5897.             //Actividades
  5898.             if (!is_null($controlServicesProposal->getActivityId()) && $type == "actividad") {
  5899.                 //                d('idea');
  5900.                 /* IDEA  */
  5901.                 /*consulta Proveedor*/
  5902.                 $activities $em->getRepository(Activities::class)->findOneBy(
  5903.                     array(
  5904.                         'id' => $controlServicesProposal->getActivityId()
  5905.                     )
  5906.                 );
  5907.                 if (!is_null($activities)) {
  5908.                     $activitiesDestination $em->getRepository(Destination::class)->findOneById($activities->getDestinationId());
  5909.                     $cities $em->getRepository(Cities::class)->findOneById($activitiesDestination->getPopulation());
  5910.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($controlServicesProposal->getActivityId());
  5911.                     $id $controlgeneral->getId();
  5912.                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5913.                         array(
  5914.                             'supplierId' => $id,
  5915.                             'servicesCatId' => '0',
  5916.                             'servicesId' => '0',
  5917.                         )
  5918.                     );
  5919.                     $descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
  5920.                         array(
  5921.                             'supplierId' => $id,
  5922.                             'language' => $proposal->getLanguage()
  5923.                         )
  5924.                     );
  5925.                     $data_all = array(
  5926.                         'id' => $activities->getId(),
  5927.                         'name' => $activities->getName(),
  5928.                         'gallery' => $gallerySupplier,
  5929.                         'description' => $descriptionSupplier,
  5930.                         'services' => null,
  5931.                     );
  5932.                 }
  5933.             }
  5934.             if (is_null($controlServicesProposal->getIdeaId()) && $type != "idea" && is_null($controlServicesProposal->getActivityId()) && $type != "actividad" && $controlServicesProposal->getSupplierId() != "0") {
  5935.                 //                d($controlServicesProposal);
  5936.                 /*consulta Proveedor*/
  5937.                 $supplier $em->getRepository(Supplier::class)->findOneBy(
  5938.                     array(
  5939.                         'id' => $controlServicesProposal->getSupplierId(),
  5940.                     )
  5941.                 );
  5942.                 if (!is_null($supplier)) {
  5943.                     /* OJO AQUI */
  5944.                     $cities $em->getRepository(Cities::class)->findOneById($supplier->getPopulation());
  5945.                     //                    d($supplier);
  5946.                     //d($typeM);
  5947.                     $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($controlServicesProposal->getSupplierId());
  5948.                     $id $controlgeneral->getId();
  5949.                     $gallerySupplier $em->getRepository(SupplierGallery::class)->findBy(
  5950.                         array(
  5951.                             'supplierId' => $id,
  5952.                             'servicesCatId' => '0',
  5953.                             'servicesId' => '0',
  5954.                         )
  5955.                     );
  5956.                     $descriptionSupplier[] = $em->getRepository(SupplierDescription::class)->findOneBy(
  5957.                         array(
  5958.                             'supplierId' => $id,
  5959.                             'language' => $proposal->getLanguage()
  5960.                         )
  5961.                     );
  5962.                     //                    $idcat = '10';
  5963.                     /*consulta de los servicios del supplier*/
  5964.                     $services $em->getRepository(ProposalSupplierServices::class)->findBy(
  5965.                         array(
  5966.                             'controlId' => $controlServicesProposal->getId(),
  5967.                             'supplierId' => $controlServicesProposal->getSupplierId(),
  5968.                             //                            'serviceCatId' => $idcat,
  5969.                         )
  5970.                     );
  5971.                     $servicesArray = array();
  5972.                     if ($ssi == 1) {
  5973.                         foreach ($services as $servicesSupplier) {
  5974.                             ///////////////////////////////////////////
  5975.                             /// estoy aqui
  5976.                             /// /////////////
  5977.                             //                        d($servicesSupplier, $servicesSupplier->getServiceCatId() );
  5978.                             $destino $em->getRepository(Destination::class)->findOneById($servicesSupplier->getDestinationId());
  5979.                             /*consulta Lounge*/
  5980.                             // d($typeM);
  5981.                             if ($servicesSupplier->getServiceId() != "0") {
  5982.                                 //$idcat = '10'; // Lounge
  5983.                                 ///
  5984.                                 //                                $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  5985.                                 switch ($servicesSupplier->getServiceCatId()) {
  5986.                                     case 1:
  5987.                                         $servicesSup $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
  5988.                                         break;
  5989.                                     case 2:
  5990.                                         $servicesSup $em->getRepository(SupplierActivities::class)->findOneById($servicesSupplier->getServiceId());
  5991.                                         break;
  5992.                                     case 3:
  5993.                                         $servicesSup $em->getRepository(SupplierAv::class)->findOneById($servicesSupplier->getServiceId());
  5994.                                         break;
  5995.                                     case 4:
  5996.                                         $servicesSup $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
  5997.                                         break;
  5998.                                     case 5:
  5999.                                         $servicesSup $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
  6000.                                         break;
  6001.                                     case 6:
  6002.                                         $servicesSup $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
  6003.                                         break;
  6004.                                     case 7:
  6005.                                         $servicesSup $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
  6006.                                         break;
  6007.                                     case 8:
  6008.                                         $servicesSup $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
  6009.                                         break;
  6010.                                     case 9:
  6011.                                         $servicesSup $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
  6012.                                         break;
  6013.                                     case 10:
  6014.                                         $servicesSup $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  6015.                                         break;
  6016.                                     case 11:
  6017.                                         $servicesSup $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
  6018.                                         break;
  6019.                                     case 12:
  6020.                                         $servicesSup $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
  6021.                                         break;
  6022.                                     case 13:
  6023.                                         $servicesSup $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
  6024.                                         break;
  6025.                                     case 14:
  6026.                                         $servicesSup $em->getRepository(SupplierTechnology::class)->findOneById($servicesSupplier->getServiceId());
  6027.                                         break;
  6028.                                 }
  6029.                                 if (!empty($servicesSup)) {
  6030.                                     $controlSup $em->getRepository(SupplierServicesControl::class)->findOneBy(
  6031.                                         array(
  6032.                                             'servicesId' => $servicesSup->getId(),
  6033.                                             'servicesCat' => $servicesSupplier->getServiceCatId(),
  6034.                                             //                                            'servicesCat' => $idcat,
  6035.                                         )
  6036.                                     );
  6037.                                     $servicesGallery $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  6038.                                     foreach ($servicesGallery as $servicesga) {
  6039.                                         array_push($gallerySupplier$servicesga);
  6040.                                     }
  6041.                                     $servicesDescription[] = $em->getRepository(SupplierServicesDescription::class)->findOneBy(
  6042.                                         array(
  6043.                                             'servicesId' => $servicesSup->getId(),
  6044.                                             'controlId' => $controlSup->getId(),
  6045.                                             'language' => $proposal->getLanguage()
  6046.                                         )
  6047.                                     );
  6048.                                     $serviceCapacity = array();
  6049.                                     if ($servicesSupplier->getServiceCatId() == 10) {
  6050.                                         //paquete de tipo
  6051.                                         $serviceCapacityBase $em->getRepository('App:SupplierLoungeCapacity')->findByServiceId($servicesSup->getId());
  6052.                                         $serviceCapacity = array();
  6053.                                         if (!empty($serviceCapacityBase)) {
  6054.                                             foreach ($serviceCapacityBase as $item) {
  6055.                                                 switch ($item->getType()) {
  6056.                                                     case 1:
  6057.                                                         $item->setType("teatro");
  6058.                                                         break;
  6059.                                                     case 2:
  6060.                                                         $item->setType("cocktail");
  6061.                                                         break;
  6062.                                                     case 3:
  6063.                                                         $item->setType("banquete");
  6064.                                                         break;
  6065.                                                     case 4:
  6066.                                                         $item->setType("imperial");
  6067.                                                         break;
  6068.                                                     case 5:
  6069.                                                         $item->setType("montaje en U");
  6070.                                                         break;
  6071.                                                     case 6:
  6072.                                                         $item->setType("cabaret");
  6073.                                                         break;
  6074.                                                     case 0:
  6075.                                                         $item->setType("escuela");
  6076.                                                         break;
  6077.                                                 }
  6078.                                                 $serviceCapacity[] = $item;
  6079.                                             }
  6080.                                         }
  6081.                                         /* ARMO EL CONTENIDO GLOBAL */
  6082.                                         $servicesArray[] = array(
  6083.                                             'services' => $servicesSup,
  6084.                                             'gallery' => $servicesGallery,
  6085.                                             'descripcion' => $servicesDescription,
  6086.                                             'capacity' => $serviceCapacity,
  6087.                                         );
  6088.                                         //d($typeM);
  6089.                                     }
  6090.                                 }
  6091.                             }
  6092.                         }
  6093.                     }
  6094.                     $data_all = array(
  6095.                         'id' => $supplier->getId(),
  6096.                         'name' => $ssi == "0" '' $supplier->getName(),
  6097.                         'gallery' => $gallerySupplier,
  6098.                         'description' => is_null($descriptionSupplier['0']) ? $servicesDescription $descriptionSupplier,
  6099.                         'services' => $servicesArray,
  6100.                     );
  6101.                 }
  6102.             }
  6103.         }
  6104.         //        d($data_all);
  6105.         //        exit();
  6106.         $serializer SerializerBuilder::create()->build();
  6107.         $array $serializer->toArray($data_all);
  6108.         $response = new JsonResponse($array);
  6109.         return $response;
  6110.     }
  6111.     /**
  6112.      * @Route("/servicesview/{idcat}/{token}", name="presentation_services_view_all_token")
  6113.      */
  6114.     public function ServicesViewAllAction($token$idcatRequest $request)
  6115.     {
  6116.         //Suppliers
  6117.         $em $this->getDoctrine()->getManager();
  6118.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  6119.         if ($proposal->getStatus() == "Cancel") {
  6120.             return $this->redirectToRoute(
  6121.                 'presentation_error_cancel',
  6122.                 array(
  6123.                     'token' => $token
  6124.                 )
  6125.             );
  6126.         }
  6127.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  6128.         // Usuario Anonimo es = "anon."
  6129.         if ($user_logueado == "anon.") {
  6130.             $proposal->setViewedAt(new \DateTime("now"));
  6131.             $em->persist($proposal);
  6132.             $em->flush();
  6133.         }
  6134.         if (is_null($proposal->getSelectType())) {
  6135.             $selectType = array();
  6136.         } else {
  6137.             $selectType explode(","$proposal->getSelectType());
  6138.         }
  6139.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  6140.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  6141.             array(
  6142.                 'proposalId' => $proposal->getId(),
  6143.                 'disabled' => '0',
  6144.             )
  6145.         );
  6146.         /*consulta de los servicios del supplier*/
  6147.         $services $em->getRepository(ProposalSupplierServices::class)->findBy(
  6148.             array(
  6149.                 'proposalId' => $proposal->getId(),
  6150.                 'serviceCatId' => $idcat,
  6151.             )
  6152.         );
  6153.         $servicesArray = array();
  6154.         $transType "Not Available";
  6155.         if (!empty($services)) {
  6156.             foreach ($services as $servicesSupplier) {
  6157.                 $transType $this->translator->trans($servicesSupplier->getServiceCatName());
  6158.                 /*consulta Lounge*/
  6159.                 // d($typeM);
  6160.                 if ($servicesSupplier->getServiceId() != "0") {
  6161.                     //                            $idcat = '10'; // Lounge
  6162.                     //                            $servicesSup = $em->getRepository(SupplierLounge::class)->findOneById($servicesSupplier->getServiceId());
  6163.                     $nameServices "";
  6164.                     switch ($idcat) {
  6165.                         case 11:
  6166.                             $servicesSup $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
  6167.                             $nameServices $servicesSup->getTitle();
  6168.                             $transType $this->translator->trans("Menu");
  6169.                             $varCat "11";
  6170.                             break;
  6171.                         case 5:
  6172.                             $servicesSup $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
  6173.                             $nameServices $servicesSup->getTitle();
  6174.                             $transType $this->translator->trans("Cruise");
  6175.                             $varCat "5";
  6176.                             break;
  6177.                         case 6:
  6178.                             $servicesSup $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
  6179.                             $nameServices $servicesSup->getName();
  6180.                             $transType $this->translator->trans("Entertainment");
  6181.                             $varCat "6";
  6182.                             break;
  6183.                         case 4:
  6184.                             $servicesSup $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
  6185.                             $nameServices $servicesSup->getTitle();
  6186.                             $transType $this->translator->trans("Comunicación");
  6187.                             $varCat "4";
  6188.                             break;
  6189.                         case 7:
  6190.                             $servicesSup $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
  6191.                             $nameServices $servicesSup->getName();
  6192.                             $transType $this->translator->trans("Gifts");
  6193.                             $varCat "7";
  6194.                             break;
  6195.                         case 8:
  6196.                             $servicesSup $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
  6197.                             $nameServices $servicesSup->getName();
  6198.                             $transType $this->translator->trans("Guide");
  6199.                             $varCat "8";
  6200.                             break;
  6201.                         case 9:
  6202.                             $servicesSup $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
  6203.                             $nameServices $servicesSup->getTitle();
  6204.                             $transType $this->translator->trans("Itineraries");
  6205.                             $varCat "9";
  6206.                             break;
  6207.                         case 13:
  6208.                             $servicesSup $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
  6209.                             $nameServices $servicesSup->getName();
  6210.                             $transType $this->translator->trans("Transport");
  6211.                             $varCat "13";
  6212.                             break;
  6213.                         case 12:
  6214.                             $servicesSup $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
  6215.                             $nameServices $servicesSup->getName();
  6216.                             $transType $this->translator->trans("Others");
  6217.                             $varCat "12";
  6218.                             break;
  6219.                         case 1:
  6220.                             $servicesSup $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
  6221.                             $nameServices $servicesSup->getName();
  6222.                             $transType $this->translator->trans("Accommodation");
  6223.                             $varCat "1";
  6224.                             break;
  6225.                     }
  6226.                     $controlSup $em->getRepository(SupplierServicesControl::class)->findOneBy(
  6227.                         array(
  6228.                             'servicesId' => $servicesSup->getId(),
  6229.                             'servicesCat' => $idcat,
  6230.                         )
  6231.                     );
  6232.                     $servicesGallery $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  6233.                     $servicesDescription $em->getRepository(SupplierServicesDescription::class)->findBy(
  6234.                         array(
  6235.                             'servicesId' => $servicesSup->getId(),
  6236.                             'controlId' => $servicesSupplier->getServiceId(),
  6237.                             'language' => $proposal->getLanguage()
  6238.                         )
  6239.                     );
  6240.                     /* ARMO EL CONTENIDO GLOBAL */
  6241.                     $servicesArray[] = array(
  6242.                         'services' => $servicesSup,
  6243.                         'name' => strtoupper($nameServices),
  6244.                         'img' => isset($servicesGallery['0']) ? $servicesGallery['0'] : null,
  6245.                         'cities' => null,
  6246.                         'type' => $transType,
  6247.                         'ids' => $varCat,
  6248.                         'gallery' => $servicesGallery,
  6249.                         'descripcion' => $servicesDescription,
  6250.                         //                        'capacity' =>$serviceCapacity,
  6251.                     );
  6252.                     //                    d($servicesArray);
  6253.                 }
  6254.             }
  6255.         }
  6256.         return $this->render(
  6257.             'MDS/EventsPresentationBundle/presentation/services-view.html.twig',
  6258.             array(
  6259.                 'token' => $token,
  6260.                 'type' => $transType,
  6261.                 //                'company' => $company,
  6262.                 'proposal' => $proposal,
  6263.                 'client' => $client,
  6264.                 'selectType' => $selectType,
  6265.                 //                'destination' => $data_destionation,
  6266.                 //                'countDestino' => $cont_destino,
  6267.                 //                'agent'=>$agentMaster,
  6268.                 'data' => $servicesArray,
  6269.                 //                'idd'=>$idd,
  6270.                 //                'sidebar' => $sidebarData,
  6271.             )
  6272.         );
  6273.     }
  6274.     /**
  6275.      * @Route("/servicesview-Ajax/{ids}/{idcat}/{token}", name="presentation_services_view_all_token_ajax")
  6276.      */
  6277.     public function ServicesViewAjaxAllAction($token$ids$idcatRequest $request)
  6278.     {
  6279.         //        d($token);
  6280.         $em $this->getDoctrine()->getManager();
  6281.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  6282.         if ($proposal->getStatus() == "Cancel") {
  6283.             return $this->redirectToRoute(
  6284.                 'presentation_error_cancel',
  6285.                 array(
  6286.                     'token' => $token
  6287.                 )
  6288.             );
  6289.         }
  6290.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  6291.         // Usuario Anonimo es = "anon."
  6292.         if ($user_logueado == "anon.") {
  6293.             $proposal->setViewedAt(new \DateTime("now"));
  6294.             $em->persist($proposal);
  6295.             $em->flush();
  6296.         }
  6297.         if (is_null($proposal->getSelectType())) {
  6298.             $selectType = array();
  6299.         } else {
  6300.             $selectType explode(","$proposal->getSelectType());
  6301.         }
  6302.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  6303.         $proposal_Control $em->getRepository(ProposalControl::class)->findBy(
  6304.             array(
  6305.                 'proposalId' => $proposal->getId(),
  6306.                 'disabled' => '0',
  6307.             )
  6308.         );
  6309.         /*consulta de los servicios del supplier*/
  6310.         $services $em->getRepository(ProposalSupplierServices::class)->findBy(
  6311.             array(
  6312.                 'proposalId' => $proposal->getId(),
  6313.                 'serviceCatId' => $idcat,
  6314.             )
  6315.         );
  6316.         $servicesArray = array();
  6317.         //        d($services);
  6318.         $transType "Not Available";
  6319.         if (!empty($services)) {
  6320.             foreach ($services as $servicesSupplier) {
  6321.                 $transType $this->translator->trans($servicesSupplier->getServiceCatName());
  6322.                 /*consulta Lounge*/
  6323.                 // d($typeM);
  6324.                 if ($servicesSupplier->getServiceId() != "0") {
  6325.                     $nameServices "";
  6326.                     switch ($idcat) {
  6327.                         case 11:
  6328.                             $servicesSup $em->getRepository(SupplierMenu::class)->findOneById($servicesSupplier->getServiceId());
  6329.                             $nameServices $servicesSup->getTitle();
  6330.                             break;
  6331.                         case 5:
  6332.                             $servicesSup $em->getRepository(SupplierCruise::class)->findOneById($servicesSupplier->getServiceId());
  6333.                             $nameServices $servicesSup->getTitle();
  6334.                             break;
  6335.                         case 6:
  6336.                             $servicesSup $em->getRepository(SupplierEntertainment::class)->findOneById($servicesSupplier->getServiceId());
  6337.                             $nameServices $servicesSup->getName();
  6338.                             break;
  6339.                         case 4:
  6340.                             $servicesSup $em->getRepository(SupplierCreative::class)->findOneById($servicesSupplier->getServiceId());
  6341.                             $nameServices $servicesSup->getTitle();
  6342.                             break;
  6343.                         case 7:
  6344.                             $servicesSup $em->getRepository(SupplierGifts::class)->findOneById($servicesSupplier->getServiceId());
  6345.                             $nameServices $servicesSup->getName();
  6346.                             break;
  6347.                         case 8:
  6348.                             $servicesSup $em->getRepository(SupplierGuide::class)->findOneById($servicesSupplier->getServiceId());
  6349.                             $nameServices $servicesSup->getName();
  6350.                             break;
  6351.                         case 9:
  6352.                             $servicesSup $em->getRepository(SupplierItineraries::class)->findOneById($servicesSupplier->getServiceId());
  6353.                             $nameServices $servicesSup->getTitle();
  6354.                             break;
  6355.                         case 13:
  6356.                             $servicesSup $em->getRepository(SupplierTransport::class)->findOneById($servicesSupplier->getServiceId());
  6357.                             $nameServices $servicesSup->getName();
  6358.                             break;
  6359.                         case 12:
  6360.                             $servicesSup $em->getRepository(SupplierOthers::class)->findOneById($servicesSupplier->getServiceId());
  6361.                             $nameServices $servicesSup->getName();
  6362.                             break;
  6363.                         case 2:
  6364.                             $servicesSup $em->getRepository(SupplierActivities::class)->findOneById($servicesSupplier->getServiceId());
  6365.                             $nameServices $servicesSup->getTitle();
  6366.                             break;
  6367.                         case 1:
  6368.                             $servicesSup $em->getRepository(SupplierAccommodation::class)->findOneById($servicesSupplier->getServiceId());
  6369.                             $nameServices $servicesSup->getName();
  6370.                             break;
  6371.                     }
  6372.                     $controlSup $em->getRepository(SupplierServicesControl::class)->findOneBy(
  6373.                         array(
  6374.                             'servicesId' => $ids,
  6375.                             'servicesCat' => $idcat,
  6376.                         )
  6377.                     );
  6378.                     $servicesGallery $em->getRepository(SupplierGallery::class)->findByControlId($controlSup->getId());
  6379.                     $servicesDescription $em->getRepository(SupplierServicesDescription::class)->findBy(
  6380.                         array(
  6381.                             'servicesId' => $ids,
  6382.                             'controlId' => $servicesSupplier->getServiceId(),
  6383.                             'language' => $proposal->getLanguage()
  6384.                         )
  6385.                     );
  6386.                     /* ARMO EL CONTENIDO GLOBAL */
  6387.                     $servicesArray = array(
  6388.                         'services' => $servicesSupplier->getServiceId(),
  6389.                         'name' => $nameServices,
  6390.                         'gallery' => $servicesGallery,
  6391.                         'descripcion' => $servicesDescription,
  6392.                         //                        'capacity' =>$serviceCapacity,
  6393.                     );
  6394.                     //                    d($servicesArray);
  6395.                 }
  6396.             }
  6397.         }
  6398.         $serializer SerializerBuilder::create()->build();
  6399.         $array $serializer->toArray($servicesArray);
  6400.         $response = new JsonResponse($array);
  6401.         return $response;
  6402.     }
  6403.     protected function sidebarAction($token$typeSide$idd)
  6404.     {
  6405.         $em $this->getDoctrine()->getManager();
  6406.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  6407.         if ($proposal->getStatus() == "Cancel") {
  6408.             return $this->redirectToRoute(
  6409.                 'presentation_error_cancel',
  6410.                 array(
  6411.                     'token' => $token
  6412.                 )
  6413.             );
  6414.         }
  6415.         /* inicio array con los agentes */
  6416.         $dataAgents = array();
  6417.         if (!is_null($proposal->getAgentId())) {
  6418.             $agenteTwo = array();
  6419.             if (!empty($proposal->getAgentTwoId())) {
  6420.                 $agenteTwo explode(","$proposal->getAgentTwoId());
  6421.             } else {
  6422.                 $agenteTwo[0] = $proposal->getAgentId();
  6423.             }
  6424.             $agentProposal $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  6425.             $teamLeader $em->getRepository(User::class)->findOneBy(
  6426.                 array(
  6427.                     'team' => $agentProposal->getTeam(),
  6428.                     'teamleader' => 1,
  6429.                 )
  6430.             );
  6431.             if (!empty($teamLeader)) {
  6432.                 $leader $teamLeader->getId();
  6433.             } else {
  6434.                 $leader $proposal->getAgentId();
  6435.             }
  6436.             $agentArray = array();
  6437.             array_push($agentArray$proposal->getAgentId());
  6438.             array_push($agentArray$agenteTwo[0]);
  6439.             array_push($agentArray$leader);
  6440.             array_push($agentArray6);
  6441.             array_push($agentArray14);
  6442.             //            array_push($agentArray, 1);
  6443.             //            array_push($agentArray, 1);
  6444.             //            $dataAgents=array();
  6445.             //d($agentArray);
  6446.             foreach ($agentArray as $agent) {
  6447.                 //d($agent);
  6448.                 $users $em->getRepository(User::class)->findOneById($agent);
  6449.                 $dataAgents[] = array(
  6450.                     'id' => $agent,
  6451.                     'fullname' => $users->getName() . ' ' $users->getLastName(),
  6452.                     'picture' => $users->getPicture()
  6453.                 );
  6454.             }
  6455.             /* fin array con los agentes */
  6456.         }
  6457.         /* inicio array con los supplier */
  6458.         $parameters = array(
  6459.             'proposalId' => $proposal->getId(),
  6460.             'serviceIdFather' => '0',
  6461.         );
  6462.         $dql 'SELECT p
  6463.                 FROM EventsBundle:ProposalSupplierServices p
  6464.                 WHERE p.proposalId = :proposalId AND p.serviceIdFather = :serviceIdFather 
  6465.                 ORDER BY p.supplierId ASC ';
  6466.         $query $em->createQuery($dql)->setParameters($parameters);
  6467.         $data_service_supplier $query->getResult();
  6468.         $supplier_Id = array();
  6469.         $idea_Id = array();
  6470.         $activity_Id = array();
  6471.         foreach ($data_service_supplier as $dataservicesupplier) {
  6472.             $controlservices_supplier $em->getRepository(ProposalSupplierControl::class)->findOneBy(
  6473.                 array(
  6474.                     'proposalId' => $proposal->getId(),
  6475.                     'disabled' => '0',
  6476.                     'id' => $dataservicesupplier->getControlId(),
  6477.                 )
  6478.             );
  6479.             if (!empty($controlservices_supplier)) {
  6480.                 $proposal_Control $em->getRepository(ProposalControl::class)->findOneBy(
  6481.                     array(
  6482.                         'proposalId' => $proposal->getId(),
  6483.                         'disabled' => '0',
  6484.                         'id' => $controlservices_supplier->getControlDestinationId(),
  6485.                     )
  6486.                 );
  6487.                 if (!empty($proposal_Control)) {
  6488.                     if ($dataservicesupplier->getSupplierId() != "0") {
  6489.                         if (!is_null($controlservices_supplier->getIdeaId())) {
  6490.                             $idea_Id[$controlservices_supplier->getIdeaId()] = array(
  6491.                                 'ideaid' => $controlservices_supplier->getIdeaId(),
  6492.                                 'destinoid' => $controlservices_supplier->getDestinoId(),
  6493.                             );
  6494.                         }
  6495.                         if (!is_null($controlservices_supplier->getActivityId())) {
  6496.                             $activity_Id[$controlservices_supplier->getActivityId()] = array(
  6497.                                 'activityid' => $controlservices_supplier->getActivityId(),
  6498.                                 'destinoid' => $controlservices_supplier->getDestinoId(),
  6499.                             );
  6500.                         }
  6501.                         if (!is_null($dataservicesupplier->getSupplierId())) {
  6502.                             $supplier_Id[$dataservicesupplier->getSupplierId()] = array(
  6503.                                 'supplierid' => $dataservicesupplier->getSupplierId(),
  6504.                                 'destinoid' => $controlservices_supplier->getDestinoId(),
  6505.                             );
  6506.                         }
  6507.                         $destination_Id[$controlservices_supplier->getDestinoId()] = $controlservices_supplier->getDestinoId();
  6508.                     }
  6509.                 }
  6510.             }
  6511.         }
  6512.         $all_Idea_control $em->getRepository(ProposalSupplierControl::class)->findBy(
  6513.             array(
  6514.                 'proposalId' => $proposal->getId(),
  6515.                 'disabled' => '0',
  6516.             )
  6517.         );
  6518.         foreach ($all_Idea_control as $allIdea) {
  6519.             if (!is_null($allIdea->getIdeaId())) {
  6520.                 $idea_Id[$allIdea->getIdeaId()] = array(
  6521.                     'ideaid' => $allIdea->getIdeaId(),
  6522.                     'destinoid' => $allIdea->getDestinoId(),
  6523.                 );
  6524.             }
  6525.             if (!is_null($allIdea->getActivityId())) {
  6526.                 $activity_Id[$allIdea->getActivityId()] = array(
  6527.                     'activityid' => $allIdea->getActivityId(),
  6528.                     'destinoid' => $allIdea->getDestinoId(),
  6529.                 );
  6530.             }
  6531.         }
  6532.         //        d($supplier_Id, $idea_Id, $activity_Id);
  6533.         /* Fin array con los supplier */
  6534.         if (is_null($proposal->getSelectType())) {
  6535.             $select_Type = array();
  6536.         } else {
  6537.             $select_Type explode(","$proposal->getSelectType());
  6538.         }
  6539.         $type = array();
  6540.         if (!empty($destination_Id)) {
  6541.             foreach ($select_Type as $selectType) {
  6542.                 //                d($selectType);
  6543.                 $destination = array();
  6544.                 if ($selectType == "IDEA") {
  6545.                     foreach ($destination_Id as $destinationId) {
  6546.                         $ideas = array();
  6547.                         foreach ($idea_Id as $ideaId) {
  6548.                             if ($destinationId == $ideaId['destinoid']) {
  6549.                                 $ideas_query $em->getRepository(Ideas::class)->findOneBy(
  6550.                                     array(
  6551.                                         'id' => $ideaId['ideaid'],
  6552.                                     )
  6553.                                 );
  6554.                                 if (!empty($ideas_query)) {
  6555.                                     $ideas[] = $ideas_query;
  6556.                                 }
  6557.                             }
  6558.                         }
  6559.                         $destino $em->getRepository(Destination::class)->findOneById($destinationId);
  6560.                         if (count($ideas) != 0) {
  6561.                             $destination[$destino->getId()] = array(
  6562.                                 'destination' => $destino,
  6563.                                 'data' => $ideas,
  6564.                             );
  6565.                         }
  6566.                     }
  6567.                 }
  6568.                 if (($selectType == "ACTIVITY") or ($selectType == "ACTIVIDADES")) {
  6569.                     foreach ($destination_Id as $destinationId) {
  6570.                         $activity = array();
  6571.                         foreach ($activity_Id as $activityId) {
  6572.                             if ($destinationId == $activityId['destinoid']) {
  6573.                                 $activities_query $em->getRepository(Activities::class)->findOneBy(
  6574.                                     array(
  6575.                                         'id' => $activityId['activityid'],
  6576.                                     )
  6577.                                 );
  6578.                                 if (!empty($activities_query)) {
  6579.                                     $activity[] = $activities_query;
  6580.                                 }
  6581.                             }
  6582.                         }
  6583.                         $destino $em->getRepository(Destination::class)->findOneById($destinationId);
  6584.                         if (count($activity) != 0) {
  6585.                             $destination[$destino->getId()] = array(
  6586.                                 'destination' => $destino,
  6587.                                 'data' => $activity,
  6588.                             );
  6589.                         }
  6590.                     }
  6591.                 }
  6592.                 foreach ($destination_Id as $destinationId) {
  6593.                     $supplier = array();
  6594.                     foreach ($supplier_Id as $supplierId) {
  6595.                         if ($destinationId == $supplierId['destinoid']) {
  6596.                             $supplier_query $em->getRepository("App:Supplier")->findOneBy(
  6597.                                 array(
  6598.                                     'id' => $supplierId['supplierid'],
  6599.                                     'type' => $selectType,                              // Funcion conversora
  6600.                                 )
  6601.                             );
  6602.                             if (!empty($supplier_query)) {
  6603.                                 $supplier[] = $supplier_query;
  6604.                             }
  6605.                         }
  6606.                     }
  6607.                     $destino $em->getRepository(Destination::class)->findOneById($destinationId);
  6608.                     if (count($supplier) != 0) {
  6609.                         $destination[$destino->getId()] = array(
  6610.                             'destination' => $destino,
  6611.                             'data' => $supplier,
  6612.                         );
  6613.                     }
  6614.                 }
  6615.                 if (count($destination) != 0) {
  6616.                     $type[] = array(
  6617.                         'type' => $selectType,
  6618.                         'destination' => $destination,
  6619.                     );
  6620.                 }
  6621.             }
  6622.         }
  6623.         $budgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findBy(
  6624.             array(
  6625.                 'proposalId' => $proposal->getId(),
  6626.                 'recommended' => 1,
  6627.             )
  6628.         );
  6629.         $agendas =  $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
  6630.             array(
  6631.                 'proposalId' => $proposal->getId()
  6632.             ),
  6633.             array(
  6634.                 'priority' => 'ASC',
  6635.                 'recommended' => 'ASC',
  6636.             )
  6637.         );
  6638.         $showAgenda = array();
  6639.         foreach ($agendas as $item) {
  6640.             $showAgenda[] = $item;
  6641.         }
  6642.         $data[] = array(
  6643.             'agent' => $dataAgents,
  6644.             'type' => $type,
  6645.             'typeSide' => $typeSide,
  6646.             'idd' => $idd,
  6647.             'budgetslist' => $budgets,
  6648.             'agendas' => $showAgenda,
  6649.         );
  6650.         //        d($data);
  6651.         //        exit();
  6652.         return $data;
  6653.     }
  6654.     /**
  6655.      * @Route("/proposal/invoice/print/{id}",  name="proposal_invoice_detector_print_externo")
  6656.      */
  6657.     public function detectorInvoicePrintAction($idRequest $request)
  6658.     {
  6659.         $em $this->getDoctrine()->getManager();
  6660.         $invoiceconsulta = array();
  6661.         $typeconsulta '';
  6662.         $invoice $em->getRepository(ProposalInvoice::class)->findOneByProposalId($id);
  6663.         if (!empty($invoice)) {
  6664.             $invoiceconsulta $invoice;
  6665.             $typeconsulta $invoice->getType();
  6666.         }
  6667.         if (!empty($invoiceconsulta)) {
  6668.             $type $typeconsulta;
  6669.             //            $number = $invoiceconsulta->getId();
  6670.             $number $invoiceconsulta->getNumber();
  6671.             $date $invoiceconsulta->getDateAt();
  6672.             $prefix $invoiceconsulta->getPrefix();
  6673.             $data $this->baseInvoiceProposal($id$type$number$prefix$date$request);
  6674.             $token $data['token'];
  6675.         } else {
  6676.             return $this->redirectToRoute(
  6677.                 'proposal_invoice_proforma_print_externo',
  6678.                 array(
  6679.                     'id' => $id
  6680.                 )
  6681.             );
  6682.         }
  6683.         $fees $em->getRepository(ProposalFeeInvoice::class)->findByProposalId($id);
  6684.         if (!empty($fees)) {
  6685.             $fees[0]->setAmount($fees[0]->getFeeNet());
  6686.             if (!($fees[0]->getToInvoice())) {
  6687.                 $fees null;
  6688.             }
  6689.         } // Si no se debe mostrar en factura se pone a null
  6690.         $summary $em->getRepository(ProposalsInvoiceSummary::class)->findOneByProposalId($id);
  6691.         $summaryInvoice = !empty($summary);
  6692.         $summaryInvoiceText = !empty($summary) ? $summary->getDescription() : null;
  6693.         return $this->render(
  6694.             'MDS/EventsBundle/services/services-invoice-print-proposal.html.twig',
  6695.             array(
  6696.                 'id' => $id,
  6697.                 'type' => $data['type'],
  6698.                 'number' => $data['number'],
  6699.                 'prefix' => $data['prefix'],
  6700.                 'date' => $data['date'],
  6701.                 'token' => $token,
  6702.                 'proposal' => $data['proposal'],
  6703.                 'company' => $data['company'],
  6704.                 'clients' => $data['clients'],
  6705.                 'datasupplier' => $data['datasupplier'],
  6706.                 'totales_neto_antes' => $data['totales_neto_antes'],
  6707.                 'totales_neto' => $data['totales_neto'],
  6708.                 'bases_imponibles' => $data['bases_imponibles'],
  6709.                 'totales_antes' => $data['totales_antes'],
  6710.                 'totales' => $data['totales'],
  6711.                 'balance' => $data['balance'],
  6712.                 'totales_generales' => $data['totales_generales'],
  6713.                 'currency' => $data['currency'],
  6714.                 'detail_iva' => 'no',
  6715.                 'discounts' => $data['discounts'],
  6716.                 'fees' => $fees,
  6717.                 'paymentInvoice' => $data['paymentInvoice'],
  6718.                 'invoiceDesposit' => $data['invoiceDesposit'],
  6719.                 'summaryInvoice' => $summaryInvoice,
  6720.                 'summaryInvoiceText' => $summaryInvoiceText,
  6721.             )
  6722.         );
  6723.     }
  6724.     /**
  6725.      * @Route("/proposal/invoice/proforma/print/{id}",  name="proposal_invoice_proforma_print_externo")
  6726.      */
  6727.     public function detailsProformaPrintAction($idRequest $request)
  6728.     {
  6729. //        dd($id);
  6730.         $data = array();
  6731.         //        $token = "";
  6732.         $em $this->getDoctrine()->getManager();
  6733.         $proforma $em->getRepository(ProposalProforma::class)->findOneByProposalId($id);
  6734.         if (!empty($proforma)) {
  6735.             $type 'Proforma';
  6736.             $number $proforma->getId();
  6737.             $date $proforma->getDateAt();
  6738.             $prefix $proforma->getPrefix();
  6739.             $data $this->baseInvoiceProposal($id$type$number$prefix$date$request);
  6740.             $token $data['token'];
  6741.         } else {
  6742.                         return $this->redirectToRoute('proposal_generate_proforma',
  6743.                             array(
  6744.                                 'id' => $id
  6745.                             )
  6746.                         );
  6747.         }
  6748.         $fees $em->getRepository(ProposalFee::class)->findByProposalId($id);
  6749.         if (!empty($fees)) {
  6750.             if (!($fees[0]->getToInvoice())) {
  6751.                 $fees null;
  6752.             }
  6753.         } // Si no se debe mostrar en factura se pone a null
  6754.         $summaryInvoice $em->getRepository(ProposalsInvoiceSummary::class)->findOneByProposalId($id);
  6755.         return $this->render(
  6756.             'MDS/EventsBundle/services/services-invoice-print-proposal.html.twig',
  6757.             array(
  6758.                 'id' => $id,
  6759.                 'type' => $data['type'],
  6760.                 'number' => $data['number'],
  6761.                 'prefix' => $data['prefix'],
  6762.                 'date' => $data['date'],
  6763.                 'token' => $token,
  6764.                 'proposal' => $data['proposal'],
  6765.                 'company' => $data['company'],
  6766.                 'clients' => $data['clients'],
  6767.                 'datasupplier' => $data['datasupplier'],
  6768.                 'totales_neto_antes' => $data['totales_neto_antes'],
  6769.                 'totales_neto' => $data['totales_neto'],
  6770.                 'bases_imponibles' => $data['bases_imponibles'],
  6771.                 'totales_antes' => $data['totales_antes'],
  6772.                 'totales' => $data['totales'],
  6773.                 'balance' => $data['balance'],
  6774.                 'totales_generales' => $data['totales_generales'],
  6775.                 'currency' => $data['currency'],
  6776.                 'detail_iva' => 'yes',
  6777.                 'discounts' => $data['discounts'],
  6778.                 'fees' => $fees,
  6779.                 'paymentInvoice' => $data['paymentInvoice'],
  6780.                 'invoiceDesposit' => $data['invoiceDesposit'],
  6781.                 'summaryInvoice' => $summaryInvoice,
  6782.             )
  6783.         );
  6784.     }
  6785.     private function baseInvoiceProposal($id$type$number$prefix$dateRequest $request)
  6786.     {
  6787.         $em $this->getDoctrine()->getManager();
  6788.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  6789.         $services_supplier $em->getRepository(ProposalSupplierServicesCostsClient::class)->findBy(
  6790.             array(
  6791.                 'proposalId' => $id,
  6792.                 'serviceIdFather' => '0'
  6793.             ),
  6794.             array(
  6795.                 'id' => 'ASC'
  6796.             )
  6797.         );
  6798.         $data_iva = array();
  6799.         $supplier_control = array();
  6800.         foreach ($services_supplier as $servicessupplier) {
  6801.             if (!is_null($servicessupplier->getActivityId())) {
  6802.                 $supplier_control[$servicessupplier->getActivityId()] = array(
  6803.                     'master' => 'activity',
  6804.                     'id' => $servicessupplier->getActivityId(),
  6805.                     'destinoId' => $servicessupplier->getDestinationId(),
  6806.                 );
  6807.             }
  6808.             if (!is_null($servicessupplier->getIdeaId())) {
  6809.                 $supplier_control[$servicessupplier->getIdeaId()] = array(
  6810.                     'master' => 'idea',
  6811.                     'id' => $servicessupplier->getIdeaId(),
  6812.                     'destinoId' => $servicessupplier->getDestinationId(),
  6813.                 );
  6814.             }
  6815.             if ((!is_null($servicessupplier->getSupplierId())) && ($servicessupplier->getIdeaId() == null) and ($servicessupplier->getActivityId() == null)) {
  6816.                 $supplier_control[$servicessupplier->getSupplierId()] = array(
  6817.                     'master' => 'supplier',
  6818.                     'id' => $servicessupplier->getSupplierId(),
  6819.                     'destinoId' => $servicessupplier->getDestinationId(),
  6820.                 );
  6821.             }
  6822.         }
  6823.         $data_serviceCat = array();
  6824.         $data_supplier = array();
  6825.         $totales_neto_all 0;
  6826.         $totales_all 0;
  6827.         $currency 0;
  6828.         $data_service_supplier = array();
  6829.         foreach ($supplier_control as $suppliercontrol) {
  6830.             //            $destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol['destinoId']);
  6831.             $destination $em->getRepository(Destination::class)->findOneById($suppliercontrol['destinoId']);
  6832.             $colorlabel "bg-success-300";
  6833.             $sqlactivities "";
  6834.             if ($suppliercontrol['master'] == 'activity') {
  6835.                 $master "activity";
  6836.                 $sqlactivities $em->getRepository(Activities::class)->findOneById($suppliercontrol['id']);
  6837.                 // ORDEN DESCENDENTE Y POR SERVICES
  6838.                 $parameters = array(
  6839.                     'proposalId' => $id,
  6840.                     'serviceIdFather' => '0',
  6841.                     'activityId' => $suppliercontrol['id']
  6842.                 );
  6843.                 $dql 'SELECT p
  6844.                         FROM EventsBundle:ProposalSupplierServicesCostsClient p
  6845.                         WHERE p.proposalId = :proposalId AND p.activityId = :activityId AND p.serviceIdFather = :serviceIdFather
  6846.                         ORDER BY p.serviceCatId, p.rank ASC ';
  6847.                 $query $em->createQuery($dql)->setParameters($parameters);
  6848.                 $data_service_supplier $query->getResult();
  6849.             }
  6850.             $sqlideas "";
  6851.             if ($suppliercontrol['master'] == 'idea') {
  6852.                 $master "idea";
  6853.                 $sqlideas $em->getRepository(Ideas::class)->findOneById($suppliercontrol['id']);
  6854.                 // ORDEN DESCENDENTE Y POR SERVICES
  6855.                 $parameters = array(
  6856.                     'proposalId' => $id,
  6857.                     'serviceIdFather' => '0',
  6858.                     'ideaId' => $suppliercontrol['id']
  6859.                 );
  6860.                 $dql 'SELECT p
  6861.                         FROM EventsBundle:ProposalSupplierServicesCostsClient p
  6862.                         WHERE p.proposalId = :proposalId AND p.ideaId = :ideaId AND p.serviceIdFather = :serviceIdFather
  6863.                         ORDER BY p.serviceCatId, p.rank ASC ';
  6864.                 $query $em->createQuery($dql)->setParameters($parameters);
  6865.                 $data_service_supplier $query->getResult();
  6866.             }
  6867.             $sqlsuppliers "";
  6868.             if ($suppliercontrol['master'] == 'supplier') {
  6869.                 $master "supplier";
  6870.                 $sqlsuppliers $em->getRepository(Supplier::class)->findOneById($suppliercontrol['id']);
  6871.                 if (!is_null($sqlsuppliers)) {
  6872.                     switch ($sqlsuppliers->getStar()) {
  6873.                         case 1:
  6874.                             $sqlsuppliers->setStar('<i class="icon-star-full2"></i>');
  6875.                             break;
  6876.                         case 2:
  6877.                             $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  6878.                             break;
  6879.                         case 3:
  6880.                             $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  6881.                             break;
  6882.                         case 4:
  6883.                             $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>');
  6884.                             break;
  6885.                         case 5:
  6886.                             $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');
  6887.                             break;
  6888.                         case 6:
  6889.                             $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>');
  6890.                             break;
  6891.                         case 7:
  6892.                             $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');
  6893.                             break;
  6894.                         case 8:
  6895.                             $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');
  6896.                             break;
  6897.                     }
  6898.                 }
  6899.                 // ORDEN DESCENDENTE Y POR SERVICES
  6900.                 $parameters = array(
  6901.                     'proposalId' => $id,
  6902.                     'serviceIdFather' => '0',
  6903.                     'supplierId' => $suppliercontrol['id']
  6904.                 );
  6905.                 $dql 'SELECT p
  6906.                         FROM EventsBundle:ProposalSupplierServicesCostsClient p
  6907.                         WHERE p.proposalId = :proposalId AND p.supplierId = :supplierId AND p.ideaId is null AND p.activityId is null AND p.serviceIdFather = :serviceIdFather
  6908.                         ORDER BY p.serviceCatId, p.rank ASC ';
  6909.                 $query $em->createQuery($dql)->setParameters($parameters);
  6910.                 $data_service_supplier $query->getResult();
  6911.                 // Agrupamos asistencias de In-Out por ID de Agente
  6912.                 $new_data_service_supplier = array();
  6913.                 $arregloAcumulador = array();
  6914.                 $acumulador = array();
  6915.                 if ($sqlsuppliers->getCompany() == 'IN OUT TRAVEL & EVENTS') {
  6916.                     // El proveedor es In Out
  6917.                     foreach ($data_service_supplier as $dtsp) {
  6918.                         $zNameSrvOrNameUsr $em->getRepository(ProposalsSupplierServicesAssistantName::class)->findOneByPrpSupSrvId($dtsp->getServiceIdProposal());
  6919.                         if ($dtsp->getServiceCatId() != 15) {
  6920.                             $new_data_service_supplier[] = $dtsp;
  6921.                         } else {
  6922.                             // Tenemos una asistencia de In Out
  6923.                             // vamos acumulando precios, over, etc
  6924.                             if ((!array_key_exists($dtsp->getAssistantId() . '-' $dtsp->getPrice(), $arregloAcumulador)) and (!is_null($dtsp->getAssistantId()))) {
  6925.                                 $zAg $em->getRepository(User::class)->findOneById($dtsp->getAssistantId());
  6926.                                 if (empty($zNameSrvOrNameUsr) && !empty($zAg)) {
  6927.                                     $dtsp->setName('Staff In Out Events: ' $zAg->getName() . ' ' $zAg->getLastName());
  6928.                                 }
  6929.                                 $dtsp->setUnits(1);
  6930.                                 $arregloAcumulador[$dtsp->getAssistantId() . '-' $dtsp->getPrice()] = $dtsp;
  6931.                             } else {
  6932.                                 if ((!is_null($dtsp->getAssistantId()))) {
  6933.                                     //                                Antes se comprobaba sololo con el id ahora el id del agente y el precio de la asistencia
  6934.                                     //                                $tempAcum = $arregloAcumulador[$dtsp->getAssistantId()];
  6935.                                     $tempAcum $arregloAcumulador[$dtsp->getAssistantId() . '-' $dtsp->getPrice()];
  6936.                                     $tempAcum->setUnits($tempAcum->getUnits() + 1);
  6937.                                     //Si el dia de inicio es menor actualizas (para establecer rangos de varios dias)
  6938.                                     if ($dtsp->getDateInAt() < $tempAcum->getDateInAt()) {
  6939.                                         $tempAcum->setDateInAt($dtsp->getDateInAt());
  6940.                                     }
  6941.                                     //Si el dia de fin es mayor actualizas (para establecer rangos de varios dias)
  6942.                                     if ($dtsp->getDateOutAt() > $tempAcum->getDateOutAt()) {
  6943.                                         $tempAcum->setDateOutAt($dtsp->getDateOutAt());
  6944.                                     }
  6945.                                     //                                Antes se comprobaba sololo con el id ahora el id del agente y el precio de la asistencia
  6946.                                     //                                $arregloAcumulador[$dtsp->getAssistantId()] = $tempAcum;
  6947.                                     $arregloAcumulador[$dtsp->getAssistantId() . '-' $dtsp->getPrice()] = $tempAcum;
  6948.                                 } else {
  6949.                                     // Tenemos una asistencia de un agente EXTERNO - este agente no se encuentra en el listado de agentes de In Out
  6950.                                     if (array_key_exists($dtsp->getName(), $arregloAcumulador)) {
  6951.                                         $tempAcum $arregloAcumulador[$dtsp->getName()];
  6952.                                         $tempAcum->setUnits($tempAcum->getUnits() + 1);
  6953.                                         if (empty($zNameSrvOrNameUsr)) {
  6954.                                             $tempAcum->setName('Staff In Out Events: ' $dtsp->getName());
  6955.                                         }
  6956.                                         $arregloAcumulador[$dtsp->getName()] = $tempAcum;
  6957.                                     } else {
  6958.                                         $arregloAcumulador[$dtsp->getName()] = $dtsp;
  6959.                                         if (empty($zNameSrvOrNameUsr)) {
  6960.                                             $arregloAcumulador[$dtsp->getName()]->setName('Staff In Out Events: ' $dtsp->getName());
  6961.                                         }
  6962.                                     }
  6963.                                 }
  6964.                             }
  6965.                         }
  6966.                     }
  6967.                     //
  6968.                     foreach ($arregloAcumulador as $aAc) {
  6969.                         $new_data_service_supplier[] = $aAc;
  6970.                     }
  6971.                     $data_service_supplier $new_data_service_supplier;
  6972.                 }
  6973.                 // FIN  -  Agrupamos asistencias de In-Out por ID de Agente
  6974.             }
  6975.             $imagenSmall null;
  6976.             $service_supplier_data = array();
  6977.             $totales_neto '0';
  6978.             $totales_iva '0';
  6979.             $totales_con_iva '0';
  6980.             $totales_paying '0';
  6981.             $totales_pago '0';
  6982.             $totales_benefit_moneda '0';
  6983.             $totales_benefit_porsentaje '0';
  6984.             foreach ($data_service_supplier as $data_service) {
  6985.                 //                d($data_service->getId());
  6986.                 //Currency
  6987.                 $currency $data_service->getCurrency();
  6988.                 if (isset($currency)) {
  6989.                     $currency "Euro";
  6990.                 }
  6991.                 if ($currency == "Euro") {
  6992.                     $currency "€";
  6993.                 }
  6994.                 if ($currency == "Dolar") {
  6995.                     $currency " $";
  6996.                 }
  6997.                 if ($currency == "MXN") {
  6998.                     $currency " MXN";
  6999.                 }
  7000.                 $data_service->setCurrency($currency);
  7001.                 $idcat $data_service->getServiceCatId();
  7002.                 $price $data_service->getPrice();
  7003.                 $units $data_service->getUnits();
  7004.                 $pax $data_service->getPax();
  7005.                 $opcommission $data_service->getOpCommission();
  7006.                 $commission $data_service->getCommission();
  7007.                 $opover $data_service->getOpOver();
  7008.                 $over $data_service->getOver();
  7009.                 $opiva $data_service->getOpIva();
  7010.                 $iva $data_service->getIva();
  7011.                 $dateInAt $data_service->getDateInAt();
  7012.                 $dateOutAt $data_service->getDateOutAt();
  7013.                 if (!is_null($dateInAt) and !is_null($dateOutAt)) {
  7014.                     $days $dateInAt->diff($dateOutAt);
  7015.                     $day $days->days;
  7016.                     //                    if (($data_service->getSupplierId() == '4') and ($data_service->getServiceCatId() == '15')){
  7017.                     //                        $day ="0";
  7018.                     //                    }
  7019.                 } else {
  7020.                     $day "0";
  7021.                     //                    if (($data_service->getSupplierId() == '4') and ($data_service->getServiceCatId() == '15')){
  7022.                     //                        $day ="0";
  7023.                     //                    }
  7024.                 }
  7025.                 if (!is_null($data_service->getIdeaId())) {
  7026.                     $name_supplier $em->getRepository(Ideas::class)->findOneById($data_service->getIdeaId());
  7027.                     if (empty($name_supplier)) {
  7028.                         $namesupplier '';
  7029.                     } else {
  7030.                         $namesupplier $name_supplier->getName();
  7031.                     }
  7032.                 }
  7033.                 if (!is_null($data_service->getSupplierId()) and $data_service->getIdeaId() == null) {
  7034.                     $name_supplier $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  7035.                     if (empty($name_supplier)) {
  7036.                         $namesupplier '';
  7037.                     } else {
  7038.                         $namesupplier $name_supplier->getName();
  7039.                     }
  7040.                 }
  7041.                 //                $name_supplier = $em->getRepository(Supplier::class)->findOneById($data_service->getSupplierId());
  7042.                 //                $namesupplier = $name_supplier->getName();
  7043.                 if ($type == 'No Vat Invoice') {
  7044.                     $iva "0";
  7045.                     $data_service->setIva($iva);
  7046.                 }
  7047.                 $calculos $this->CalculoTotalesservicesDos($price$units$pax$day$opcommission$commission$opover$over$opiva$iva$idcat);
  7048.                 $data_service->setPrice($calculos['precio']); //ojo aqui
  7049.                 $service_supplier_data[] = array(
  7050.                     'calculos' => $calculos,
  7051.                     'services_data' => $data_service,
  7052.                     'namesupplier' => $namesupplier
  7053.                 );
  7054.                 $totales_neto += $calculos['total_neto'];
  7055.                 $totales_iva += $calculos['sub_total_iva'];
  7056.                 $totales_con_iva += $calculos['total'];
  7057.                 $totales_paying += $calculos['total_paying'];
  7058.                 $totales_pago += $calculos['total_pago'];
  7059.                 $totales_benefit_moneda += $calculos['benefit_moneda'];
  7060.                 /* base imponible por servicios */
  7061.                 if (empty($base_imponible_service[$idcat])) {
  7062.                     $base_imponible_service[$idcat] = 0;
  7063.                 }
  7064.                 $base_imponible_service[$idcat] += $calculos['total_neto'];
  7065.                 $data_serviceCat[$idcat] = array(
  7066.                     'idcat' => $idcat,
  7067.                     'total_neto' => $base_imponible_service[$idcat],
  7068.                 );
  7069.                 /* base impobnible detalles por diferentes Ivas */
  7070.                 if (empty($base_imponible_iva[$iva])) {
  7071.                     $base_imponible_iva[$iva] = 0;
  7072.                 }
  7073.                 $base_imponible_iva[$iva] += $calculos['total_neto'];
  7074.                 if (empty($totales_ivas_all[$iva])) {
  7075.                     $totales_ivas_all[$iva] = 0;
  7076.                 }
  7077.                 $totales_ivas_all[$iva] += $calculos['sub_total_iva'];
  7078.                 $totales_neto_all += $calculos['total_neto'];
  7079.                 $totales_all += $calculos['total'];
  7080.                 $data_iva[$iva] = array(
  7081.                     'iva' => $iva,
  7082.                     'ivas' => $totales_ivas_all[$iva],
  7083.                     'total_iva' => $base_imponible_iva[$iva]
  7084.                 );
  7085.                 if ($totales_benefit_moneda == '0') {
  7086.                     $totales_benefit_porsentaje =  '0';
  7087.                 } else {
  7088.                     if ($totales_neto != 0) {
  7089.                         $totales_benefit_porsentaje $totales_benefit_moneda $totales_neto 100// arreglado or esteban
  7090.                     } else {
  7091.                         $totales_benefit_porsentaje 0;
  7092.                     }
  7093.                 }
  7094.             }
  7095.             $calculos_totatales = array(
  7096.                 'totales_neto' => $totales_neto,
  7097.                 'totales_iva' => $totales_iva,
  7098.                 'totales_con_iva' => $totales_con_iva,
  7099.                 'totales_paying' => $totales_paying,
  7100.                 'totales_benefit_moneda' => $totales_benefit_moneda,
  7101.                 'totales_benefit_porsentaje' => $totales_benefit_porsentaje
  7102.             );
  7103.             $data_supplier[$destination->getTitle()][] = array(
  7104.                 'master' => $master,
  7105.                 'colorlabel' => $colorlabel,
  7106.                 'control' => "1",
  7107.                 'supplier' => $sqlsuppliers,
  7108.                 'idea' => $sqlideas,
  7109.                 'activity' => $sqlactivities,
  7110.                 'image' => $imagenSmall,
  7111.                 'services' => $service_supplier_data,
  7112.                 'totales_services' => $calculos_totatales
  7113.             );
  7114.         }
  7115.         $totales_neto_antes $totales_neto_all;
  7116.         $totales_antes $totales_all;
  7117.         /*Group Everything*/
  7118.         if ($type == 'Group Everything') {
  7119.             $data_supplier = array();
  7120.             $service_supplier_data = array();
  7121.             $messageitems $this->translator->trans('Grouped Services');
  7122.             $data_service = array(
  7123.                 "price" => $totales_neto_antes,
  7124.                 "name" => $messageitems,
  7125.                 "units" => 1,
  7126.                 "iva" => $iva,
  7127.                 "dateInAt" => "2018-4-4",
  7128.                 "dateOutAt" => "2018-4-4",
  7129.             );
  7130.             $calculos = array(
  7131.                 "precio" => $totales_neto_antes,
  7132.                 "total_days" => 1,
  7133.                 "sub_total" => $totales_neto_antes,
  7134.                 "sub_total_iva" => 0,
  7135.                 "total_neto" => $totales_neto_antes,
  7136.                 "total_iva" => 0,
  7137.                 "total_paying" => 0,
  7138.                 "total_pago" => 0,
  7139.                 "total_comision" => "0",
  7140.                 "total" => $totales_antes,
  7141.                 "benefit_moneda" => 0,
  7142.             );
  7143.             $service_supplier_data[] = array(
  7144.                 'calculos' => $calculos,
  7145.                 'services_data' => $data_service,
  7146.                 'namesupplier' => ""
  7147.             );
  7148.             $calculos_totatales = array(
  7149.                 'totales_neto' => $totales_neto_antes,
  7150.                 'totales_iva' => "",
  7151.                 'totales_con_iva' => $totales_antes,
  7152.                 'totales_paying' => "",
  7153.                 'totales_benefit_moneda' => "",
  7154.                 'totales_benefit_porsentaje' => ""
  7155.             );
  7156.             $data_supplier[$messageitems][] = array(
  7157.                 'master' => '',
  7158.                 'colorlabel' => '',
  7159.                 'control' => "1",
  7160.                 'supplier' => '',
  7161.                 'idea' => '',
  7162.                 'activity' => '',
  7163.                 'image' => '',
  7164.                 'services' => $service_supplier_data,
  7165.                 'totales_services' => $calculos_totatales
  7166.             );
  7167.         }
  7168.         $data_serviceOut = array(
  7169.             'idcat' => null,
  7170.             'total_neto' => $totales_neto_all,
  7171.         );
  7172.         array_push($data_serviceCat$data_serviceOut);
  7173.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  7174.         $parameters = array(
  7175.             'id' => $proposal->getclientId(),
  7176.         );
  7177.         $dql 'SELECT cl,  c.country, re.region, p.name, r.city
  7178.                 FROM App:Client cl
  7179.                 INNER JOIN App:Country c WITH c.id = cl.country
  7180.                 INNER JOIN App:Regions re WITH re.id = cl.region
  7181.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  7182.                 INNER JOIN App:Cities r WITH r.id = cl.population
  7183.                 WHERE cl.id = :id';
  7184.         $query $em->createQuery($dql)->setParameters($parameters);
  7185.         $client $query->getResult();
  7186.         $data_invoice = array();
  7187.         $inv_neto_total 0;
  7188.         $inv_total 0;
  7189.         $invoice_deposit_control $em->getRepository(ProposalInvoiceDepositControl::class)->findByProposalId($proposal->getId());
  7190.         if (!empty($invoice_deposit_control)) {
  7191.             foreach ($invoice_deposit_control as $invoicedepositcontrol) {
  7192.                 $data_items_inv = array();
  7193.                 $invoice_deposit_items $em->getRepository(ProposalInvoiceDepositItems::class)->findByControlId($invoicedepositcontrol->getId());
  7194.                 foreach ($invoice_deposit_items as $invoicedeposititems) {
  7195.                     $invamount $invoicedeposititems->getAmount();
  7196.                     $invamount_iva $invoicedeposititems->getIva();
  7197.                     $invamount_el_iva $invamount * ($invamount_iva 100);
  7198.                     $invamount_con_iva $invamount * (($invamount_iva 100) + 1);
  7199.                     $inv_neto_total += $invamount;
  7200.                     $inv_total += $invamount_con_iva;
  7201.                     if (is_null($invoicedepositcontrol->getNumber())) {
  7202.                         $numInvoice $invoicedepositcontrol->getId();
  7203.                     } else {
  7204.                         $numInvoice $invoicedepositcontrol->getNumber();
  7205.                     }
  7206.                     $data_items_inv[] = array(
  7207.                         'numInvoice' => $numInvoice,
  7208.                         'name' => $invoicedeposititems->getName(),
  7209.                         'amount' => $invoicedeposititems->getAmount(),
  7210.                         'iva' => $invoicedeposititems->getIva(),
  7211.                         'ivaamount' => $invamount_el_iva,
  7212.                         'total' => $invamount_con_iva,
  7213.                     );
  7214.                     foreach ($data_iva as $items_iva) {
  7215.                         if ($items_iva['iva'] == $invoicedeposititems->getIva()) {
  7216.                             $new_iva $items_iva['iva'];
  7217.                             $new_ivas $items_iva['ivas'] - $invamount_el_iva;
  7218.                             $new_total_iva $items_iva['total_iva'] - $invoicedeposititems->getAmount();
  7219.                             $new_data_iva = array(
  7220.                                 'iva' => $new_iva,
  7221.                                 'ivas' => $new_ivas,
  7222.                                 'total_iva' => $new_total_iva
  7223.                             );
  7224.                             $data_iva array_replace($data_iva, array($new_iva => $new_data_iva));
  7225.                         }
  7226.                     }
  7227.                 }
  7228.                 $data_invoice[] = array(
  7229.                     'itemsInvoice' => $data_items_inv,
  7230.                 );
  7231.             }
  7232.             //            d($inv_neto_total, $inv_total);
  7233.             $totales_neto_all $totales_neto_all $inv_neto_total;
  7234.             $totales_all $totales_all $inv_total;
  7235.             //            d($totales_neto_all, $totales_all);
  7236.         }
  7237.         $consulta_discount $em->getRepository(ProposalDiscount::class)->findByProposalId($id);
  7238.         $cuantosdiscount count($consulta_discount);
  7239.         $totales_generales "";
  7240.         $descuento = array();
  7241.         if (!empty($consulta_discount)) {
  7242.             //            d($data_serviceCat);
  7243.             $quitar_en_todos 0.00;
  7244.             $datos_total_neto_suma 0.00;
  7245.             foreach ($data_serviceCat as $dataserviceat) {
  7246.                 $name "";
  7247.                 $amount "";
  7248.                 $type_des "";
  7249.                 $iva_discount "";
  7250.                 $datos_idcat $dataserviceat['idcat'];
  7251.                 $datos_total_neto $dataserviceat['total_neto'];
  7252.                 $totales_neto_des $datos_total_neto;
  7253.                 $datosiva_neto_des $datos_total_neto;
  7254.                 $calculo_net_negativo "";
  7255.                 $total_con_iva_desc "";
  7256.                 $contarveces 1;
  7257.                 foreach ($consulta_discount as $consultadiscount) {
  7258.                     if ($dataserviceat['idcat'] == null) {
  7259.                         if ($contarveces 1) {
  7260.                             $totales_neto_des $datos_total_neto_suma;
  7261.                             $datosiva_neto_des $datos_total_neto_suma;
  7262.                             $datos_total_neto $datos_total_neto_suma;
  7263.                         } else {
  7264.                             if ($cuantosdiscount 1) {
  7265.                                 $totales_neto_des $dataserviceat['total_neto'] - $quitar_en_todos;
  7266.                                 $datosiva_neto_des $dataserviceat['total_neto'] - $quitar_en_todos;
  7267.                                 $datos_total_neto $dataserviceat['total_neto'] - $quitar_en_todos;
  7268.                             }
  7269.                         }
  7270.                         $contarveces += 1;
  7271.                     }
  7272.                     if ($dataserviceat['idcat'] == $consultadiscount->getServiceId()) {
  7273.                         $iva $consultadiscount->getIva() / 100;
  7274.                         if ($consultadiscount->getType() == "0") {
  7275.                             $por $consultadiscount->getAmount() / 100;
  7276.                             //                            $datosiva_neto_des = $datosiva_neto_des / ($por + 1) ;
  7277.                             $datosiva_neto_des $datosiva_neto_des - ($datosiva_neto_des $por);
  7278.                             $name $consultadiscount->getName();
  7279.                             $type_des $consultadiscount->getType();
  7280.                             $amount $consultadiscount->getAmount();
  7281.                         }
  7282.                         if ($consultadiscount->getType() == "1") {
  7283.                             $datosiva_neto_des $datosiva_neto_des $consultadiscount->getAmount();
  7284.                             $name $consultadiscount->getName();
  7285.                             $type_des $consultadiscount->getType();
  7286.                             $amount $consultadiscount->getAmount();
  7287.                         }
  7288.                         //                        d($dataserviceat['idcat'], $datos_total_neto);
  7289.                         // resultados en negativo
  7290.                         $calculo_net_negativo =  $datosiva_neto_des $datos_total_neto;
  7291.                         //                        d($calculo_net_negativo);
  7292.                         $total_desc "0";
  7293.                         // resultados para calculos
  7294.                         $calculo_net $datos_total_neto $datosiva_neto_des;
  7295.                         if ($consultadiscount->getOpIva() == '0') {
  7296.                             $iva_discount $calculo_net - ($calculo_net / ($iva 1));
  7297.                             $calculo_net_negativo $calculo_net_negativo $iva_discount;
  7298.                             $totales_neto_des $totales_neto_des $iva_discount;
  7299.                             $total_desc $iva_discount;
  7300.                         }
  7301.                         if ($consultadiscount->getOpIva() == '1') {
  7302.                             $iva_discount $calculo_net $iva;
  7303.                             $total_desc $iva_discount;
  7304.                         }
  7305.                         if ($type == 'No Vat Invoice') {
  7306.                             $iva_discount "0";
  7307.                         }
  7308.                         //                        if($dataserviceat['idcat'] == null){
  7309.                         $datos_total_neto_suma $datos_total_neto abs((float)$calculo_net_negativo);
  7310.                         //                        }
  7311.                         $quitar_en_todos $quitar_en_todos abs((float)$calculo_net_negativo);
  7312.                         $total_con_iva_desc $calculo_net_negativo $iva_discount;
  7313.                         $totales_neto_all $totales_neto_all abs((float)$calculo_net_negativo);
  7314.                         $totales_all $totales_all abs($total_con_iva_desc);
  7315.                         $descuento[] = array(
  7316.                             'name' => $name,
  7317.                             'type' => $type_des,
  7318.                             'amount' => $amount,
  7319.                             'iva' => $consultadiscount->getIva(),
  7320.                             'iva_amount' => $iva_discount,
  7321.                             'totales_neto_des' => $calculo_net_negativo,
  7322.                             'total' => $total_con_iva_desc,
  7323.                         );
  7324.                         // Nueva actualizacion 17-07-2019 Recalcular Ivas
  7325.                         foreach ($data_iva as $items_iva) {
  7326.                             if ($items_iva['iva'] == $consultadiscount->getIva()) {
  7327.                                 $new_iva $items_iva['iva'];
  7328.                                 $new_ivas $items_iva['ivas'] - $iva_discount;
  7329.                                 $new_total_iva $items_iva['total_iva'] - $iva_discount;
  7330.                                 $new_data_iva = array(
  7331.                                     'iva' => $new_iva,
  7332.                                     'ivas' => $new_ivas,
  7333.                                     'total_iva' => $new_total_iva
  7334.                                 );
  7335.                                 $data_iva array_replace($data_iva, array($new_iva => $new_data_iva));
  7336.                             }
  7337.                         }
  7338.                     }
  7339.                 }
  7340.             }
  7341.         }
  7342.         $payments $em->getRepository(ProposalPaymentsClient::class)->findByProposalId($id);
  7343.         $amount_pay 0;
  7344.         foreach ($payments as $payment) {
  7345.             $amount_pay $amount_pay $payment->getAmount();
  7346.         }
  7347.         $totales_all round($totales_all2);
  7348.         $totales_total $totales_all;
  7349.         if (!empty($payments)) {
  7350.             $totales_all $totales_all $amount_pay;
  7351.         }
  7352.         $data = array(
  7353.             'id' => $id,
  7354.             'type' => $type,
  7355.             'number' => $number,
  7356.             'prefix' => $prefix,
  7357.             'date' => $date,
  7358.             'token' => $proposal->getAccessKey(),
  7359.             'proposal' => $proposal,
  7360.             'company' => $company,
  7361.             'clients' => $client,
  7362.             'datasupplier' => $data_supplier,
  7363.             'totales_neto_antes' => $totales_neto_antes,
  7364.             'totales_neto' => $totales_neto_all,
  7365.             'totales_generales' => $totales_generales,
  7366.             'bases_imponibles' => $data_iva,
  7367.             'totales_antes' => $totales_antes,
  7368.             'totales' => $totales_total,
  7369.             'balance' => $totales_all,
  7370.             'currency' => $currency,
  7371.             'paymentInvoice' => $amount_pay,
  7372.             'discounts' => $descuento,
  7373.             'invoiceDesposit' => $data_invoice,
  7374.         );
  7375.         // ************************************************  FEE    ************************************************************
  7376.         $fees $em->getRepository(ProposalFee::class)->findByProposalId($id);
  7377.         $feesInvoice $em->getRepository(ProposalFeeInvoice::class)->findByProposalId($id);
  7378.         if (!empty($feesInvoice)) {
  7379.             // Fee en factura
  7380.             // 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
  7381.             if ($feesInvoice[0]->getToinvoice() == true) {
  7382.                 foreach ($feesInvoice as $feeInv) {
  7383.                     if ($feeInv->getType() == 0) {
  7384.                         // Tenemos un porcentaje en el Fee de la factura, debe calcularse
  7385.                         $feeNet = ($data['totales_neto_antes'] * $feeInv->getAmount()) / 100;
  7386.                     } else {
  7387.                         $feeNet $feeInv->getAmount();
  7388.                     }
  7389.                     $feeTotal $feeNet 1.21;                     //El fee siempre será al 21%, Esteban Rincón
  7390.                     if ($feeInv->getToInvoice() == true) {
  7391.                         $data['totales_neto'] += $feeNet;
  7392.                         $data['totales'] += $feeTotal;
  7393.                         $data['balance'] += $feeTotal;
  7394.                         if (array_key_exists('21'$data['bases_imponibles'])) {
  7395.                             $data['bases_imponibles']['21']['ivas'] += $feeNet 0.21;
  7396.                             $data['bases_imponibles']['21']['total_iva'] += $feeNet;
  7397.                         } else {
  7398.                             $data['bases_imponibles']['21']['iva'] = '21';
  7399.                             $data['bases_imponibles']['21']['ivas'] = $feeNet 0.21;
  7400.                             $data['bases_imponibles']['21']['total_iva'] = $feeNet;
  7401.                         }
  7402.                     }
  7403.                     if ($feeInv->getFeeNet() == or empty($feeInv->getFeeNet())) {
  7404.                         // La asignación solo se hace la primera vez
  7405.                         $feeInv->setFeeNet($feeNet);
  7406.                         $feeInv->setFeeTotal($feeTotal);
  7407.                         $em->persist($feeInv);
  7408.                         $em->flush();
  7409.                     }
  7410.                 }
  7411.             }
  7412.         } else {
  7413.             // Fee en proforma
  7414.             if (!empty($fees)) {
  7415.                 // 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
  7416.                 if ($fees[0]->getToinvoice() == true) {
  7417.                     foreach ($fees as $fee) {
  7418.                         if ($fee->getType() == 0) {
  7419.                             // Tenemos un porcentaje, debe calcularse
  7420.                             $amount = ($data['totales_neto_antes'] * $fee->getAmount()) / 100;
  7421.                             $fee->setAmount($amount);
  7422.                         }
  7423.                         $fee->setFeeTotal($fee->getAmount() * 1.21);        //El fee siempre será al 21%, Esteban Rincón
  7424.                         if ($fee->getToInvoice() == true) {
  7425.                             $data['totales_neto'] += $fee->getAmount();
  7426.                             $data['totales'] += $fee->getFeeTotal();
  7427.                             $data['balance'] += $fee->getFeeTotal();
  7428.                             if (array_key_exists('21'$data['bases_imponibles'])) {
  7429.                                 $data['bases_imponibles']['21']['ivas'] += $fee->getAmount() * 0.21;
  7430.                                 $data['bases_imponibles']['21']['total_iva'] += $fee->getAmount();
  7431.                             } else {
  7432.                                 $data['bases_imponibles']['21']['iva'] = '21';
  7433.                                 $data['bases_imponibles']['21']['ivas'] = $fee->getAmount() * 0.21;
  7434.                                 $data['bases_imponibles']['21']['total_iva'] = $fee->getAmount();
  7435.                             }
  7436.                         }
  7437.                     }
  7438.                 }
  7439.             }
  7440.         }
  7441.         // ************************************************  FEE    ************************************************************
  7442.         return $data;
  7443.     }
  7444.     /**
  7445.      * @Route("/proposal/invoicedeposit/print/proforma/{id}",  name="proposal_invoice_deposit_proforma_print_externo")
  7446.      */
  7447.     public function printdetailsProformadepositAction($idRequest $request)
  7448.     {
  7449.         $data = array();
  7450.         $controlId null;
  7451.         $type "Proforma";
  7452.         $prefix "PFD-";
  7453.         $date = new \DateTime('now');
  7454.         $data $this->baseInvoiceDepositProposal($id$controlId$type$id$prefix$date$request);
  7455.         return $this->render(
  7456.             'MDS/EventsBundle/invoice/print-invoice-deposit-proforma.html.twig',
  7457.             array(
  7458.                 'id' => $id,
  7459.                 'type' => $data['type'],
  7460.                 'number' => $data['number'],
  7461.                 'numberadmin' => $data['numberadmin'],
  7462.                 'prefix' => $data['prefix'],
  7463.                 'date' => $data['date'],
  7464.                 'token' =>  $data['token'],
  7465.                 'proposal' => $data['proposal'],
  7466.                 'company' => $data['company'],
  7467.                 'clients' => $data['clients'],
  7468.                 'invoicedeposititems' => $data['invoicedeposititems'],
  7469.                 'totales_neto' => $data['totales_neto'],
  7470.                 'totales_iva' => $data['totales_iva'],
  7471.                 'totales' => $data['totales'],
  7472.                 'bases_imponibles' => $data['ivas'],
  7473.                 'currency' => $data['currency'],
  7474.             )
  7475.         );
  7476.     }
  7477.     /**
  7478.      * @Route("/proposal/invoicedeposit/print/invoice/{id}/{fid}",  name="proposal_invoice_deposit_invoice_print_externo")
  7479.      */
  7480.     public function printdetailsInvoicedepositAction($id$fidRequest $request)
  7481.     {
  7482.         $data = array();
  7483.         $em $this->getDoctrine()->getManager();
  7484.         $invoicedepositcontrolconsulta $em->getRepository(ProposalInvoiceDepositControl::class)->findOneBy(
  7485.             array(
  7486.                 'proposalId' => $id,
  7487.                 'id' => $fid
  7488.             )
  7489.         );
  7490.         $type "Invoice";
  7491.         $controlId $invoicedepositcontrolconsulta->getId();
  7492.         $date $invoicedepositcontrolconsulta->getDateAt();
  7493.         $prefix $invoicedepositcontrolconsulta->getPrefix();
  7494.         $data $this->baseInvoiceDepositProposal($id$controlId$type$id$prefix$date$request);
  7495.         return $this->render(
  7496.             'MDS/EventsBundle/invoice/print-invoice-deposit-proforma.html.twig',
  7497.             array(
  7498.                 'id' => $id,
  7499.                 'type' => $data['type'],
  7500.                 'number' => $data['number'],
  7501.                 'prefix' => $data['prefix'],
  7502.                 'numberadmin' => $data['numberadmin'],
  7503.                 'date' => $data['date'],
  7504.                 'token' =>  $data['token'],
  7505.                 'proposal' => $data['proposal'],
  7506.                 'company' => $data['company'],
  7507.                 'clients' => $data['clients'],
  7508.                 'invoicedeposititems' => $data['invoicedeposititems'],
  7509.                 'totales_neto' => $data['totales_neto'],
  7510.                 'totales_iva' => $data['totales_iva'],
  7511.                 'totales' => $data['totales'],
  7512.                 'bases_imponibles' => $data['ivas'],
  7513.                 'currency' => $data['currency'],
  7514.             )
  7515.         );
  7516.     }
  7517.     private function baseInvoiceDepositProposal($id$controlId$type$number$prefix$dateRequest $request)
  7518.     {
  7519.         $em $this->getDoctrine()->getManager();
  7520.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  7521.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  7522.         $parameters = array(
  7523.             'id' => $proposal->getclientId(),
  7524.         );
  7525.         $dql 'SELECT cl,  c.country, re.region, p.name, r.city 
  7526.                 FROM App:Client cl
  7527.                 INNER JOIN App:Country c WITH c.id = cl.country
  7528.                 INNER JOIN App:Regions re WITH re.id = cl.region
  7529.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  7530.                 INNER JOIN App:Cities r WITH r.id = cl.population
  7531.                 WHERE cl.id = :id';
  7532.         $query $em->createQuery($dql)->setParameters($parameters);
  7533.         $client $query->getResult();
  7534.         if (!is_null($controlId)) {
  7535.             $invoicecontrol $em->getRepository(ProposalInvoiceDepositControl::class)->findOneById($controlId);
  7536.             if (!is_null($invoicecontrol->getNumber())) {
  7537.                 $numberadmin $invoicecontrol->getNumber();
  7538.             } else {
  7539.                 $numberadmin null;
  7540.             }
  7541.         } else {
  7542.             $numberadmin null;
  7543.         }
  7544.         $invoicedeposititems $em->getRepository(ProposalInvoiceDepositItems::class)->findBy(
  7545.             array(
  7546.                 'proposalId' => $id,
  7547.                 'controlId' => $controlId,
  7548.             )
  7549.         );
  7550.         $totales_neto_all "0";
  7551.         $totales_iva_all "0";
  7552.         $totales_con_iva_all "0";
  7553.         $data_iva = array();
  7554.         foreach ($invoicedeposititems as $deposititems) {
  7555.             $amount $deposititems->getAmount();
  7556.             $iva_base $deposititems->getIva();
  7557.             $iva $iva_base 100;
  7558.             $amount_iva = ($iva_base != '0') ? ($amount $iva) : 0;
  7559. //            if ($iva_base != '0') {
  7560. //                $amount_iva = $amount * $iva;
  7561. //            }
  7562.             $amount_con_iva $amount $amount_iva;
  7563.             $totales_neto_all += $amount;
  7564.             $totales_iva_all += $amount_iva;
  7565.             $totales_con_iva_all += $amount_con_iva;
  7566.             if (empty($totales_ivas_all[$iva_base])) {
  7567.                 $totales_ivas_all[$iva_base] = 0;
  7568.             }
  7569.             $totales_ivas_all[$iva_base] += $amount_iva;
  7570.             $data_iva[$iva_base] = array(
  7571.                 'iva' => $iva_base,
  7572.                 'ivas' => $totales_ivas_all[$iva_base],
  7573.             );
  7574.             $data_deposititems[] = array(
  7575.                 'name' => $deposititems->getName(),
  7576.                 'amount' => $amount,
  7577.                 'iva' => $iva_base,
  7578.                 'total' => $amount_con_iva
  7579.             );
  7580.         }
  7581.         $currency "€";
  7582.         $data = array(
  7583.             'id' => $id,
  7584.             'type' => $type,
  7585.             'number' => $number,
  7586.             'prefix' => $prefix,
  7587.             'numberadmin' => $numberadmin,
  7588.             'date' => $date,
  7589.             'token' => $proposal->getAccessKey(),
  7590.             'proposal' => $proposal,
  7591.             'company' => $company,
  7592.             'clients' => $client,
  7593.             'invoicedeposititems' => $data_deposititems,
  7594.             'totales_neto' => $totales_neto_all,
  7595.             'totales_iva' => $totales_iva_all,
  7596.             'totales' => $totales_con_iva_all,
  7597.             'ivas' => $data_iva,
  7598.             'currency' => $currency,
  7599.         );
  7600.         return $data;
  7601.     }
  7602.     public function CalculoTotalesservicesDos($price$units$pax$days$opcommission$commission$opover$over$opiva$iva$idcat)
  7603.     {
  7604.         $commission = (float)$commission;
  7605.         $price = (float)trim($price);
  7606.         $over = (float)trim($over);
  7607.         //$price = str_replace(",", ".", $price);
  7608.         //$over = str_replace(",", ".", $over);
  7609.         $iva $iva 100;
  7610.         if ($opiva == '0') {
  7611.             $price = (float)$price / ($iva 1);
  7612.         }
  7613.         if ($opcommission == '0') {
  7614.             $commission = (100 $commission) / 100;
  7615.             $precio_units $price;
  7616.             $price $price $commission;
  7617.         }
  7618.         if ($opcommission == '1') {
  7619.             $commission = ($commission 100) + 1;
  7620.             $precio_units $price $commission;
  7621.         }
  7622.         //Units
  7623.         if (empty($units) or $units == "0") {
  7624.             //            d('entre');
  7625.             $units "1";
  7626.         }
  7627.         // Calculo Especial por categoria
  7628.         //Alojamientos
  7629.         if ($idcat == "1") {
  7630.             $informativo_days "si";
  7631.             $pax "1";
  7632.         }
  7633.         //Transporte
  7634.         elseif ($idcat == "13") {
  7635.             $informativo_days "no";
  7636.             $pax "1";
  7637.             //            if($days > "1"){
  7638.             //                $days = "2";
  7639.             //            }else{
  7640.             //                $days = "1";
  7641.             //            }
  7642.         }
  7643.         //Lounge
  7644.         elseif ($idcat == "10") {
  7645.             $informativo_days "no";
  7646.             $pax "1";
  7647.         }
  7648.         //Guia
  7649.         elseif ($idcat == "8") {
  7650.             $informativo_days "no";
  7651.             $pax "1";
  7652.         }
  7653.         //Asistencia
  7654.         elseif ($idcat == "15") {
  7655.             $informativo_days "no";
  7656.             $days '0';
  7657.         } else {
  7658.             $informativo_days "no";
  7659.         }
  7660.         //Pax
  7661.         if (empty($pax) or $pax == "0") {
  7662.             $pax "1";
  7663.         }
  7664.         if ($informativo_days == "no") {
  7665.             //Days
  7666.             if (empty($days) or $days == "0") {
  7667.                 $days "1";
  7668.             } else {
  7669.                 $days $days 1;
  7670.             }
  7671.         }
  7672.         $total_items $price $units $pax $days;
  7673.         //        $total_pdirect = $price * $units * $pax * $days;
  7674.         $total_over = (float)$over * (float)$units * (float)$pax * (float)$days;
  7675.         if ($opcommission == '0') {
  7676.             $total_neto $total_items $commission;
  7677.         }
  7678.         if ($opcommission == '1') {
  7679.             $total_neto $total_items $commission;
  7680.         }
  7681.         if ($opover == '0') {
  7682.             $total_neto $total_neto $total_over;
  7683.             $precio_units = (float)$precio_units - (float)$over;
  7684.         }
  7685.         if ($opover == '1') {
  7686.             $total_neto $total_neto +  $total_over;
  7687.             $precio_units = (float)$precio_units + (float)$over;
  7688.         }
  7689.         $total_paying $total_items * ($iva 1);
  7690.         $total_comision "0";
  7691.         $total_pago $total_items;
  7692.         $total_iva $total_items $iva;
  7693.         $sub_total_iva $total_neto $iva;
  7694.         $total $total_neto $sub_total_iva;
  7695.         $benefit_moneda $total_neto $total_items;
  7696.         $data_calculos = array(
  7697.             'precio' => $precio_units,
  7698.             'total_days' => $days,
  7699.             'sub_total' => $total_items,
  7700.             'sub_total_iva' => $sub_total_iva,
  7701.             'total_neto' => $total_neto,
  7702.             'total_iva' => $total_iva,
  7703.             'total_paying' => $total_paying,
  7704.             'total_pago' => $total_pago,
  7705.             'total_comision' => $total_comision,
  7706.             'total' => $total,
  7707.             'benefit_moneda' => $benefit_moneda
  7708.         );
  7709.         return $data_calculos;
  7710.     }
  7711.     /**
  7712.      * Añadido el 11/06/2018 por Miguel Aguire
  7713.      */
  7714.     /**
  7715.      * @Route("/invoice/{token}",  name="proposal_presentation_invoice")
  7716.      */
  7717.     public function detectorPresentationInvoiceAction($tokenRequest $request)
  7718.     {
  7719.         $em $this->getDoctrine()->getManager();
  7720.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7721.         if ($proposal->getStatus() == "Cancel") {
  7722.             return $this->redirectToRoute(
  7723.                 'presentation_error_cancel',
  7724.                 array(
  7725.                     'proposal' => $proposal,
  7726.                     'token' => $token
  7727.                 )
  7728.             );
  7729.         }
  7730.         if (is_null($proposal->getSelectType())) {
  7731.             $selectType = array();
  7732.         } else {
  7733.             $selectType explode(","$proposal->getSelectType());
  7734.         }
  7735.         $invoiceconsulta = array();
  7736.         $typeconsulta '';
  7737.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7738.         $invoice $em->getRepository(ProposalInvoice::class)->findOneByProposalId($proposal->getId());
  7739.         if (!empty($invoice)) {
  7740.             $invoiceconsulta $invoice;
  7741.             $typeconsulta $invoice->getType();
  7742.         }
  7743.         $parametersNew = array(
  7744.             'proposalId' => $proposal->getId(),
  7745.             'recommended' => '0',
  7746.             'priority' => '0',
  7747.         );
  7748.         $dqlNew 'SELECT p
  7749.                     FROM EventsBundle:ProposalSupplierServicesBudgetControl p
  7750.                     WHERE p.proposalId = :proposalId 
  7751.                     AND p.recommended = :recommended
  7752.                     AND p.priority != :priority
  7753.                     ORDER BY p.priority ASC';
  7754.         $queryNew $em->createQuery($dqlNew)->setParameters($parametersNew);
  7755.         $controlbudgetsNew $queryNew->getResult();
  7756.         $sidebarData $this->sidebarAction($token"""");
  7757.         $noinvoice false;
  7758.         if (!empty($invoiceconsulta)) {
  7759.             $type $invoiceconsulta->getType();
  7760.             $number $invoiceconsulta->getNumber();
  7761.             $date $invoiceconsulta->getDateAt();
  7762.             $prefix $invoiceconsulta->getPrefix();
  7763.             $data $this->baseInvoiceProposal($proposal->getId(), $type$number$prefix$date$request);
  7764.             $token $data['token'];
  7765.             return $this->render(
  7766.                 'MDS/EventsPresentationBundle/presentation/invoice.html.twig',
  7767.                 array(
  7768.                     'id' => $proposal->getId(),
  7769.                     'type' => $data['type'],
  7770.                     'number' => $data['number'],
  7771.                     'prefix' => $data['prefix'],
  7772.                     'date' => $data['date'],
  7773.                     'token' => $token,
  7774.                     'proposal' => $data['proposal'],
  7775.                     'company' => $data['company'],
  7776.                     'clients' => $data['clients'],
  7777.                     'datasupplier' => $data['datasupplier'],
  7778.                     'totales_neto_antes' => $data['totales_neto_antes'],
  7779.                     'totales_neto' => $data['totales_neto'], // totales neto
  7780.                     'bases_imponibles' => $data['bases_imponibles'],
  7781.                     'totales_antes' => $data['totales_antes'],
  7782.                     'totales' => $data['totales'], // totales generales
  7783.                     'balance' => $data['balance'],
  7784.                     'totales_generales' => $data['totales_generales'],
  7785.                     'currency' => $data['currency'],
  7786.                     'detail_iva' => 'no',
  7787.                     'discounts' => $data['discounts'],
  7788.                     'paymentInvoice' => $data['paymentInvoice'],
  7789.                     'invoiceDesposit' => $data['invoiceDesposit'],
  7790.                     'mcp' => $data['proposal']->getMcp(),
  7791.                     'noinvoice' => $noinvoice,
  7792.                     'sidebar' => $sidebarData,
  7793.                     'client' => $client,
  7794.                     'budgetNew' => $controlbudgetsNew,
  7795.                     //                    'agendas' => $showAgenda,
  7796.                 )
  7797.             );
  7798.         } else {
  7799.             $noinvoice true;
  7800.             $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  7801.             return $this->render(
  7802.                 'MDS/EventsPresentationBundle/presentation/invoice.html.twig',
  7803.                 array(
  7804.                     'id' => $proposal->getId(),
  7805.                     'proposal' => $proposal,
  7806.                     'noinvoice' => $noinvoice,
  7807.                     'sidebar' => $sidebarData,
  7808.                     'client' => $client,
  7809.                     'token' => $token,
  7810.                     'budgetNew' => $controlbudgetsNew,
  7811.                     'selectType' => $selectType,
  7812.                     //                    'agendas' => $showAgenda,
  7813.                     'company' => $company,
  7814.                 )
  7815.             );
  7816.         }
  7817.     }
  7818.     /**
  7819.      * @Route("/cancelled/{token}",  name="presentation_error_cancel")
  7820.      */
  7821.     public function canceledInvoiceAction($tokenRequest $request)
  7822.     {
  7823.         $em $this->getDoctrine()->getManager();
  7824.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7825.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7826.         $sidebarData $this->sidebarAction($token"""");
  7827.         return $this->render(
  7828.             'MDS/EventsPresentationBundle/presentation/canceled_invoice.html.twig',
  7829.             array(
  7830.                 'proposal' => $proposal,
  7831.                 'sidebar' => $sidebarData,
  7832.                 'client' => $client,
  7833.                 'token' => $token,
  7834.             )
  7835.         );
  7836.     }
  7837.     /**
  7838.      * @Route("/disclaimer/",  name="disclaimer")
  7839.      */
  7840.     public function disclaimer($tokenRequest $request)
  7841.     {
  7842.         return $this->render(
  7843.             'MDS/EventsPresentationBundle/presentation/disclaimer.html.twig'
  7844.         );
  7845.     }
  7846.     /**
  7847.      * @Route("/showDiary/{token}/{controlId}",  name="presentation_show_diary")
  7848.      */
  7849.     public function showDiaryAction($token$controlIdRequest $request)
  7850.     {
  7851.         $em $this->getDoctrine()->getManager();
  7852.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7853.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7854.         $sidebarData $this->sidebarAction($token"""");
  7855.         $diary $em->getRepository(ProposalAgendaPresupuesto::class)->findBy(
  7856.             array(
  7857.                 'proposalId' => $proposal->getId(),
  7858.                 'controlId' => $controlId,
  7859.             ),
  7860.             array(
  7861.                 'dateInAt' => 'ASC',
  7862.             )
  7863.         );
  7864.         $generalDiaryData $em->getRepository(ProposalAgendaPresupuestoControl::class)->findOneBy(
  7865.             array(
  7866.                 'proposalId' => $proposal->getId(),
  7867.                 'controlId' => $controlId,
  7868.             )
  7869.         );
  7870.         $diaryData = array();
  7871.         $dateAux null;
  7872.         foreach ($diary as $data) {
  7873.             $diaryData[$data->getDateInAt()->format('Y/m/d')]['services'][] = $data;
  7874.             if ($dateAux != $data->getDateInAt()->format('Y/m/d')) {
  7875.                 $dateAux $data->getDateInAt()->format('Y/m/d');
  7876.                 $diaryData[$data->getDateInAt()->format('Y/m/d')]['date'] = $dateAux;
  7877.             }
  7878.             //            $diaryData[] = $data;
  7879.         }
  7880.         return $this->render(
  7881.             'MDS/EventsPresentationBundle/presentation/agenda-presupuesto.html.twig',
  7882.             array(
  7883.                 'proposal' => $proposal,
  7884.                 'sidebar' => $sidebarData,
  7885.                 'client' => $client,
  7886.                 'token' => $token,
  7887.                 'diary' => $diaryData,
  7888.                 'general' => $generalDiaryData,
  7889.                 //                'agendas' => $showAgenda,
  7890.             )
  7891.         );
  7892.     }
  7893.     /**
  7894.      * @Route("/aboutUs/{token}",  name="presentation_about_us")
  7895.      */
  7896.     public function aboutUsAction($tokenRequest $request)
  7897.     {
  7898.         $em $this->getDoctrine()->getManager();
  7899.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7900.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7901.         $sidebarData $this->sidebarAction($token"""");
  7902.         return $this->render(
  7903.             'MDS/EventsPresentationBundle/presentation/aboutUs.html.twig',
  7904.             array(
  7905.                 'proposal' => $proposal,
  7906.                 'sidebar' => $sidebarData,
  7907.                 'client' => $client,
  7908.                 'token' => $token,
  7909.                 //                'agendas' => $showAgenda,
  7910.             )
  7911.         );
  7912.     }
  7913.     // Funcion para insertar historico de seguimiento
  7914.     private function TracingHistoryOperations($id$text)
  7915.     {
  7916.         $em $this->getDoctrine()->getManager();
  7917.         /* Obtengo usuario logueado */
  7918.         $user_id "0";
  7919.         $history = new ProposalTracing();
  7920.         $history->setDateAt(new \DateTime('now'));
  7921.         $history->setText($text);
  7922.         $history->setAgentId($user_id);
  7923.         $history->setProposalId($id);
  7924.         $history->setViewed('no');
  7925.         $history->setCreatedId($user_id);
  7926.         $history->setUpdatedId($user_id);
  7927.         $em->persist($history);
  7928.         $em->flush();
  7929.         $success 'success';
  7930.         return $success;
  7931.     }
  7932.     /**
  7933.      * @Route("/menu/{token}", name="presentation_menu_view_token")
  7934.      */
  7935.     public function MenuAction($tokenRequest $request)
  7936.     {
  7937.         $em $this->getDoctrine()->getManager();
  7938.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  7939.         if ($proposal->getStatus() == "Cancel") {
  7940.             return $this->redirectToRoute(
  7941.                 'presentation_error_cancel',
  7942.                 array(
  7943.                     'token' => $token
  7944.                 )
  7945.             );
  7946.         }
  7947.         if (is_null($proposal->getSelectType())) {
  7948.             $selectTypearray = array();
  7949.         } else {
  7950.             $selectTypearray explode(","$proposal->getSelectType());
  7951.         }
  7952.         //        d($selectTypearray);
  7953.         $selectType = array();
  7954.         foreach ($selectTypearray as $selectTypedata) {
  7955.             $agrupacionetiquetas $em->getRepository(SupplierSettingsType::class)->findOneByBase($selectTypedata);
  7956.             if (empty($agrupacionetiquetas)) {
  7957.                 $selectType['NoHay'][] = $selectTypedata;
  7958.             } else {
  7959.                 if (is_null($agrupacionetiquetas->getGroupBase())) {
  7960.                     $selectType['NoHay'][] = $selectTypedata;
  7961.                 } else {
  7962.                     $selectType[$agrupacionetiquetas->getGroupBase()][] = $selectTypedata;
  7963.                 }
  7964.             }
  7965.         }
  7966.         //        d($selectType);
  7967.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  7968.         // Usuario Anonimo es = "anon."
  7969.         if ($user_logueado == "anon.") {
  7970.             $proposal->setViewedAt(new \DateTime("now"));
  7971.             $em->persist($proposal);
  7972.             $em->flush();
  7973.         }
  7974.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  7975.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  7976.         $musica =  $em->getRepository(PresentationMusic::class)->findOneBy(
  7977.             array(
  7978.                 'id' => $proposal->getIdMusic()
  7979.             )
  7980.         );
  7981.         return $this->render(
  7982.             'MDS/EventsPresentationBundle/presentation/menu.html.twig',
  7983.             array(
  7984.                 'token' => $token,
  7985.                 'proposal' => $proposal,
  7986.                 'selectType' => $selectType,
  7987.                 'company' => $company,
  7988.                 'client' => $client,
  7989.                 'music' => $musica,
  7990.             )
  7991.         );
  7992.     }
  7993.     /**
  7994.      * @Route("/submenu/{idg}/{token}", name="presentation_submenu_view_token")
  7995.      */
  7996.     public function SubmenuViewAction($idg$tokenRequest $request)
  7997.     {
  7998.         $em $this->getDoctrine()->getManager();
  7999.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  8000.         if ($proposal->getStatus() == "Cancel") {
  8001.             return $this->redirectToRoute(
  8002.                 'presentation_error_cancel',
  8003.                 array(
  8004.                     'token' => $token
  8005.                 )
  8006.             );
  8007.         }
  8008.         switch ($idg) {
  8009.             case 1:
  8010.                 $namerGroup "LOGÍSTICA";
  8011.                 break;
  8012.             case 2:
  8013.                 $namerGroup "PRODUCCIÓN";
  8014.                 break;
  8015.             case 3:
  8016.                 $namerGroup "TECNOLOGÍA";
  8017.                 break;
  8018.         }
  8019.         if (is_null($proposal->getSelectType())) {
  8020.             $selectTypearray = array();
  8021.         } else {
  8022.             $selectTypearray explode(","$proposal->getSelectType());
  8023.         }
  8024.         //        d($selectTypearray);
  8025.         $selectType = array();
  8026.         foreach ($selectTypearray as $selectTypedata) {
  8027.             $agrupacionetiquetas $em->getRepository(SupplierSettingsType::class)->findOneByBase($selectTypedata);
  8028.             if (empty($agrupacionetiquetas)) {
  8029.                 $selectType['NoHay'][] = $selectTypedata;
  8030.             } else {
  8031.                 if (is_null($agrupacionetiquetas->getGroupBase())) {
  8032.                     $selectType['NoHay'][] = $selectTypedata;
  8033.                 } else {
  8034.                     if ($namerGroup == $agrupacionetiquetas->getGroupBase()) {
  8035.                         $selectType[$agrupacionetiquetas->getGroupBase()][] = $selectTypedata;
  8036.                     }
  8037.                 }
  8038.             }
  8039.         }
  8040.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  8041.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  8042.         //        d($selectType);
  8043.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8044.         // Usuario Anonimo es = "anon."
  8045.         if ($user_logueado == "anon.") {
  8046.             $proposal->setViewedAt(new \DateTime("now"));
  8047.             $em->persist($proposal);
  8048.             $em->flush();
  8049.         }
  8050.         //
  8051.         return $this->render(
  8052.             'MDS/EventsPresentationBundle/presentation/submenu.html.twig',
  8053.             array(
  8054.                 'token' => $token,
  8055.                 'proposal' => $proposal,
  8056.                 'selectType' => $selectType,
  8057.                 'client' => $client,
  8058.                 'company' => $company,
  8059.             )
  8060.         );
  8061.     }
  8062.     /**
  8063.      * @Route("/presupuesto/{token}", name="presentation_presupuesto_view_token")
  8064.      */
  8065.     public function PresupuestoViewAction($tokenRequest $request)
  8066.     {
  8067.         $em $this->getDoctrine()->getManager();
  8068.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  8069.         if ($proposal->getStatus() == "Cancel") {
  8070.             return $this->redirectToRoute(
  8071.                 'presentation_error_cancel',
  8072.                 array(
  8073.                     'token' => $token
  8074.                 )
  8075.             );
  8076.         }
  8077.         if (is_null($proposal->getSelectType())) {
  8078.             $selectTypearray = array();
  8079.         } else {
  8080.             $selectTypearray explode(","$proposal->getSelectType());
  8081.         }
  8082.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  8083.         // Usuario Anonimo es = "anon."
  8084.         if ($user_logueado == "anon.") {
  8085.             $proposal->setViewedAt(new \DateTime("now"));
  8086.             $em->persist($proposal);
  8087.             $em->flush();
  8088.         }
  8089.         $controlbudget = array(
  8090.             '0' => array(),
  8091.             '1' => array(),
  8092.             '0a' => array()
  8093.         );
  8094.         $controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($proposal->getId());
  8095.         foreach ($controlbudgets as $controlbudge) {
  8096.             if (is_null($controlbudge->getByClient())) {
  8097.                 $byclient "";
  8098.             } else {
  8099.                 $byclient "a";
  8100.             }
  8101.             $controlbudget[$controlbudge->getRecommended() . $byclient][] = $controlbudge;
  8102.         }
  8103.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  8104.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  8105.         return $this->render(
  8106.             'MDS/EventsPresentationBundle/presentation/presupuesto.html.twig',
  8107.             array(
  8108.                 'token' => $token,
  8109.                 'proposal' => $proposal,
  8110.                 'budgets' => $controlbudget,
  8111.                 'client' => $client,
  8112.                 'company' => $company,
  8113.             )
  8114.         );
  8115.     }
  8116.     /**
  8117.      * @Route("/idea/{token}",  name="presentation_ideaview")
  8118.      */
  8119.     public function IdeaViewAction($tokenRequest $request)
  8120.     {
  8121.         $em $this->getDoctrine()->getManager();
  8122.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  8123.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  8124.         $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  8125.         $galeria $em->getRepository(PresentationGallery::class)->findByProposalId($proposal->getId());
  8126.         $description $em->getRepository(ProposalDescription::class)->findOneBy(
  8127.             array('proposalId' => $proposal->getId(), 'language' => $proposal->getLanguage())
  8128.         );
  8129.         //        d($description);exit();
  8130.         $musica =  $em->getRepository(PresentationMusic::class)->findOneBy(
  8131.             array(
  8132.                 'id' => $proposal->getIdMusic()
  8133.             )
  8134.         );
  8135.         $video_sinservices $em->getRepository(PresentationVideo::class)->findByProposalId($proposal->getId());
  8136.         $datos_videos = array();
  8137.         if (!empty($video_sinservices)) {
  8138.             foreach ($video_sinservices as $videoview) {
  8139.                 $urlvideo $videoview->getVideo();
  8140.                 $esyoutube strpos($urlvideo'youtube');
  8141.                 if ($esyoutube !== false) {
  8142.                     $urvideo_final '<iframe class="embed-responsive-item" src="' $urlvideo '"></iframe>';
  8143.                 }
  8144.                 $esvimeo strpos($urlvideo'vimeo');
  8145.                 if ($esvimeo !== false) {
  8146.                     $urvideo_final '<iframe allowfullscreen="" frameborder="0" mozallowfullscreen="" src="' $urlvideo '?title=0&amp;byline=0&amp;portrait=0" webkitallowfullscreen=""></iframe>';
  8147.                 }
  8148.                 $datos_videos[] = array(
  8149.                     'id' => $videoview->getId(),
  8150.                     'urlvideo' => $urvideo_final
  8151.                 );
  8152.             }
  8153.         }
  8154.         $bg '/assets/img/presentation-two/02hero.jpg';
  8155.         //            d($galeria); exit();
  8156.         return $this->render(
  8157.             'MDS/EventsPresentationBundle/presentation/idea.html.twig',
  8158.             array(
  8159.                 'proposal' => $proposal,
  8160.                 'client' => $client,
  8161.                 'bg' => $bg,
  8162.                 'token' => $token,
  8163.                 'galeria' => $galeria,
  8164.                 'video' => $datos_videos,
  8165.                 'description' => $description,
  8166.                 'company' => $company,
  8167.                 'music' => $musica,
  8168.             )
  8169.         );
  8170.     }
  8171. }