src/MDS/AvexpressBundle/Controller/FilesController.php line 744

Open in your IDE?
  1. <?php
  2. namespace App\MDS\AvexpressBundle\Controller;
  3. use App\Entity\Cities;
  4. use App\Entity\Client;
  5. use App\Entity\Configuration;
  6. use App\Entity\Country;
  7. use App\Entity\Destination;
  8. use App\Entity\Regions;
  9. use App\Entity\SettingsCompany;
  10. use App\Entity\User;
  11. use App\Entity\HtFile;
  12. use App\MDS\AvexpressBundle\Entity\AveBenefitsSupplier;
  13. use App\MDS\AvexpressBundle\Entity\AveBriefings;
  14. use App\MDS\AvexpressBundle\Entity\AveBudgetPending;
  15. use App\MDS\GreenPatioBundle\Entity\Reservation;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use DateTime;
  20. use App\MDS\AvexpressBundle\Entity\AveFiles;
  21. use App\MDS\AvexpressBundle\Entity\AveBudgetToProforma;
  22. use App\MDS\AvexpressBundle\Entity\AveDocInvoice;
  23. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceItems;
  24. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRec;
  25. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRecItems;
  26. use App\MDS\AvexpressBundle\Entity\AveDocProforma;
  27. use App\MDS\AvexpressBundle\Entity\AveDocProformaItems;
  28. use App\MDS\AvexpressBundle\Entity\AvePaymentsClient;
  29. use App\MDS\AvexpressBundle\Entity\AveProduct;
  30. use App\MDS\AvexpressBundle\Entity\AveProductFile;
  31. use App\MDS\AvexpressBundle\Entity\AveServices;
  32. use App\MDS\DevelupBundle\Entity\MdvTelegramUser;
  33. use App\MDS\EventsBundle\Entity\Proposal;
  34. use App\MDS\EventsBundle\Entity\ProposalAgents;
  35. use App\MDS\EventsBundle\Entity\ProposalInvoice;
  36. use App\MDS\EventsBundle\Entity\ProposalSupplierControl;
  37. use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
  38. use Swift_Mailer;
  39. use Swift_Message;
  40. use Swift_SmtpTransport;
  41. use Symfony\Contracts\Translation\TranslatorInterface;
  42. class FilesController extends AbstractController
  43. {
  44.     private $translator;
  45.     public function __construct(TranslatorInterface $translator) {
  46.         $this->translator $translator;
  47.     }
  48.     
  49.     /**
  50.      * @Route("/fileadd/",  name="ave_add_file")
  51.      * Agregar un expediente
  52.      */
  53.     public function addFileActionRequest $request)
  54.     {
  55.         $em $this->getDoctrine()->getManager();
  56.         $clients $em->getRepository(Client::class)->findAll();
  57.         $destinations $em->getRepository(Destination::class)->findAll();
  58.         $aveFiles $em->getRepository(AveFiles::class)->findAll();
  59.         $id =0;
  60.         if (empty($aveFiles)){
  61.             $id ++;
  62.         } else {
  63.             $lastElem end($aveFiles);
  64.             $id $lastElem->getId() + 1;
  65.         }
  66.         return $this->render('MDS/AvexpressBundle/Avexpress/add-files.html.twig',
  67.             array(
  68.                 'id' => $id,
  69.                 'clients' => $clients,
  70.                 'destinations' => $destinations,
  71.                 'clientId' => 0,
  72.             ));
  73.     }
  74.     /**
  75.      * @Route("/filelist/",  name="ave_list_file")
  76.      * Listar expedientes
  77.      */
  78.     public function listFileActionRequest $request)
  79.     {
  80.         $em $this->getDoctrine()->getManager();
  81.         $idgroup null;
  82.         $parameters = array( 'status' => 'Deleted' );
  83.         $dql 'SELECT i
  84.                 FROM AvexpressBundle:AveFiles i
  85.                 WHERE i.status != :status
  86.                 ORDER BY i.dateStart DESC ';
  87.         $query $em->createQuery($dql)->setParameters($parameters);
  88.         $ref = array();
  89.         $reservas $query->getResult();
  90.         foreach ($reservas as $res) {
  91.             $client $em->getRepository(Client::class)->findOneById($res->getClient());
  92.             if (!empty($client)) { $res->setClient($client->getName()); } else { $res->setClient(null); }
  93.             if (!empty($res->getDateStart()) and !empty($res->getDateEnd())) {
  94.                 $ref[$res->getId()] = '#' . ($res->getDateStart())->format('ymd') . ($res->getDateEnd())->format('ymd');
  95.             } else {
  96.                 $ref[$res->getId()] = '#' '000000' '000000';
  97.             }
  98.         }
  99.         $reservasZero = array();
  100.         foreach ($reservas as $res) {
  101.             $reservasZero[] = array(
  102.                 'dateStart' => $res->getDateStart(),
  103.                 'dateEnd' => $res->getDateEnd(),
  104.                 'id' => $res->getId(),
  105.                 'title' => $res->getTitle(),
  106.                 'client' => $res->getClient(),
  107.                 'createdId' => $res->getCreatedId(),
  108.                 'ref' => $ref[$res->getId()],
  109.                 'reservation' => $res->getReservation(),
  110.             );
  111.         }
  112.         $reservas $reservasZero;
  113.         return $this->render('MDS/AvexpressBundle/Avexpress/list-files.html.twig',
  114.             array(
  115.                 'groups' => null,
  116.                 'listofdeletedfiles' => false,
  117.                 'reservations' => $reservas
  118.             )
  119.         );
  120.     }
  121.     /**
  122.      * @Route("/filesave/",  name="ave_save_file")
  123.      * Guardar un expediente nuevo
  124.      */
  125.     public function saveFileActionRequest $request)
  126.     {
  127.         $em $this->getDoctrine()->getManager();
  128.         $newRequest $request->request->get('avexpress');
  129.         if (empty($newRequest['title'])){ return $this->redirectToRoute('ave_add_file'); }
  130.         /* Obtengo usuario logueado */
  131.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  132.         $user_id $user_logueado->getId();
  133.         $newFile = new AveFiles();
  134.         $newFile->setTitle($newRequest['title']);
  135.         $newFile->setClient($newRequest['client']);
  136.         if (!empty($newRequest['idProposal'])){
  137.             $newFile->setIdProposal($newRequest['idProposal']);
  138.         } else {
  139.             $newFile->setIdProposal(null);
  140.         }
  141.         $newFile->setStatus($newRequest['status']);
  142.         $newFile->setAdvancePayment($newRequest['advancePayment']);
  143.         $newFile->setDescription($newRequest['description']);
  144.         if (empty($newRequest['dateStart'])){
  145.             $newFile->setDateStart(new \DateTime("now"));
  146.         } else {
  147.             $newFile->setDateStart(new \DateTime($newRequest['dateStart']));}
  148.         if (empty($newRequest['dateEnd'])){
  149.             $newFile->setDateEnd(new \DateTime("now"));
  150.         } else {
  151.             $newFile->setDateEnd(new \DateTime($newRequest['dateEnd']));}
  152.         if (!empty($newRequest['destination'])){
  153.             $newFile->setDestinoId($newRequest['destination']);
  154.         }
  155.         $newFile->setCreatedId($user_id);
  156.         $newFile->setUpdatedId($user_id);
  157.         $newFile->setCreatedAt(new \DateTime("now"));
  158.         $newFile->setUpdatedAt(new \DateTime("now"));
  159.         $em->persist($newFile);
  160.         $em->flush();
  161.         $clients $em->getRepository(Client::class)->findAll();
  162.         $products $em->getRepository(AveProduct::class)->findAll();
  163.         $data $this->calculosFile($newFile->getId(), null0'File');
  164.         $sumatoriaTotalNet 0;
  165.         $sumatoriaTotalVat 0;
  166.         $sumatoriaTotal 0;
  167.         $resultados = array(
  168.             'totalNeto' => $sumatoriaTotalNet,
  169.             'vat' => $sumatoriaTotalVat,
  170.             'total' => $sumatoriaTotal,
  171.         );
  172.         $productInFile $em->getRepository(AveProductFile::class)->findByFileId($newFile->getId());
  173.         $numeroItems sizeof($productInFile);
  174.         return $this->redirectToRoute('ave_edit_file', array( 'id' => $newFile->getId() ));
  175.     }
  176.     /**
  177.      * @Route("/fileupdate/{id}",  name="ave_update_file")
  178.      * Actualizar un expediente
  179.      */
  180.     public function updateFileAction($idRequest $request)
  181.     {
  182.         $logTelegram false;
  183.         $numberToPrefix 0;
  184.         $em $this->getDoctrine()->getManager();
  185.         $newFile $em->getRepository(AveFiles::class)->findOneById($id);
  186.         $newRequest $request->request->get('avexpress');
  187.         $srvInconsistentes '';                    // Mensaje de alerta por inconsistencia en los servicios
  188.         // INICIO: Si existe un documento creado no se puede cambiar el cliente
  189.         $oldDoc $em->getRepository(AveDocInvoice::class)->findOneByFileId($id);
  190.         $noexistefactura = empty($oldDoc);
  191.         // FIN: Si existe un documento creado no se puede cambiar el cliente
  192.         /* Obtengo usuario logueado */
  193.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  194.         $user_id $user_logueado->getId();
  195.         if (!empty($newRequest['title'])){$newFile->setTitle($newRequest['title']);}
  196.         if ($noexistefactura)
  197.             {
  198.                 $newFile->setClient($newRequest['client']);
  199.                 $msjErrorClt '';
  200.             }
  201.         else
  202.             { /* Hay una factura, no se debe cambiar el cliente */
  203.                 // Verificamos si intenta cambiar el cliente para informar que no es posible hacerlo
  204.                 if (!($newFile->getClient() == $newRequest['client'])){
  205.                     $msjErrorClt 'El cliente no puede ser modificado, ya existe una factura previa';
  206.                 } else {
  207.                     $msjErrorClt '';
  208.                 }
  209.             }
  210.         if (!empty($newRequest['idProposal'])){$newFile->setIdProposal($newRequest['idProposal']);} else {$newFile->setIdProposal(null);}
  211.         $newFile->setStatus($newRequest['status']);
  212.         $newFile->setDescription($newRequest['description']);
  213.         $newFile->setUpdatedId($user_id);
  214.         $newFile->setUpdatedAt(new \DateTime("now"));
  215.         if (!empty($newRequest['destination'])){$newFile->setDestinoId($newRequest['destination']);}
  216.         if (!empty($newRequest['dateStart'])){$newFile->setDateStart(new DateTime($newRequest['dateStart']));}
  217.         if (!empty($newRequest['dateEnd'])){$newFile->setDateEnd(new DateTime($newRequest['dateEnd']));}
  218.         if (!empty($newRequest['xtraFieldOne'])){$newFile->setXtraFieldOne($newRequest['xtraFieldOne']);}
  219.         try{
  220.             $em->persist($newFile);
  221.             $em->flush();
  222.             $event 'El expediente ha sido actualizado. ';
  223.             if (!empty($msjErrorClt)){ $event $event.$msjErrorClt; }
  224.             $successMessage $this->translator->trans($event);
  225.             $this->addFlash('mensajeav'$successMessage);
  226.         } catch (\Exception $e){
  227.             $event 'An error occurred: '.$e->getMessage();
  228.             /* Para el usuario */
  229.             $errorMessage $this->translator->trans($event);
  230.             $this->addFlash('mensajeaverror'$errorMessage);
  231.         }
  232.         $productInFile $em->getRepository(AveProductFile::class)->findByFileId($newFile->getId());
  233.         $txtWarning '';
  234.         if(!empty($newFile->getIdProposal())){
  235.             // El expediente se ha relacionado con un proposal, se debe actualizar en eventos
  236.             $file $newFile;
  237.             // Si hay proposal se debe actualizar en el expediente de Eventos
  238.             if (!empty($file->getIdProposal()) and is_numeric($file->getIdProposal())){
  239.                 // Buscamos el destino donde se encuentre Avexpress y ahi agregamos el servicio, si no se encuentra no se agregara el servicio
  240.                 $control $em->getRepository(ProposalSupplierControl::class)->findOneBy(
  241.                     array(
  242.                         'supplierId' => 80,                                          // El supplier 80 es Avexpress
  243.                         'proposalId' => $file->getIdProposal(),
  244.                     )
  245.                 );
  246.                 // INICIO: Buscamos la info del lado de eventos (SINCRONIZACION)
  247.                 $txtOfChanges ''//Mensaje para el agente de cambios en los servicios hechos desde AvExpress
  248.                 $proposal $em->getRepository(Proposal::class)->findOneById($file->getIdProposal());
  249.                 $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  250.                 $agentFullName $agent->getName().' '.$agent->getLastName();
  251.                 $proposalTitle $proposal->getId().' - '.$proposal->getTitle();
  252.                 // FIN: Buscamos la info del lado de eventos
  253.                 foreach ($productInFile as $item){
  254.                     //Si las fechas de inicio y fin no coinciden con el campo dias se debe enviar alerta
  255.                     $txtWarning = ($item->getDateOutAt()->diff($item->getDateInAt()))->days <> $item->getDays() ? '<br>'.$item->getProductName() : '';
  256.                     if (!empty($txtWarning)){
  257.                         if (empty($srvInconsistentes)){ $srvInconsistentes 'Hay inconsistencias en: '.'<br>'.$txtWarning; } else { $srvInconsistentes $srvInconsistentes.'<br>'.$txtWarning; }
  258.                     }
  259.                     if (!empty($control)){
  260.                         // Existe un destino con AvExpress como proveedor, ahĆ­ se agregara el servicio
  261.                         $yaexistiaunservicio false$proposalServicex null;
  262.                         // Se verifica que no el productfile Av no tenga imagen en Eventos
  263.                         if (!empty($item->getOriginId())){
  264.                             // Se verifica que aun exista en Eventos  el servicio
  265.                             $proposalServicex $em->getRepository(ProposalSupplierServices::class)->findOneById($item->getOriginId());
  266.                             if (!empty($proposalServicex)){ $yaexistiaunservicio true; } else { $yaexistiaunservicio false; }
  267.                         } else {
  268.                             // no estaba relacionado con nada en eventos, se crea uno nuevo
  269.                             $yaexistiaunservicio false;
  270.                         }
  271.                         if ($yaexistiaunservicio){
  272.                             $prpInv $em->getRepository(ProposalInvoice::class)->findOneByProposalId($file->getIdProposal());
  273.                             if (empty($prpInv)) { //Si hay factura en InOut no se debe modificar
  274.                                 $service $proposalServicex;
  275.                                 $oldServiceEvent = array(
  276.                                     'activityId' => $service->getActivityId(),
  277.                                     'assistantId' => $service->getAssistantId(),
  278.                                     'breakdown' => $service->getBreakdown(),
  279.                                     'commission' => $service->getCommission(),
  280.                                     'controlId' => $service->getControlId(),
  281.                                     'currency' => $service->getCurrency(),
  282.                                     'dateBlockLimit' => $service->getDateBlockLimit(),
  283.                                     'dateInAt' => $service->getDateInAt(),
  284.                                     'dateOutAt' => $service->getDateOutAt(),
  285.                                     'destinationId' => $service->getDestinationId(),
  286.                                     'directPayment' => $service->getDirectPayment(),
  287.                                     'hour' => $service->getHour(),
  288.                                     'ideaId' => $service->getIdeaId(),
  289.                                     'isFather' => $service->getIsFather(),
  290.                                     'iva' => $service->getIva(),
  291.                                     'name' => $service->getName(),
  292.                                     'opCommission' => $service->getOpCommission(),
  293.                                     'opIva' => $service->getOpIva(),
  294.                                     'opOver' => $service->getOpOver(),
  295.                                     'originalIva' => $service->getOriginalIva(),
  296.                                     'originalPrice' => $service->getOriginalPrice(),
  297.                                     'originalopIva' => $service->getOriginalopIva(),
  298.                                     'over' => $service->getOver(),
  299.                                     'pax' => $service->getPax(),
  300.                                     'preCommission' => $service->getPreCommission(),
  301.                                     'preIva' => $service->getPreIva(),
  302.                                     'price' => $service->getPrice(),
  303.                                     'proposalId' => $service->getProposalId(),
  304.                                     'rank' => $service->getRank(),
  305.                                     'serviceCatId' => $service->getServiceCatId(),
  306.                                     'serviceCatName' => $service->getServiceCatName(),
  307.                                     'serviceId' => $service->getServiceId(),
  308.                                     'serviceIdFather' => $service->getServiceIdFather(),
  309.                                     'status' => $service->getStatus(),
  310.                                     'statusRec' => $service->getStatusRec(),
  311.                                     'statusinternal' => $service->getStatusinternal(),
  312.                                     'supplierId' => $service->getSupplierId(),
  313.                                     'units' => $service->getUnits(),
  314.                                 );
  315.                                 $service->setName($item->getProductName());
  316.                                 // Se verifican los precios en ambas partes (AV Express e InOut)
  317.                                 if (!($service->getPrice() == $item->getServicePrice())) {
  318.                                     // Si ambos precios unitarios son distintos se ha modificado el numero de dĆ­as en Av Express
  319.                                     $newPriceInOut $this->precioPorVariacionDeDias($service$item);
  320.                                     $service->setPrice($newPriceInOut);
  321.                                 } else {
  322.                                     // si son iguales tambien se deben verificar el numero de dias
  323.                                     if (!(($service->getDateOutAt()->diff($service->getDateInAt())->days 1) == $item->getDays())) {
  324.                                         $newPriceInOut $this->precioPorVariacionDeDias($service$item);
  325.                                         $service->setPrice($newPriceInOut);
  326.                                     }
  327.                                 }
  328.                                 $service->setCurrency($item->getCurrency());
  329.                                 $service->setUnits($item->getUnits());
  330. //                            $service->setCommission(0);                                       // InOut puede haber metido una Comision y no se le debe modificar
  331. //                            $service->setOver(0);                                             // InOut puede haber metido un Over y no se le debe modificar
  332.                                 $service->setIva(21);
  333.                                 if (empty($item->getPax())) {
  334.                                     $service->setPax(1);
  335.                                 } else {
  336.                                     $service->setPax($item->getPax());
  337.                                 }
  338.                                 $service->setHour(null);
  339.                                 $service->setDateInAt($item->getDateInAt());
  340.                                 $service->setDateOutAt($item->getDateOutAt());
  341.                                 $service->setDirectPayment(0);
  342. //                            $service->setStatus('Pending');                                   // InOut puede haber Confirmado y no se le debe modificar
  343.                                 $service->setStatusinternal('Additional');
  344.                                 $service->setPreCommission(null);
  345.                                 $service->setPreIva(null);
  346.                                 $service->setDateBlockLimit(null);
  347. //                            $service->setOpCommission(1);                                     // InOut puede haber metido una Op Comision y no se le debe modificar
  348. //                            $service->setOpOver(1);                                           // InOut puede haber metido una Op Over y no se le debe modificar
  349. //                            $service->setOpIva(1);                                            // InOut puede haber metido una Op Iva y no se le debe modificar
  350.                                 $service->setBreakdown(0);
  351.                                 $service->setIsFather(0);
  352.                                 $service->setRank($this->rankAvParaInOutService($item->getId()));
  353.                                 $service->setOriginalopIva(1);
  354.                                 $service->setStatusRec('normal');
  355.                                 $service->setCreatedId($user_id);
  356.                                 $service->setUpdatedId($user_id);
  357.                                 $em->persist($service);
  358.                                 $em->flush();
  359.                                 // Se debe notificar por Telegram al agente de eventos
  360.                                 $logTelegram true;
  361.                                 //Verificamos cambios e informamos al agente del proposal
  362.                                 $boolChanges false;
  363.                                 if (!($service->getRank() == $oldServiceEvent['rank'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Orden</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['rank'].', su nuevo valor es: '.$service->getRank().'<br>'$boolChanges true; }
  364.                                 if (!($service->getName() == $oldServiceEvent['name'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Nombre</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['name'].', su nuevo valor es: '.$service->getName().'<br>'$boolChanges true; }
  365.                                 if (!($service->getPrice() == $oldServiceEvent['price'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Precio</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['price'].', su nuevo valor es: '.$service->getPrice().'<br>'$boolChanges true; }
  366.                                 if (!($service->getCurrency() == $oldServiceEvent['currency'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Moneda</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['currency'].', su nuevo valor es: '.$service->getCurrency().'<br>'$boolChanges true; }
  367.                                 if (!($service->getUnits() == $oldServiceEvent['units'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Cantidad</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['units'].', su nuevo valor es: '.$service->getUnits().'<br>'$boolChanges true; }
  368.                                 if (!($service->getPax() == $oldServiceEvent['pax'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Personas</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['pax'].', su nuevo valor es: '.$service->getPax().'<br>'$boolChanges true; }
  369.                                 if (!($service->getOpOver() == $oldServiceEvent['opOver'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>OpciĆ³n (-/+) del Over</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['opOver'].', su nuevo valor es: '.$service->getOpOver().'<br>'$boolChanges true; }
  370.                                 if (!($service->getOver() == $oldServiceEvent['over'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Over</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['over'].', su nuevo valor es: '.$service->getOver().'<br>'$boolChanges true; }
  371.                                 if (!($service->getOpCommission() == $oldServiceEvent['opCommission'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>OpciĆ³n (-/+) de la ComisiĆ³n</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['opCommission'].', su nuevo valor es: '.$service->getOpCommission().'<br>'$boolChanges true; }
  372.                                 if (!($service->getCommission() == $oldServiceEvent['commission'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>ComisiĆ³n" ha sido modificado. Su valor era: '.$oldServiceEvent['commission'].', su nuevo valor es: '.$service->getCommission().'<br>'$boolChanges true; }
  373.                                 if (!($service->getOpIva() == $oldServiceEvent['opIva'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>OpciĆ³n (-/+) del Iva</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['opIva'].', su nuevo valor es: '.$service->getOpIva().'<br>'$boolChanges true; }
  374.                                 if (!($service->getIva() == $oldServiceEvent['iva'])){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Iva</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['iva'].', su nuevo valor es: '.$service->getIva().'<br>'$boolChanges true; }
  375.                                 if (!($service->getDateInAt()->format('H:i') == $oldServiceEvent['dateInAt']->format('H:i'))){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Hora inicio</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['dateInAt']->format('H:i').', su nuevo valor es: '.$service->getDateInAt()->format('H:i').'<br>'$boolChanges true; }
  376.                                 if (!($service->getDateInAt()->format('Ymd') == $oldServiceEvent['dateInAt']->format('Ymd'))){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Fecha inicio</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['dateInAt']->format('d/m/Y').', su nuevo valor es: '.$service->getDateInAt()->format('d/m/Y').'<br>'$boolChanges true; }
  377.                                 if (!($service->getDateOutAt()->format('H:i') == $oldServiceEvent['dateOutAt']->format('H:i'))){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Hora fin</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['dateOutAt']->format('H:i').', su nuevo valor es: '.$service->getDateOutAt()->format('H:i').'<br>'$boolChanges true; }
  378.                                 if (!($service->getDateOutAt()->format('Ymd') == $oldServiceEvent['dateOutAt']->format('Ymd'))){ if (!$boolChanges){ $txtOfChanges =  $txtOfChanges.'<br><br>En el servicio: '.$service->getName().'<br>'; } $txtOfChanges $txtOfChanges '<br><br>El campo "<strong>Fecha fin</strong>" ha sido modificado. Su valor era: '.$oldServiceEvent['dateOutAt']->format('d/m/Y').', su nuevo valor es: '.$service->getDateOutAt()->format('d/m/Y').'<br>'$boolChanges true; }
  379.                             } else {
  380.                                 $srvAlreadyInvoiced 'Error al sincronizar. <br><br> InOut ya ha facturado.';
  381.                                 $this->addFlash('mensajeaverror'$srvAlreadyInvoiced);
  382.                             }
  383.                         } else{
  384.                             $prpInv $em->getRepository(ProposalInvoice::class)->findOneByProposalId($file->getIdProposal());
  385.                             if (empty($prpInv)) { //Si hay factura en InOut no se debe modificar
  386.                                 $service = new ProposalSupplierServices();
  387.                                 $service->setServiceIdFather(0);
  388.                                 $service->setControlId($control->getId());
  389.                                 $service->setProposalId($file->getIdProposal());
  390.                                 $service->setDestinationId($control->getDestinoId());
  391.                                 $service->setSupplierId(80);                                    // 80 es AvExpress
  392.                                 $service->setIdeaId(null);
  393.                                 $service->setServiceId($item->getProductId());
  394.                                 $service->setServiceCatName('Av');
  395.                                 $service->setServiceCatId(3);
  396.                                 $service->setName($item->getProductName());
  397.                                 $priceInOut $item->getSubTotalPrice();
  398.                                 if (!($item->getPax() == 0)) {
  399.                                     $priceInOut $priceInOut $item->getPax();                    // Se devuelve el calculo dividiendo entre personas
  400.                                 }
  401.                                 if (!($item->getUnits() == 0)) {
  402.                                     $priceInOut $priceInOut $item->getUnits();                  // Se devuelve el calculo dividiendo entre cantidades
  403.                                 }
  404.                                 if (!($item->getDays() == 0)) {
  405.                                     $priceInOut $priceInOut round($item->getDays());            // Se devuelve el calculo dividiendo entre dias, se redondea por si es 1.5
  406.                                 }
  407.                                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  408.                                 $priceInOut round($priceInOut2PHP_ROUND_HALF_UP);
  409.                                 $service->setPrice($priceInOut);
  410.                                 $service->setCurrency($item->getCurrency());
  411.                                 $service->setUnits($item->getUnits());
  412.                                 $service->setCommission(0);
  413.                                 $service->setOver(0);
  414.                                 $service->setIva(21);
  415.                                 if (empty($item->getPax())) { $service->setPax(1); } else { $service->setPax($item->getPax()); }
  416.                                 $service->setHour(null);
  417.                                 $service->setDateInAt($item->getDateInAt());
  418.                                 $service->setDateOutAt($item->getDateOutAt());
  419.                                 $service->setDirectPayment(0);
  420.                                 $service->setStatus('Pending');
  421.                                 $service->setStatusinternal('Additional');
  422.                                 $service->setPreCommission(null);
  423.                                 $service->setPreIva(null);
  424.                                 $service->setDateBlockLimit(null);
  425.                                 $service->setOpCommission(1);
  426.                                 $service->setOpOver(1);
  427.                                 $service->setOpIva(1);
  428.                                 $service->setBreakdown(0);
  429.                                 $service->setIsFather(0);
  430.                                 $service->setRank($this->rankAvParaInOutService($item->getId()));
  431.                                 $service->setOriginalopIva(1);
  432.                                 $service->setOriginalIva(null);
  433.                                 $service->setOriginalPrice(null);
  434.                                 $service->setStatusRec('normal');
  435.                                 $service->setAssistantId(null);
  436.                                 $service->setCreatedId($user_id);
  437.                                 $service->setUpdatedId($user_id);
  438.                                 $service->setCreatedAt(new \DateTime("now"));
  439.                                 $service->setUpdatedAt(new \DateTime("now"));
  440.                                 $em->persist($service);
  441.                                 $em->flush();
  442.                                 // Se relaciona el nuevo Servicio InOut con el Servicio AV
  443.                                 $item->setOriginId($service->getId());
  444.                                 $em->persist($item);
  445.                                 $em->flush();
  446.                                 // Se debe notificar por Telegram al agente de eventos
  447.                                 $logTelegram true;
  448.                             } else {
  449.                                 $srvAlreadyInvoiced 'Error al sincronizar. <br><br> InOut ya ha facturado.';
  450.                                 $this->addFlash('mensajeaverror'$srvAlreadyInvoiced);
  451.                             }
  452.                         }
  453.                     }
  454.                     // Notificamos al agente de InOut si se hicieron actualizaciones en los servicios desde AvExpress
  455.                     if (!empty($txtOfChanges)) { $this->messageOfChangesToAgent($txtOfChanges$proposal->getId()); }
  456.                     //INICIO: Creamos una orden de hacer proforma
  457.                     //INICIO: Calculamos el ID de la proforma
  458.                     $numberToPrefix $em->getRepository(AveDocProforma::class)->findAll();
  459.                     if (empty($numberToPrefix)){
  460.                         $numberToPrefix 0;
  461.                     } else {
  462.                         $numberToPrefix end($numberToPrefix)->getId();
  463.                     }
  464.                     $numberToPrefix++;
  465.                     //FIN: Calculamos el ID de la proforma
  466.                     $order = new AveBudgetToProforma();
  467.                     $order->setStatus('Pending');
  468.                     $order->setFileId($file->getId());
  469.                     $order->setProductFileId($item->getId());
  470.                     $order->setUserConfirmedId($proposal->getAgentId());
  471.                     $order->setUserConfirmedFullName($agentFullName);
  472.                     $order->setProposalTitle($proposalTitle);
  473.                     $order->setProformaId($numberToPrefix);
  474.                     $em->persist($order);
  475.                     $em->flush();
  476.                     //FIN: Creamos una orden de hacer proforma
  477.                 }
  478.                 $event 'Expediente guardado correctamente.';
  479.                 $successMessage $this->translator->trans($event);
  480.                 $this->addFlash('mensajeav'$successMessage);
  481.                 if (!empty($srvInconsistentes) and !empty($newFile->getIdProposal())){ $this->addFlash('mensajeaverror'$srvInconsistentes); }
  482.                 //INICIO: Notificamos al agente por Telegram
  483.                 if ($logTelegram){
  484.                     //Buscamos todos los agentes del proposal
  485.                     $proposalAgents $em->getRepository(ProposalAgents::class)->findOneByIdProp($proposal->getId());
  486.                     //Buscamos el Destino
  487.                     $proposalDestino $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
  488.                     //Buscamos el agente de Avexpress
  489.                     $userData $em->getRepository(User::class)->findOneById($user_id);
  490.                     if (!empty($proposalAgents) and !($user_id == 22)){
  491.                         if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))){
  492.                             $this->sendTelegram($proposalAgents->getAgOne(),'1. PROPOSAL ACTUALIZADO DESDE AVEXPRESS __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: AvExpress __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  493.                         }
  494.                         if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))){
  495.                             $this->sendTelegram($proposalAgents->getAgTwo(),'2. PROPOSAL ACTUALIZADO DESDE AVEXPRESS __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: AvExpress __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  496.                         }
  497.                         if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))){
  498.                             $this->sendTelegram($proposalAgents->getAgThree(),'3. PROPOSAL ACTUALIZADO DESDE AVEXPRESS __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: AvExpress __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  499.                         }
  500.                         if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))){
  501.                             $this->sendTelegram($proposalAgents->getAgFour(),'4. PROPOSAL ACTUALIZADO DESDE AVEXPRESS __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: AvExpress __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  502.                         }
  503.                     }
  504.                 }
  505.                 //FIN: Notificamos al agente por Telegram
  506.                 //INICIO: Creamos el presupuesto (proforma)
  507.                 $budToPro $em->getRepository(AveBudgetToProforma::class)->findByProformaId($numberToPrefix);
  508.                 //INICIO: Se agrupan por expediente (fileId)
  509.                 $proformas = array();
  510.                 foreach ($budToPro as $item){
  511.                     $proformas[$item->getFileId()][] = $item;
  512.                 }
  513.                 //FIN: Se agrupan por expediente (fileId)
  514.                 if (!empty($budToPro)){
  515.                     foreach ($proformas as $key => $elemento){
  516.                         //INICIO: Creamos las proformas
  517.                         $newProforma = new AveDocProforma();
  518.                         $newProforma->setPrefix('AVE-' . (new DateTime('now'))->format('dmy') . '-' $numberToPrefix '-' $key);
  519.                         $newProforma->setDateAt(new DateTime('now'));
  520.                         $newProforma->setFileId($key);
  521.                         $newProforma->setCreatedId($user_id);
  522.                         $newProforma->setUpdatedId($user_id);
  523.                         $newProforma->setCreatedAt(new DateTime('now'));
  524.                         $newProforma->setUpdatedAt(new DateTime('now'));
  525. //                        $em->persist($newProforma);
  526.                         $em->flush();
  527.                         //FIN: Creamos las proformas
  528.                         foreach ($elemento as $item) {
  529.                             //$key es el id del expediente
  530.                             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  531.                             //INICIO: Creamos los elemento que iran dentro de las proformas
  532.                             $itemProforma = new AveDocProformaItems();
  533.                             $itemProforma->setType('PRODUCT');
  534.                             $itemProforma->setFileId($key);
  535.                             $itemProforma->setProformaId($newProforma->getId());
  536.                             $itemProforma->setControlId($item->getProductFileId());
  537. //                            $em->persist($itemProforma);
  538.                             $em->flush();
  539.                             //INICIO: Confirmamos el BudToProforma
  540. //                            $item->setStatus('Tosend');              // El elemento se ha pasado a la proforma, solo falta enviar
  541.                             $item->setProformaId($newProforma->getId());
  542. //                            $em->persist($item);
  543.                             $em->flush();
  544.                             //FIN: Confirmamos el BudToProforma
  545.                             //FIN: Creamos los elemento que iran dentro de las proformas
  546.                         }
  547.                     }
  548.                 }
  549.                 //FIN: Creamos el presupuesto (proforma)
  550.                 // INICIO: Se envia al agente el presupuesto
  551.                 $budToPro $em->getRepository(AveBudgetToProforma::class)->findByStatus('Tosend');
  552.                 /* Obtengo usuario logueado */
  553.                 $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  554.                 $user_id $user_logueado->getId();
  555.                 $arrayIdPro = array();          // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  556.                 //INICIO: Se agrupan por expediente (fileId)
  557.                 $proformas = array();
  558.                 foreach ($budToPro as $item){
  559.                     $proformas[$item->getFileId()][] = $item;
  560.                 }
  561.                 //FIN: Se agrupan por expediente (fileId)
  562.                 if (!empty($budToPro)){
  563.                     foreach ($proformas as $key => $elemento){
  564.                         //INICIO: Creamos las proformas
  565.                         foreach ($elemento as $item) {
  566.                             //$key es el id del expediente
  567.                             if (!empty($item->getProformaId())) {
  568.                                 $arrayIdPro[$item->getProformaId()] = $item->getUserConfirmedId();             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  569.                             }
  570.                             //INICIO: Confirmamos el BudToProforma
  571.                             $item->setStatus('Confirmed');              // El elemento se ha pasado a confirmado porque se enviara por correo
  572.                             $em->persist($item);
  573.                             $em->flush();
  574.                             //FIN: Confirmamos el BudToProforma
  575.                             //FIN: Creamos los elemento que iran dentro de las proformas
  576.                         }
  577.                     }
  578.                 }
  579.                 //INICIO: Notificamos de todos los presupuestos (proformas) que se han creado
  580.                 foreach ($arrayIdPro as $key => $item){
  581.                     //Buscamos la info del proposal
  582.                     $xprof $em->getRepository(AveDocProforma::class)->findOneById($key);
  583.                     if (!empty($xprof)){
  584.                         $xfile $em->getRepository(AveFiles::class)->findOneById($xprof->getFileId());
  585.                         $xprop $em->getRepository(Proposal::class)->findOneById($xfile->getIdProposal());
  586.                         $xcli $em->getRepository(Client::class)->findOneById($xprop->getClientId());
  587.                         $xbody 'Proposal #'.$xprop->getId().' - '.$xprop->getName().
  588.                             '<br><a href="http://' $request->server->get('HTTP_HOST') . '/events/proposal/edit/' $xprop->getId() . '">Ver el Proposal</a>'.
  589.                             '<br>Cliente: '.$xcli->getName().
  590.                             '<br><br>' .'Presupuesto AvExpress #' $key  ', ' '<br><a href="http://' $request->server->get('HTTP_HOST') . '/pdf/avexpressproforma/' $key '">Ver el PDF del presupuesto</a><br><br>NotificaciĆ³n de nuevo presupuesto: Este presupuesto ha sido creado de forma automĆ”tica.' .
  591.                             '<br>Si el enlace al presupuesto no funciona correctamente, se debe a que desde AV lo han modificado o descartado.'.
  592.                             '<br><br>';
  593.                     } else {
  594.                         $xbody 'Presupuesto AvExpress #' $key  ', ' '<br><a href="http://' $request->server->get('HTTP_HOST') . '/pdf/avexpressproforma/' $key '">Ver el PDF del presupuesto</a><br><br>NotificaciĆ³n de nuevo presupuesto: Este presupuesto ha sido creado de forma automĆ”tica.' '<br><br>';
  595.                     }
  596.                     //Buscamos los agentes a notificar
  597.                     // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  598.                     $agent $em->getRepository(User::class)->findOneById($item);
  599.                     $agentMail $agent->getEmail();
  600.                     $mailAgent $agentMail;
  601.                     //Se prepara el correo con los agentes a notificar
  602.                     $firmGmail $agent->getFirmGmail();
  603.                     $data = array(
  604.                         'body' => $xbody,
  605.                         'firm' => $firmGmail,
  606.                     );
  607.                     // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  608.                     $transporter = new Swift_SmtpTransport();
  609.                         $transporter->setHost('smtp.gmail.com')
  610.                         ->setEncryption('ssl')//ssl / tls
  611.                         ->setPort(465)// 465 / 587
  612.                         ->setUsername('desarrollo@develup.solutions')
  613.                         ->setPassword('MeDITeRRANeAN_Develup30102023#');
  614.                     $mailer = new Swift_Mailer($transporter);
  615.                     $message = new Swift_Message();
  616.                         $message->setSubject('Presupuesto #' $key ', NotificaciĆ³n de nuevo presupuesto')
  617.                         ->setSender($agentMail)
  618.                         ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  619.                         ->setReplyTo($agentMail)
  620.                         ->setTo($mailAgent)
  621.                         ->setBody(
  622.                             $this->renderView(
  623.                                 'mail/structure-mail.html.twig',
  624.                                 array('data' => $data)
  625.                             ),
  626.                             'text/html'
  627.                         );
  628.                     $mailer->send($message);
  629.                 }
  630.                 //FIN: Notificamos de todos los presupuestos (proformas) que se han creado
  631.                 // FIN: Se envia al agente el presupuesto
  632.             }
  633.         }
  634.         if(!empty($msjErrorClt)){
  635.             $errorMessage $this->translator->trans('Error, el cliente no puede ser modificado, ya existe una factura previa');
  636.             $this->addFlash('mensajeaverror'$errorMessage);
  637.             return $this->redirectToRoute('ave_edit_file', array('id' => $newFile->getId()));
  638.         }
  639.         return $this->redirectToRoute('ave_edit_file', array('id' => $newFile->getId()));
  640.     }
  641.     /**
  642.      * @Route("/fileedit/{id}",  name="ave_edit_file")
  643.      * Editar un expediente
  644.      */
  645.     public function editFileAction$idRequest $request)
  646.     {
  647.         $em $this->getDoctrine()->getManager();
  648.         $editFile $em->getRepository(AveFiles::class)->findOneById($id);
  649.         $clients $em->getRepository(Client::class)->findAll();
  650.         $clientSelected $em->getRepository(Client::class)->findOneById($editFile->getClient());
  651.         $products $em->getRepository(AveProduct::class)->findAll();
  652.         $destinations $em->getRepository(Destination::class)->findAll();
  653.         /* Obtengo usuario logueado */
  654.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  655.         $data $this->calculosFile($idnull0'File');
  656.         $sumatoriaTotalNet 0;
  657.         $sumatoriaTotalVat 0;
  658.         $sumatoriaTotal 0;
  659.         $resultados = array(
  660.             'totalNeto' => $sumatoriaTotalNet,
  661.             'vat' => $sumatoriaTotalVat,
  662.             'total' => $sumatoriaTotal,
  663.         );
  664.         $productInFile $em->getRepository(AveProductFile::class)->findByFileId($id);
  665.         $numeroItems sizeof($productInFile);
  666.         $facturas $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  667.         $facturasRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
  668.         foreach ($facturasRec as $item){ array_push($facturas,$item); }
  669.         $proformas = array();
  670.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($id);
  671.         foreach ($allProformas as $item) {
  672.             $dataTwo $this->baseInvoiceDoneFileTwo($id$item->getId(), 'P');
  673.             $bases 0;
  674.             if (is_numeric($dataTwo['totales']) and is_numeric($dataTwo['totales_neto'])) {
  675.                 $bases $dataTwo['totales'] - $dataTwo['totales_neto'];
  676.             }
  677.             $itemsInProforma = array();
  678.             if (array_key_exists('product'$dataTwo['datasupplier'])) {
  679.                 foreach ($dataTwo['datasupplier']['product'] as $elem) {
  680.                     $itemsInProforma[] = $em->getRepository(AveProductFile::class)->findOneById($elem['id']);
  681.                 }
  682.                 $proformas[] = array(
  683.                     'id' => $dataTwo['number'],
  684.                     'itemsInProforma' => $itemsInProforma,
  685.                     'date' => $dataTwo['date'],
  686.                     'neto' => $dataTwo['totales_neto'],
  687.                     'bases_imponibles' => $bases,
  688.                     'total' => $dataTwo['totales'],
  689.                 );
  690.             }
  691.         }
  692.         // Calculamos el beneficio
  693.         $dataThree $this->baseBenefits($id);
  694.         // Buscamos los serviicos pendientes
  695.         $pendingBuds $em->getRepository(AveBudgetPending::class)->findByProposalId($editFile->getIdProposal());
  696.         $pBuds = array();
  697.         // Creamos la agrupacion por proposal
  698.         foreach ($pendingBuds as $item){
  699.             if (!(array_key_exists($item->getProposalId(),$pBuds))){
  700.                 if (!empty($item->getOriginId())){    // Los vacios solo contienen briefings
  701.                     $pBuds[$item->getProposalId()] = null;
  702.                 }
  703.             }
  704.         }
  705.         // Metemos los items en el arreglo clasificado por proposal
  706.         foreach ($pendingBuds as $item){
  707.             if (!empty($item->getOriginId())) {    // Los vacios solo contienen briefings
  708.                 $pBuds[$item->getProposalId()][] = $item;
  709.             }
  710.         }
  711.         ksort($pBuds);
  712.         $keysPbuds array_keys($pBuds);
  713.         $gpFile $em->getRepository(Reservation::class)->findOneById($editFile->getReservation());
  714.         $htFile = !(empty($gpFile)) ? (in_array($user_logueado->getUserrol(),[9,23,24,37,47,53]) ? $em->getRepository(HtFile::class)->findOneByReservation($gpFile) : null ) : null;
  715.         $gpFile in_array($user_logueado->getUserrol(),[9,23,24,37,47,53]) ? $gpFile null ;
  716.         return $this->render('MDS/AvexpressBundle/Avexpress/edit-files.html.twig',
  717.             array(
  718.                 'id' => $id,
  719.                 'clients' => $clients,
  720.                 'clientId' => $editFile->getClient(),
  721.                 'clientSelected' => $clientSelected,
  722.                 'file' => $editFile,
  723.                 'numeroItems' => $numeroItems,
  724.                 'arrayProductFile' => $data['datasupplier']['product'],
  725.                 'products' => $products,
  726.                 'services' => null,
  727.                 'facturas' => $facturas,
  728.                 'proformas' => $proformas,
  729.                 'paymentNotIvoiced' => null,
  730.                 'paymentsAll' => null,
  731.                 'resultados' => $resultados,
  732.                 'totales_global_con_iva' => $data['totales'], //$data['totales_global_con_iva'],
  733.                 'totales_global_iva' => $data['bases_imponibles']['ivaMontoVeintiUno'], //$data['totales_global_iva'],
  734.                 'totales_global_neto' => $data['totales_neto'], //$data['totales_global_neto'],
  735.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  736.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  737.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  738.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  739.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  740.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  741.                 'benefitEuro' => $dataThree['benefitEuro'],
  742.                 'benefitPerc' => $dataThree['benefitPerc'],
  743.                 'pendingBudgets' => $pBuds,
  744.                 'keysPendingBudgets' => $keysPbuds,
  745.                 'destinations' => $destinations,
  746.                 'htFile' => $htFile,
  747.                 'gpFile' => $gpFile,
  748.             ));
  749.     }
  750.     /**
  751.      * @Route("/filedelete/{id}",  name="ave_delete_file")
  752.      * Actualizar un expediente
  753.      */
  754.     public function deleteFileAction($idRequest $request)
  755.     {
  756.         $em $this->getDoctrine()->getManager();
  757.         $newFile $em->getRepository(AveFiles::class)->findOneById($id);
  758.         /* Obtengo usuario logueado */
  759.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  760.         $user_id $user_logueado->getId();
  761.         $newFile->setStatus('Deleted');
  762.         $newFile->setUpdatedId($user_id);
  763.         $newFile->setUpdatedAt(new \DateTime("now"));
  764.         $em->persist($newFile);
  765.         $em->flush();
  766.         return $this->redirectToRoute('ave_edit_file', array( 'id' => $id ));
  767.     }
  768.     /**
  769.      * @Route("/filefrombudget/{id}",  name="ave_add_file_from_budget")
  770.      * Agregar un expediente desde un presupuesto
  771.      */
  772.     public function addFileFromBudgetAction$idRequest $request)
  773.     {
  774.         $em $this->getDoctrine()->getManager();
  775.         $budget $em->getRepository(AveBudgetPending::class)->findOneById($id);
  776.         $proposal $em->getRepository(Proposal::class)->findOneById($budget->getProposalId());
  777.         $newFile $em->getRepository(AveFiles::class)->findOneByIdProposal($proposal->getId());
  778.         /* Obtengo usuario logueado */
  779.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  780.         $user_id $user_logueado->getId();
  781.         if (empty($newFile)){
  782.             // No hay un File asociado a ese proposal, se debe crear uno nuevo
  783.             $newFile = new AveFiles();
  784.             $newFile->setTitle($proposal->getId().' - ' .$budget->getProposalTitle());
  785.             $newFile->setClient(262);                           // In Out es el cliente
  786.             $newFile->setIdProposal($proposal->getId());
  787.             $newFile->setStatus('Pending');
  788.             $newFile->setAdvancePayment(null);
  789.             if (!empty($budget->getBriefing())){
  790.                 $newFile->setDescription('<p> *********  MENSAJE DEL AGENTE  ********* </p>' $budget->getBriefing());
  791.             }
  792.             $newFile->setDateStart(new \DateTime("now"));
  793.             $newFile->setDateEnd(new \DateTime("now"));
  794.             $newFile->setCreatedId($user_id);
  795.             $newFile->setUpdatedId($user_id);
  796.             $newFile->setCreatedAt(new \DateTime("now"));
  797.             $newFile->setUpdatedAt(new \DateTime("now"));
  798.         } else {
  799.             // Ya existe un File asociado a ese proposal
  800.             $newFile->setClient(262);                           // In Out es el cliente
  801.             $newFile->setStatus('Pending');
  802.             if (!empty($budget->getBriefing())) {
  803.                 $newFile->setDescription($newFile->getDescription() . '<p> *********  MENSAJE DEL AGENTE  ********* </p>' $budget->getBriefing());
  804.             }
  805.             $newFile->setUpdatedId($user_id);
  806.             $newFile->setUpdatedAt(new \DateTime("now"));
  807.         }
  808.         $em->persist($newFile);
  809.         $em->flush();
  810.         $em->remove($budget);
  811.         $em->flush();
  812.         //Actualizamos los Briefings que esten en FileId null con el recien generado fileId en base al proposalId
  813.         $allBriefings $em->getRepository(AveBriefings::class)->findByProposalId($proposal->getId());
  814.         foreach ($allBriefings as $item){
  815.             if (empty($item->getFileId())) {
  816.                 $item->setFileId($newFile->getId());
  817.                 $em->persist($item);
  818.                 $em->flush();
  819.             }
  820.         }
  821.         return $this->redirectToRoute('ave_edit_file', array( 'id' => $newFile->getId() ));
  822.     }
  823.     /**
  824.      * @Route("/filelistbriefings/{id}",  name="ave_list_file_briefings")
  825.      * Listar briefings del expediente
  826.      */
  827.     public function listFileBriefingsAction($idRequest $request){
  828.         $em $this->getDoctrine()->getManager();
  829.         $briefings $em->getRepository(AveBriefings::class)->findByFileId($id);
  830.         return $this->render('MDS/AvexpressBundle/Avexpress/list-briefings.html.twig',
  831.             array(
  832.                 'id' => $id,
  833.                 'briefings' => $briefings,
  834.             )
  835.         );
  836.     }
  837.     /**
  838.      * @Route("/briefingadd/{id}",  name="ave_add_file_briefings")
  839.      * Agregar briefing al expediente
  840.      */
  841.     public function addFileBriefingsAction($idRequest $request){
  842.         $brif $request->request->get('newbriefing');
  843.         $em $this->getDoctrine()->getManager();
  844.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  845.         $proposalId $file->getIdProposal();
  846.         /* Obtengo usuario logueado */
  847.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  848.         $user_id $user_logueado->getId();
  849.         $userConfirmedFullName $user_logueado->getName().' '.$user_logueado->getLastName();
  850.         $briefing = new AveBriefings();
  851.         $briefing->setProposalId($proposalId);
  852.         $briefing->setBriefing($brif);
  853.         $briefing->setBudgetPendingId(null);
  854.         $briefing->setFileId($id);
  855.         $briefing->setUserConfirmedFullName($userConfirmedFullName);
  856.         $briefing->setUserConfirmedId($user_id);
  857.         $briefing->setCreatedAt(new \DateTime("now"));
  858.         $em->persist($briefing);
  859.         $em->flush();
  860.         $briefings $em->getRepository(AveBriefings::class)->findByFileId($id);
  861.         return $this->render('MDS/AvexpressBundle/Avexpress/list-briefings.html.twig',
  862.             array(
  863.                 'id' => $id,
  864.                 'briefings' => $briefings,
  865.             )
  866.         );
  867.     }
  868.     /**
  869.      * @Route("/filedeletedlist/",  name="ave_list_file_deleted")
  870.      * Listar expedientes cancelados
  871.      */
  872.     public function listFileDeletedActionRequest $request)
  873.     {
  874.         $em $this->getDoctrine()->getManager();
  875.         $idgroup null$ref = array();
  876.         $reservas $em->getRepository(AveFiles::class)->findByStatus('Deleted');
  877.         foreach ($reservas as $res) {
  878.             $client $em->getRepository(Client::class)->findOneById($res->getClient());
  879.             if (!empty($client)) { $res->setClient($client->getName()); } else { $res->setClient(null); }
  880.             if (!empty($res->getDateStart()) and !empty($res->getDateEnd())) {
  881.                 $ref[$res->getId()] = '#' . ($res->getDateStart())->format('ymd') . ($res->getDateEnd())->format('ymd');
  882.             } else {
  883.                 $ref[$res->getId()] = '#' '000000' '000000';
  884.             }
  885.         }
  886.         $reservasZero = array();
  887.         foreach ($reservas as $res) {
  888.             $reservasZero[] = array(
  889.                 'dateStart' => $res->getDateStart(),
  890.                 'dateEnd' => $res->getDateEnd(),
  891.                 'id' => $res->getId(),
  892.                 'title' => $res->getTitle(),
  893.                 'client' => $res->getClient(),
  894.                 'createdId' => $res->getCreatedId(),
  895.                 'ref' => $ref[$res->getId()],
  896.                 'reservation' => $res->getReservation(),
  897.             );
  898.         }
  899.         $reservas $reservasZero;
  900.         return $this->render('MDS/AvexpressBundle/Avexpress/list-files.html.twig',
  901.             array(
  902.                 'groups' => null,
  903.                 'listofdeletedfiles' => true,
  904.                 'reservations' => $reservas
  905.             )
  906.         );
  907.     }
  908.     /**
  909.      * @Route("/updatefilecomments/{id}",  name="ave_update_file_comments")
  910.      * Actualizar Comentarios y booleanos del expediente
  911.      */
  912.     public function updateFileCommentsAction($idRequest $request){
  913.         $em $this->getDoctrine()->getManager();
  914.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  915.         $newComments $request->request->get('comments');
  916.         $chkCommentsToPro $request->request->get('chkCommentsToPro');
  917.         $chkCommentsToInv $request->request->get('chkCommentsToInv');
  918.         if ($chkCommentsToInv == 'on'){ $chkCommentsToInv true; } else { $chkCommentsToInv false; }
  919.         if ($chkCommentsToPro == 'on'){ $chkCommentsToPro true; } else { $chkCommentsToPro false; }
  920.         $file->setComments($newComments);
  921.         $file->setCommentsInInv($chkCommentsToInv);
  922.         $file->setCommentsInPro($chkCommentsToPro);
  923.         $em->persist($file);
  924.         $em->flush();
  925.         return $this->redirectToRoute('ave_edit_file', array( 'id' => $id ));
  926.     }
  927.     private function baseInvoiceDoneFileTwo($fileId$invoiceId$typeBase)
  928.     {
  929.         $em $this->getDoctrine()->getManager();
  930.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  931.         $dateDocument null;                                                                           //Fecha final del documento
  932.         $subneto 0;
  933.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  934.             if ($typeBase == 'I') {
  935.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  936.             } else {
  937.                 // Es proforma
  938. //                $items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
  939. //                $items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
  940.                 $parameters = array(
  941.                     'fileId' => $fileId,
  942.                     'proformaId' => $invoiceId,
  943.                 );
  944.                 $dql 'SELECT i
  945.                         FROM AvexpressBundle:AveProductFile i
  946.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  947.                         WHERE i.fileId = :fileId AND c.proformaId =:proformaId
  948.                         ORDER BY i.rankAv ASC';
  949.                 $query $em->createQuery($dql)->setParameters($parameters);
  950.                 $items $query->getResult();
  951.                 $arrayLocation = array();
  952.                 $arrayLocationWithNull false;
  953.                 foreach ($items as $item){
  954.                     if (!empty($item->getLocation())){
  955.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  956.                     } else {
  957.                         $arrayLocationWithNull true;
  958.                     }
  959.                 }
  960.                 if ($arrayLocationWithNull){ $arrayLocation['null'] = 'null'; }
  961.                 $productsInFile = array();
  962.                 foreach ($arrayLocation as $item){
  963.                     // VIDEO
  964.                     $parameters = array(
  965.                         'fileId' => $fileId,
  966.                         'type' => 'VĆ­deo',
  967.                         'location' => $item,
  968.                         'proformaId' => $invoiceId,
  969.                     );
  970.                     $dql 'SELECT i                            
  971.                             FROM AvexpressBundle:AveProductFile i
  972.                             INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  973.                             WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  974.                             ORDER BY i.rankAv ASC';
  975.                     $query $em->createQuery($dql)->setParameters($parameters);
  976.                     $productsInFileVid $query->getResult();
  977.                     // SONIDO
  978.                     $parameters = array(
  979.                         'fileId' => $fileId,
  980.                         'type' => 'Sonido',
  981.                         'location' => $item,
  982.                         'proformaId' => $invoiceId,
  983.                     );
  984.                     $dql 'SELECT i
  985.                             FROM AvexpressBundle:AveProductFile i
  986.                             INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  987.                             WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  988.                             ORDER BY i.rankAv ASC';
  989.                     $query $em->createQuery($dql)->setParameters($parameters);
  990.                     $productsInFileSound $query->getResult();
  991.                     // ILUMINACION
  992.                     $parameters = array(
  993.                         'fileId' => $fileId,
  994.                         'type' => 'IluminaciĆ³n',
  995.                         'location' => $item,
  996.                         'proformaId' => $invoiceId,
  997.                     );
  998.                     $dql 'SELECT i
  999.                             FROM AvexpressBundle:AveProductFile i
  1000.                             INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1001.                             WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  1002.                             ORDER BY i.rankAv ASC';
  1003.                     $query $em->createQuery($dql)->setParameters($parameters);
  1004.                     $productsInFileLights $query->getResult();
  1005.                     // OTROS
  1006.                     $parameters = array(
  1007.                         'fileId' => $fileId,
  1008.                         'typeV' => 'VĆ­deo',
  1009.                         'typeS' => 'Sonido',
  1010.                         'typeI' => 'IluminaciĆ³n',
  1011.                         'location' => $item,
  1012.                         'proformaId' => $invoiceId,
  1013.                     );
  1014.                     $dql 'SELECT i
  1015.                             FROM AvexpressBundle:AveProductFile i
  1016.                             INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1017.                             WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId)
  1018.                             ORDER BY i.rankAv ASC';
  1019.                     $query $em->createQuery($dql)->setParameters($parameters);
  1020.                     $productsInFileOther $query->getResult();
  1021.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  1022.                     $parameters = array(
  1023.                         'fileId' => $fileId,
  1024.                         'location' => $item,
  1025.                         'proformaId' => $invoiceId,
  1026.                     );
  1027.                     $dql 'SELECT i
  1028.                             FROM AvexpressBundle:AveProductFile i
  1029.                             INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1030.                             WHERE (i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId)
  1031.                             ORDER BY i.rankAv ASC';
  1032.                     $query $em->createQuery($dql)->setParameters($parameters);
  1033.                     $productsInFileNull $query->getResult();
  1034.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  1035.                     if ($item == 'null'){
  1036.                         // VIDEO
  1037.                         $parameters = array(
  1038.                             'fileId' => $fileId,
  1039.                             'type' => 'VĆ­deo',
  1040.                             'proformaId' => $invoiceId,
  1041. //                    'location' => $item,
  1042.                         );
  1043.                         $dql 'SELECT i
  1044.                                 FROM AvexpressBundle:AveProductFile i
  1045.                                 INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1046.                                 WHERE i.fileId = :fileId AND i.type = :type AND i.location IS NULL AND c.proformaId =:proformaId
  1047.                                 ORDER BY i.rankAv ASC';
  1048.                         $query $em->createQuery($dql)->setParameters($parameters);
  1049.                         $productsInFileVid $query->getResult();
  1050.                         // SONIDO
  1051.                         $parameters = array(
  1052.                             'fileId' => $fileId,
  1053.                             'type' => 'Sonido',
  1054.                             'proformaId' => $invoiceId,
  1055. //                    'location' => $item,
  1056.                         );
  1057.                         $dql 'SELECT i
  1058.                                 FROM AvexpressBundle:AveProductFile i
  1059.                                 INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1060.                                 WHERE i.fileId = :fileId AND i.type = :type AND i.location IS NULL AND c.proformaId =:proformaId
  1061.                                 ORDER BY i.rankAv ASC';
  1062.                         $query $em->createQuery($dql)->setParameters($parameters);
  1063.                         $productsInFileSound $query->getResult();
  1064.                         // ILUMINACION
  1065.                         $parameters = array(
  1066.                             'fileId' => $fileId,
  1067.                             'type' => 'IluminaciĆ³n',
  1068.                             'proformaId' => $invoiceId,
  1069. //                    'location' => $item,
  1070.                         );
  1071.                         $dql 'SELECT i
  1072.                                 FROM AvexpressBundle:AveProductFile i
  1073.                                 INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1074.                                 WHERE i.fileId = :fileId AND i.type = :type AND i.location IS NULL AND c.proformaId =:proformaId
  1075.                                 ORDER BY i.rankAv ASC';
  1076.                         $query $em->createQuery($dql)->setParameters($parameters);
  1077.                         $productsInFileLights $query->getResult();
  1078.                         // OTROS
  1079.                         $parameters = array(
  1080.                             'fileId' => $fileId,
  1081.                             'typeV' => 'VĆ­deo',
  1082.                             'typeS' => 'Sonido',
  1083.                             'typeI' => 'IluminaciĆ³n',
  1084.                             'proformaId' => $invoiceId,
  1085. //                    'location' => $item,
  1086.                         );
  1087.                         $dql 'SELECT i
  1088.                                 FROM AvexpressBundle:AveProductFile i
  1089.                                 INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1090.                                 WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location IS NULL AND c.proformaId =:proformaId)
  1091.                                 ORDER BY i.rankAv ASC';
  1092.                         $query $em->createQuery($dql)->setParameters($parameters);
  1093.                         $productsInFileOther $query->getResult();
  1094.                         // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  1095.                         $parameters = array(
  1096.                             'fileId' => $fileId,
  1097.                             'proformaId' => $invoiceId,
  1098. //                    'location' => $item,
  1099.                         );
  1100.                         $dql 'SELECT i
  1101.                                 FROM AvexpressBundle:AveProductFile i
  1102.                                 INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  1103.                                 WHERE (i.fileId = :fileId AND i.type IS NULL AND i.location IS NULL AND c.proformaId =:proformaId)
  1104.                                 ORDER BY i.rankAv ASC';
  1105.                         $query $em->createQuery($dql)->setParameters($parameters);
  1106.                         $productsInFileNull $query->getResult();
  1107.                     }
  1108.                     $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  1109.                 }
  1110.                 $items $productsInFile;       // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
  1111.             }
  1112.         } else {
  1113.             // No es factura ni proforma, es una rectificativa
  1114.             $items $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  1115.         }
  1116.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  1117.         $client $em->getRepository(Client::class)->findById($file->getClient());
  1118.         if (empty($client)){
  1119.             $client[0] = new Client();
  1120.             $client[0]->setName('');
  1121.             $client[0]->setTitle('');
  1122.             $client[0]->setIdDocument('');
  1123.             $client[0]->setPopulation('');
  1124.             $client[0]->setRegion('');
  1125.             $client[0]->setCountry('');
  1126.         } else {
  1127.             if (is_numeric($client[0]->getPopulation())){
  1128.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  1129.                 $client[0]->setPopulation($city->getCity());
  1130.             }
  1131.             if (is_numeric($client[0]->getRegion())){
  1132.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  1133.                 $client[0]->setRegion($region->getRegion());
  1134.             }
  1135.             if (is_numeric($client[0]->getCountry())){
  1136.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  1137.                 $client[0]->setCountry($country->getCountry());
  1138.             }
  1139.         }
  1140.         // Acumuladores de los calculos
  1141.         $totales_neto_all 0;
  1142.         $data_iva = array(
  1143.             'iva' => 21,
  1144.             'ivaMontoVeintiUno' => 0,
  1145.             'ivaMontoDiez' => 0,
  1146.             'ivaMontoCero' => 0,
  1147.         );
  1148.         //INICIO: Determinamos el numero de factura o proforma
  1149.         if ($typeBase == 'I'){
  1150.             // Es una Factura
  1151.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  1152.             $dateDocument $number->getDateAt();
  1153.             $number $number->getNumber();
  1154.             $type 'Invoice';
  1155.         } else {
  1156.             if ($typeBase == 'R'){
  1157.                 // Es una factura rectificativa
  1158.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  1159.                 $dateDocument $number->getDateAt();
  1160.                 $type 'Invoice Rec';
  1161.             } else {
  1162.                 // Es una Proforma
  1163.                 $number $invoiceId;
  1164.                 $type 'Proforma';
  1165.             }
  1166.         }
  1167.         //FIN: Determinamos el numero de factura o proforma
  1168.         // Buscamos los productos, pagos y servicios
  1169.         $arrayItems = array();
  1170.         $fileProducts = array();
  1171.         $payments = array();
  1172.         $services = array();
  1173.         if (!empty($items)) {
  1174.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  1175.                 foreach ($items as $item) {
  1176.                     switch ($item->getItemType()) {
  1177.                         case 'PRODUCT'// Producto
  1178.                             $fileProducts[] = $item;
  1179.                             break;
  1180.                         case 'PAYMENT'// Pago
  1181.                             $payments[] = $item;
  1182.                             break;
  1183.                         case 'SERVICE'// Servicio
  1184.                             $services[] = $item;
  1185.                             break;
  1186.                         default:
  1187.                             break;
  1188.                     }
  1189.                 }
  1190.             } else {
  1191.                 // Es una proforma
  1192.                 foreach ($items as $item) {
  1193.                     switch ($item->getType()) {
  1194.                         case 'PRODUCT'// Producto
  1195.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  1196.                             if (!empty($productPro)) {
  1197.                                 $fileProducts[] = $productPro;
  1198.                             }
  1199.                             break;
  1200.                         case 'PAYMENT'// Pago
  1201.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  1202.                             if (!empty($paymentPro)) {
  1203.                                 $payments[] = $paymentPro;
  1204.                             }
  1205.                             break;
  1206.                         case 'SERVICE'// Servicio
  1207.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  1208.                             if (!empty($servicePro)) {
  1209.                                 $services[] = $servicePro;
  1210.                             }
  1211.                             break;
  1212.                         default:
  1213.                             // Producto  (Video, Iluminacion, Sonido, Otros)
  1214.                             if (!empty($item)) {
  1215.                                 $fileProducts[] = $item;
  1216.                             }
  1217.                         break;
  1218.                     }
  1219.                 }
  1220.             }
  1221.         }
  1222.         $data_supplier = array();
  1223.         $i 0;
  1224.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĆ³n del impuesto, siempre serĆ” un 21%"
  1225.         $pax '1';
  1226.         $qty '1';
  1227.         $product = array(
  1228.             'neto' => 0,
  1229.             'sumSubT' => 0,
  1230.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  1231.         $service = array(
  1232.             'neto' => 0,
  1233.             'sumSubT' => 0,
  1234.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  1235.         foreach ($fileProducts as $item){
  1236.             if (!is_null($item->getUnits()) or !empty($item->getUnits())){
  1237.                 $qty $item->getUnits();
  1238.             }
  1239.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  1240.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())){
  1241.                     $subtotal 0;
  1242.                     $neto 0;
  1243.                     $subtotalProduct 0;
  1244.                 } else {
  1245. //                    $subtotalProduct = $item->getPrdServicePrice() * 1.21;
  1246.                     $subtotalProduct $item->getPrdSubTotalPrice() * 1.21;
  1247. //                    $subneto = $item->getPrdServicePrice();
  1248.                     $subneto $item->getPrdSubTotalPrice();
  1249.                     $subtotal =  $subtotalProduct;
  1250.                     $neto =  $subneto;
  1251.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  1252.                     $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  1253.                     $neto round($neto,2,PHP_ROUND_HALF_UP);
  1254.                     $arrayItems[] = array(
  1255.                         'type' => 'Product',
  1256.                         'name' => $item->getPrdName(),
  1257.                         'amount' => $neto,
  1258.                         'iva' => '21',
  1259.                         'total' => $subtotal,
  1260.                     );
  1261.                 }
  1262.             } else {
  1263.                 // Es proforma
  1264.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
  1265.                     $subtotal 0;
  1266.                     $neto 0;
  1267.                     $subtotalProduct 0;
  1268.                 } else {
  1269. //                    $subtotalProduct = $item->getServicePrice() * 1.21;
  1270.                     $subtotalProduct $item->getSubTotalPrice() * 1.21;
  1271. //                    $subneto = $item->getServicePrice();
  1272.                     $subneto $item->getSubTotalPrice();
  1273.                     $subtotal =  $subtotalProduct;
  1274.                     $neto =  $subneto;
  1275.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  1276.                     $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  1277.                     $neto round($neto,2,PHP_ROUND_HALF_UP);
  1278.                     $arrayItems[] = array(
  1279.                         'type' => 'Product',
  1280.                         'name' => $item->getProductName(),
  1281.                         'amount' => $neto,
  1282.                         'iva' => '21',
  1283.                         'total' => $subtotal,
  1284.                     );
  1285.                 }
  1286.             }
  1287.             // Acumula netos totales e IVA
  1288.             $totales_neto_all $totales_neto_all $neto;
  1289.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  1290.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  1291.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  1292.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  1293.             // Acumula netos totales e IVA
  1294.             $product['neto'] = $product['neto'] + $neto;
  1295.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  1296.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  1297.             $product['neto'] = round($product['neto'],2,PHP_ROUND_HALF_UP);
  1298.             $product['sumSubT'] = round($product['sumSubT'],2,PHP_ROUND_HALF_UP);
  1299.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  1300.                 $data_supplier['product'][$i] = array(
  1301.                     'id' => $item->getId(),
  1302.                     'productName' => $item->getPrdName(),
  1303.                     'productId' => $item->getPrdProductId(),
  1304.                     'dateStart' => $item->getPrdDateStart(),
  1305.                     'dateEnd' => $item->getPrdDateEnd(),
  1306.                     'servicePrice' => $item->getPrdServicePrice(),
  1307.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  1308.                     'subtotalProduct' => $subtotalProduct,
  1309.                     'iva' => $iva,
  1310.                     'pax' => $pax,
  1311.                     'qty' => $qty,
  1312.                     'type' => $item->getPrdType(),
  1313.                     'subtotal' => $subtotal,
  1314.                 );
  1315.             } else {
  1316.                 // Es proforma
  1317.                 $data_supplier['product'][$i] = array(
  1318.                     'id' => $item->getId(),
  1319.                     'productName' => $item->getProductName(),
  1320.                     'productId' => $item->getProductId(),
  1321.                     'dateStart' => $item->getDateStart(),
  1322.                     'dateEnd' => $item->getDateEnd(),
  1323.                     'servicePrice' => $item->getServicePrice(),
  1324.                     'subtotalProduct' => $subtotalProduct,
  1325.                     'iva' => $iva,
  1326.                     'pax' => $pax,
  1327.                     'qty' => $qty,
  1328.                     'type' => $item->getType(),
  1329.                     'subtotal' => $subtotal,
  1330.                 );
  1331.             }
  1332.             $i++;
  1333.         }
  1334.         $data_supplier['productSubTotal'] = array(
  1335.             'neto' => $product['neto'],
  1336.             'sumSubT' => $product['sumSubT'],
  1337.         );
  1338.         $payment = array(
  1339.             'sumSubT' => 0,
  1340.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  1341.         $i 0;
  1342.         foreach ($payments as $item){
  1343.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  1344.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  1345.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  1346.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  1347.                 $data_supplier['payment'][$i] = array(
  1348.                     'id' => $item->getId(),
  1349.                     'amount' => $item->getPayAmount(),
  1350.                     'amountTotal' => $item->getPayAmountTotal(),
  1351.                     'vat' => $item->getPayVat(),
  1352.                     'datePayAt' => $item->getPayDatePayAt(),
  1353.                     'wayToPay' => $item->getPayWayToPay(),
  1354.                 );
  1355.                 $arrayItems[] = array(
  1356.                     'type' => 'Payment',
  1357.                     'name' => $item->getPayWayToPay(),
  1358.                     'amount' => $item->getPayAmount(),
  1359.                     'total' => $item->getPayAmountTotal(),
  1360.                     'iva' => $item->getPayVat(),
  1361.                 );
  1362.             } else {
  1363.                 // Es una proforma
  1364.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  1365.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  1366.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  1367.                 $data_supplier['payment'][$i] = array(
  1368.                     'id' => $item->getId(),
  1369.                     'amount' => $item->getAmount(),
  1370.                     'amountTotal' => $item->getAmountTotal(),
  1371.                     'vat' => $item->getVat(),
  1372.                     'datePayAt' => $item->getDatePayAt(),
  1373.                     'wayToPay' => $item->getWayToPay(),
  1374.                 );
  1375.                 $arrayItems[] = array(
  1376.                     'type' => 'Payment',
  1377.                     'name' => $item->getWayToPay(),
  1378.                     'amount' => $item->getAmount(),
  1379.                     'total' => $item->getAmountTotal(),
  1380.                     'iva' => $item->getVat(),
  1381.                 );
  1382.             }
  1383.             $i++;
  1384.         }
  1385.         if (!empty($payments)) {
  1386.             $data_supplier['paymentSubTotal'] = array(
  1387.                 'sumSubT' => $payment['sumSubT'],
  1388.             );
  1389.         }
  1390.         foreach ($services as $item){
  1391.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  1392.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  1393.                     $subtotal 0;
  1394.                     $neto 0;
  1395.                     $subtotalService 0;
  1396.                 } else {
  1397.                     $subtotalService $item->getSrvPrice();
  1398.                     $subneto $item->getSrvPrice();
  1399.                     // Commission
  1400.                     if ($item->getSrvOpCommission() == '1') {
  1401.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  1402.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  1403.                     } else {
  1404.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  1405.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  1406.                     }
  1407.                     // Over
  1408.                     if ($item->getSrvOpOver() == '1') {
  1409.                         $subtotalService $subtotalService $item->getSrvOver();
  1410.                         $subneto $subneto $item->getSrvOver();
  1411.                     } else {
  1412.                         $subtotalService $subtotalService $item->getSrvOver();
  1413.                         $subneto $subneto $item->getSrvOver();
  1414.                     }
  1415.                     // IVA
  1416.                     if ($item->getSrvOpIva() == '1') {
  1417.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  1418.                     } else {
  1419.                         $subtotalService $item->getSrvPrice();
  1420.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  1421.                     }
  1422.                     switch ($item->getSrvServiceCatId()) {
  1423.                         case 1// Alojamiento
  1424.                             // el numero de noches $numNoches; precio unitario $subneto
  1425.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  1426.                             // La personas no afectan este calculo
  1427.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  1428.                             $subnetoUnit $subneto;
  1429.                             $subneto $subneto $numNoches $item->getSrvUnits();
  1430.                             $data_supplier['service'][$i] = array(
  1431.                                 'id' => $item->getId(),
  1432.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1433.                                 'serviceName' => $item->getSrvName(),
  1434.                                 'serviceType' => 'Hotel',
  1435.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  1436.                                 'qty' => $item->getSrvUnits(),
  1437.                                 'iva' => $item->getSrvIva(),
  1438.                                 'pax' => '-',
  1439.                                 'precioUnit' => $subnetoUnit,
  1440.                                 'subneto' => $subneto,
  1441.                                 'subtotal' => $subtotal,
  1442.                             );
  1443.                             break;
  1444.                         case 2//Actividades
  1445.                             // El nĆŗmero de personas es considerado en el calculo
  1446.                             $pax $item->getSrvPax();
  1447.                             if (empty($pax) or $pax == "0") {
  1448.                                 $pax 1;
  1449.                             }
  1450.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1451.                             if ($days 1) {
  1452.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1453.                             } else {
  1454.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1455.                             }
  1456.                             $subtotal $subtotalService $days $item->getSrvUnits();
  1457.                             $subnetoUnit $subneto;
  1458.                             $subneto $subneto $days $item->getSrvUnits();
  1459.                             $data_supplier['service'][$i] = array(
  1460.                                 'id' => $item->getId(),
  1461.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1462.                                 'serviceName' => $item->getSrvName(),
  1463.                                 'serviceType' => 'Actividad',
  1464.                                 'date' => $dateServ,
  1465.                                 'qty' => $item->getSrvUnits(),
  1466.                                 'iva' => $item->getSrvIva(),
  1467.                                 'pax' => $item->getSrvPax(),
  1468.                                 'precioUnit' => $subnetoUnit,
  1469.                                 'subneto' => $subneto,
  1470.                                 'subtotal' => $subtotal,
  1471.                             );
  1472.                             break;
  1473.                         case 3// AV
  1474.                             $pax $item->getSrvPax();
  1475.                             if (empty($pax) or $pax == "0") {
  1476.                                 $pax 1;
  1477.                             }
  1478.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1479.                             if ($days 1) {
  1480.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1481.                             } else {
  1482.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1483.                             }
  1484.                             $unitsServ $item->getSrvUnits();
  1485.                             if (empty($unitsServ) or $unitsServ == "0") {
  1486.                                 $unitsServ 1;
  1487.                             }
  1488.                             $subtotal $subtotalService $days $unitsServ $pax;
  1489.                             $subnetoUnit $subneto;
  1490.                             $subneto $subneto $days $unitsServ $pax;
  1491.                             $data_supplier['service'][$i] = array(
  1492.                                 'id' => $item->getId(),
  1493.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1494.                                 'serviceName' => $item->getSrvName(),
  1495.                                 'serviceType' => 'AV',
  1496.                                 'date' => $dateServ,
  1497.                                 'qty' => $unitsServ,
  1498.                                 'iva' => $item->getSrvIva(),
  1499.                                 'pax' => $item->getSrvPax(),
  1500.                                 'precioUnit' => $subnetoUnit,
  1501.                                 'subneto' => $subneto,
  1502.                                 'subtotal' => $subtotal,
  1503.                             );
  1504.                             break;
  1505.                         case 4//Creative
  1506.                             $pax $item->getSrvPax();
  1507.                             if (empty($pax) or $pax == "0") {
  1508.                                 $pax 1;
  1509.                             }
  1510.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1511.                             if ($days 1) {
  1512.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1513.                             } else {
  1514.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1515.                             }
  1516.                             $unitsServ $item->getSrvUnits();
  1517.                             if (empty($unitsServ) or $unitsServ == "0") {
  1518.                                 $unitsServ 1;
  1519.                             }
  1520.                             $subtotal $subtotalService $days $unitsServ $pax;
  1521.                             $subnetoUnit $subneto;
  1522.                             $subneto $subneto $days $unitsServ $pax;
  1523.                             $data_supplier['service'][$i] = array(
  1524.                                 'id' => $item->getId(),
  1525.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1526.                                 'serviceName' => $item->getSrvName(),
  1527.                                 'serviceType' => 'Creativo',
  1528.                                 'date' => $dateServ,
  1529.                                 'qty' => $unitsServ,
  1530.                                 'iva' => $item->getSrvIva(),
  1531.                                 'pax' => $item->getSrvPax(),
  1532.                                 'precioUnit' => $subnetoUnit,
  1533.                                 'subneto' => $subneto,
  1534.                                 'subtotal' => $subtotal,
  1535.                             );
  1536.                             break;
  1537.                         case 5//Cruise
  1538.                             $pax $item->getSrvPax();
  1539.                             if (empty($pax) or $pax == "0") {
  1540.                                 $pax 1;
  1541.                             }
  1542.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  1543.                             if ($days 1) {
  1544.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1545.                             } else {
  1546.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1547.                             }
  1548.                             $unitsServ $item->getSrvUnits();
  1549.                             if (empty($unitsServ) or $unitsServ == "0") {
  1550.                                 $unitsServ 1;
  1551.                             }
  1552.                             $subtotal $subtotalService $days $unitsServ $pax;
  1553.                             $subnetoUnit $subneto;
  1554.                             $subneto $subneto $days $unitsServ $pax;
  1555.                             $data_supplier['service'][$i] = array(
  1556.                                 'id' => $item->getId(),
  1557.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1558.                                 'serviceName' => $item->getSrvName(),
  1559.                                 'serviceType' => 'Crucero',
  1560.                                 'date' => $dateServ,
  1561.                                 'qty' => $unitsServ,
  1562.                                 'iva' => $item->getSrvIva(),
  1563.                                 'pax' => $item->getSrvPax(),
  1564.                                 'precioUnit' => $subnetoUnit,
  1565.                                 'subneto' => $subneto,
  1566.                                 'subtotal' => $subtotal,
  1567.                             );
  1568.                             break;
  1569.                         case 6//Entertaiment
  1570.                             $pax $item->getSrvPax();
  1571.                             if (empty($pax) or $pax == "0") {
  1572.                                 $pax 1;
  1573.                             }
  1574.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1575.                             if ($days 1) {
  1576.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1577.                             } else {
  1578.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1579.                             }
  1580.                             $unitsServ $item->getSrvUnits();
  1581.                             if (empty($unitsServ) or $unitsServ == "0") {
  1582.                                 $unitsServ 1;
  1583.                             }
  1584.                             $subtotal $subtotalService $days $unitsServ $pax;
  1585.                             $subnetoUnit $subneto;
  1586.                             $subneto $subneto $days $unitsServ $pax;
  1587.                             $data_supplier['service'][$i] = array(
  1588.                                 'id' => $item->getId(),
  1589.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1590.                                 'serviceName' => $item->getSrvName(),
  1591.                                 'serviceType' => 'Entretenimiento',
  1592.                                 'date' => $dateServ,
  1593.                                 'qty' => $unitsServ,
  1594.                                 'iva' => $item->getSrvIva(),
  1595.                                 'pax' => $item->getSrvPax(),
  1596.                                 'precioUnit' => $subnetoUnit,
  1597.                                 'subneto' => $subneto,
  1598.                                 'subtotal' => $subtotal,
  1599.                             );
  1600.                             break;
  1601.                         case 7// Gifts
  1602.                             $pax $item->getSrvPax();
  1603.                             if (empty($pax) or $pax == "0") {
  1604.                                 $pax 1;
  1605.                             }
  1606. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1607.                             $days 1;
  1608.                             if ($days 1) {
  1609.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1610.                             } else {
  1611.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1612.                             }
  1613.                             $unitsServ $item->getSrvUnits();
  1614.                             if (empty($unitsServ) or $unitsServ == "0") {
  1615.                                 $unitsServ 1;
  1616.                             }
  1617.                             $subtotal $subtotalService $days $unitsServ $pax;
  1618.                             $subnetoUnit $subneto;
  1619.                             $subneto $subneto $days $unitsServ $pax;
  1620.                             $data_supplier['service'][$i] = array(
  1621.                                 'id' => $item->getId(),
  1622.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1623.                                 'serviceName' => $item->getSrvName(),
  1624.                                 'serviceType' => 'Regalos',
  1625.                                 'date' => $dateServ,
  1626.                                 'qty' => $unitsServ,
  1627.                                 'iva' => $item->getSrvIva(),
  1628.                                 'pax' => $item->getSrvPax(),
  1629.                                 'precioUnit' => $subnetoUnit,
  1630.                                 'subneto' => $subneto,
  1631.                                 'subtotal' => $subtotal,
  1632.                             );
  1633.                             break;
  1634.                         case 8//Guide
  1635.                             $pax $item->getSrvPax();
  1636.                             if (empty($pax) or $pax == "0") {
  1637.                                 $pax 1;
  1638.                             }
  1639.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1640.                             if ($days 1) {
  1641.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1642.                             } else {
  1643.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1644.                             }
  1645.                             $unitsServ $item->getSrvUnits();
  1646.                             if (empty($unitsServ) or $unitsServ == "0") {
  1647.                                 $unitsServ 1;
  1648.                             }
  1649.                             $subtotal $subtotalService $days $unitsServ $pax;
  1650.                             $subnetoUnit $subneto;
  1651.                             $subneto $subneto $days $unitsServ $pax;
  1652.                             $data_supplier['service'][$i] = array(
  1653.                                 'id' => $item->getId(),
  1654.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1655.                                 'serviceName' => $item->getSrvName(),
  1656.                                 'serviceType' => 'Regalos',
  1657.                                 'date' => $dateServ,
  1658.                                 'qty' => $unitsServ,
  1659.                                 'iva' => $item->getSrvIva(),
  1660.                                 'pax' => $item->getSrvPax(),
  1661.                                 'precioUnit' => $subnetoUnit,
  1662.                                 'subneto' => $subneto,
  1663.                                 'subtotal' => $subtotal,
  1664.                             );
  1665.                             break;
  1666.                         case 9//Itineraries
  1667.                             $pax $item->getSrvPax();
  1668.                             if (empty($pax) or $pax == "0") {
  1669.                                 $pax 1;
  1670.                             }
  1671.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1672.                             if ($days 1) {
  1673.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1674.                             } else {
  1675.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1676.                             }
  1677.                             $unitsServ $item->getSrvUnits();
  1678.                             if (empty($unitsServ) or $unitsServ == "0") {
  1679.                                 $unitsServ 1;
  1680.                             }
  1681.                             $subtotal $subtotalService $days $unitsServ $pax;
  1682.                             $subnetoUnit $subneto;
  1683.                             $subneto $subneto $days $unitsServ $pax;
  1684.                             $data_supplier['service'][$i] = array(
  1685.                                 'id' => $item->getId(),
  1686.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1687.                                 'serviceName' => $item->getSrvName(),
  1688.                                 'serviceType' => 'Itinerarios',
  1689.                                 'date' => $dateServ,
  1690.                                 'qty' => $unitsServ,
  1691.                                 'iva' => $item->getSrvIva(),
  1692.                                 'pax' => $item->getSrvPax(),
  1693.                                 'precioUnit' => $subnetoUnit,
  1694.                                 'subneto' => $subneto,
  1695.                                 'subtotal' => $subtotal,
  1696.                             );
  1697.                             break;
  1698.                         case 10//Lounge  -- No Aplica
  1699. //                        $pax = $item->getPax();
  1700. //                        if (empty($pax) or $pax == "0") {
  1701. //                            $pax = 1;
  1702. //                        }
  1703. //
  1704. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1705. //                        if ($days > 1){
  1706. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1707. //                        } else {
  1708. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1709. //                        }
  1710. //
  1711. //                        $unitsServ = $item->getUnits();
  1712. //                        if (empty($unitsServ) or $unitsServ == "0") {
  1713. //                            $unitsServ = 1;
  1714. //                        }
  1715. //
  1716. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  1717. //                        $subnetoUnit = $subneto;
  1718. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  1719. //
  1720. //                        $data_supplier['service'][$i] = array (
  1721. //                            'id' => $item->getId(),
  1722. //                            'serviceCatId' => $item->getServiceCatId(),
  1723. //                            'serviceName' => $item->getName(),
  1724. //                            'serviceType' => 'Itinerarios',
  1725. //                            'date' => $dateServ,
  1726. //                            'qty' => $unitsServ,
  1727. //                            'iva' => $item->getIva(),
  1728. //                            'pax' => $item->getPax(),
  1729. //                            'precioUnit' => $subnetoUnit,
  1730. //                            'subneto' => $subneto,
  1731. //                            'subtotal' => $subtotal,
  1732. //                        );
  1733.                             break;
  1734.                         case 11//Menu
  1735.                             $pax $item->getSrvPax();
  1736.                             if (empty($pax) or $pax == "0") {
  1737.                                 $pax 1;
  1738.                             }
  1739.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1740.                             if ($days 1) {
  1741.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1742.                             } else {
  1743.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1744.                             }
  1745.                             $unitsServ $item->getSrvUnits();
  1746.                             if (empty($unitsServ) or $unitsServ == "0") {
  1747.                                 $unitsServ 1;
  1748.                             }
  1749.                             $subtotal $subtotalService $days $unitsServ $pax;
  1750.                             $subnetoUnit $subneto;
  1751.                             $subneto $subneto $days $unitsServ $pax;
  1752.                             $data_supplier['service'][$i] = array(
  1753.                                 'id' => $item->getId(),
  1754.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1755.                                 'serviceName' => $item->getSrvName(),
  1756.                                 'serviceType' => 'MenĆŗ',
  1757.                                 'date' => $dateServ,
  1758.                                 'qty' => $unitsServ,
  1759.                                 'iva' => $item->getSrvIva(),
  1760.                                 'pax' => $item->getSrvPax(),
  1761.                                 'precioUnit' => $subnetoUnit,
  1762.                                 'subneto' => $subneto,
  1763.                                 'subtotal' => $subtotal,
  1764.                             );
  1765.                             break;
  1766.                         case 12//Others
  1767.                             $pax $item->getSrvPax();
  1768.                             if (empty($pax) or $pax == "0") {
  1769.                                 $pax 1;
  1770.                             }
  1771.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1772.                             if ($days 1) {
  1773.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1774.                             } else {
  1775.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1776.                             }
  1777.                             $unitsServ $item->getSrvUnits();
  1778.                             if (empty($unitsServ) or $unitsServ == "0") {
  1779.                                 $unitsServ 1;
  1780.                             }
  1781.                             $subtotal $subtotalService $days $unitsServ $pax;
  1782.                             $subnetoUnit $subneto;
  1783.                             $subneto $subneto $days $unitsServ $pax;
  1784.                             $data_supplier['service'][$i] = array(
  1785.                                 'id' => $item->getId(),
  1786.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1787.                                 'serviceName' => $item->getSrvName(),
  1788.                                 'serviceType' => 'Otros',
  1789.                                 'date' => $dateServ,
  1790.                                 'qty' => $unitsServ,
  1791.                                 'iva' => $item->getSrvIva(),
  1792.                                 'pax' => $item->getSrvPax(),
  1793.                                 'precioUnit' => $subnetoUnit,
  1794.                                 'subneto' => $subneto,
  1795.                                 'subtotal' => $subtotal,
  1796.                             );
  1797.                             break;
  1798.                         case 13//Transport
  1799.                             $pax $item->getSrvPax();
  1800.                             if (empty($pax) or $pax == "0") {
  1801.                                 $pax 1;
  1802.                             }
  1803.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1804.                             if ($days 1) {
  1805.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1806.                             } else {
  1807.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1808.                             }
  1809.                             $unitsServ $item->getSrvUnits();
  1810.                             if (empty($unitsServ) or $unitsServ == "0") {
  1811.                                 $unitsServ 1;
  1812.                             }
  1813.                             $subtotal $subtotalService $days $unitsServ $pax;
  1814.                             $subnetoUnit $subneto;
  1815.                             $subneto $subneto $days $unitsServ $pax;
  1816.                             $data_supplier['service'][$i] = array(
  1817.                                 'id' => $item->getId(),
  1818.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1819.                                 'serviceName' => $item->getSrvName(),
  1820.                                 'serviceType' => 'Transporte',
  1821.                                 'date' => $dateServ,
  1822.                                 'qty' => $unitsServ,
  1823.                                 'iva' => $item->getSrvIva(),
  1824.                                 'pax' => $item->getSrvPax(),
  1825.                                 'precioUnit' => $subnetoUnit,
  1826.                                 'subneto' => $subneto,
  1827.                                 'subtotal' => $subtotal,
  1828.                             );
  1829.                             break;
  1830.                         case 14//Technology
  1831.                             $pax $item->getSrvPax();
  1832.                             if (empty($pax) or $pax == "0") {
  1833.                                 $pax 1;
  1834.                             }
  1835. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1836.                             $days 1;
  1837. //                        if ($days > 1){
  1838. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1839. //                        } else {
  1840. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1841. //                        }
  1842.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1843.                             $unitsServ $item->getSrvUnits();
  1844.                             if (empty($unitsServ) or $unitsServ == "0") {
  1845.                                 $unitsServ 1;
  1846.                             }
  1847.                             $subtotal $subtotalService $days $unitsServ $pax;
  1848.                             $subnetoUnit $subneto;
  1849.                             $subneto $subneto $days $unitsServ $pax;
  1850.                             $data_supplier['service'][$i] = array(
  1851.                                 'id' => $item->getId(),
  1852.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1853.                                 'serviceName' => $item->getSrvName(),
  1854.                                 'serviceType' => 'TecnologĆ­a',
  1855.                                 'date' => $dateServ,
  1856.                                 'qty' => $unitsServ,
  1857.                                 'iva' => $item->getSrvIva(),
  1858.                                 'pax' => $item->getSrvPax(),
  1859.                                 'precioUnit' => $subnetoUnit,
  1860.                                 'subneto' => $subneto,
  1861.                                 'subtotal' => $subtotal,
  1862.                             );
  1863.                             break;
  1864.                         case 15//Assisstant
  1865.                             $pax $item->getSrvPax();
  1866.                             if (empty($pax) or $pax == "0") {
  1867.                                 $pax 1;
  1868.                             }
  1869.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1870.                             if ($days 1) {
  1871.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1872.                             } else {
  1873.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1874.                             }
  1875.                             $unitsServ $item->getSrvUnits();
  1876.                             if (empty($unitsServ) or $unitsServ == "0") {
  1877.                                 $unitsServ 1;
  1878.                             }
  1879.                             $subtotal $subtotalService $days $unitsServ $pax;
  1880.                             $subnetoUnit $subneto;
  1881.                             $subneto $subneto $days $unitsServ $pax;
  1882.                             $data_supplier['service'][$i] = array(
  1883.                                 'id' => $item->getId(),
  1884.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1885.                                 'serviceName' => $item->getSrvName(),
  1886.                                 'serviceType' => 'Asistente',
  1887.                                 'date' => $dateServ,
  1888.                                 'qty' => $unitsServ,
  1889.                                 'iva' => $item->getSrvIva(),
  1890.                                 'pax' => $item->getSrvPax(),
  1891.                                 'precioUnit' => $subnetoUnit,
  1892.                                 'subneto' => $subneto,
  1893.                                 'subtotal' => $subtotal,
  1894.                             );
  1895.                             break;
  1896.                         case 16//DDR
  1897.                             $pax $item->getSrvPax();
  1898.                             if (empty($pax) or $pax == "0") {
  1899.                                 $pax 1;
  1900.                             }
  1901.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1902.                             if ($days 1) {
  1903.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1904.                             } else {
  1905.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1906.                             }
  1907.                             $unitsServ $item->getSrvUnits();
  1908.                             if (empty($unitsServ) or $unitsServ == "0") {
  1909.                                 $unitsServ 1;
  1910.                             }
  1911.                             $subtotal $subtotalService $days $unitsServ $pax;
  1912.                             $subnetoUnit $subneto;
  1913.                             $subneto $subneto $days $unitsServ $pax;
  1914.                             $data_supplier['service'][$i] = array(
  1915.                                 'id' => $item->getId(),
  1916.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1917.                                 'serviceName' => $item->getSrvName(),
  1918.                                 'serviceType' => 'DDR',
  1919.                                 'date' => $dateServ,
  1920.                                 'qty' => $unitsServ,
  1921.                                 'iva' => $item->getSrvIva(),
  1922.                                 'pax' => $item->getSrvPax(),
  1923.                                 'precioUnit' => $subnetoUnit,
  1924.                                 'subneto' => $subneto,
  1925.                                 'subtotal' => $subtotal,
  1926.                             );
  1927.                             break;
  1928.                         default:
  1929.                             break;
  1930.                     }
  1931.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  1932.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  1933.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  1934.                     $arrayItems[] = array(
  1935.                         'type' => 'Service',
  1936.                         'name' => $item->getSrvName(),
  1937.                         'amount' => $neto,
  1938.                         'iva' => $item->getSrvIva(),
  1939.                         'total' => $subtotal,
  1940.                     );
  1941.                 }
  1942.                 switch ($item->getSrvIva()) {
  1943.                     // Acumula IVA
  1944.                     case 21:
  1945.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  1946.                         break;
  1947.                     case 10:
  1948.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  1949.                         break;
  1950.                     case 0:
  1951.                         break;
  1952.                     default:
  1953.                         break;
  1954.                 }
  1955.             } else {
  1956.                 // Es una proforma
  1957.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  1958.                     $subtotal 0;
  1959.                     $neto 0;
  1960.                     $subtotalService 0;
  1961.                 } else {
  1962.                     $subtotalService $item->getPrice();
  1963.                     $subneto $item->getPrice();
  1964.                     // Commission
  1965.                     if ($item->getOpCommission() == '1') {
  1966.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  1967.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  1968.                     } else {
  1969.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  1970.                         $subneto $subneto * (- ($item->getCommission() / 100));
  1971.                     }
  1972.                     // Over
  1973.                     if ($item->getOpOver() == '1') {
  1974.                         $subtotalService $subtotalService $item->getOver();
  1975.                         $subneto $subneto $item->getOver();
  1976.                     } else {
  1977.                         $subtotalService $subtotalService $item->getOver();
  1978.                         $subneto $subneto $item->getOver();
  1979.                     }
  1980.                     // IVA
  1981.                     if ($item->getOpIva() == '1') {
  1982.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  1983.                     } else {
  1984.                         $subtotalService $item->getPrice();
  1985.                         $subneto = ($subneto 100) / (100 $item->getIva());
  1986.                     }
  1987.                     switch ($item->getServiceCatId()) {
  1988.                         case 1// Alojamiento
  1989.                             // el numero de noches $numNoches; precio unitario $subneto
  1990.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  1991.                             // La personas no afectan este calculo
  1992.                             $subtotal $subtotalService $numNoches $item->getUnits();
  1993.                             $subnetoUnit $subneto;
  1994.                             $subneto $subneto $numNoches $item->getUnits();
  1995.                             $data_supplier['service'][$i] = array(
  1996.                                 'id' => $item->getId(),
  1997.                                 'serviceCatId' => $item->getServiceCatId(),
  1998.                                 'serviceName' => $item->getName(),
  1999.                                 'serviceType' => 'Hotel',
  2000.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  2001.                                 'qty' => $item->getUnits(),
  2002.                                 'iva' => $item->getIva(),
  2003.                                 'pax' => '-',
  2004.                                 'precioUnit' => $subnetoUnit,
  2005.                                 'subneto' => $subneto,
  2006.                                 'subtotal' => $subtotal,
  2007.                             );
  2008.                             break;
  2009.                         case 2//Actividades
  2010.                             // El nĆŗmero de personas es considerado en el calculo
  2011.                             $pax $item->getPax();
  2012.                             if (empty($pax) or $pax == "0") {
  2013.                                 $pax 1;
  2014.                             }
  2015.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2016.                             if ($days 1) {
  2017.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2018.                             } else {
  2019.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2020.                             }
  2021.                             $subtotal $subtotalService $days $item->getUnits();
  2022.                             $subnetoUnit $subneto;
  2023.                             $subneto $subneto $days $item->getUnits();
  2024.                             $data_supplier['service'][$i] = array(
  2025.                                 'id' => $item->getId(),
  2026.                                 'serviceCatId' => $item->getServiceCatId(),
  2027.                                 'serviceName' => $item->getName(),
  2028.                                 'serviceType' => 'Actividad',
  2029.                                 'date' => $dateServ,
  2030.                                 'qty' => $item->getUnits(),
  2031.                                 'iva' => $item->getIva(),
  2032.                                 'pax' => $item->getPax(),
  2033.                                 'precioUnit' => $subnetoUnit,
  2034.                                 'subneto' => $subneto,
  2035.                                 'subtotal' => $subtotal,
  2036.                             );
  2037.                             break;
  2038.                         case 3// AV
  2039.                             $pax $item->getPax();
  2040.                             if (empty($pax) or $pax == "0") {
  2041.                                 $pax 1;
  2042.                             }
  2043.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2044.                             if ($days 1) {
  2045.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2046.                             } else {
  2047.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2048.                             }
  2049.                             $unitsServ $item->getUnits();
  2050.                             if (empty($unitsServ) or $unitsServ == "0") {
  2051.                                 $unitsServ 1;
  2052.                             }
  2053.                             $subtotal $subtotalService $days $unitsServ $pax;
  2054.                             $subnetoUnit $subneto;
  2055.                             $subneto $subneto $days $unitsServ $pax;
  2056.                             $data_supplier['service'][$i] = array(
  2057.                                 'id' => $item->getId(),
  2058.                                 'serviceCatId' => $item->getServiceCatId(),
  2059.                                 'serviceName' => $item->getName(),
  2060.                                 'serviceType' => 'AV',
  2061.                                 'date' => $dateServ,
  2062.                                 'qty' => $unitsServ,
  2063.                                 'iva' => $item->getIva(),
  2064.                                 'pax' => $item->getPax(),
  2065.                                 'precioUnit' => $subnetoUnit,
  2066.                                 'subneto' => $subneto,
  2067.                                 'subtotal' => $subtotal,
  2068.                             );
  2069.                             break;
  2070.                         case 4//Creative
  2071.                             $pax $item->getPax();
  2072.                             if (empty($pax) or $pax == "0") {
  2073.                                 $pax 1;
  2074.                             }
  2075.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2076.                             if ($days 1) {
  2077.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2078.                             } else {
  2079.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2080.                             }
  2081.                             $unitsServ $item->getUnits();
  2082.                             if (empty($unitsServ) or $unitsServ == "0") {
  2083.                                 $unitsServ 1;
  2084.                             }
  2085.                             $subtotal $subtotalService $days $unitsServ $pax;
  2086.                             $subnetoUnit $subneto;
  2087.                             $subneto $subneto $days $unitsServ $pax;
  2088.                             $data_supplier['service'][$i] = array(
  2089.                                 'id' => $item->getId(),
  2090.                                 'serviceCatId' => $item->getServiceCatId(),
  2091.                                 'serviceName' => $item->getName(),
  2092.                                 'serviceType' => 'Creativo',
  2093.                                 'date' => $dateServ,
  2094.                                 'qty' => $unitsServ,
  2095.                                 'iva' => $item->getIva(),
  2096.                                 'pax' => $item->getPax(),
  2097.                                 'precioUnit' => $subnetoUnit,
  2098.                                 'subneto' => $subneto,
  2099.                                 'subtotal' => $subtotal,
  2100.                             );
  2101.                             break;
  2102.                         case 5//Cruise
  2103.                             $pax $item->getPax();
  2104.                             if (empty($pax) or $pax == "0") {
  2105.                                 $pax 1;
  2106.                             }
  2107.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  2108.                             if ($days 1) {
  2109.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2110.                             } else {
  2111.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2112.                             }
  2113.                             $unitsServ $item->getUnits();
  2114.                             if (empty($unitsServ) or $unitsServ == "0") {
  2115.                                 $unitsServ 1;
  2116.                             }
  2117.                             $subtotal $subtotalService $days $unitsServ $pax;
  2118.                             $subnetoUnit $subneto;
  2119.                             $subneto $subneto $days $unitsServ $pax;
  2120.                             $data_supplier['service'][$i] = array(
  2121.                                 'id' => $item->getId(),
  2122.                                 'serviceCatId' => $item->getServiceCatId(),
  2123.                                 'serviceName' => $item->getName(),
  2124.                                 'serviceType' => 'Crucero',
  2125.                                 'date' => $dateServ,
  2126.                                 'qty' => $unitsServ,
  2127.                                 'iva' => $item->getIva(),
  2128.                                 'pax' => $item->getPax(),
  2129.                                 'precioUnit' => $subnetoUnit,
  2130.                                 'subneto' => $subneto,
  2131.                                 'subtotal' => $subtotal,
  2132.                             );
  2133.                             break;
  2134.                         case 6//Entertaiment
  2135.                             $pax $item->getPax();
  2136.                             if (empty($pax) or $pax == "0") {
  2137.                                 $pax 1;
  2138.                             }
  2139.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2140.                             if ($days 1) {
  2141.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2142.                             } else {
  2143.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2144.                             }
  2145.                             $unitsServ $item->getUnits();
  2146.                             if (empty($unitsServ) or $unitsServ == "0") {
  2147.                                 $unitsServ 1;
  2148.                             }
  2149.                             $subtotal $subtotalService $days $unitsServ $pax;
  2150.                             $subnetoUnit $subneto;
  2151.                             $subneto $subneto $days $unitsServ $pax;
  2152.                             $data_supplier['service'][$i] = array(
  2153.                                 'id' => $item->getId(),
  2154.                                 'serviceCatId' => $item->getServiceCatId(),
  2155.                                 'serviceName' => $item->getName(),
  2156.                                 'serviceType' => 'Entretenimiento',
  2157.                                 'date' => $dateServ,
  2158.                                 'qty' => $unitsServ,
  2159.                                 'iva' => $item->getIva(),
  2160.                                 'pax' => $item->getPax(),
  2161.                                 'precioUnit' => $subnetoUnit,
  2162.                                 'subneto' => $subneto,
  2163.                                 'subtotal' => $subtotal,
  2164.                             );
  2165.                             break;
  2166.                         case 7// Gifts
  2167.                             $pax $item->getPax();
  2168.                             if (empty($pax) or $pax == "0") {
  2169.                                 $pax 1;
  2170.                             }
  2171. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  2172.                             $days 1;
  2173.                             if ($days 1) {
  2174.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2175.                             } else {
  2176.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2177.                             }
  2178.                             $unitsServ $item->getUnits();
  2179.                             if (empty($unitsServ) or $unitsServ == "0") {
  2180.                                 $unitsServ 1;
  2181.                             }
  2182.                             $subtotal $subtotalService $days $unitsServ $pax;
  2183.                             $subnetoUnit $subneto;
  2184.                             $subneto $subneto $days $unitsServ $pax;
  2185.                             $data_supplier['service'][$i] = array(
  2186.                                 'id' => $item->getId(),
  2187.                                 'serviceCatId' => $item->getServiceCatId(),
  2188.                                 'serviceName' => $item->getName(),
  2189.                                 'serviceType' => 'Regalos',
  2190.                                 'date' => $dateServ,
  2191.                                 'qty' => $unitsServ,
  2192.                                 'iva' => $item->getIva(),
  2193.                                 'pax' => $item->getPax(),
  2194.                                 'precioUnit' => $subnetoUnit,
  2195.                                 'subneto' => $subneto,
  2196.                                 'subtotal' => $subtotal,
  2197.                             );
  2198.                             break;
  2199.                         case 8//Guide
  2200.                             $pax $item->getPax();
  2201.                             if (empty($pax) or $pax == "0") {
  2202.                                 $pax 1;
  2203.                             }
  2204.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2205.                             if ($days 1) {
  2206.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2207.                             } else {
  2208.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2209.                             }
  2210.                             $unitsServ $item->getUnits();
  2211.                             if (empty($unitsServ) or $unitsServ == "0") {
  2212.                                 $unitsServ 1;
  2213.                             }
  2214.                             $subtotal $subtotalService $days $unitsServ $pax;
  2215.                             $subnetoUnit $subneto;
  2216.                             $subneto $subneto $days $unitsServ $pax;
  2217.                             $data_supplier['service'][$i] = array(
  2218.                                 'id' => $item->getId(),
  2219.                                 'serviceCatId' => $item->getServiceCatId(),
  2220.                                 'serviceName' => $item->getName(),
  2221.                                 'serviceType' => 'Regalos',
  2222.                                 'date' => $dateServ,
  2223.                                 'qty' => $unitsServ,
  2224.                                 'iva' => $item->getIva(),
  2225.                                 'pax' => $item->getPax(),
  2226.                                 'precioUnit' => $subnetoUnit,
  2227.                                 'subneto' => $subneto,
  2228.                                 'subtotal' => $subtotal,
  2229.                             );
  2230.                             break;
  2231.                         case 9//Itineraries
  2232.                             $pax $item->getPax();
  2233.                             if (empty($pax) or $pax == "0") {
  2234.                                 $pax 1;
  2235.                             }
  2236.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2237.                             if ($days 1) {
  2238.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2239.                             } else {
  2240.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2241.                             }
  2242.                             $unitsServ $item->getUnits();
  2243.                             if (empty($unitsServ) or $unitsServ == "0") {
  2244.                                 $unitsServ 1;
  2245.                             }
  2246.                             $subtotal $subtotalService $days $unitsServ $pax;
  2247.                             $subnetoUnit $subneto;
  2248.                             $subneto $subneto $days $unitsServ $pax;
  2249.                             $data_supplier['service'][$i] = array(
  2250.                                 'id' => $item->getId(),
  2251.                                 'serviceCatId' => $item->getServiceCatId(),
  2252.                                 'serviceName' => $item->getName(),
  2253.                                 'serviceType' => 'Itinerarios',
  2254.                                 'date' => $dateServ,
  2255.                                 'qty' => $unitsServ,
  2256.                                 'iva' => $item->getIva(),
  2257.                                 'pax' => $item->getPax(),
  2258.                                 'precioUnit' => $subnetoUnit,
  2259.                                 'subneto' => $subneto,
  2260.                                 'subtotal' => $subtotal,
  2261.                             );
  2262.                             break;
  2263.                         case 10//Lounge  -- No Aplica
  2264. //                        $pax = $item->getPax();
  2265. //                        if (empty($pax) or $pax == "0") {
  2266. //                            $pax = 1;
  2267. //                        }
  2268. //
  2269. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  2270. //                        if ($days > 1){
  2271. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2272. //                        } else {
  2273. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2274. //                        }
  2275. //
  2276. //                        $unitsServ = $item->getUnits();
  2277. //                        if (empty($unitsServ) or $unitsServ == "0") {
  2278. //                            $unitsServ = 1;
  2279. //                        }
  2280. //
  2281. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  2282. //                        $subnetoUnit = $subneto;
  2283. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  2284. //
  2285. //                        $data_supplier['service'][$i] = array (
  2286. //                            'id' => $item->getId(),
  2287. //                            'serviceCatId' => $item->getServiceCatId(),
  2288. //                            'serviceName' => $item->getName(),
  2289. //                            'serviceType' => 'Itinerarios',
  2290. //                            'date' => $dateServ,
  2291. //                            'qty' => $unitsServ,
  2292. //                            'iva' => $item->getIva(),
  2293. //                            'pax' => $item->getPax(),
  2294. //                            'precioUnit' => $subnetoUnit,
  2295. //                            'subneto' => $subneto,
  2296. //                            'subtotal' => $subtotal,
  2297. //                        );
  2298.                             break;
  2299.                         case 11//Menu
  2300.                             $pax $item->getPax();
  2301.                             if (empty($pax) or $pax == "0") {
  2302.                                 $pax 1;
  2303.                             }
  2304.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2305.                             if ($days 1) {
  2306.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2307.                             } else {
  2308.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2309.                             }
  2310.                             $unitsServ $item->getUnits();
  2311.                             if (empty($unitsServ) or $unitsServ == "0") {
  2312.                                 $unitsServ 1;
  2313.                             }
  2314.                             $subtotal $subtotalService $days $unitsServ $pax;
  2315.                             $subnetoUnit $subneto;
  2316.                             $subneto $subneto $days $unitsServ $pax;
  2317.                             $data_supplier['service'][$i] = array(
  2318.                                 'id' => $item->getId(),
  2319.                                 'serviceCatId' => $item->getServiceCatId(),
  2320.                                 'serviceName' => $item->getName(),
  2321.                                 'serviceType' => 'MenĆŗ',
  2322.                                 'date' => $dateServ,
  2323.                                 'qty' => $unitsServ,
  2324.                                 'iva' => $item->getIva(),
  2325.                                 'pax' => $item->getPax(),
  2326.                                 'precioUnit' => $subnetoUnit,
  2327.                                 'subneto' => $subneto,
  2328.                                 'subtotal' => $subtotal,
  2329.                             );
  2330.                             break;
  2331.                         case 12//Others
  2332.                             $pax $item->getPax();
  2333.                             if (empty($pax) or $pax == "0") {
  2334.                                 $pax 1;
  2335.                             }
  2336.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2337.                             if ($days 1) {
  2338.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2339.                             } else {
  2340.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2341.                             }
  2342.                             $unitsServ $item->getUnits();
  2343.                             if (empty($unitsServ) or $unitsServ == "0") {
  2344.                                 $unitsServ 1;
  2345.                             }
  2346.                             $subtotal $subtotalService $days $unitsServ $pax;
  2347.                             $subnetoUnit $subneto;
  2348.                             $subneto $subneto $days $unitsServ $pax;
  2349.                             $data_supplier['service'][$i] = array(
  2350.                                 'id' => $item->getId(),
  2351.                                 'serviceCatId' => $item->getServiceCatId(),
  2352.                                 'serviceName' => $item->getName(),
  2353.                                 'serviceType' => 'Otros',
  2354.                                 'date' => $dateServ,
  2355.                                 'qty' => $unitsServ,
  2356.                                 'iva' => $item->getIva(),
  2357.                                 'pax' => $item->getPax(),
  2358.                                 'precioUnit' => $subnetoUnit,
  2359.                                 'subneto' => $subneto,
  2360.                                 'subtotal' => $subtotal,
  2361.                             );
  2362.                             break;
  2363.                         case 13//Transport
  2364.                             $pax $item->getPax();
  2365.                             if (empty($pax) or $pax == "0") {
  2366.                                 $pax 1;
  2367.                             }
  2368.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2369.                             if ($days 1) {
  2370.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2371.                             } else {
  2372.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2373.                             }
  2374.                             $unitsServ $item->getUnits();
  2375.                             if (empty($unitsServ) or $unitsServ == "0") {
  2376.                                 $unitsServ 1;
  2377.                             }
  2378.                             $subtotal $subtotalService $days $unitsServ $pax;
  2379.                             $subnetoUnit $subneto;
  2380.                             $subneto $subneto $days $unitsServ $pax;
  2381.                             $data_supplier['service'][$i] = array(
  2382.                                 'id' => $item->getId(),
  2383.                                 'serviceCatId' => $item->getServiceCatId(),
  2384.                                 'serviceName' => $item->getName(),
  2385.                                 'serviceType' => 'Transporte',
  2386.                                 'date' => $dateServ,
  2387.                                 'qty' => $unitsServ,
  2388.                                 'iva' => $item->getIva(),
  2389.                                 'pax' => $item->getPax(),
  2390.                                 'precioUnit' => $subnetoUnit,
  2391.                                 'subneto' => $subneto,
  2392.                                 'subtotal' => $subtotal,
  2393.                             );
  2394.                             break;
  2395.                         case 14//Technology
  2396.                             $pax $item->getPax();
  2397.                             if (empty($pax) or $pax == "0") {
  2398.                                 $pax 1;
  2399.                             }
  2400. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  2401.                             $days 1;
  2402. //                        if ($days > 1){
  2403. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2404. //                        } else {
  2405. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2406. //                        }
  2407.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2408.                             $unitsServ $item->getUnits();
  2409.                             if (empty($unitsServ) or $unitsServ == "0") {
  2410.                                 $unitsServ 1;
  2411.                             }
  2412.                             $subtotal $subtotalService $days $unitsServ $pax;
  2413.                             $subnetoUnit $subneto;
  2414.                             $subneto $subneto $days $unitsServ $pax;
  2415.                             $data_supplier['service'][$i] = array(
  2416.                                 'id' => $item->getId(),
  2417.                                 'serviceCatId' => $item->getServiceCatId(),
  2418.                                 'serviceName' => $item->getName(),
  2419.                                 'serviceType' => 'TecnologĆ­a',
  2420.                                 'date' => $dateServ,
  2421.                                 'qty' => $unitsServ,
  2422.                                 'iva' => $item->getIva(),
  2423.                                 'pax' => $item->getPax(),
  2424.                                 'precioUnit' => $subnetoUnit,
  2425.                                 'subneto' => $subneto,
  2426.                                 'subtotal' => $subtotal,
  2427.                             );
  2428.                             break;
  2429.                         case 15//Assisstant
  2430.                             $pax $item->getPax();
  2431.                             if (empty($pax) or $pax == "0") {
  2432.                                 $pax 1;
  2433.                             }
  2434.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2435.                             if ($days 1) {
  2436.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2437.                             } else {
  2438.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2439.                             }
  2440.                             $unitsServ $item->getUnits();
  2441.                             if (empty($unitsServ) or $unitsServ == "0") {
  2442.                                 $unitsServ 1;
  2443.                             }
  2444.                             $subtotal $subtotalService $days $unitsServ $pax;
  2445.                             $subnetoUnit $subneto;
  2446.                             $subneto $subneto $days $unitsServ $pax;
  2447.                             $data_supplier['service'][$i] = array(
  2448.                                 'id' => $item->getId(),
  2449.                                 'serviceCatId' => $item->getServiceCatId(),
  2450.                                 'serviceName' => $item->getName(),
  2451.                                 'serviceType' => 'Asistente',
  2452.                                 'date' => $dateServ,
  2453.                                 'qty' => $unitsServ,
  2454.                                 'iva' => $item->getIva(),
  2455.                                 'pax' => $item->getPax(),
  2456.                                 'precioUnit' => $subnetoUnit,
  2457.                                 'subneto' => $subneto,
  2458.                                 'subtotal' => $subtotal,
  2459.                             );
  2460.                             break;
  2461.                         case 16//DDR
  2462.                             $pax $item->getPax();
  2463.                             if (empty($pax) or $pax == "0") {
  2464.                                 $pax 1;
  2465.                             }
  2466.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2467.                             if ($days 1) {
  2468.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2469.                             } else {
  2470.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2471.                             }
  2472.                             $unitsServ $item->getUnits();
  2473.                             if (empty($unitsServ) or $unitsServ == "0") {
  2474.                                 $unitsServ 1;
  2475.                             }
  2476.                             $subtotal $subtotalService $days $unitsServ $pax;
  2477.                             $subnetoUnit $subneto;
  2478.                             $subneto $subneto $days $unitsServ $pax;
  2479.                             $data_supplier['service'][$i] = array(
  2480.                                 'id' => $item->getId(),
  2481.                                 'serviceCatId' => $item->getServiceCatId(),
  2482.                                 'serviceName' => $item->getName(),
  2483.                                 'serviceType' => 'DDR',
  2484.                                 'date' => $dateServ,
  2485.                                 'qty' => $unitsServ,
  2486.                                 'iva' => $item->getIva(),
  2487.                                 'pax' => $item->getPax(),
  2488.                                 'precioUnit' => $subnetoUnit,
  2489.                                 'subneto' => $subneto,
  2490.                                 'subtotal' => $subtotal,
  2491.                             );
  2492.                             break;
  2493.                         default:
  2494.                             break;
  2495.                     }
  2496.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2497.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  2498.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  2499.                     $arrayItems[] = array(
  2500.                         'type' => 'Service',
  2501.                         'name' => $item->getName(),
  2502.                         'amount' => $neto,
  2503.                         'iva' => $item->getIva(),
  2504.                         'total' => $subtotal,
  2505.                     );
  2506.                 }
  2507.                 switch ($item->getIva()) {
  2508.                     // Acumula IVA
  2509.                     case 21:
  2510.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  2511.                         break;
  2512.                     case 10:
  2513.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  2514.                         break;
  2515.                     case 0:
  2516.                         break;
  2517.                     default:
  2518.                         break;
  2519.                 }
  2520.             }
  2521.             $totales_neto_all $totales_neto_all $neto;
  2522.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2523.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  2524.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  2525.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  2526.             // Acumula netos totales e IVA
  2527.             $service['neto'] = $service['neto'] + $neto;
  2528.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  2529.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2530.             $service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
  2531.             $service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
  2532.             $i++;
  2533.         }
  2534.         $data_supplier['serviceSubTotal'] = array(
  2535.             'neto' => $service['neto'],
  2536.             'sumSubT' => $service['sumSubT'],
  2537.         );
  2538.         $currency 'ā‚¬';
  2539.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  2540.         if (!empty($payments)) {
  2541.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  2542.         } else {
  2543.             $amount_pay 0;
  2544.         }
  2545.         $totales_all $totales_total $amount_pay;
  2546.         if (empty($dateDocument)){
  2547.             $dateDocument = new DateTime('now');
  2548.         }
  2549.         $data = array(
  2550.             'id' => $fileId,
  2551.             'type' => $type,
  2552. //            'type' => '',
  2553.             'number' => $number,
  2554. //            'prefix' => $prefix,
  2555.             'prefix' => 'AVE-'.(new DateTime('now'))->format('dmy').'-'.$invoiceId,
  2556.             'date' => $dateDocument,
  2557.             'file' => $file,
  2558.             'token' => $file->getAccessKey(),
  2559.             'company' => $company,
  2560.             'clients' => $client,
  2561.             'arrayItems' => $arrayItems,
  2562.             'datasupplier' => $data_supplier,
  2563.             'currency' => $currency,
  2564.             'totales_neto' => $totales_neto_all,
  2565.             'bases_imponibles' => $data_iva,
  2566.             'totales' => $totales_total,
  2567.             'balance' => $totales_all,
  2568.             'paymentInvoice' => $amount_pay,
  2569.         );
  2570.         return $data;
  2571.     }
  2572.     // Replicar cambios entre FileController y ProductsFilesController
  2573.     private function calculosFile($id$arrayBools$number$type)
  2574.     {
  2575.         // $id Id del Expediente (File)
  2576.         // $arrayBool arreglo de logicos
  2577.         // $number  *********************
  2578.         // $type tipo de calculos a realizar (edicion de expediente, factura, factura de deposito, proforma)
  2579.         $em $this->getDoctrine()->getManager();
  2580.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  2581. //        $items = $em->getRepository(AveProductFile::class)->findByFileId($file->getId());
  2582.         // Primero se agrupan por sala (Ubicacion), luego por tipo y finalmente por RankAv
  2583.         // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĆ” (Video - Sonido - Iluminacion - Otros)
  2584.         $allProductFile $em->getRepository(AveProductFile::class)->findByFileId($id);
  2585.         $arrayLocation = array();
  2586.         $arrayLocationWithNull false;
  2587.         foreach ($allProductFile as $item){
  2588.             if (!empty($item->getLocation())){
  2589.                 $arrayLocation[$item->getLocation()] = $item->getLocation();
  2590.             } else {
  2591.                 $arrayLocationWithNull true;
  2592.             }
  2593.         }
  2594.         if ($arrayLocationWithNull){ $arrayLocation['null'] = 'null'; }
  2595.         $productsInFile = array();
  2596.         $items = array();
  2597.         foreach ($arrayLocation as $item){
  2598.             // VIDEO
  2599.             $parameters = array(
  2600.                 'fileId' => $id,
  2601.                 'type' => 'VĆ­deo',
  2602.                 'location' => $item,
  2603.             );
  2604.             $dql 'SELECT i
  2605.                     FROM AvexpressBundle:AveProductFile i
  2606.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  2607.                     ORDER BY i.rankAv ASC';
  2608.             $query $em->createQuery($dql)->setParameters($parameters);
  2609.             $productsInFileVid $query->getResult();
  2610.             // SONIDO
  2611.             $parameters = array(
  2612.                 'fileId' => $id,
  2613.                 'type' => 'Sonido',
  2614.                 'location' => $item,
  2615.             );
  2616.             $dql 'SELECT i
  2617.                     FROM AvexpressBundle:AveProductFile i
  2618.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  2619.                     ORDER BY i.rankAv ASC';
  2620.             $query $em->createQuery($dql)->setParameters($parameters);
  2621.             $productsInFileSound $query->getResult();
  2622.             // ILUMINACION
  2623.             $parameters = array(
  2624.                 'fileId' => $id,
  2625.                 'type' => 'IluminaciĆ³n',
  2626.                 'location' => $item,
  2627.             );
  2628.             $dql 'SELECT i
  2629.                     FROM AvexpressBundle:AveProductFile i
  2630.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  2631.                     ORDER BY i.rankAv ASC';
  2632.             $query $em->createQuery($dql)->setParameters($parameters);
  2633.             $productsInFileLights $query->getResult();
  2634.             // OTROS
  2635.             $parameters = array(
  2636.                 'fileId' => $id,
  2637.                 'typeV' => 'VĆ­deo',
  2638.                 'typeS' => 'Sonido',
  2639.                 'typeI' => 'IluminaciĆ³n',
  2640.                 'location' => $item,
  2641.             );
  2642.             $dql 'SELECT i
  2643.                     FROM AvexpressBundle:AveProductFile i
  2644.                     WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location)
  2645.                     ORDER BY i.rankAv ASC';
  2646.             $query $em->createQuery($dql)->setParameters($parameters);
  2647.             $productsInFileOther $query->getResult();
  2648.             // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  2649.             $parameters = array(
  2650.                 'fileId' => $id,
  2651.                 'location' => $item,
  2652.             );
  2653.             $dql 'SELECT i
  2654.                     FROM AvexpressBundle:AveProductFile i
  2655.                     WHERE (i.fileId = :fileId AND i.type IS NULL AND i.location = :location)
  2656.                     ORDER BY i.rankAv ASC';
  2657.             $query $em->createQuery($dql)->setParameters($parameters);
  2658.             $productsInFileNull $query->getResult();
  2659.             // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  2660.             if ($item == 'null'){
  2661.                 // VIDEO
  2662.                 $parameters = array(
  2663.                     'fileId' => $id,
  2664.                     'type' => 'VĆ­deo',
  2665.                     'location' => '',
  2666.                 );
  2667.                 $dql 'SELECT i
  2668.                         FROM AvexpressBundle:AveProductFile i
  2669.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  2670.                         ORDER BY i.rankAv ASC';
  2671.                 $query $em->createQuery($dql)->setParameters($parameters);
  2672.                 $productsInFileVid $query->getResult();
  2673.                 // SONIDO
  2674.                 $parameters = array(
  2675.                     'fileId' => $id,
  2676.                     'type' => 'Sonido',
  2677.                     'location' => '',
  2678.                 );
  2679.                 $dql 'SELECT i
  2680.                         FROM AvexpressBundle:AveProductFile i
  2681.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) 
  2682.                         ORDER BY i.rankAv ASC';
  2683.                 $query $em->createQuery($dql)->setParameters($parameters);
  2684.                 $productsInFileSound $query->getResult();
  2685.                 // ILUMINACION
  2686.                 $parameters = array(
  2687.                     'fileId' => $id,
  2688.                     'type' => 'IluminaciĆ³n',
  2689.                     'location' => '',
  2690.                 );
  2691.                 $dql 'SELECT i
  2692.                         FROM AvexpressBundle:AveProductFile i
  2693.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  2694.                         ORDER BY i.rankAv ASC';
  2695.                 $query $em->createQuery($dql)->setParameters($parameters);
  2696.                 $productsInFileLights $query->getResult();
  2697.                 // OTROS
  2698.                 $parameters = array(
  2699.                     'fileId' => $id,
  2700.                     'typeV' => 'VĆ­deo',
  2701.                     'typeS' => 'Sonido',
  2702.                     'typeI' => 'IluminaciĆ³n',
  2703.                     'location' => '',
  2704.                 );
  2705.                 $dql 'SELECT i
  2706.                         FROM AvexpressBundle:AveProductFile i
  2707.                         WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND (i.location IS NULL OR i.location = :location))
  2708.                         ORDER BY i.rankAv ASC';
  2709.                 $query $em->createQuery($dql)->setParameters($parameters);
  2710.                 $productsInFileOther $query->getResult();
  2711.                 // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  2712.                 $parameters = array(
  2713.                     'fileId' => $id,
  2714.                     'location' => '',
  2715.                 );
  2716.                 $dql 'SELECT i
  2717.                         FROM AvexpressBundle:AveProductFile i
  2718.                         WHERE (i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location))
  2719.                         ORDER BY i.rankAv ASC';
  2720.                 $query $em->createQuery($dql)->setParameters($parameters);
  2721.                 $productsInFileNull $query->getResult();
  2722.             }
  2723.             $items array_merge($items,$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  2724.         }
  2725.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  2726.         $client $em->getRepository(Client::class)->findById($file->getClient());
  2727.         if (!empty($client)){
  2728.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2729.             $client[0]->setPopulation($city);
  2730.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2731.             $client[0]->setRegion($region);
  2732.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2733.             $client[0]->setCountry($country);
  2734.         } else {
  2735.             $client[0] = new Client();
  2736.             $client[0]->setName('');
  2737.             $client[0]->setTitle('');
  2738.             $client[0]->setIdDocument('');
  2739.             $client[0]->setPopulation('');
  2740.             $client[0]->setRegion('');
  2741.             $client[0]->setCountry('');
  2742.         }
  2743.         // Acumuladores de los calculos
  2744.         $totales_neto_all 0;
  2745.         $data_iva = array(
  2746.             'iva' => 21,
  2747.             'ivaMontoVeintiUno' => 0,
  2748.             'ivaMontoDiez' => 0,
  2749.             'ivaMontoCero' => 0,
  2750.         );
  2751.         //INICIO: Determinamos el numero de factura o proforma
  2752.         if (substr($number,0,1) == 'I'){
  2753.             // Es una Factura
  2754.             $numberInvoiceOrProforma substr($number,1);
  2755.             $number $numberInvoiceOrProforma;
  2756.             $type 'Invoice';
  2757.         } else {
  2758.             // Es una Proforma
  2759.             $numberInvoiceOrProforma substr($number,1);
  2760.             $number $numberInvoiceOrProforma;
  2761.             $type 'Proforma';
  2762.         }
  2763.         //FIN: Determinamos el numero de factura o proforma
  2764.         // Buscamos las salas reservadas, pagos y servicios para el evento
  2765.         $arrayItems = array();
  2766.         $fileProducts = array();
  2767.         if (!empty($arrayBools['lounge'])) {
  2768.             foreach ($arrayBools['lounge'] as $key => $item) {
  2769.                 if ($item == 'true') {
  2770. //                    $fileProducts[] = $em->getRepository('DevelupBundle:ReservationLoungeSimple')->findOneById($key);
  2771.                 }
  2772.             }
  2773.         }
  2774.         $payments = array();
  2775.         if (!empty($arrayBools['payment'])) {
  2776.             foreach ($arrayBools['payment'] as $key => $item) {
  2777.                 if ($item == 'true') {
  2778. //                    $payments[] = $em->getRepository('DevelupBundle:ReservationPaymentsClient')->findOneById($key);
  2779.                 }
  2780.             }
  2781.         }
  2782.         $services = array();
  2783.         if (!empty($arrayBools['service'])) {
  2784.             foreach ($arrayBools['service'] as $key => $item) {
  2785.                 if ($item == 'true') {
  2786. //                    $services[] = $em->getRepository('DevelupBundle:ReservationService')->findOneById($key);
  2787.                 }
  2788.             }
  2789.         }
  2790.         $data_supplier = array();
  2791.         $i 0;
  2792.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĆ³n del impuesto, siempre serĆ” un 21%"
  2793.         $pax '-';
  2794.         $qty '1';
  2795.         $product = array(
  2796.             'neto' => 0,
  2797.             'sumSubT' => 0,
  2798.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  2799.         $service = array(
  2800.             'neto' => 0,
  2801.             'sumSubT' => 0,
  2802.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  2803.         if (empty($items)){
  2804.             $data_supplier['product'][0] = null;
  2805.         }
  2806.         foreach ($items as $item){
  2807.             $days '1';
  2808.             if (!empty($item->getUnits())){
  2809.                 $qty $item->getUnits();
  2810.             }
  2811.             if (!empty($item->getDays())){
  2812.                 $days $item->getDays();
  2813.             }
  2814.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
  2815.                 $subtotal 0;
  2816.                 $neto 0;
  2817.                 $subtotalProduct 0;
  2818.             } else {
  2819. //                $subtotalProduct = $item->getServicePrice() * 1.21;
  2820.                 $subtotalProduct $item->getSubTotalPrice() * 1.21;
  2821. //                $subneto = $item->getServicePrice();
  2822.                 $subneto $item->getSubTotalPrice();
  2823.                 $subtotal =  $subtotalProduct;
  2824.                 $neto =  $subneto;
  2825.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2826.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  2827.                 $neto round($neto,2,PHP_ROUND_HALF_UP);
  2828.                 $arrayItems[] = array(
  2829.                     'type' => 'Product',
  2830.                     'name' => $item->getProductName(),
  2831.                     'amount' => $neto,
  2832.                     'iva' => '21',
  2833.                     'total' => $subtotal,
  2834.                 );
  2835.             }
  2836.             // Acumula netos totales e IVA
  2837.             $totales_neto_all $totales_neto_all $neto;
  2838.             switch ($item->getIva()){
  2839.                 case 21$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21); break;
  2840.                 case 10$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1); break;
  2841.                 case 0$data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0); break;
  2842.                 default:  break;
  2843.             }
  2844.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2845.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  2846.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  2847.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  2848.             // Acumula netos totales e IVA
  2849.             $product['neto'] = $product['neto'] + $neto;
  2850.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  2851.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2852.             $product['neto'] = round($product['neto'],2,PHP_ROUND_HALF_UP);
  2853.             $product['sumSubT'] = round($product['sumSubT'],2,PHP_ROUND_HALF_UP);
  2854.             $data_supplier['product'][$i] = array (
  2855.                 'id' => $item->getId(),
  2856.                 'productName' => $item->getProductName(),
  2857.                 'description' => $item->getDescription(),
  2858.                 'productId' => $item->getProductId(),
  2859.                 'dateStart' => $item->getDateStart(),
  2860.                 'dateEnd' => $item->getDateEnd(),
  2861.                 'servicePrice' => $item->getServicePrice(),
  2862.                 'subTotalPrice' => $item->getSubTotalPrice(),
  2863.                 'subtotalProduct' => $subtotalProduct,
  2864.                 'iva' => $iva,
  2865.                 'pax' => $pax,
  2866.                 'qty' => $qty,
  2867.                 'days' => $days,
  2868.                 'type' => $item->getType(),
  2869.                 'subtotal' => $subtotal,
  2870.             );
  2871.             $i++;
  2872.         }
  2873.         $data_supplier['productSubTotal'] = array(
  2874.             'neto' => $product['neto'],
  2875.             'sumSubT' => $product['sumSubT'],
  2876.         );
  2877.         $payment = array(
  2878.             'sumSubT' => 0,
  2879.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  2880.         $i 0;
  2881.         foreach ($payments as $item){
  2882.             $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  2883.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2884.             $payment['sumSubT'] = round($payment['sumSubT'],2,PHP_ROUND_HALF_UP);
  2885.             $data_supplier['payment'][$i] = array (
  2886.                 'id' => $item->getId(),
  2887.                 'amount' => $item->getAmount(),
  2888.                 'amountTotal' => $item->getAmountTotal(),
  2889.                 'vat' => $item->getVat(),
  2890.                 'datePayAt' => $item->getDatePayAt(),
  2891.                 'wayToPay' => $item->getWayToPay(),
  2892.             );
  2893.             $arrayItems[] = array(
  2894.                 'type' => 'Payment',
  2895.                 'name' => $item->getWayToPay(),
  2896.                 'amount' => $item->getAmount(),
  2897.                 'total' => $item->getAmountTotal(),
  2898.                 'iva' => $item->getVat(),
  2899.             );
  2900.             $i++;
  2901.         }
  2902.         if (!empty($payments)) {
  2903.             $data_supplier['paymentSubTotal'] = array(
  2904.                 'sumSubT' => $payment['sumSubT'],
  2905.             );
  2906.         }
  2907.         foreach ($services as $item){
  2908.             if (is_null($item->getPrice()) or empty($item->getPrice())){
  2909.                 $subtotal 0;
  2910.                 $neto 0;
  2911.                 $subtotalService 0;
  2912.             } else {
  2913.                 $subtotalService $item->getPrice();
  2914.                 $subneto $item->getPrice();
  2915.                 // Commission
  2916.                 if ($item->getOpCommission()=='1'){
  2917.                     $subtotalService $subtotalService * (+ ($item->getCommission()/100));
  2918.                     $subneto $subneto  * (+ ($item->getCommission()/100));
  2919.                 } else {
  2920.                     $subtotalService $subtotalService * (- ($item->getCommission()/100));
  2921.                     $subneto $subneto * (- ($item->getCommission()/100));
  2922.                 }
  2923.                 // Over
  2924.                 if ($item->getOpOver()=='1'){
  2925.                     $subtotalService $subtotalService $item->getOver();
  2926.                     $subneto $subneto $item->getOver();
  2927.                 } else {
  2928.                     $subtotalService $subtotalService $item->getOver();
  2929.                     $subneto $subneto $item->getOver();
  2930.                 }
  2931.                 // IVA
  2932.                 if ($item->getOpIva()=='1'){
  2933.                     $subtotalService $subtotalService * (+ ($item->getIva()/100));
  2934.                 } else {
  2935.                     $subtotalService $item->getPrice();
  2936.                     $subneto = ($subneto 100) / (100 $item->getIva());
  2937.                 }
  2938.                 switch ($item->getServiceCatId()){
  2939.                     case 1// Alojamiento
  2940.                         // el numero de noches $numNoches; precio unitario $subneto
  2941.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  2942.                         // La personas no afectan este calculo
  2943.                         $subtotal $subtotalService $numNoches $item->getUnits();
  2944.                         $subnetoUnit $subneto;
  2945.                         $subneto $subneto $numNoches $item->getUnits();
  2946.                         $data_supplier['service'][$i] = array (
  2947.                             'id' => $item->getId(),
  2948.                             'serviceCatId' => $item->getServiceCatId(),
  2949.                             'serviceName' => $item->getName(),
  2950.                             'serviceType' => 'Hotel',
  2951.                             'date' => ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y'),
  2952.                             'qty' => $item->getUnits(),
  2953.                             'iva' => $item->getIva(),
  2954.                             'pax' => '-',
  2955.                             'precioUnit' => $subnetoUnit,
  2956.                             'subneto' => $subneto,
  2957.                             'subtotal' => $subtotal,
  2958.                         );
  2959.                         break;
  2960.                     case 2//Actividades
  2961.                         // El nĆŗmero de personas es considerado en el calculo
  2962.                         $pax $item->getPax();
  2963.                         if (empty($pax) or $pax == "0") {
  2964.                             $pax 1;
  2965.                         }
  2966.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2967.                         if ($days 1){
  2968.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2969.                         } else {
  2970.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2971.                         }
  2972.                         $subtotal $subtotalService $days $item->getUnits();
  2973.                         $subnetoUnit $subneto;
  2974.                         $subneto $subneto $days $item->getUnits();
  2975.                         $data_supplier['service'][$i] = array (
  2976.                             'id' => $item->getId(),
  2977.                             'serviceCatId' => $item->getServiceCatId(),
  2978.                             'serviceName' => $item->getName(),
  2979.                             'serviceType' => 'Actividad',
  2980.                             'date' => $dateServ,
  2981.                             'qty' => $item->getUnits(),
  2982.                             'iva' => $item->getIva(),
  2983.                             'pax' => $item->getPax(),
  2984.                             'precioUnit' => $subnetoUnit,
  2985.                             'subneto' => $subneto,
  2986.                             'subtotal' => $subtotal,
  2987.                         );
  2988.                         break;
  2989.                     case 3// AV
  2990.                         $pax $item->getPax();
  2991.                         if (empty($pax) or $pax == "0") {
  2992.                             $pax 1;
  2993.                         }
  2994.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2995.                         if ($days 1){
  2996.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2997.                         } else {
  2998.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2999.                         }
  3000.                         $unitsServ $item->getUnits();
  3001.                         if (empty($unitsServ) or $unitsServ == "0") {
  3002.                             $unitsServ 1;
  3003.                         }
  3004.                         $subtotal $subtotalService $days $unitsServ $pax;
  3005.                         $subnetoUnit $subneto;
  3006.                         $subneto $subneto $days $unitsServ $pax;
  3007.                         $data_supplier['service'][$i] = array (
  3008.                             'id' => $item->getId(),
  3009.                             'serviceCatId' => $item->getServiceCatId(),
  3010.                             'serviceName' => $item->getName(),
  3011.                             'serviceType' => 'AV',
  3012.                             'date' => $dateServ,
  3013.                             'qty' => $unitsServ,
  3014.                             'iva' => $item->getIva(),
  3015.                             'pax' => $item->getPax(),
  3016.                             'precioUnit' => $subnetoUnit,
  3017.                             'subneto' => $subneto,
  3018.                             'subtotal' => $subtotal,
  3019.                         );
  3020.                         break;
  3021.                     case 4//Creative
  3022.                         $pax $item->getPax();
  3023.                         if (empty($pax) or $pax == "0") {
  3024.                             $pax 1;
  3025.                         }
  3026.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3027.                         if ($days 1){
  3028.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3029.                         } else {
  3030.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3031.                         }
  3032.                         $unitsServ $item->getUnits();
  3033.                         if (empty($unitsServ) or $unitsServ == "0") {
  3034.                             $unitsServ 1;
  3035.                         }
  3036.                         $subtotal $subtotalService $days $unitsServ $pax;
  3037.                         $subnetoUnit $subneto;
  3038.                         $subneto $subneto $days $unitsServ $pax;
  3039.                         $data_supplier['service'][$i] = array (
  3040.                             'id' => $item->getId(),
  3041.                             'serviceCatId' => $item->getServiceCatId(),
  3042.                             'serviceName' => $item->getName(),
  3043.                             'serviceType' => 'Creativo',
  3044.                             'date' => $dateServ,
  3045.                             'qty' => $unitsServ,
  3046.                             'iva' => $item->getIva(),
  3047.                             'pax' => $item->getPax(),
  3048.                             'precioUnit' => $subnetoUnit,
  3049.                             'subneto' => $subneto,
  3050.                             'subtotal' => $subtotal,
  3051.                         );
  3052.                         break;
  3053.                     case 5//Cruise
  3054.                         $pax $item->getPax();
  3055.                         if (empty($pax) or $pax == "0") {
  3056.                             $pax 1;
  3057.                         }
  3058.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  3059.                         if ($days 1){
  3060.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3061.                         } else {
  3062.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3063.                         }
  3064.                         $unitsServ $item->getUnits();
  3065.                         if (empty($unitsServ) or $unitsServ == "0") {
  3066.                             $unitsServ 1;
  3067.                         }
  3068.                         $subtotal $subtotalService $days $unitsServ $pax;
  3069.                         $subnetoUnit $subneto;
  3070.                         $subneto $subneto $days $unitsServ $pax;
  3071.                         $data_supplier['service'][$i] = array (
  3072.                             'id' => $item->getId(),
  3073.                             'serviceCatId' => $item->getServiceCatId(),
  3074.                             'serviceName' => $item->getName(),
  3075.                             'serviceType' => 'Crucero',
  3076.                             'date' => $dateServ,
  3077.                             'qty' => $unitsServ,
  3078.                             'iva' => $item->getIva(),
  3079.                             'pax' => $item->getPax(),
  3080.                             'precioUnit' => $subnetoUnit,
  3081.                             'subneto' => $subneto,
  3082.                             'subtotal' => $subtotal,
  3083.                         );
  3084.                         break;
  3085.                     case 6//Entertaiment
  3086.                         $pax $item->getPax();
  3087.                         if (empty($pax) or $pax == "0") {
  3088.                             $pax 1;
  3089.                         }
  3090.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3091.                         if ($days 1){
  3092.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3093.                         } else {
  3094.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3095.                         }
  3096.                         $unitsServ $item->getUnits();
  3097.                         if (empty($unitsServ) or $unitsServ == "0") {
  3098.                             $unitsServ 1;
  3099.                         }
  3100.                         $subtotal $subtotalService $days $unitsServ $pax;
  3101.                         $subnetoUnit $subneto;
  3102.                         $subneto $subneto $days $unitsServ $pax;
  3103.                         $data_supplier['service'][$i] = array (
  3104.                             'id' => $item->getId(),
  3105.                             'serviceCatId' => $item->getServiceCatId(),
  3106.                             'serviceName' => $item->getName(),
  3107.                             'serviceType' => 'Entretenimiento',
  3108.                             'date' => $dateServ,
  3109.                             'qty' => $unitsServ,
  3110.                             'iva' => $item->getIva(),
  3111.                             'pax' => $item->getPax(),
  3112.                             'precioUnit' => $subnetoUnit,
  3113.                             'subneto' => $subneto,
  3114.                             'subtotal' => $subtotal,
  3115.                         );
  3116.                         break;
  3117.                     case 7// Gifts
  3118.                         $pax $item->getPax();
  3119.                         if (empty($pax) or $pax == "0") {
  3120.                             $pax 1;
  3121.                         }
  3122. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  3123.                         $days 1;
  3124.                         if ($days 1){
  3125.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3126.                         } else {
  3127.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3128.                         }
  3129.                         $unitsServ $item->getUnits();
  3130.                         if (empty($unitsServ) or $unitsServ == "0") {
  3131.                             $unitsServ 1;
  3132.                         }
  3133.                         $subtotal $subtotalService $days $unitsServ $pax;
  3134.                         $subnetoUnit $subneto;
  3135.                         $subneto $subneto $days $unitsServ $pax;
  3136.                         $data_supplier['service'][$i] = array (
  3137.                             'id' => $item->getId(),
  3138.                             'serviceCatId' => $item->getServiceCatId(),
  3139.                             'serviceName' => $item->getName(),
  3140.                             'serviceType' => 'Regalos',
  3141.                             'date' => $dateServ,
  3142.                             'qty' => $unitsServ,
  3143.                             'iva' => $item->getIva(),
  3144.                             'pax' => $item->getPax(),
  3145.                             'precioUnit' => $subnetoUnit,
  3146.                             'subneto' => $subneto,
  3147.                             'subtotal' => $subtotal,
  3148.                         );
  3149.                         break;
  3150.                     case 8//Guide
  3151.                         $pax $item->getPax();
  3152.                         if (empty($pax) or $pax == "0") {
  3153.                             $pax 1;
  3154.                         }
  3155.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3156.                         if ($days 1){
  3157.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3158.                         } else {
  3159.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3160.                         }
  3161.                         $unitsServ $item->getUnits();
  3162.                         if (empty($unitsServ) or $unitsServ == "0") {
  3163.                             $unitsServ 1;
  3164.                         }
  3165.                         $subtotal $subtotalService $days $unitsServ $pax;
  3166.                         $subnetoUnit $subneto;
  3167.                         $subneto $subneto $days $unitsServ $pax;
  3168.                         $data_supplier['service'][$i] = array (
  3169.                             'id' => $item->getId(),
  3170.                             'serviceCatId' => $item->getServiceCatId(),
  3171.                             'serviceName' => $item->getName(),
  3172.                             'serviceType' => 'Regalos',
  3173.                             'date' => $dateServ,
  3174.                             'qty' => $unitsServ,
  3175.                             'iva' => $item->getIva(),
  3176.                             'pax' => $item->getPax(),
  3177.                             'precioUnit' => $subnetoUnit,
  3178.                             'subneto' => $subneto,
  3179.                             'subtotal' => $subtotal,
  3180.                         );
  3181.                         break;
  3182.                     case 9//Itineraries
  3183.                         $pax $item->getPax();
  3184.                         if (empty($pax) or $pax == "0") {
  3185.                             $pax 1;
  3186.                         }
  3187.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3188.                         if ($days 1){
  3189.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3190.                         } else {
  3191.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3192.                         }
  3193.                         $unitsServ $item->getUnits();
  3194.                         if (empty($unitsServ) or $unitsServ == "0") {
  3195.                             $unitsServ 1;
  3196.                         }
  3197.                         $subtotal $subtotalService $days $unitsServ $pax;
  3198.                         $subnetoUnit $subneto;
  3199.                         $subneto $subneto $days $unitsServ $pax;
  3200.                         $data_supplier['service'][$i] = array (
  3201.                             'id' => $item->getId(),
  3202.                             'serviceCatId' => $item->getServiceCatId(),
  3203.                             'serviceName' => $item->getName(),
  3204.                             'serviceType' => 'Itinerarios',
  3205.                             'date' => $dateServ,
  3206.                             'qty' => $unitsServ,
  3207.                             'iva' => $item->getIva(),
  3208.                             'pax' => $item->getPax(),
  3209.                             'precioUnit' => $subnetoUnit,
  3210.                             'subneto' => $subneto,
  3211.                             'subtotal' => $subtotal,
  3212.                         );
  3213.                         break;
  3214.                     case 10//Lounge  -- No Aplica
  3215. //                        $pax = $item->getPax();
  3216. //                        if (empty($pax) or $pax == "0") {
  3217. //                            $pax = 1;
  3218. //                        }
  3219. //
  3220. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  3221. //                        if ($days > 1){
  3222. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3223. //                        } else {
  3224. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3225. //                        }
  3226. //
  3227. //                        $unitsServ = $item->getUnits();
  3228. //                        if (empty($unitsServ) or $unitsServ == "0") {
  3229. //                            $unitsServ = 1;
  3230. //                        }
  3231. //
  3232. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  3233. //                        $subnetoUnit = $subneto;
  3234. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  3235. //
  3236. //                        $data_supplier['service'][$i] = array (
  3237. //                            'id' => $item->getId(),
  3238. //                            'serviceCatId' => $item->getServiceCatId(),
  3239. //                            'serviceName' => $item->getName(),
  3240. //                            'serviceType' => 'Itinerarios',
  3241. //                            'date' => $dateServ,
  3242. //                            'qty' => $unitsServ,
  3243. //                            'iva' => $item->getIva(),
  3244. //                            'pax' => $item->getPax(),
  3245. //                            'precioUnit' => $subnetoUnit,
  3246. //                            'subneto' => $subneto,
  3247. //                            'subtotal' => $subtotal,
  3248. //                        );
  3249.                         break;
  3250.                     case 11//Menu
  3251.                         $pax $item->getPax();
  3252.                         if (empty($pax) or $pax == "0") {
  3253.                             $pax 1;
  3254.                         }
  3255.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3256.                         if ($days 1){
  3257.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3258.                         } else {
  3259.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3260.                         }
  3261.                         $unitsServ $item->getUnits();
  3262.                         if (empty($unitsServ) or $unitsServ == "0") {
  3263.                             $unitsServ 1;
  3264.                         }
  3265.                         $subtotal $subtotalService $days $unitsServ $pax;
  3266.                         $subnetoUnit $subneto;
  3267.                         $subneto $subneto $days $unitsServ $pax;
  3268.                         $data_supplier['service'][$i] = array (
  3269.                             'id' => $item->getId(),
  3270.                             'serviceCatId' => $item->getServiceCatId(),
  3271.                             'serviceName' => $item->getName(),
  3272.                             'serviceType' => 'MenĆŗ',
  3273.                             'date' => $dateServ,
  3274.                             'qty' => $unitsServ,
  3275.                             'iva' => $item->getIva(),
  3276.                             'pax' => $item->getPax(),
  3277.                             'precioUnit' => $subnetoUnit,
  3278.                             'subneto' => $subneto,
  3279.                             'subtotal' => $subtotal,
  3280.                         );
  3281.                         break;
  3282.                     case 12//Others
  3283.                         $pax $item->getPax();
  3284.                         if (empty($pax) or $pax == "0") {
  3285.                             $pax 1;
  3286.                         }
  3287.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3288.                         if ($days 1){
  3289.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3290.                         } else {
  3291.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3292.                         }
  3293.                         $unitsServ $item->getUnits();
  3294.                         if (empty($unitsServ) or $unitsServ == "0") {
  3295.                             $unitsServ 1;
  3296.                         }
  3297.                         $subtotal $subtotalService $days $unitsServ $pax;
  3298.                         $subnetoUnit $subneto;
  3299.                         $subneto $subneto $days $unitsServ $pax;
  3300.                         $data_supplier['service'][$i] = array (
  3301.                             'id' => $item->getId(),
  3302.                             'serviceCatId' => $item->getServiceCatId(),
  3303.                             'serviceName' => $item->getName(),
  3304.                             'serviceType' => 'Otros',
  3305.                             'date' => $dateServ,
  3306.                             'qty' => $unitsServ,
  3307.                             'iva' => $item->getIva(),
  3308.                             'pax' => $item->getPax(),
  3309.                             'precioUnit' => $subnetoUnit,
  3310.                             'subneto' => $subneto,
  3311.                             'subtotal' => $subtotal,
  3312.                         );
  3313.                         break;
  3314.                     case 13//Transport
  3315.                         $pax $item->getPax();
  3316.                         if (empty($pax) or $pax == "0") {
  3317.                             $pax 1;
  3318.                         }
  3319.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3320.                         if ($days 1){
  3321.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3322.                         } else {
  3323.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3324.                         }
  3325.                         $unitsServ $item->getUnits();
  3326.                         if (empty($unitsServ) or $unitsServ == "0") {
  3327.                             $unitsServ 1;
  3328.                         }
  3329.                         $subtotal $subtotalService $days $unitsServ $pax;
  3330.                         $subnetoUnit $subneto;
  3331.                         $subneto $subneto $days $unitsServ $pax;
  3332.                         $data_supplier['service'][$i] = array (
  3333.                             'id' => $item->getId(),
  3334.                             'serviceCatId' => $item->getServiceCatId(),
  3335.                             'serviceName' => $item->getName(),
  3336.                             'serviceType' => 'Transporte',
  3337.                             'date' => $dateServ,
  3338.                             'qty' => $unitsServ,
  3339.                             'iva' => $item->getIva(),
  3340.                             'pax' => $item->getPax(),
  3341.                             'precioUnit' => $subnetoUnit,
  3342.                             'subneto' => $subneto,
  3343.                             'subtotal' => $subtotal,
  3344.                         );
  3345.                         break;
  3346.                     case 14//Technology
  3347.                         $pax $item->getPax();
  3348.                         if (empty($pax) or $pax == "0") {
  3349.                             $pax 1;
  3350.                         }
  3351. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  3352.                         $days 1;
  3353. //                        if ($days > 1){
  3354. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3355. //                        } else {
  3356. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3357. //                        }
  3358.                         $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3359.                         $unitsServ $item->getUnits();
  3360.                         if (empty($unitsServ) or $unitsServ == "0") {
  3361.                             $unitsServ 1;
  3362.                         }
  3363.                         $subtotal $subtotalService $days $unitsServ $pax;
  3364.                         $subnetoUnit $subneto;
  3365.                         $subneto $subneto $days $unitsServ $pax;
  3366.                         $data_supplier['service'][$i] = array (
  3367.                             'id' => $item->getId(),
  3368.                             'serviceCatId' => $item->getServiceCatId(),
  3369.                             'serviceName' => $item->getName(),
  3370.                             'serviceType' => 'TecnologĆ­a',
  3371.                             'date' => $dateServ,
  3372.                             'qty' => $unitsServ,
  3373.                             'iva' => $item->getIva(),
  3374.                             'pax' => $item->getPax(),
  3375.                             'precioUnit' => $subnetoUnit,
  3376.                             'subneto' => $subneto,
  3377.                             'subtotal' => $subtotal,
  3378.                         );
  3379.                         break;
  3380.                     case 15//Assisstant
  3381.                         $pax $item->getPax();
  3382.                         if (empty($pax) or $pax == "0") {
  3383.                             $pax 1;
  3384.                         }
  3385.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3386.                         if ($days 1){
  3387.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3388.                         } else {
  3389.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3390.                         }
  3391.                         $unitsServ $item->getUnits();
  3392.                         if (empty($unitsServ) or $unitsServ == "0") {
  3393.                             $unitsServ 1;
  3394.                         }
  3395.                         $subtotal $subtotalService $days $unitsServ $pax;
  3396.                         $subnetoUnit $subneto;
  3397.                         $subneto $subneto $days $unitsServ $pax;
  3398.                         $data_supplier['service'][$i] = array (
  3399.                             'id' => $item->getId(),
  3400.                             'serviceCatId' => $item->getServiceCatId(),
  3401.                             'serviceName' => $item->getName(),
  3402.                             'serviceType' => 'Asistente',
  3403.                             'date' => $dateServ,
  3404.                             'qty' => $unitsServ,
  3405.                             'iva' => $item->getIva(),
  3406.                             'pax' => $item->getPax(),
  3407.                             'precioUnit' => $subnetoUnit,
  3408.                             'subneto' => $subneto,
  3409.                             'subtotal' => $subtotal,
  3410.                         );
  3411.                         break;
  3412.                     case 16//DDR
  3413.                         $pax $item->getPax();
  3414.                         if (empty($pax) or $pax == "0") {
  3415.                             $pax 1;
  3416.                         }
  3417.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  3418.                         if ($days 1){
  3419.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  3420.                         } else {
  3421.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  3422.                         }
  3423.                         $unitsServ $item->getUnits();
  3424.                         if (empty($unitsServ) or $unitsServ == "0") {
  3425.                             $unitsServ 1;
  3426.                         }
  3427.                         $subtotal $subtotalService $days $unitsServ $pax;
  3428.                         $subnetoUnit $subneto;
  3429.                         $subneto $subneto $days $unitsServ $pax;
  3430.                         $data_supplier['service'][$i] = array (
  3431.                             'id' => $item->getId(),
  3432.                             'serviceCatId' => $item->getServiceCatId(),
  3433.                             'serviceName' => $item->getName(),
  3434.                             'serviceType' => 'DDR',
  3435.                             'date' => $dateServ,
  3436.                             'qty' => $unitsServ,
  3437.                             'iva' => $item->getIva(),
  3438.                             'pax' => $item->getPax(),
  3439.                             'precioUnit' => $subnetoUnit,
  3440.                             'subneto' => $subneto,
  3441.                             'subtotal' => $subtotal,
  3442.                         );
  3443.                         break;
  3444.                     default:
  3445.                         break;
  3446.                 }
  3447.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  3448.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  3449.                 $neto round($subneto,2,PHP_ROUND_HALF_UP);
  3450.                 $arrayItems[] = array(
  3451.                     'type' => 'Service',
  3452.                     'name' => $item->getName(),
  3453.                     'amount' => $neto,
  3454.                     'iva' => $item->getIva(),
  3455.                     'total' => $subtotal,
  3456.                 );
  3457.             }
  3458.             switch ($item->getIva()){
  3459.                 // Acumula IVA
  3460.                 case 21:
  3461.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva()/100));
  3462.                     break;
  3463.                 case 10:
  3464.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva()/100));
  3465.                     break;
  3466.                 case 0:
  3467.                     break;
  3468.                 default:
  3469.                     break;
  3470.             }
  3471.             $totales_neto_all $totales_neto_all $neto;
  3472.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  3473.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  3474.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  3475.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  3476.             // Acumula netos totales e IVA
  3477.             $service['neto'] = $service['neto'] + $neto;
  3478.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  3479.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  3480.             $service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
  3481.             $service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
  3482.             $i++;
  3483.         }
  3484.         $data_supplier['serviceSubTotal'] = array(
  3485.             'neto' => $service['neto'],
  3486.             'sumSubT' => $service['sumSubT'],
  3487.         );
  3488.         $currency 'ā‚¬';
  3489.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  3490.         if (!empty($payments)) {
  3491.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  3492.         } else {
  3493.             $amount_pay 0;
  3494.         }
  3495.         $totales_all $totales_total $amount_pay;
  3496.         if ($type == 'Invoice'){
  3497.             $em->clear();   // sin este clear se producia error al guardar
  3498.             $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($numberInvoiceOrProforma);
  3499.             $newInvoice->setBalance($totales_all);
  3500.             $em->persist($newInvoice);
  3501.             $em->flush();
  3502.         }
  3503.         $data = array(
  3504.             'id' => $id,
  3505.             'type' => $type,
  3506.             'number' => $number,
  3507.             'prefix' => 'AVE-'.(new DateTime('now'))->format('dmy').'-',
  3508.             'date' => new DateTime('now'),
  3509.             'file' => $file,
  3510.             'company' => $company,
  3511.             'clients' => $client,
  3512.             'arrayItems' => $arrayItems,
  3513.             'datasupplier' => $data_supplier,
  3514.             'currency' => $currency,
  3515.             'totales_neto' => $totales_neto_all,
  3516.             'bases_imponibles' => $data_iva,
  3517.             'totales' => $totales_total,
  3518.             'balance' => $totales_all,
  3519.             'paymentInvoice' => $amount_pay,
  3520.         );
  3521.         return $data;
  3522.     }
  3523.     private function sendTelegram($id$text )
  3524.     {
  3525.         $em $this->getDoctrine()->getManager();
  3526.         // No es necesario tener una tabla de TelegramUser para el modulo de AvExpress
  3527.         $telegUser $em->getRepository(MdvTelegramUser::class)->findOneByUserId($id);
  3528.         if (empty($telegUser)){return true;}
  3529.         $parameters = array(
  3530.             'chat_id' => $telegUser->getChatId(),
  3531.             'text' => $text,
  3532.         );
  3533.         $bot_token $telegUser->getBotToken();
  3534.         $url "https://api.telegram.org/bot$bot_token/sendMessage";
  3535.         if (!$curl curl_init()){
  3536.             exit();
  3537.         }
  3538.         curl_setopt($curl,CURLOPT_POST,true);
  3539.         curl_setopt($curl,CURLOPT_POSTFIELDS,$parameters);
  3540.         curl_setopt($curl,CURLOPT_URL,$url);
  3541.         curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  3542.         $output curl_exec($curl);
  3543.         curl_close($curl);
  3544.         return true;
  3545.     }
  3546.     private function baseBenefits($fileId){
  3547.         $em $this->getDoctrine()->getManager();
  3548. //        $file = $em->getRepository(AveFiles::class)->findOneById($fileId);
  3549.         $productsInFile $em->getRepository(AveProductFile::class)->findByFileId($fileId);
  3550.         $benefitEuro 0;
  3551.         $benefitPerc 0;
  3552.         $totalSale 0;
  3553.         foreach ($productsInFile as $item){
  3554.             if(empty($item->getSupplierExt()) or ($item->getSupplierExt() == 'AV EXPRESS S.L.')){
  3555.                 // El proveedor es AV, el beneficio es 100%
  3556.                 $benefitEuro $benefitEuro $item->getSubTotalPrice();
  3557.             } else {
  3558.                 // El proveedor es externo, el beneficio lo determinan el over y la comision
  3559. //                $subTotalPriceExt = $item->getServicePrice() * $item->getUnits() * $item->getDays();        // Precio sin Over ni Comision
  3560. //                $benefitEuro = $benefitEuro + ($item->getSubTotalPrice() - $subTotalPriceExt);
  3561.                 $prdPrice $item->getServicePrice(); if (empty($prdPrice)){ $prdPrice 0; }
  3562.                 $prdUnits $item->getUnits(); if (empty($prdUnits)){ $prdUnits 1; }
  3563.                 $prdDays $item->getDays(); if (empty($prdDays)){ $prdDays 1; }
  3564.                 $prdPax $item->getPax(); if (empty($prdPax)){ $prdPax 1; }
  3565.                 $subTotalPriceExt $prdPrice $prdUnits $prdDays $prdPax;                             // Precio sin Over ni Comision
  3566.                 $benefitEuro $benefitEuro + ($item->getSubTotalPrice() - $subTotalPriceExt);
  3567.             }
  3568.             $totalSale $totalSale $item->getSubTotalPrice();
  3569.         }
  3570.         // Verificamos beneficios simplificados de proveedores
  3571.         $simplyBen $em->getRepository(AveBenefitsSupplier::class)->findByFileId($fileId);
  3572.         foreach ($simplyBen as $item){ $benefitEuro $benefitEuro $item->getBenefitSupplier(); }
  3573.         if (!($totalSale == 0)){
  3574.             $benefitPerc = ($benefitEuro 100)/$totalSale;
  3575.         }
  3576.         $data = array(
  3577.             'id' => $fileId,
  3578.             'benefitEuro' => $benefitEuro,
  3579.             'benefitPerc' => $benefitPerc,
  3580.         );
  3581.         return $data;
  3582.     }
  3583.     private function precioPorVariacionDeDias ($supplierService$productFile){
  3584.         // El precio unitario debe ser dividido en funcion de los dias que tiene InOut y no en funcion de los dias de Av Express
  3585.         $days = ($supplierService->getDateOutAt()->diff($supplierService->getDateInAt())->days)===$supplierService->getDateOutAt()->diff($supplierService->getDateInAt())->days +1;
  3586.         $newPrice $productFile->getSubTotalPrice() / ( $days );
  3587.         $newPrice $newPrice $supplierService->getUnits();
  3588.         $newPrice round($newPrice,2,PHP_ROUND_HALF_UP);
  3589.         return $newPrice;
  3590.     }
  3591.     private function rankAvParaInOutService($idProduct){
  3592.         // con el ID del product buscamos en "ave_doc_invoice_items" con prdControl($idProduct) para determinar la factura, y buscamos elementos dentro de esa factura
  3593.         // luego si es vacio repetimos para proformas en "ave_doc_proforma_items"
  3594.         // Devuelve el numero de RankAv considerando la posible asociacion por sala y ordenando segun el criterio (video, sonido, iluminacion, otros)
  3595.         $em $this->getDoctrine()->getManager();
  3596.         $rankAv 1$proformaItemsInSameProforma = array(); $boolFound false;
  3597.         $invoiceItem $em->getRepository(AveDocInvoiceItems::class)->findOneByPrdControlId($idProduct);
  3598.         $invoiceItemsInSameInvoice = (!empty($invoiceItem)) ? $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($invoiceItem->getInvoiceId()) : array();
  3599.         if (empty($invoiceItemsInSameInvoice)){
  3600.             // No se encontraba facturado, buscamos en proforma el item y los elementos que esten en esa proforma
  3601.             $proformaItem $em->getRepository(AveDocProformaItems::class)->findOneByControlId($idProduct);
  3602.             $proformaItemsInSameProforma = (!empty($proformaItem)) ? $em->getRepository(AveDocProformaItems::class)->findByProformaId($proformaItem->getProformaId()) : array();
  3603.         }
  3604.         $arrayItems = empty($invoiceItemsInSameInvoice) ? $proformaItemsInSameProforma $invoiceItemsInSameInvoice;
  3605.         foreach ($arrayItems as $item){
  3606.             $idToCheck = empty($invoiceItemsInSameInvoice) ? $item->getControlId() : $item->getPrdControlId();
  3607.             if (!($idToCheck == $idProduct)){ if(!($boolFound)){ $rankAv++;} } else { $boolFound true; }
  3608.         }
  3609.         // 001, 002, ... 010, 011, ..., 100, 101
  3610.         $rankAv = ($rankAv 100) ? (($rankAv 10) ? '00'$rankAv '0'$rankAv) : $rankAv;
  3611.         return $rankAv;
  3612.     }
  3613.     private function messageOfChangesToAgent($message$proposalId){
  3614.         // $message mensaje a enviar a los agentes del proposal
  3615.         if ($proposalId  == 0){ return true; }
  3616.         $em $this->getDoctrine()->getManager();
  3617.         $proposal $em->getRepository(Proposal::class)->findOneById($proposalId);
  3618.         /* Obtengo usuario logueado */
  3619.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3620.         $user_id $user_logueado->getId();
  3621.         $agent $em->getRepository(User::class)->findOneById($user_id);
  3622.         $message 'El proposal <strong>#'.$proposalId.' '.$proposal->getName().'</strong>'.' ha sido modificacdo por el agente: '.$agent->getName().' '.$agent->getLastName().'<br><br><br>'.$message;
  3623.         $proposalAgents $em->getRepository(ProposalAgents::class)->findOneByIdProp($proposalId);
  3624.         $mailArrayTo = array();
  3625.         if (!empty($agent)){ $mailArrayTo[$agent->getEmail()] = $agent->getEmail(); }
  3626.         if (!empty($proposalAgents)){
  3627.             if (!empty($proposalAgents->getAgOne())){
  3628.                 $agent $em->getRepository(User::class)->findOneById($proposalAgents->getAgOne());
  3629.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  3630.             }
  3631.             if (!empty($proposalAgents->getAgTwo())){
  3632.                 $agent $em->getRepository(User::class)->findOneById($proposalAgents->getAgTwo());
  3633.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  3634.             }
  3635.             if (!empty($proposalAgents->getAgThree())){
  3636.                 $agent $em->getRepository(User::class)->findOneById($proposalAgents->getAgThree());
  3637.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  3638.             }
  3639.             if (!empty($proposalAgents->getAgFour())){
  3640.                 $agent $em->getRepository(User::class)->findOneById($proposalAgents->getAgFour());
  3641.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  3642.             }
  3643.         }
  3644.         if (!empty($mailArrayTo)){
  3645.             $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  3646.             $replyTo = array();
  3647.             foreach ($mailArrayTo as $item){ $replyTo[$item] = $item; }
  3648.             $agentMail $agent->getEmail();
  3649.             //Se prepara el correo con los agentes a notificar
  3650.             $firmGmail $agent->getFirmGmail();
  3651.             $data = array(
  3652.                 'body' => $message,
  3653.                 'firm' => $firmGmail,
  3654.             );
  3655.             // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  3656.             $transporter = new Swift_SmtpTransport();
  3657.                 $transporter->setHost('smtp.gmail.com')
  3658.                 ->setEncryption('ssl')//ssl / tls
  3659.                 ->setPort(465)// 465 / 587
  3660.                 ->setUsername('desarrollo@develup.solutions')
  3661.                 ->setPassword('MeDITeRRANeAN_Develup30102023#');
  3662.             $mailer = new Swift_Mailer($transporter);
  3663.             $message = new Swift_Message();
  3664.                 $message->setSubject('ActualizaciĆ³n de servicios AvExpress del proposal: '$proposalId)
  3665.                 ->setSender($agentMail)
  3666.                 ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  3667.                 ->setReplyTo($agentMail)
  3668.                 ->setTo($replyTo)
  3669.                 ->setBody(
  3670.                     $this->renderView(
  3671.                         'mail/structure-mail.html.twig',
  3672.                         array('data' => $data)
  3673.                     ),
  3674.                     'text/html'
  3675.                 );
  3676.             $mailer->send($message);
  3677.         }
  3678.         return true;
  3679.     }
  3680. };