src/MDS/DevelupBundle/Controller/FilesController.php line 590

Open in your IDE?
  1. <?php
  2. namespace App\MDS\DevelupBundle\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\MDS\DevelupBundle\Entity\MdvDocInvoiceRecItems;
  12. use App\MDS\DevelupBundle\Entity\MdvBriefings;
  13. use App\MDS\DevelupBundle\Entity\MdvBudgetPending;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use DateTime;
  18. use App\MDS\DevelupBundle\Entity\MdvFiles;
  19. use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
  20. use App\MDS\DevelupBundle\Entity\MdvBudgetToProforma;
  21. use App\MDS\DevelupBundle\Entity\MdvDocInvoice;
  22. use App\MDS\DevelupBundle\Entity\MdvDocInvoiceItems;
  23. use App\MDS\DevelupBundle\Entity\MdvDocInvoiceRec;
  24. use App\MDS\DevelupBundle\Entity\MdvDocProforma;
  25. use App\MDS\DevelupBundle\Entity\MdvDocProformaItems;
  26. use App\MDS\DevelupBundle\Entity\MdvPaymentsClient;
  27. use App\MDS\DevelupBundle\Entity\MdvProduct;
  28. use App\MDS\DevelupBundle\Entity\MdvProductFile;
  29. use App\MDS\DevelupBundle\Entity\MdvServices;
  30. use App\MDS\DevelupBundle\Entity\MdvTelegramUser;
  31. use App\MDS\EventsBundle\Entity\Proposal;
  32. use App\MDS\EventsBundle\Entity\ProposalAgents;
  33. use App\MDS\EventsBundle\Entity\ProposalSupplierControl;
  34. use Swift_Mailer;
  35. use Swift_Message;
  36. use Swift_SmtpTransport;
  37. class FilesController extends AbstractController
  38. {
  39.     /**
  40.      * @Route("/fileadd/",  name="mdv_add_file")
  41.      * Agregar un expediente
  42.      */
  43.     public function addFileActionRequest $request)
  44.     {
  45.         $em $this->getDoctrine()->getManager();
  46.         $clients $em->getRepository(Client::class)->findAll();
  47.         $mdvFiles $em->getRepository(MdvFiles::class)->findAll();
  48.         $id =0;
  49.         if (empty($mdvFiles)){
  50.             $id ++;
  51.         } else {
  52.             $lastElem end($mdvFiles);
  53.             $id $lastElem->getId() + 1;
  54.         }
  55.         return $this->render('MDS/DevelupBundle/Develup/add-files.html.twig',
  56.             array(
  57.                 'id' => $id,
  58.                 'clients' => $clients,
  59.                 'clientId' => 0,
  60.             ));
  61.     }
  62.     /**
  63.      * @Route("/filedelete/{id}",  name="mdv_file_delete")
  64.      * Eliminar un expediente
  65.      */
  66.     public function deleteFileAction($idRequest $request)
  67.     {
  68.         $em $this->getDoctrine()->getManager();
  69.         $file $em->getRepository(MdvFiles::class)->findOneById($id);
  70.         if (!empty($file)){
  71.             // se debe verificar que no haya factura asociada al expediente
  72.             $file->setStatus('Deleted');
  73.             $em->persist($file);
  74.             $em->flush();
  75.         }
  76.         return $this->redirectToRoute('mdv_list_file');
  77.     }
  78.     /**
  79.      * @Route("/filelist/",  name="mdv_list_file")
  80.      * Listar expedientes
  81.      */
  82.     public function listFileActionRequest $request)
  83.     {
  84.         $em $this->getDoctrine()->getManager();
  85.         $idgroup null;
  86.         $parameters = array(
  87.             'status' => 'Deleted'
  88.         );
  89.         $dql 'SELECT i
  90.                 FROM DevelupBundle:MdvFiles i
  91.                 WHERE i.status != :status
  92.                 ORDER BY i.dateStart ASC';
  93.         $query $em->createQuery($dql)->setParameters($parameters);
  94.         $ref = array();
  95.         if ($idgroup == 0) {
  96.             $reservas $query->getResult();
  97.         } else {
  98.             $reservas $query->getResult();
  99.         }
  100.         foreach ($reservas as $res) {
  101.             $client $em->getRepository(Client::class)->findOneById($res->getClient());
  102.             if (!empty($client)) {
  103.                 $res->setClient($client->getName());
  104.             } else {
  105.                 $res->setClient(null);
  106.             }
  107. //            $res->setCreatedBy(
  108. //                ($em->getRepository(User::class)->findOneById($res->getCreatedBy()))->getName() . ' ' .
  109. //                ($em->getRepository(User::class)->findOneById($res->getCreatedBy()))->getLastName());
  110.             if (!empty($res->getDateStart()) and !empty($res->getDateEnd())) {
  111.                 $ref[$res->getId()] = '#' . ($res->getDateStart())->format('ymd') . ($res->getDateEnd())->format('ymd');
  112.             } else {
  113.                 $ref[$res->getId()] = '#' '000000' '000000';
  114.             }
  115.         }
  116.         for ($i 0$i sizeof($reservas); $i++) {
  117.             if ($reservas[$i]->getStatus() == "Deleted") {
  118.                 unset($reservas[$i]);
  119.             }
  120.         }
  121.         $reservasZero = array();
  122.         foreach ($reservas as $res) {
  123.             $reservasZero[] = array(
  124.                 'dateStart' => $res->getDateStart(),
  125.                 'dateEnd' => $res->getDateEnd(),
  126.                 'id' => $res->getId(),
  127.                 'title' => $res->getTitle(),
  128.                 'client' => $res->getClient(),
  129.                 'createdId' => $res->getCreatedId(),
  130.                 'ref' => $ref[$res->getId()],
  131.             );
  132.         }
  133.         $reservas $reservasZero;
  134.         return $this->render('MDS/DevelupBundle/Develup/list-files.html.twig',
  135.             array(
  136.                 'groups' => null,
  137.                 'titleView' => '',
  138.                 'reservations' => $reservas
  139.             )
  140.         );
  141.     }
  142.     /**
  143.      * @Route("/filesave/",  name="mdv_save_file")
  144.      * Guardar un expediente nuevo
  145.      */
  146.     public function saveFileActionRequest $request)
  147.     {
  148.         $em $this->getDoctrine()->getManager();
  149.         $newRequest $request->request->get('develup');
  150.         if (empty($newRequest['title'])){
  151.             return $this->redirectToRoute('mdv_add_file');
  152.         }
  153.         /* Obtengo usuario logueado */
  154.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  155.         $user_id $user_logueado->getId();
  156.         $newFile = new MdvFiles();
  157.         $newFile->setTitle($newRequest['title']);
  158.         $newFile->setClient($newRequest['client']);
  159.         if (!empty($newRequest['idProposal'])){
  160.             $newFile->setIdProposal($newRequest['idProposal']);
  161.         } else {
  162.             $newFile->setIdProposal(null);
  163.         }
  164.         $newFile->setStatus($newRequest['status']);
  165.         $newFile->setAdvancePayment($newRequest['advancePayment']);
  166.         $newFile->setDescription($newRequest['description']);
  167.         if (empty($newRequest['dateStart'])){
  168.             $newFile->setDateStart(new \DateTime("now"));
  169.         } else {
  170.             $newFile->setDateStart(new \DateTime($newRequest['dateStart']));}
  171.         if (empty($newRequest['dateEnd'])){
  172.             $newFile->setDateEnd(new \DateTime("now"));
  173.         } else {
  174.             $newFile->setDateEnd(new \DateTime($newRequest['dateEnd']));}
  175.         $newFile->setCreatedId($user_id);
  176.         $newFile->setUpdatedId($user_id);
  177.         $newFile->setCreatedAt(new \DateTime("now"));
  178.         $newFile->setUpdatedAt(new \DateTime("now"));
  179.         $em->persist($newFile);
  180.         $em->flush();
  181.         $clients $em->getRepository(Client::class)->findAll();
  182.         $products $em->getRepository(MdvProduct::class)->findAll();
  183.         $data $this->calculosFile($newFile->getId(), null0'File');
  184.         $sumatoriaTotalNet 0;
  185.         $sumatoriaTotalVat 0;
  186.         $sumatoriaTotal 0;
  187.         $resultados = array(
  188.             'totalNeto' => $sumatoriaTotalNet,
  189.             'vat' => $sumatoriaTotalVat,
  190.             'total' => $sumatoriaTotal,
  191.         );
  192.         $productInFile $em->getRepository(MdvProductFile::class)->findByFileId($newFile->getId());
  193.         $numeroItems sizeof($productInFile);
  194.         return $this->redirectToRoute('mdv_edit_file', array( 'id' => $newFile->getId() ));
  195.     }
  196.     /**
  197.      * @Route("/fileupdate/{id}",  name="mdv_update_file")
  198.      * Actualizar un expediente
  199.      */
  200.     public function updateFileAction($idRequest $request)
  201.     {
  202.         $logTelegram false;
  203.         $numberToPrefix 0;
  204.         $em $this->getDoctrine()->getManager();
  205.         $newFile $em->getRepository(MdvFiles::class)->findOneById($id);
  206.         $newRequest $request->request->get('develup');
  207.         /* Obtengo usuario logueado */
  208.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  209.         $user_id $user_logueado->getId();
  210.         if (!empty($newRequest['title'])){$newFile->setTitle($newRequest['title']);}
  211.         $newFile->setClient($newRequest['client']);
  212.         if (!empty($newRequest['idProposal'])){$newFile->setIdProposal($newRequest['idProposal']);} else {$newFile->setIdProposal(null);}
  213.         $newFile->setStatus($newRequest['status']);
  214.         $newFile->setAdvancePayment($newRequest['advancePayment']);
  215.         $newFile->setDescription($newRequest['description']);
  216.         $newFile->setUpdatedId($user_id);
  217.         $newFile->setUpdatedAt(new \DateTime("now"));
  218.         $em->persist($newFile);
  219.         $em->flush();
  220.         $productInFile $em->getRepository(MdvProductFile::class)->findByFileId($newFile->getId());
  221.         if(!empty($newFile->getIdProposal())){
  222.             // El expediente se ha relacionado con un proposal, se debe actualizar en eventos
  223.             $file $newFile;
  224.             // Si hay proposal se debe actualizar en el expediente de Eventos
  225.             if (!empty($file->getIdProposal()) and is_numeric($file->getIdProposal())){
  226.                 // Buscamos el destino donde se encuentre Develup y ahi agregamos el servicio, si no se encuentra no se agregara el servicio
  227.                 $control $em->getRepository(ProposalSupplierControl::class)->findOneBy(
  228.                     array(
  229.                         'supplierId' => 2,                                          // El supplier 2 es Develup
  230.                         'proposalId' => $file->getIdProposal(),
  231.                     )
  232.                 );
  233.                 // INICIO: Buscamos la info del lado de eventos
  234.                 $proposal $em->getRepository(Proposal::class)->findOneById($file->getIdProposal());
  235.                 $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  236.                 $agentFullName $agent->getName().' '.$agent->getLastName();
  237.                 $proposalTitle $proposal->getId().' - '.$proposal->getTitle();
  238.                 // FIN: Buscamos la info del lado de eventos
  239.                 foreach ($productInFile as $item){
  240.                     if (!empty($control)){
  241.                         // Existe un destino con Develup  como proveedor, hay se agregara el servicio
  242.                         $productOriginal $em->getRepository(MdvProduct::class)->findOneById($item->getProductId());
  243.                         $service = new ProposalSupplierServices();
  244.                         $service->setServiceIdFather(0);
  245.                         $service->setControlId($control->getId());
  246.                         $service->setProposalId($file->getIdProposal());
  247.                         $service->setDestinationId($control->getDestinoId());
  248.                         $service->setSupplierId(2);
  249.                         $service->setIdeaId(null);
  250.                         $service->setServiceId($item->getProductId());
  251.                         $service->setServiceCatName('Technology');
  252.                         $service->setServiceCatId(14);
  253.                         $service->setName($item->getProductName());
  254.                         // Si el precio no ha sido modificado se copia el original en Eventos
  255. //                        if (bcdiv($productOriginal->getPrice(), 1.21, 2) == $item->getServicePrice()){
  256. //                            $service->setPrice($productOriginal->getPrice());
  257. //                        } else {
  258. //                             El precio se ha modificado en Develup, en Eventos se debe reflejar el cambio y no es el valor por defecto
  259. //                            $service->setPrice(round($item->getServicePrice()*1.21,2));
  260. //                        }
  261.                         // Siempre vamos a tomar el precio que establezca Develup, se haya modificado o no
  262.                         $service->setPrice($item->getServicePrice());
  263.                         $service->setCurrency(null);
  264.                         $service->setUnits(1);
  265.                         $service->setCommission(0);
  266.                         $service->setOver(0);
  267.                         $service->setIva(21);
  268.                         $service->setPax(0);
  269.                         $service->setHour(null);
  270.                         $service->setDateInAt(new \DateTime("now"));
  271.                         $service->setDateOutAt(new \DateTime("now"));
  272.                         $service->setDirectPayment(0);
  273.                         $service->setStatus('Pending');
  274.                         $service->setStatusinternal('Additional');
  275.                         $service->setPreCommission(null);
  276.                         $service->setPreIva(null);
  277.                         $service->setDateBlockLimit(null);
  278.                         $service->setOpCommission(1);
  279.                         $service->setOpOver(1);
  280.                         $service->setOpIva(1);
  281.                         $service->setBreakdown(0);
  282.                         $service->setIsFather(0);
  283.                         $service->setRank(1);
  284.                         $service->setOriginalopIva(1);
  285.                         $service->setOriginalIva(null);
  286.                         $service->setOriginalPrice(null);
  287.                         $service->setStatusRec('normal');
  288.                         $service->setAssistantId(null);
  289.                         $service->setCreatedId($user_id);
  290.                         $service->setUpdatedId($user_id);
  291.                         $service->setCreatedAt(new \DateTime("now"));
  292.                         $service->setUpdatedAt(new \DateTime("now"));
  293.                         $em->persist($service);
  294.                         $em->flush();
  295.                         // Se debe notificar por Telegram al agente de eventos
  296.                         $logTelegram true;
  297.                     }
  298.                     //INICIO: Creamos una orden de hacer proforma
  299.                     //INICIO: Calculamos el ID de la proforma
  300.                     $numberToPrefix $em->getRepository(MdvDocProforma::class)->findAll();
  301.                     if (empty($numberToPrefix)){
  302.                         $numberToPrefix 0;
  303.                     } else {
  304.                         $numberToPrefix end($numberToPrefix)->getId();
  305.                     }
  306.                     $numberToPrefix++;
  307.                     //FIN: Calculamos el ID de la proforma
  308.                     $order = new MdvBudgetToProforma();
  309.                     $order->setStatus('Pending');
  310.                     $order->setFileId($file->getId());
  311.                     $order->setProductFileId($item->getId());
  312.                     $order->setUserConfirmedId($proposal->getAgentId());
  313.                     $order->setUserConfirmedFullName($agentFullName);
  314.                     $order->setProposalTitle($proposalTitle);
  315.                     $order->setProformaId($numberToPrefix);
  316.                     $em->persist($order);
  317.                     $em->flush();
  318.                     //FIN: Creamos una orden de hacer proforma
  319.                 }
  320.                 //INICIO: Notificamos al agente por Telegram
  321.                 if ($logTelegram){
  322.                     //Buscamos todos los agentes del proposal
  323.                     $proposalAgents $em->getRepository(ProposalAgents::class)->findOneByIdProp($proposal->getId());
  324.                     //Buscamos el Destino
  325.                     $proposalDestino $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
  326.                     //Buscamos el agente de Develup
  327.                     $userData $em->getRepository(User::class)->findOneById($user_id);
  328.                     if (!empty($proposalAgents)){
  329.                         if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))){
  330.                             $this->sendTelegram($proposalAgents->getAgOne(),'1. PROPOSAL ACTUALIZADO DESDE DEVELUP __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  331.                             //d('entro en 1',$proposalAgents->getAgOne(), $proposalDestino->getTitle());
  332.                         }
  333.                         if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))){
  334.                             $this->sendTelegram($proposalAgents->getAgTwo(),'2. PROPOSAL ACTUALIZADO DESDE DEVELUP __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  335.                             //d('entro en 2',$proposalAgents->getAgTwo(), $proposalDestino->getTitle());
  336.                         }
  337.                         if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))){
  338.                             $this->sendTelegram($proposalAgents->getAgThree(),'3. PROPOSAL ACTUALIZADO DESDE DEVELUP __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  339.                             //d('entro en 3', $proposalAgents->getAgThree(), $proposalDestino->getTitle());
  340.                         }
  341.                         if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))){
  342.                             $this->sendTelegram($proposalAgents->getAgFour(),'4. PROPOSAL ACTUALIZADO DESDE DEVELUP __ ID: '.$proposal->getId().' __ DESTINO: '.$proposalDestino->getTitle().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
  343.                             //d('entro en 4', $proposalAgents->getAgFour(), $proposalDestino->getTitle());
  344.                         }
  345.                     }
  346.                 }
  347.                 //FIN: Notificamos al agente por Telegram
  348.                 //INICIO: Creamos el presupuesto (proforma)
  349.                 $budToPro $em->getRepository(MdvBudgetToProforma::class)->findByProformaId($numberToPrefix);
  350.                 //INICIO: Se agrupan por expediente (fileId)
  351.                 $proformas = array();
  352.                 foreach ($budToPro as $item){
  353.                     $proformas[$item->getFileId()][] = $item;
  354.                 }
  355.                 //FIN: Se agrupan por expediente (fileId)
  356.                 if (!empty($budToPro)){
  357.                     foreach ($proformas as $key => $elemento){
  358.                         //INICIO: Creamos las proformas
  359.                         $newProforma = new MdvDocProforma();
  360.                         $newProforma->setPrefix('MDV-' . (new DateTime('now'))->format('dmy') . '-' $numberToPrefix '-' $key);
  361.                         $newProforma->setDateAt(new DateTime('now'));
  362.                         $newProforma->setFileId($key);
  363.                         $newProforma->setCreatedId($user_id);
  364.                         $newProforma->setUpdatedId($user_id);
  365.                         $newProforma->setCreatedAt(new DateTime('now'));
  366.                         $newProforma->setUpdatedAt(new DateTime('now'));
  367.                         $em->persist($newProforma);
  368.                         $em->flush();
  369.                         //FIN: Creamos las proformas
  370.                         foreach ($elemento as $item) {
  371.                             //$key es el id del expediente
  372. //                    $arrayIdPro[$numberToPrefix] = $item->getUserConfirmedId();             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  373.                             //INICIO: Creamos los elemento que iran dentro de las proformas
  374.                             $itemProforma = new MdvDocProformaItems();
  375.                             $itemProforma->setType('PRODUCT');
  376.                             $itemProforma->setFileId($key);
  377.                             $itemProforma->setProformaId($newProforma->getId());
  378.                             $itemProforma->setControlId($item->getProductFileId());
  379.                             $em->persist($itemProforma);
  380.                             $em->flush();
  381.                             //INICIO: Confirmamos el BudToProforma
  382.                             $item->setStatus('Tosend');              // El elemento se ha pasado a la proforma, solo falta enviar
  383.                             $item->setProformaId($newProforma->getId());
  384.                             $em->persist($item);
  385.                             $em->flush();
  386.                             //FIN: Confirmamos el BudToProforma
  387.                             //FIN: Creamos los elemento que iran dentro de las proformas
  388.                         }
  389.                     }
  390.                 }
  391.                 //FIN: Creamos el presupuesto (proforma)
  392.                 // INICIO: Se envia al agente el presupuesto
  393.                 $budToPro $em->getRepository(MdvBudgetToProforma::class)->findByStatus('Tosend');
  394.                 /* Obtengo usuario logueado */
  395.                 $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  396.                 $user_id $user_logueado->getId();
  397.                 $arrayIdPro = array();          // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  398.                 //INICIO: Se agrupan por expediente (fileId)
  399.                 $proformas = array();
  400.                 foreach ($budToPro as $item){
  401.                     $proformas[$item->getFileId()][] = $item;
  402.                 }
  403.                 //FIN: Se agrupan por expediente (fileId)
  404.                 if (!empty($budToPro)){
  405.                     foreach ($proformas as $key => $elemento){
  406.                         //INICIO: Creamos las proformas
  407.                         //INICIO: Calculamos el ID de la proforma
  408. //                $numberToPrefix = $em->getRepository(MdvDocProforma::class)->findAll();
  409. //                if (empty($numberToPrefix)){
  410. //                    $numberToPrefix = 0;
  411. //                } else {
  412. //                    $numberToPrefix = end($numberToPrefix)->getId();
  413. //                }
  414. //                $numberToPrefix++;
  415. //                $numberToPrefix++;
  416.                         //FIN: Calculamos el ID de la proforma
  417. //d($proformas, $elemento);exit();
  418. //                $newProforma = new MdvDocProforma();
  419. //                $newProforma->setPrefix('MDV-' . (new DateTime('now'))->format('dmy') . '-' . $numberToPrefix . '-' . $key);
  420. //                $newProforma->setDateAt(new DateTime('now'));
  421. //                $newProforma->setFileId($key);
  422. //
  423. //                $newProforma->setCreatedId($user_id);
  424. //                $newProforma->setUpdatedId($user_id);
  425. //                $newProforma->setCreatedAt(new DateTime('now'));
  426. //                $newProforma->setUpdatedAt(new DateTime('now'));
  427. //
  428. //                $em->persist($newProforma);
  429. //                $em->flush();
  430.                         //FIN: Creamos las proformas
  431.                         foreach ($elemento as $item) {
  432.                             //$key es el id del expediente
  433.                             if (!empty($item->getProformaId())) {
  434.                                 $arrayIdPro[$item->getProformaId()] = $item->getUserConfirmedId();             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  435.                             }
  436.                             //INICIO: Creamos los elemento que iran dentro de las proformas
  437. //                    $itemProforma = new MdvDocProformaItems();
  438. //                    $itemProforma->setType('PRODUCT');
  439. //                    $itemProforma->setFileId($key);
  440. //                    $itemProforma->setProformaId($newProforma->getId());
  441. //                    $itemProforma->setControlId($item->getProductFileId());
  442. //
  443. //                    $em->persist($itemProforma);
  444. //                    $em->flush();
  445.                             //INICIO: Confirmamos el BudToProforma
  446.                             $item->setStatus('Confirmed');              // El elemento se ha pasado a confirmado porque se enviara por correo
  447.                             $em->persist($item);
  448.                             $em->flush();
  449.                             //FIN: Confirmamos el BudToProforma
  450.                             //FIN: Creamos los elemento que iran dentro de las proformas
  451.                         }
  452.                     }
  453.                 }
  454.                 //INICIO: Notificamos de todos los presupuestos (proformas) que se han creado
  455.                 foreach ($arrayIdPro as $key => $item){
  456.                     //Buscamos los agentes a notificar
  457.                     // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  458.                     $agent $em->getRepository(User::class)->findOneById($item);
  459.                     $agentMail $agent->getEmail();
  460.                     $mailAgent $agentMail;
  461.                     //Se prepara el correo con los agentes a notificar
  462.                     $firmGmail $agent->getFirmGmail();
  463.                     $data = array(
  464.                         'body' => 'Presupuesto Develup #' $key  ', ' '<br><a href="http://' $request->server->get('HTTP_HOST') . '/pdf/develupproforma/' $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>',
  465.                         'firm' => $firmGmail,
  466.                     );
  467.                     // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  468.                     $transporter = new Swift_SmtpTransport();
  469.                     $transporter->setHost('smtp.gmail.com')
  470.                         ->setEncryption('ssl')//ssl / tls
  471.                         ->setPort(465)// 465 / 587
  472.                         ->setUsername('desarrollo@develup.solutions')
  473.                         ->setPassword('utvh hzoi wfdo ztjs');
  474.                     $mailer = new Swift_Mailer($transporter);
  475.                     $message = new Swift_Message();
  476.                     $message->setSubject('Presupuesto #' $key ', Notificación de nuevo presupuesto')
  477.                         ->setSender($agentMail)
  478.                         ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  479.                         ->setReplyTo($agentMail)
  480.                         ->setTo($mailAgent)
  481.                         ->setBody(
  482.                             $this->renderView(
  483.                                 'mail/structure-mail.html.twig',
  484.                                 array('data' => $data)
  485.                             ),
  486.                             'text/html'
  487.                         );
  488.                     $mailer->send($message);
  489.                 }
  490.                 //FIN: Notificamos de todos los presupuestos (proformas) que se han creado
  491.                 // FIN: Se envia al agente el presupuesto
  492.             }
  493.         }
  494.         return $this->redirectToRoute('mdv_edit_file',
  495.             array(
  496.                 'id' => $newFile->getId()
  497.             )
  498.         );
  499.     }
  500.     /**
  501.      * @Route("/fileedit/{id}", name="mdv_edit_file")
  502.      * Editar un expediente
  503.      */
  504.     public function editFileAction$idRequest $request)
  505.     {
  506.         $em $this->getDoctrine()->getManager();
  507.         $editFile $em->getRepository(MdvFiles::class)->findOneById($id);
  508.         $clients $em->getRepository(Client::class)->findAll();
  509.         $clientSelected $em->getRepository(Client::class)->findOneById($editFile->getClient());
  510.         $products $em->getRepository(MdvProduct::class)->findAll();
  511.         $data $this->calculosFile($idnull0'File');
  512.         $sumatoriaTotalNet 0;
  513.         $sumatoriaTotalVat 0;
  514.         $sumatoriaTotal 0;
  515.         $resultados = array(
  516.             'totalNeto' => $sumatoriaTotalNet,
  517.             'vat' => $sumatoriaTotalVat,
  518.             'total' => $sumatoriaTotal,
  519.         );
  520.         $productInFile $em->getRepository(MdvProductFile::class)->findByFileId($id);
  521.         $numeroItems sizeof($productInFile);
  522.         $facturas $em->getRepository(MdvDocInvoice::class)->findByFileId($id);
  523.         $facturasRec $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($id);
  524.         foreach ($facturasRec as $item){
  525.             array_push($facturas,$item);
  526.         }
  527.         $proformas = array();
  528.         $allProformas $em->getRepository(MdvDocProforma::class)->findByFileId($id);
  529.         foreach ($allProformas as $item){
  530.             $dataTwo $this->baseInvoiceDoneFileTwo($id$item->getId(),'P');
  531.             $bases 0;
  532.             if (is_numeric($dataTwo['totales']) and is_numeric($dataTwo['totales_neto'])){$bases $dataTwo['totales'] - $dataTwo['totales_neto'];}
  533.             $allItemsProforma $em->getRepository(MdvDocProformaItems::class)->findByProformaId($dataTwo['number']);
  534.             $itemsInProforma = array();
  535.             foreach ($allItemsProforma as $elem){
  536.                 $itemsInProforma[] = $em->getRepository(MdvProductFile::class)->findOneById($elem->getControlId());
  537.             }
  538.             $proformas[] = array(
  539.                 'id' => $dataTwo['number'],
  540.                 'itemsInProforma' => $itemsInProforma,
  541.                 'date' => $dataTwo['date'],
  542.                 'neto' => $dataTwo['totales_neto'],
  543.                 'bases_imponibles' => $bases,
  544.                 'total' => $dataTwo['totales'],
  545.             );
  546.         }
  547.         return $this->render('MDS/DevelupBundle/Develup/edit-files.html.twig',
  548.             array(
  549.                 'id' => $id,
  550.                 'clients' => $clients,
  551.                 'clientId' => $editFile->getClient(),
  552.                 'clientSelected' => $clientSelected,
  553.                 'file' => $editFile,
  554.                 'numeroItems' => $numeroItems,
  555.                 'arrayProductFile' => $data['datasupplier']['product'],
  556.                 'products' => $products,
  557.                 'services' => null,
  558.                 'facturas' => $facturas,
  559.                 'proformas' => $proformas,
  560.                 'paymentNotIvoiced' => null,
  561.                 'paymentsAll' => null,
  562.                 'resultados' => $resultados,
  563.                 'totales_global_con_iva' => $data['totales'], //$data['totales_global_con_iva'],
  564.                 'totales_global_iva' => $data['bases_imponibles']['ivaMontoVeintiUno'], //$data['totales_global_iva'],
  565.                 'totales_global_neto' => $data['totales_neto'], //$data['totales_global_neto'],
  566.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  567.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  568.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  569.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  570.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  571.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  572.             ));
  573.     }
  574.     /**
  575.      * @Route("/filefrombudget/{id}",  name="mdv_add_file_from_budget")
  576.      * Agregar un expediente desde un presupuesto
  577.      */
  578.     public function addFileFromBudgetAction$idRequest $request)
  579.     {
  580.         $em $this->getDoctrine()->getManager();
  581.         $budget $em->getRepository(MdvBudgetPending::class)->findOneById($id);
  582.         $proposal $em->getRepository(Proposal::class)->findOneById($budget->getProposalId());
  583.         $newFile $em->getRepository(MdvFiles::class)->findOneByIdProposal($proposal->getId());
  584.         /* Obtengo usuario logueado */
  585.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  586.         $user_id $user_logueado->getId();
  587.         if (empty($newFile)){
  588.             // No hay un File asociado a ese proposal, se debe crear uno nuevo
  589.             $newFile = new MdvFiles();
  590.             $newFile->setTitle($proposal->getId().' - ' .$budget->getProposalTitle());
  591.             $newFile->setClient(262);                           // In Out es el cliente
  592.             $newFile->setIdProposal($proposal->getId());
  593.             $newFile->setStatus('Pending');
  594.             $newFile->setAdvancePayment(null);
  595.             if (!empty($budget->getBriefing())) {
  596.                 $newFile->setDescription('<p> *********  MENSAJE DEL AGENTE  ********* </p>' $budget->getBriefing());
  597.             }
  598.             $newFile->setDateStart(new \DateTime("now"));
  599.             $newFile->setDateEnd(new \DateTime("now"));
  600.             $newFile->setCreatedId($user_id);
  601.             $newFile->setUpdatedId($user_id);
  602.             $newFile->setCreatedAt(new \DateTime("now"));
  603.             $newFile->setUpdatedAt(new \DateTime("now"));
  604.         } else {
  605.             // Ya existe un File asociado a ese proposal
  606.             $newFile->setClient(262);                           // In Out es el cliente
  607.             $newFile->setStatus('Pending');
  608.             if (!empty($budget->getBriefing())) {
  609.                 $newFile->setDescription($newFile->getDescription() . '<p> *********  MENSAJE DEL AGENTE  ********* </p>' $budget->getBriefing());
  610.             }
  611.             $newFile->setUpdatedId($user_id);
  612.             $newFile->setUpdatedAt(new \DateTime("now"));
  613.         }
  614.         $em->persist($newFile);
  615.         $em->flush();
  616.         $em->remove($budget);
  617.         $em->flush();
  618.         //Actualizamos los Briefings que esten en FileId null con el recien generado fileId en base al proposalId
  619.         $allBriefings $em->getRepository(MdvBriefings::class)->findByProposalId($proposal->getId());
  620.         foreach ($allBriefings as $item){
  621.             if (empty($item->getFileId())) {
  622.                 $item->setFileId($newFile->getId());
  623.                 $em->persist($item);
  624.                 $em->flush();
  625.             }
  626.         }
  627.         return $this->redirectToRoute('mdv_edit_file',
  628.             array(
  629.                 'id' => $newFile->getId()
  630.             )
  631.         );
  632.     }
  633.     /**
  634.      * @Route("/filelistbriefings/{id}",  name="mdv_list_file_briefings")
  635.      * Listar briefings del expediente
  636.      */
  637.     public function listFileBriefingsAction($idRequest $request){
  638.         $em $this->getDoctrine()->getManager();
  639.         $briefings $em->getRepository(MdvBriefings::class)->findByFileId($id);
  640.         return $this->render('MDS/DevelupBundle/Develup/list-briefings.html.twig',
  641.             array(
  642.                 'id' => $id,
  643.                 'briefings' => $briefings,
  644.             )
  645.         );
  646.     }
  647.     /**
  648.      * @Route("/briefingadd/{id}",  name="mdv_add_file_briefings")
  649.      * Agregar briefing al expediente
  650.      */
  651.     public function addFileBriefingsAction($idRequest $request){
  652.         $brif $request->request->get('newbriefing');
  653.         $em $this->getDoctrine()->getManager();
  654.         $file $em->getRepository(MdvFiles::class)->findOneById($id);
  655.         $proposalId $file->getIdProposal();
  656.         /* Obtengo usuario logueado */
  657.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  658.         $user_id $user_logueado->getId();
  659.         $userConfirmedFullName $user_logueado->getName().' '.$user_logueado->getLastName();
  660.         $briefing = new MdvBriefings();
  661.         $briefing->setProposalId($proposalId);
  662.         $briefing->setBriefing($brif);
  663.         $briefing->setBudgetPendingId(null);
  664.         $briefing->setFileId($id);
  665.         $briefing->setUserConfirmedFullName($userConfirmedFullName);
  666.         $briefing->setUserConfirmedId($user_id);
  667.         $briefing->setCreatedAt(new \DateTime("now"));
  668.         $em->persist($briefing);
  669.         $em->flush();
  670.         $briefings $em->getRepository(MdvBriefings::class)->findByFileId($id);
  671.         return $this->render('MDS/DevelupBundle/Develup/list-briefings.html.twig',
  672.             array(
  673.                 'id' => $id,
  674.                 'briefings' => $briefings,
  675.             )
  676.         );
  677.     }
  678.     private function baseInvoiceDoneFileTwo($fileId$invoiceId$typeBase)
  679.     {
  680.         $em $this->getDoctrine()->getManager();
  681.         $file $em->getRepository(MdvFiles::class)->findOneById($fileId);
  682.         $dateDocument null;                                                                           //Fecha final del documento
  683.         $subneto 0;
  684.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  685.             if ($typeBase == 'I') {
  686.                 $items $em->getRepository(MdvDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  687.             } else {
  688.                 // Es factura ni proforma
  689.                 $items $em->getRepository(MdvDocProformaItems::class)->findBy(array('fileId' => $fileId'proformaId' => $invoiceId));
  690.             }
  691.         } else {
  692.             // No es factura ni proforma, es una rectificativa
  693.             $items $em->getRepository(MdvDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  694.         }
  695.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
  696.         $client $em->getRepository(Client::class)->findById($file->getClient());
  697.         if (empty($client)){
  698.             $client[0] = new Client();
  699.             $client[0]->setName('');
  700.             $client[0]->setTitle('');
  701.             $client[0]->setIdDocument('');
  702.             $client[0]->setPopulation('');
  703.             $client[0]->setRegion('');
  704.             $client[0]->setCountry('');
  705.         } else {
  706.             if (is_numeric($client[0]->getPopulation())){
  707.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  708.                 $client[0]->setPopulation($city->getCity());
  709.             }
  710.             if (is_numeric($client[0]->getRegion())){
  711.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  712.                 $client[0]->setRegion($region->getRegion());
  713.             }
  714.             if (is_numeric($client[0]->getCountry())){
  715.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  716.                 $client[0]->setCountry($country->getCountry());
  717.             }
  718.         }
  719.         // Acumuladores de los calculos
  720.         $totales_neto_all 0;
  721.         $data_iva = array(
  722.             'iva' => 21,
  723.             'ivaMontoVeintiUno' => 0,
  724.             'ivaMontoDiez' => 0,
  725.             'ivaMontoCero' => 0,
  726.         );
  727.         //INICIO: Determinamos el numero de factura o proforma
  728.         if ($typeBase == 'I'){
  729.             // Es una Factura
  730.             $number $em->getRepository(MdvDocInvoice::class)->findOneById($invoiceId);
  731.             $dateDocument $number->getDateAt();
  732.             $number $number->getNumber();
  733.             $type 'Invoice';
  734.         } else {
  735.             if ($typeBase == 'R'){
  736.                 // Es una factura rectificativa
  737.                 $number $em->getRepository(MdvDocInvoiceRec::class)->findOneById($invoiceId);
  738.                 $dateDocument $number->getDateAt();
  739.                 $type 'Invoice Rec';
  740.             } else {
  741.                 // Es una Proforma
  742.                 $number $invoiceId;
  743.                 $type 'Proforma';
  744.             }
  745.         }
  746.         //FIN: Determinamos el numero de factura o proforma
  747.         // Buscamos los productos, pagos y servicios
  748.         $arrayItems = array();
  749.         $fileProducts = array();
  750.         $payments = array();
  751.         $services = array();
  752.         if (!empty($items)) {
  753.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  754.                 foreach ($items as $item) {
  755.                     switch ($item->getItemType()) {
  756.                         case 'PRODUCT'// Producto
  757.                             $fileProducts[] = $item;
  758.                             break;
  759.                         case 'PAYMENT'// Pago
  760.                             $payments[] = $item;
  761.                             break;
  762.                         case 'SERVICE'// Servicio
  763.                             $services[] = $item;
  764.                             break;
  765.                         default:
  766.                             break;
  767.                     }
  768.                 }
  769.             } else {
  770.                 // Es una proforma
  771.                 foreach ($items as $item) {
  772.                     switch ($item->getType()) {
  773.                         case 'PRODUCT'// Producto
  774.                             $productPro $em->getRepository(MdvProductFile::class)->findOneById($item->getControlId());
  775.                             if (!empty($productPro)) {
  776.                                 $fileProducts[] = $productPro;
  777.                             }
  778.                             break;
  779.                         case 'PAYMENT'// Pago
  780.                             $paymentPro $em->getRepository(MdvPaymentsClient::class)->findOneById($item->getControlId());
  781.                             if (!empty($paymentPro)) {
  782.                                 $payments[] = $paymentPro;
  783.                             }
  784.                             break;
  785.                         case 'SERVICE'// Servicio
  786.                             $servicePro $em->getRepository(MdvServices::class)->findOneById($item->getControlId());
  787.                             if (!empty($servicePro)) {
  788.                                 $services[] = $servicePro;
  789.                             }
  790.                             break;
  791.                         default:
  792.                             break;
  793.                     }
  794.                 }
  795.             }
  796.         }
  797.         $data_supplier = array();
  798.         $i 0;
  799.         $iva '21';            // Esteban Rincon: "Por Ley de localización del impuesto, siempre será un 21%"
  800.         $pax '1';
  801.         $qty '1';
  802.         $product = array(
  803.             'neto' => 0,
  804.             'sumSubT' => 0,
  805.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  806.         $service = array(
  807.             'neto' => 0,
  808.             'sumSubT' => 0,
  809.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  810.         foreach ($fileProducts as $item){
  811.             if (!is_null($item->getUnits()) or !empty($item->getUnits())){
  812.                 $qty $item->getUnits();
  813.             }
  814.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  815.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())){
  816.                     $subtotal 0;
  817.                     $neto 0;
  818.                     $subtotalProduct 0;
  819.                 } else {
  820. //                    $subtotalProduct = $item->getPrdServicePrice() * 1.21;
  821.                     $subtotalProduct $item->getPrdSubTotalPrice() * 1.21;
  822. //                    $subneto = $item->getPrdServicePrice();
  823.                     $subneto $item->getPrdSubTotalPrice();
  824.                     $subtotal =  $subtotalProduct;
  825.                     $neto =  $subneto;
  826.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  827.                     $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  828.                     $neto round($neto,2,PHP_ROUND_HALF_UP);
  829.                     $arrayItems[] = array(
  830.                         'type' => 'Product',
  831.                         'name' => $item->getPrdName(),
  832.                         'amount' => $neto,
  833.                         'iva' => '21',
  834.                         'total' => $subtotal,
  835.                     );
  836.                 }
  837.             } else {
  838.                 // Es proforma
  839.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
  840.                     $subtotal 0;
  841.                     $neto 0;
  842.                     $subtotalProduct 0;
  843.                 } else {
  844. //                    $subtotalProduct = $item->getServicePrice() * 1.21;
  845.                     $subtotalProduct $item->getSubTotalPrice() * 1.21;
  846. //                    $subneto = $item->getServicePrice();
  847.                     $subneto $item->getSubTotalPrice();
  848.                     $subtotal =  $subtotalProduct;
  849.                     $neto =  $subneto;
  850.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  851.                     $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  852.                     $neto round($neto,2,PHP_ROUND_HALF_UP);
  853.                     $arrayItems[] = array(
  854.                         'type' => 'Product',
  855.                         'name' => $item->getProductName(),
  856.                         'amount' => $neto,
  857.                         'iva' => '21',
  858.                         'total' => $subtotal,
  859.                     );
  860.                 }
  861.             }
  862.             // Acumula netos totales e IVA
  863.             $totales_neto_all $totales_neto_all $neto;
  864.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  865.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  866.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  867.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  868.             // Acumula netos totales e IVA
  869.             $product['neto'] = $product['neto'] + $neto;
  870.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  871.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  872.             $product['neto'] = round($product['neto'],2,PHP_ROUND_HALF_UP);
  873.             $product['sumSubT'] = round($product['sumSubT'],2,PHP_ROUND_HALF_UP);
  874.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  875.                 $data_supplier['product'][$i] = array(
  876.                     'id' => $item->getId(),
  877.                     'productName' => $item->getPrdName(),
  878.                     'productId' => $item->getPrdProductId(),
  879.                     'dateStart' => $item->getPrdDateStart(),
  880.                     'dateEnd' => $item->getPrdDateEnd(),
  881.                     'servicePrice' => $item->getPrdServicePrice(),
  882.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  883.                     'subtotalProduct' => $subtotalProduct,
  884.                     'iva' => $iva,
  885.                     'pax' => $pax,
  886.                     'qty' => $qty,
  887.                     'type' => $item->getPrdType(),
  888.                     'subtotal' => $subtotal,
  889.                 );
  890.             } else {
  891.                 // Es proforma
  892.                 $data_supplier['product'][$i] = array(
  893.                     'id' => $item->getId(),
  894.                     'productName' => $item->getProductName(),
  895.                     'productId' => $item->getProductId(),
  896.                     'dateStart' => $item->getDateStart(),
  897.                     'dateEnd' => $item->getDateEnd(),
  898.                     'servicePrice' => $item->getServicePrice(),
  899.                     'subtotalProduct' => $subtotalProduct,
  900.                     'iva' => $iva,
  901.                     'pax' => $pax,
  902.                     'qty' => $qty,
  903.                     'type' => $item->getType(),
  904.                     'subtotal' => $subtotal,
  905.                 );
  906.             }
  907.             $i++;
  908.         }
  909.         $data_supplier['productSubTotal'] = array(
  910.             'neto' => $product['neto'],
  911.             'sumSubT' => $product['sumSubT'],
  912.         );
  913.         $payment = array(
  914.             'sumSubT' => 0,
  915.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  916.         $i 0;
  917.         foreach ($payments as $item){
  918.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  919.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  920.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  921.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  922.                 $data_supplier['payment'][$i] = array(
  923.                     'id' => $item->getId(),
  924.                     'amount' => $item->getPayAmount(),
  925.                     'amountTotal' => $item->getPayAmountTotal(),
  926.                     'vat' => $item->getPayVat(),
  927.                     'datePayAt' => $item->getPayDatePayAt(),
  928.                     'wayToPay' => $item->getPayWayToPay(),
  929.                 );
  930.                 $arrayItems[] = array(
  931.                     'type' => 'Payment',
  932.                     'name' => $item->getPayWayToPay(),
  933.                     'amount' => $item->getPayAmount(),
  934.                     'total' => $item->getPayAmountTotal(),
  935.                     'iva' => $item->getPayVat(),
  936.                 );
  937.             } else {
  938.                 // Es una proforma
  939.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  940.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  941.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  942.                 $data_supplier['payment'][$i] = array(
  943.                     'id' => $item->getId(),
  944.                     'amount' => $item->getAmount(),
  945.                     'amountTotal' => $item->getAmountTotal(),
  946.                     'vat' => $item->getVat(),
  947.                     'datePayAt' => $item->getDatePayAt(),
  948.                     'wayToPay' => $item->getWayToPay(),
  949.                 );
  950.                 $arrayItems[] = array(
  951.                     'type' => 'Payment',
  952.                     'name' => $item->getWayToPay(),
  953.                     'amount' => $item->getAmount(),
  954.                     'total' => $item->getAmountTotal(),
  955.                     'iva' => $item->getVat(),
  956.                 );
  957.             }
  958.             $i++;
  959.         }
  960.         if (!empty($payments)) {
  961.             $data_supplier['paymentSubTotal'] = array(
  962.                 'sumSubT' => $payment['sumSubT'],
  963.             );
  964.         }
  965.         foreach ($services as $item){
  966.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  967.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  968.                     $subtotal 0;
  969.                     $neto 0;
  970.                     $subtotalService 0;
  971.                 } else {
  972.                     $subtotalService $item->getSrvPrice();
  973.                     $subneto $item->getSrvPrice();
  974.                     // Commission
  975.                     if ($item->getSrvOpCommission() == '1') {
  976.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  977.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  978.                     } else {
  979.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  980.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  981.                     }
  982.                     // Over
  983.                     if ($item->getSrvOpOver() == '1') {
  984.                         $subtotalService $subtotalService $item->getSrvOver();
  985.                         $subneto $subneto $item->getSrvOver();
  986.                     } else {
  987.                         $subtotalService $subtotalService $item->getSrvOver();
  988.                         $subneto $subneto $item->getSrvOver();
  989.                     }
  990.                     // IVA
  991.                     if ($item->getSrvOpIva() == '1') {
  992.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  993.                     } else {
  994.                         $subtotalService $item->getSrvPrice();
  995.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  996.                     }
  997.                     switch ($item->getSrvServiceCatId()) {
  998.                         case 1// Alojamiento
  999.                             // el numero de noches $numNoches; precio unitario $subneto
  1000.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  1001.                             // La personas no afectan este calculo
  1002.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  1003.                             $subnetoUnit $subneto;
  1004.                             $subneto $subneto $numNoches $item->getSrvUnits();
  1005.                             $data_supplier['service'][$i] = array(
  1006.                                 'id' => $item->getId(),
  1007.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1008.                                 'serviceName' => $item->getSrvName(),
  1009.                                 'serviceType' => 'Hotel',
  1010.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  1011.                                 'qty' => $item->getSrvUnits(),
  1012.                                 'iva' => $item->getSrvIva(),
  1013.                                 'pax' => '-',
  1014.                                 'precioUnit' => $subnetoUnit,
  1015.                                 'subneto' => $subneto,
  1016.                                 'subtotal' => $subtotal,
  1017.                             );
  1018.                             break;
  1019.                         case 2//Actividades
  1020.                             // El número de personas es considerado en el calculo
  1021.                             $pax $item->getSrvPax();
  1022.                             if (empty($pax) or $pax == "0") {
  1023.                                 $pax 1;
  1024.                             }
  1025.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1026.                             if ($days 1) {
  1027.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1028.                             } else {
  1029.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1030.                             }
  1031.                             $subtotal $subtotalService $days $item->getSrvUnits();
  1032.                             $subnetoUnit $subneto;
  1033.                             $subneto $subneto $days $item->getSrvUnits();
  1034.                             $data_supplier['service'][$i] = array(
  1035.                                 'id' => $item->getId(),
  1036.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1037.                                 'serviceName' => $item->getSrvName(),
  1038.                                 'serviceType' => 'Actividad',
  1039.                                 'date' => $dateServ,
  1040.                                 'qty' => $item->getSrvUnits(),
  1041.                                 'iva' => $item->getSrvIva(),
  1042.                                 'pax' => $item->getSrvPax(),
  1043.                                 'precioUnit' => $subnetoUnit,
  1044.                                 'subneto' => $subneto,
  1045.                                 'subtotal' => $subtotal,
  1046.                             );
  1047.                             break;
  1048.                         case 3// AV
  1049.                             $pax $item->getSrvPax();
  1050.                             if (empty($pax) or $pax == "0") {
  1051.                                 $pax 1;
  1052.                             }
  1053.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1054.                             if ($days 1) {
  1055.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1056.                             } else {
  1057.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1058.                             }
  1059.                             $unitsServ $item->getSrvUnits();
  1060.                             if (empty($unitsServ) or $unitsServ == "0") {
  1061.                                 $unitsServ 1;
  1062.                             }
  1063.                             $subtotal $subtotalService $days $unitsServ $pax;
  1064.                             $subnetoUnit $subneto;
  1065.                             $subneto $subneto $days $unitsServ $pax;
  1066.                             $data_supplier['service'][$i] = array(
  1067.                                 'id' => $item->getId(),
  1068.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1069.                                 'serviceName' => $item->getSrvName(),
  1070.                                 'serviceType' => 'AV',
  1071.                                 'date' => $dateServ,
  1072.                                 'qty' => $unitsServ,
  1073.                                 'iva' => $item->getSrvIva(),
  1074.                                 'pax' => $item->getSrvPax(),
  1075.                                 'precioUnit' => $subnetoUnit,
  1076.                                 'subneto' => $subneto,
  1077.                                 'subtotal' => $subtotal,
  1078.                             );
  1079.                             break;
  1080.                         case 4//Creative
  1081.                             $pax $item->getSrvPax();
  1082.                             if (empty($pax) or $pax == "0") {
  1083.                                 $pax 1;
  1084.                             }
  1085.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1086.                             if ($days 1) {
  1087.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1088.                             } else {
  1089.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1090.                             }
  1091.                             $unitsServ $item->getSrvUnits();
  1092.                             if (empty($unitsServ) or $unitsServ == "0") {
  1093.                                 $unitsServ 1;
  1094.                             }
  1095.                             $subtotal $subtotalService $days $unitsServ $pax;
  1096.                             $subnetoUnit $subneto;
  1097.                             $subneto $subneto $days $unitsServ $pax;
  1098.                             $data_supplier['service'][$i] = array(
  1099.                                 'id' => $item->getId(),
  1100.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1101.                                 'serviceName' => $item->getSrvName(),
  1102.                                 'serviceType' => 'Creativo',
  1103.                                 'date' => $dateServ,
  1104.                                 'qty' => $unitsServ,
  1105.                                 'iva' => $item->getSrvIva(),
  1106.                                 'pax' => $item->getSrvPax(),
  1107.                                 'precioUnit' => $subnetoUnit,
  1108.                                 'subneto' => $subneto,
  1109.                                 'subtotal' => $subtotal,
  1110.                             );
  1111.                             break;
  1112.                         case 5//Cruise
  1113.                             $pax $item->getSrvPax();
  1114.                             if (empty($pax) or $pax == "0") {
  1115.                                 $pax 1;
  1116.                             }
  1117.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  1118.                             if ($days 1) {
  1119.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1120.                             } else {
  1121.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1122.                             }
  1123.                             $unitsServ $item->getSrvUnits();
  1124.                             if (empty($unitsServ) or $unitsServ == "0") {
  1125.                                 $unitsServ 1;
  1126.                             }
  1127.                             $subtotal $subtotalService $days $unitsServ $pax;
  1128.                             $subnetoUnit $subneto;
  1129.                             $subneto $subneto $days $unitsServ $pax;
  1130.                             $data_supplier['service'][$i] = array(
  1131.                                 'id' => $item->getId(),
  1132.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1133.                                 'serviceName' => $item->getSrvName(),
  1134.                                 'serviceType' => 'Crucero',
  1135.                                 'date' => $dateServ,
  1136.                                 'qty' => $unitsServ,
  1137.                                 'iva' => $item->getSrvIva(),
  1138.                                 'pax' => $item->getSrvPax(),
  1139.                                 'precioUnit' => $subnetoUnit,
  1140.                                 'subneto' => $subneto,
  1141.                                 'subtotal' => $subtotal,
  1142.                             );
  1143.                             break;
  1144.                         case 6//Entertaiment
  1145.                             $pax $item->getSrvPax();
  1146.                             if (empty($pax) or $pax == "0") {
  1147.                                 $pax 1;
  1148.                             }
  1149.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1150.                             if ($days 1) {
  1151.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1152.                             } else {
  1153.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1154.                             }
  1155.                             $unitsServ $item->getSrvUnits();
  1156.                             if (empty($unitsServ) or $unitsServ == "0") {
  1157.                                 $unitsServ 1;
  1158.                             }
  1159.                             $subtotal $subtotalService $days $unitsServ $pax;
  1160.                             $subnetoUnit $subneto;
  1161.                             $subneto $subneto $days $unitsServ $pax;
  1162.                             $data_supplier['service'][$i] = array(
  1163.                                 'id' => $item->getId(),
  1164.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1165.                                 'serviceName' => $item->getSrvName(),
  1166.                                 'serviceType' => 'Entretenimiento',
  1167.                                 'date' => $dateServ,
  1168.                                 'qty' => $unitsServ,
  1169.                                 'iva' => $item->getSrvIva(),
  1170.                                 'pax' => $item->getSrvPax(),
  1171.                                 'precioUnit' => $subnetoUnit,
  1172.                                 'subneto' => $subneto,
  1173.                                 'subtotal' => $subtotal,
  1174.                             );
  1175.                             break;
  1176.                         case 7// Gifts
  1177.                             $pax $item->getSrvPax();
  1178.                             if (empty($pax) or $pax == "0") {
  1179.                                 $pax 1;
  1180.                             }
  1181. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1182.                             $days 1;
  1183.                             if ($days 1) {
  1184.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1185.                             } else {
  1186.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1187.                             }
  1188.                             $unitsServ $item->getSrvUnits();
  1189.                             if (empty($unitsServ) or $unitsServ == "0") {
  1190.                                 $unitsServ 1;
  1191.                             }
  1192.                             $subtotal $subtotalService $days $unitsServ $pax;
  1193.                             $subnetoUnit $subneto;
  1194.                             $subneto $subneto $days $unitsServ $pax;
  1195.                             $data_supplier['service'][$i] = array(
  1196.                                 'id' => $item->getId(),
  1197.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1198.                                 'serviceName' => $item->getSrvName(),
  1199.                                 'serviceType' => 'Regalos',
  1200.                                 'date' => $dateServ,
  1201.                                 'qty' => $unitsServ,
  1202.                                 'iva' => $item->getSrvIva(),
  1203.                                 'pax' => $item->getSrvPax(),
  1204.                                 'precioUnit' => $subnetoUnit,
  1205.                                 'subneto' => $subneto,
  1206.                                 'subtotal' => $subtotal,
  1207.                             );
  1208.                             break;
  1209.                         case 8//Guide
  1210.                             $pax $item->getSrvPax();
  1211.                             if (empty($pax) or $pax == "0") {
  1212.                                 $pax 1;
  1213.                             }
  1214.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1215.                             if ($days 1) {
  1216.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1217.                             } else {
  1218.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1219.                             }
  1220.                             $unitsServ $item->getSrvUnits();
  1221.                             if (empty($unitsServ) or $unitsServ == "0") {
  1222.                                 $unitsServ 1;
  1223.                             }
  1224.                             $subtotal $subtotalService $days $unitsServ $pax;
  1225.                             $subnetoUnit $subneto;
  1226.                             $subneto $subneto $days $unitsServ $pax;
  1227.                             $data_supplier['service'][$i] = array(
  1228.                                 'id' => $item->getId(),
  1229.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1230.                                 'serviceName' => $item->getSrvName(),
  1231.                                 'serviceType' => 'Regalos',
  1232.                                 'date' => $dateServ,
  1233.                                 'qty' => $unitsServ,
  1234.                                 'iva' => $item->getSrvIva(),
  1235.                                 'pax' => $item->getSrvPax(),
  1236.                                 'precioUnit' => $subnetoUnit,
  1237.                                 'subneto' => $subneto,
  1238.                                 'subtotal' => $subtotal,
  1239.                             );
  1240.                             break;
  1241.                         case 9//Itineraries
  1242.                             $pax $item->getSrvPax();
  1243.                             if (empty($pax) or $pax == "0") {
  1244.                                 $pax 1;
  1245.                             }
  1246.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1247.                             if ($days 1) {
  1248.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1249.                             } else {
  1250.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1251.                             }
  1252.                             $unitsServ $item->getSrvUnits();
  1253.                             if (empty($unitsServ) or $unitsServ == "0") {
  1254.                                 $unitsServ 1;
  1255.                             }
  1256.                             $subtotal $subtotalService $days $unitsServ $pax;
  1257.                             $subnetoUnit $subneto;
  1258.                             $subneto $subneto $days $unitsServ $pax;
  1259.                             $data_supplier['service'][$i] = array(
  1260.                                 'id' => $item->getId(),
  1261.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1262.                                 'serviceName' => $item->getSrvName(),
  1263.                                 'serviceType' => 'Itinerarios',
  1264.                                 'date' => $dateServ,
  1265.                                 'qty' => $unitsServ,
  1266.                                 'iva' => $item->getSrvIva(),
  1267.                                 'pax' => $item->getSrvPax(),
  1268.                                 'precioUnit' => $subnetoUnit,
  1269.                                 'subneto' => $subneto,
  1270.                                 'subtotal' => $subtotal,
  1271.                             );
  1272.                             break;
  1273.                         case 10//Lounge  -- No Aplica
  1274. //                        $pax = $item->getPax();
  1275. //                        if (empty($pax) or $pax == "0") {
  1276. //                            $pax = 1;
  1277. //                        }
  1278. //
  1279. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1280. //                        if ($days > 1){
  1281. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1282. //                        } else {
  1283. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1284. //                        }
  1285. //
  1286. //                        $unitsServ = $item->getUnits();
  1287. //                        if (empty($unitsServ) or $unitsServ == "0") {
  1288. //                            $unitsServ = 1;
  1289. //                        }
  1290. //
  1291. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  1292. //                        $subnetoUnit = $subneto;
  1293. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  1294. //
  1295. //                        $data_supplier['service'][$i] = array (
  1296. //                            'id' => $item->getId(),
  1297. //                            'serviceCatId' => $item->getServiceCatId(),
  1298. //                            'serviceName' => $item->getName(),
  1299. //                            'serviceType' => 'Itinerarios',
  1300. //                            'date' => $dateServ,
  1301. //                            'qty' => $unitsServ,
  1302. //                            'iva' => $item->getIva(),
  1303. //                            'pax' => $item->getPax(),
  1304. //                            'precioUnit' => $subnetoUnit,
  1305. //                            'subneto' => $subneto,
  1306. //                            'subtotal' => $subtotal,
  1307. //                        );
  1308.                             break;
  1309.                         case 11//Menu
  1310.                             $pax $item->getSrvPax();
  1311.                             if (empty($pax) or $pax == "0") {
  1312.                                 $pax 1;
  1313.                             }
  1314.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1315.                             if ($days 1) {
  1316.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1317.                             } else {
  1318.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1319.                             }
  1320.                             $unitsServ $item->getSrvUnits();
  1321.                             if (empty($unitsServ) or $unitsServ == "0") {
  1322.                                 $unitsServ 1;
  1323.                             }
  1324.                             $subtotal $subtotalService $days $unitsServ $pax;
  1325.                             $subnetoUnit $subneto;
  1326.                             $subneto $subneto $days $unitsServ $pax;
  1327.                             $data_supplier['service'][$i] = array(
  1328.                                 'id' => $item->getId(),
  1329.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1330.                                 'serviceName' => $item->getSrvName(),
  1331.                                 'serviceType' => 'Menú',
  1332.                                 'date' => $dateServ,
  1333.                                 'qty' => $unitsServ,
  1334.                                 'iva' => $item->getSrvIva(),
  1335.                                 'pax' => $item->getSrvPax(),
  1336.                                 'precioUnit' => $subnetoUnit,
  1337.                                 'subneto' => $subneto,
  1338.                                 'subtotal' => $subtotal,
  1339.                             );
  1340.                             break;
  1341.                         case 12//Others
  1342.                             $pax $item->getSrvPax();
  1343.                             if (empty($pax) or $pax == "0") {
  1344.                                 $pax 1;
  1345.                             }
  1346.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1347.                             if ($days 1) {
  1348.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1349.                             } else {
  1350.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1351.                             }
  1352.                             $unitsServ $item->getSrvUnits();
  1353.                             if (empty($unitsServ) or $unitsServ == "0") {
  1354.                                 $unitsServ 1;
  1355.                             }
  1356.                             $subtotal $subtotalService $days $unitsServ $pax;
  1357.                             $subnetoUnit $subneto;
  1358.                             $subneto $subneto $days $unitsServ $pax;
  1359.                             $data_supplier['service'][$i] = array(
  1360.                                 'id' => $item->getId(),
  1361.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1362.                                 'serviceName' => $item->getSrvName(),
  1363.                                 'serviceType' => 'Otros',
  1364.                                 'date' => $dateServ,
  1365.                                 'qty' => $unitsServ,
  1366.                                 'iva' => $item->getSrvIva(),
  1367.                                 'pax' => $item->getSrvPax(),
  1368.                                 'precioUnit' => $subnetoUnit,
  1369.                                 'subneto' => $subneto,
  1370.                                 'subtotal' => $subtotal,
  1371.                             );
  1372.                             break;
  1373.                         case 13//Transport
  1374.                             $pax $item->getSrvPax();
  1375.                             if (empty($pax) or $pax == "0") {
  1376.                                 $pax 1;
  1377.                             }
  1378.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1379.                             if ($days 1) {
  1380.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1381.                             } else {
  1382.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1383.                             }
  1384.                             $unitsServ $item->getSrvUnits();
  1385.                             if (empty($unitsServ) or $unitsServ == "0") {
  1386.                                 $unitsServ 1;
  1387.                             }
  1388.                             $subtotal $subtotalService $days $unitsServ $pax;
  1389.                             $subnetoUnit $subneto;
  1390.                             $subneto $subneto $days $unitsServ $pax;
  1391.                             $data_supplier['service'][$i] = array(
  1392.                                 'id' => $item->getId(),
  1393.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1394.                                 'serviceName' => $item->getSrvName(),
  1395.                                 'serviceType' => 'Transporte',
  1396.                                 'date' => $dateServ,
  1397.                                 'qty' => $unitsServ,
  1398.                                 'iva' => $item->getSrvIva(),
  1399.                                 'pax' => $item->getSrvPax(),
  1400.                                 'precioUnit' => $subnetoUnit,
  1401.                                 'subneto' => $subneto,
  1402.                                 'subtotal' => $subtotal,
  1403.                             );
  1404.                             break;
  1405.                         case 14//Technology
  1406.                             $pax $item->getSrvPax();
  1407.                             if (empty($pax) or $pax == "0") {
  1408.                                 $pax 1;
  1409.                             }
  1410. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1411.                             $days 1;
  1412. //                        if ($days > 1){
  1413. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1414. //                        } else {
  1415. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1416. //                        }
  1417.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1418.                             $unitsServ $item->getSrvUnits();
  1419.                             if (empty($unitsServ) or $unitsServ == "0") {
  1420.                                 $unitsServ 1;
  1421.                             }
  1422.                             $subtotal $subtotalService $days $unitsServ $pax;
  1423.                             $subnetoUnit $subneto;
  1424.                             $subneto $subneto $days $unitsServ $pax;
  1425.                             $data_supplier['service'][$i] = array(
  1426.                                 'id' => $item->getId(),
  1427.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1428.                                 'serviceName' => $item->getSrvName(),
  1429.                                 'serviceType' => 'Tecnología',
  1430.                                 'date' => $dateServ,
  1431.                                 'qty' => $unitsServ,
  1432.                                 'iva' => $item->getSrvIva(),
  1433.                                 'pax' => $item->getSrvPax(),
  1434.                                 'precioUnit' => $subnetoUnit,
  1435.                                 'subneto' => $subneto,
  1436.                                 'subtotal' => $subtotal,
  1437.                             );
  1438.                             break;
  1439.                         case 15//Assisstant
  1440.                             $pax $item->getSrvPax();
  1441.                             if (empty($pax) or $pax == "0") {
  1442.                                 $pax 1;
  1443.                             }
  1444.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1445.                             if ($days 1) {
  1446.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1447.                             } else {
  1448.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1449.                             }
  1450.                             $unitsServ $item->getSrvUnits();
  1451.                             if (empty($unitsServ) or $unitsServ == "0") {
  1452.                                 $unitsServ 1;
  1453.                             }
  1454.                             $subtotal $subtotalService $days $unitsServ $pax;
  1455.                             $subnetoUnit $subneto;
  1456.                             $subneto $subneto $days $unitsServ $pax;
  1457.                             $data_supplier['service'][$i] = array(
  1458.                                 'id' => $item->getId(),
  1459.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1460.                                 'serviceName' => $item->getSrvName(),
  1461.                                 'serviceType' => 'Asistente',
  1462.                                 'date' => $dateServ,
  1463.                                 'qty' => $unitsServ,
  1464.                                 'iva' => $item->getSrvIva(),
  1465.                                 'pax' => $item->getSrvPax(),
  1466.                                 'precioUnit' => $subnetoUnit,
  1467.                                 'subneto' => $subneto,
  1468.                                 'subtotal' => $subtotal,
  1469.                             );
  1470.                             break;
  1471.                         case 16//DDR
  1472.                             $pax $item->getSrvPax();
  1473.                             if (empty($pax) or $pax == "0") {
  1474.                                 $pax 1;
  1475.                             }
  1476.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  1477.                             if ($days 1) {
  1478.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  1479.                             } else {
  1480.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  1481.                             }
  1482.                             $unitsServ $item->getSrvUnits();
  1483.                             if (empty($unitsServ) or $unitsServ == "0") {
  1484.                                 $unitsServ 1;
  1485.                             }
  1486.                             $subtotal $subtotalService $days $unitsServ $pax;
  1487.                             $subnetoUnit $subneto;
  1488.                             $subneto $subneto $days $unitsServ $pax;
  1489.                             $data_supplier['service'][$i] = array(
  1490.                                 'id' => $item->getId(),
  1491.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  1492.                                 'serviceName' => $item->getSrvName(),
  1493.                                 'serviceType' => 'DDR',
  1494.                                 'date' => $dateServ,
  1495.                                 'qty' => $unitsServ,
  1496.                                 'iva' => $item->getSrvIva(),
  1497.                                 'pax' => $item->getSrvPax(),
  1498.                                 'precioUnit' => $subnetoUnit,
  1499.                                 'subneto' => $subneto,
  1500.                                 'subtotal' => $subtotal,
  1501.                             );
  1502.                             break;
  1503.                         default:
  1504.                             break;
  1505.                     }
  1506.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  1507.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  1508.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  1509.                     $arrayItems[] = array(
  1510.                         'type' => 'Service',
  1511.                         'name' => $item->getSrvName(),
  1512.                         'amount' => $neto,
  1513.                         'iva' => $item->getSrvIva(),
  1514.                         'total' => $subtotal,
  1515.                     );
  1516.                 }
  1517.                 switch ($item->getSrvIva()) {
  1518.                     // Acumula IVA
  1519.                     case 21:
  1520.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  1521.                         break;
  1522.                     case 10:
  1523.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  1524.                         break;
  1525.                     case 0:
  1526.                         break;
  1527.                     default:
  1528.                         break;
  1529.                 }
  1530.             } else {
  1531.                 // Es una proforma
  1532.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  1533.                     $subtotal 0;
  1534.                     $neto 0;
  1535.                     $subtotalService 0;
  1536.                 } else {
  1537.                     $subtotalService $item->getPrice();
  1538.                     $subneto $item->getPrice();
  1539.                     // Commission
  1540.                     if ($item->getOpCommission() == '1') {
  1541.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  1542.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  1543.                     } else {
  1544.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  1545.                         $subneto $subneto * (- ($item->getCommission() / 100));
  1546.                     }
  1547.                     // Over
  1548.                     if ($item->getOpOver() == '1') {
  1549.                         $subtotalService $subtotalService $item->getOver();
  1550.                         $subneto $subneto $item->getOver();
  1551.                     } else {
  1552.                         $subtotalService $subtotalService $item->getOver();
  1553.                         $subneto $subneto $item->getOver();
  1554.                     }
  1555.                     // IVA
  1556.                     if ($item->getOpIva() == '1') {
  1557.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  1558.                     } else {
  1559.                         $subtotalService $item->getPrice();
  1560.                         $subneto = ($subneto 100) / (100 $item->getIva());
  1561.                     }
  1562.                     switch ($item->getServiceCatId()) {
  1563.                         case 1// Alojamiento
  1564.                             // el numero de noches $numNoches; precio unitario $subneto
  1565.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  1566.                             // La personas no afectan este calculo
  1567.                             $subtotal $subtotalService $numNoches $item->getUnits();
  1568.                             $subnetoUnit $subneto;
  1569.                             $subneto $subneto $numNoches $item->getUnits();
  1570.                             $data_supplier['service'][$i] = array(
  1571.                                 'id' => $item->getId(),
  1572.                                 'serviceCatId' => $item->getServiceCatId(),
  1573.                                 'serviceName' => $item->getName(),
  1574.                                 'serviceType' => 'Hotel',
  1575.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  1576.                                 'qty' => $item->getUnits(),
  1577.                                 'iva' => $item->getIva(),
  1578.                                 'pax' => '-',
  1579.                                 'precioUnit' => $subnetoUnit,
  1580.                                 'subneto' => $subneto,
  1581.                                 'subtotal' => $subtotal,
  1582.                             );
  1583.                             break;
  1584.                         case 2//Actividades
  1585.                             // El número de personas es considerado en el calculo
  1586.                             $pax $item->getPax();
  1587.                             if (empty($pax) or $pax == "0") {
  1588.                                 $pax 1;
  1589.                             }
  1590.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1591.                             if ($days 1) {
  1592.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1593.                             } else {
  1594.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1595.                             }
  1596.                             $subtotal $subtotalService $days $item->getUnits();
  1597.                             $subnetoUnit $subneto;
  1598.                             $subneto $subneto $days $item->getUnits();
  1599.                             $data_supplier['service'][$i] = array(
  1600.                                 'id' => $item->getId(),
  1601.                                 'serviceCatId' => $item->getServiceCatId(),
  1602.                                 'serviceName' => $item->getName(),
  1603.                                 'serviceType' => 'Actividad',
  1604.                                 'date' => $dateServ,
  1605.                                 'qty' => $item->getUnits(),
  1606.                                 'iva' => $item->getIva(),
  1607.                                 'pax' => $item->getPax(),
  1608.                                 'precioUnit' => $subnetoUnit,
  1609.                                 'subneto' => $subneto,
  1610.                                 'subtotal' => $subtotal,
  1611.                             );
  1612.                             break;
  1613.                         case 3// AV
  1614.                             $pax $item->getPax();
  1615.                             if (empty($pax) or $pax == "0") {
  1616.                                 $pax 1;
  1617.                             }
  1618.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1619.                             if ($days 1) {
  1620.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1621.                             } else {
  1622.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1623.                             }
  1624.                             $unitsServ $item->getUnits();
  1625.                             if (empty($unitsServ) or $unitsServ == "0") {
  1626.                                 $unitsServ 1;
  1627.                             }
  1628.                             $subtotal $subtotalService $days $unitsServ $pax;
  1629.                             $subnetoUnit $subneto;
  1630.                             $subneto $subneto $days $unitsServ $pax;
  1631.                             $data_supplier['service'][$i] = array(
  1632.                                 'id' => $item->getId(),
  1633.                                 'serviceCatId' => $item->getServiceCatId(),
  1634.                                 'serviceName' => $item->getName(),
  1635.                                 'serviceType' => 'AV',
  1636.                                 'date' => $dateServ,
  1637.                                 'qty' => $unitsServ,
  1638.                                 'iva' => $item->getIva(),
  1639.                                 'pax' => $item->getPax(),
  1640.                                 'precioUnit' => $subnetoUnit,
  1641.                                 'subneto' => $subneto,
  1642.                                 'subtotal' => $subtotal,
  1643.                             );
  1644.                             break;
  1645.                         case 4//Creative
  1646.                             $pax $item->getPax();
  1647.                             if (empty($pax) or $pax == "0") {
  1648.                                 $pax 1;
  1649.                             }
  1650.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1651.                             if ($days 1) {
  1652.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1653.                             } else {
  1654.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1655.                             }
  1656.                             $unitsServ $item->getUnits();
  1657.                             if (empty($unitsServ) or $unitsServ == "0") {
  1658.                                 $unitsServ 1;
  1659.                             }
  1660.                             $subtotal $subtotalService $days $unitsServ $pax;
  1661.                             $subnetoUnit $subneto;
  1662.                             $subneto $subneto $days $unitsServ $pax;
  1663.                             $data_supplier['service'][$i] = array(
  1664.                                 'id' => $item->getId(),
  1665.                                 'serviceCatId' => $item->getServiceCatId(),
  1666.                                 'serviceName' => $item->getName(),
  1667.                                 'serviceType' => 'Creativo',
  1668.                                 'date' => $dateServ,
  1669.                                 'qty' => $unitsServ,
  1670.                                 'iva' => $item->getIva(),
  1671.                                 'pax' => $item->getPax(),
  1672.                                 'precioUnit' => $subnetoUnit,
  1673.                                 'subneto' => $subneto,
  1674.                                 'subtotal' => $subtotal,
  1675.                             );
  1676.                             break;
  1677.                         case 5//Cruise
  1678.                             $pax $item->getPax();
  1679.                             if (empty($pax) or $pax == "0") {
  1680.                                 $pax 1;
  1681.                             }
  1682.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  1683.                             if ($days 1) {
  1684.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1685.                             } else {
  1686.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1687.                             }
  1688.                             $unitsServ $item->getUnits();
  1689.                             if (empty($unitsServ) or $unitsServ == "0") {
  1690.                                 $unitsServ 1;
  1691.                             }
  1692.                             $subtotal $subtotalService $days $unitsServ $pax;
  1693.                             $subnetoUnit $subneto;
  1694.                             $subneto $subneto $days $unitsServ $pax;
  1695.                             $data_supplier['service'][$i] = array(
  1696.                                 'id' => $item->getId(),
  1697.                                 'serviceCatId' => $item->getServiceCatId(),
  1698.                                 'serviceName' => $item->getName(),
  1699.                                 'serviceType' => 'Crucero',
  1700.                                 'date' => $dateServ,
  1701.                                 'qty' => $unitsServ,
  1702.                                 'iva' => $item->getIva(),
  1703.                                 'pax' => $item->getPax(),
  1704.                                 'precioUnit' => $subnetoUnit,
  1705.                                 'subneto' => $subneto,
  1706.                                 'subtotal' => $subtotal,
  1707.                             );
  1708.                             break;
  1709.                         case 6//Entertaiment
  1710.                             $pax $item->getPax();
  1711.                             if (empty($pax) or $pax == "0") {
  1712.                                 $pax 1;
  1713.                             }
  1714.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1715.                             if ($days 1) {
  1716.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1717.                             } else {
  1718.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1719.                             }
  1720.                             $unitsServ $item->getUnits();
  1721.                             if (empty($unitsServ) or $unitsServ == "0") {
  1722.                                 $unitsServ 1;
  1723.                             }
  1724.                             $subtotal $subtotalService $days $unitsServ $pax;
  1725.                             $subnetoUnit $subneto;
  1726.                             $subneto $subneto $days $unitsServ $pax;
  1727.                             $data_supplier['service'][$i] = array(
  1728.                                 'id' => $item->getId(),
  1729.                                 'serviceCatId' => $item->getServiceCatId(),
  1730.                                 'serviceName' => $item->getName(),
  1731.                                 'serviceType' => 'Entretenimiento',
  1732.                                 'date' => $dateServ,
  1733.                                 'qty' => $unitsServ,
  1734.                                 'iva' => $item->getIva(),
  1735.                                 'pax' => $item->getPax(),
  1736.                                 'precioUnit' => $subnetoUnit,
  1737.                                 'subneto' => $subneto,
  1738.                                 'subtotal' => $subtotal,
  1739.                             );
  1740.                             break;
  1741.                         case 7// Gifts
  1742.                             $pax $item->getPax();
  1743.                             if (empty($pax) or $pax == "0") {
  1744.                                 $pax 1;
  1745.                             }
  1746. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1747.                             $days 1;
  1748.                             if ($days 1) {
  1749.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1750.                             } else {
  1751.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1752.                             }
  1753.                             $unitsServ $item->getUnits();
  1754.                             if (empty($unitsServ) or $unitsServ == "0") {
  1755.                                 $unitsServ 1;
  1756.                             }
  1757.                             $subtotal $subtotalService $days $unitsServ $pax;
  1758.                             $subnetoUnit $subneto;
  1759.                             $subneto $subneto $days $unitsServ $pax;
  1760.                             $data_supplier['service'][$i] = array(
  1761.                                 'id' => $item->getId(),
  1762.                                 'serviceCatId' => $item->getServiceCatId(),
  1763.                                 'serviceName' => $item->getName(),
  1764.                                 'serviceType' => 'Regalos',
  1765.                                 'date' => $dateServ,
  1766.                                 'qty' => $unitsServ,
  1767.                                 'iva' => $item->getIva(),
  1768.                                 'pax' => $item->getPax(),
  1769.                                 'precioUnit' => $subnetoUnit,
  1770.                                 'subneto' => $subneto,
  1771.                                 'subtotal' => $subtotal,
  1772.                             );
  1773.                             break;
  1774.                         case 8//Guide
  1775.                             $pax $item->getPax();
  1776.                             if (empty($pax) or $pax == "0") {
  1777.                                 $pax 1;
  1778.                             }
  1779.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1780.                             if ($days 1) {
  1781.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1782.                             } else {
  1783.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1784.                             }
  1785.                             $unitsServ $item->getUnits();
  1786.                             if (empty($unitsServ) or $unitsServ == "0") {
  1787.                                 $unitsServ 1;
  1788.                             }
  1789.                             $subtotal $subtotalService $days $unitsServ $pax;
  1790.                             $subnetoUnit $subneto;
  1791.                             $subneto $subneto $days $unitsServ $pax;
  1792.                             $data_supplier['service'][$i] = array(
  1793.                                 'id' => $item->getId(),
  1794.                                 'serviceCatId' => $item->getServiceCatId(),
  1795.                                 'serviceName' => $item->getName(),
  1796.                                 'serviceType' => 'Regalos',
  1797.                                 'date' => $dateServ,
  1798.                                 'qty' => $unitsServ,
  1799.                                 'iva' => $item->getIva(),
  1800.                                 'pax' => $item->getPax(),
  1801.                                 'precioUnit' => $subnetoUnit,
  1802.                                 'subneto' => $subneto,
  1803.                                 'subtotal' => $subtotal,
  1804.                             );
  1805.                             break;
  1806.                         case 9//Itineraries
  1807.                             $pax $item->getPax();
  1808.                             if (empty($pax) or $pax == "0") {
  1809.                                 $pax 1;
  1810.                             }
  1811.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1812.                             if ($days 1) {
  1813.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1814.                             } else {
  1815.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1816.                             }
  1817.                             $unitsServ $item->getUnits();
  1818.                             if (empty($unitsServ) or $unitsServ == "0") {
  1819.                                 $unitsServ 1;
  1820.                             }
  1821.                             $subtotal $subtotalService $days $unitsServ $pax;
  1822.                             $subnetoUnit $subneto;
  1823.                             $subneto $subneto $days $unitsServ $pax;
  1824.                             $data_supplier['service'][$i] = array(
  1825.                                 'id' => $item->getId(),
  1826.                                 'serviceCatId' => $item->getServiceCatId(),
  1827.                                 'serviceName' => $item->getName(),
  1828.                                 'serviceType' => 'Itinerarios',
  1829.                                 'date' => $dateServ,
  1830.                                 'qty' => $unitsServ,
  1831.                                 'iva' => $item->getIva(),
  1832.                                 'pax' => $item->getPax(),
  1833.                                 'precioUnit' => $subnetoUnit,
  1834.                                 'subneto' => $subneto,
  1835.                                 'subtotal' => $subtotal,
  1836.                             );
  1837.                             break;
  1838.                         case 10//Lounge  -- No Aplica
  1839. //                        $pax = $item->getPax();
  1840. //                        if (empty($pax) or $pax == "0") {
  1841. //                            $pax = 1;
  1842. //                        }
  1843. //
  1844. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1845. //                        if ($days > 1){
  1846. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1847. //                        } else {
  1848. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1849. //                        }
  1850. //
  1851. //                        $unitsServ = $item->getUnits();
  1852. //                        if (empty($unitsServ) or $unitsServ == "0") {
  1853. //                            $unitsServ = 1;
  1854. //                        }
  1855. //
  1856. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  1857. //                        $subnetoUnit = $subneto;
  1858. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  1859. //
  1860. //                        $data_supplier['service'][$i] = array (
  1861. //                            'id' => $item->getId(),
  1862. //                            'serviceCatId' => $item->getServiceCatId(),
  1863. //                            'serviceName' => $item->getName(),
  1864. //                            'serviceType' => 'Itinerarios',
  1865. //                            'date' => $dateServ,
  1866. //                            'qty' => $unitsServ,
  1867. //                            'iva' => $item->getIva(),
  1868. //                            'pax' => $item->getPax(),
  1869. //                            'precioUnit' => $subnetoUnit,
  1870. //                            'subneto' => $subneto,
  1871. //                            'subtotal' => $subtotal,
  1872. //                        );
  1873.                             break;
  1874.                         case 11//Menu
  1875.                             $pax $item->getPax();
  1876.                             if (empty($pax) or $pax == "0") {
  1877.                                 $pax 1;
  1878.                             }
  1879.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1880.                             if ($days 1) {
  1881.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1882.                             } else {
  1883.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1884.                             }
  1885.                             $unitsServ $item->getUnits();
  1886.                             if (empty($unitsServ) or $unitsServ == "0") {
  1887.                                 $unitsServ 1;
  1888.                             }
  1889.                             $subtotal $subtotalService $days $unitsServ $pax;
  1890.                             $subnetoUnit $subneto;
  1891.                             $subneto $subneto $days $unitsServ $pax;
  1892.                             $data_supplier['service'][$i] = array(
  1893.                                 'id' => $item->getId(),
  1894.                                 'serviceCatId' => $item->getServiceCatId(),
  1895.                                 'serviceName' => $item->getName(),
  1896.                                 'serviceType' => 'Menú',
  1897.                                 'date' => $dateServ,
  1898.                                 'qty' => $unitsServ,
  1899.                                 'iva' => $item->getIva(),
  1900.                                 'pax' => $item->getPax(),
  1901.                                 'precioUnit' => $subnetoUnit,
  1902.                                 'subneto' => $subneto,
  1903.                                 'subtotal' => $subtotal,
  1904.                             );
  1905.                             break;
  1906.                         case 12//Others
  1907.                             $pax $item->getPax();
  1908.                             if (empty($pax) or $pax == "0") {
  1909.                                 $pax 1;
  1910.                             }
  1911.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1912.                             if ($days 1) {
  1913.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1914.                             } else {
  1915.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1916.                             }
  1917.                             $unitsServ $item->getUnits();
  1918.                             if (empty($unitsServ) or $unitsServ == "0") {
  1919.                                 $unitsServ 1;
  1920.                             }
  1921.                             $subtotal $subtotalService $days $unitsServ $pax;
  1922.                             $subnetoUnit $subneto;
  1923.                             $subneto $subneto $days $unitsServ $pax;
  1924.                             $data_supplier['service'][$i] = array(
  1925.                                 'id' => $item->getId(),
  1926.                                 'serviceCatId' => $item->getServiceCatId(),
  1927.                                 'serviceName' => $item->getName(),
  1928.                                 'serviceType' => 'Otros',
  1929.                                 'date' => $dateServ,
  1930.                                 'qty' => $unitsServ,
  1931.                                 'iva' => $item->getIva(),
  1932.                                 'pax' => $item->getPax(),
  1933.                                 'precioUnit' => $subnetoUnit,
  1934.                                 'subneto' => $subneto,
  1935.                                 'subtotal' => $subtotal,
  1936.                             );
  1937.                             break;
  1938.                         case 13//Transport
  1939.                             $pax $item->getPax();
  1940.                             if (empty($pax) or $pax == "0") {
  1941.                                 $pax 1;
  1942.                             }
  1943.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  1944.                             if ($days 1) {
  1945.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1946.                             } else {
  1947.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1948.                             }
  1949.                             $unitsServ $item->getUnits();
  1950.                             if (empty($unitsServ) or $unitsServ == "0") {
  1951.                                 $unitsServ 1;
  1952.                             }
  1953.                             $subtotal $subtotalService $days $unitsServ $pax;
  1954.                             $subnetoUnit $subneto;
  1955.                             $subneto $subneto $days $unitsServ $pax;
  1956.                             $data_supplier['service'][$i] = array(
  1957.                                 'id' => $item->getId(),
  1958.                                 'serviceCatId' => $item->getServiceCatId(),
  1959.                                 'serviceName' => $item->getName(),
  1960.                                 'serviceType' => 'Transporte',
  1961.                                 'date' => $dateServ,
  1962.                                 'qty' => $unitsServ,
  1963.                                 'iva' => $item->getIva(),
  1964.                                 'pax' => $item->getPax(),
  1965.                                 'precioUnit' => $subnetoUnit,
  1966.                                 'subneto' => $subneto,
  1967.                                 'subtotal' => $subtotal,
  1968.                             );
  1969.                             break;
  1970.                         case 14//Technology
  1971.                             $pax $item->getPax();
  1972.                             if (empty($pax) or $pax == "0") {
  1973.                                 $pax 1;
  1974.                             }
  1975. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  1976.                             $days 1;
  1977. //                        if ($days > 1){
  1978. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  1979. //                        } else {
  1980. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  1981. //                        }
  1982.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  1983.                             $unitsServ $item->getUnits();
  1984.                             if (empty($unitsServ) or $unitsServ == "0") {
  1985.                                 $unitsServ 1;
  1986.                             }
  1987.                             $subtotal $subtotalService $days $unitsServ $pax;
  1988.                             $subnetoUnit $subneto;
  1989.                             $subneto $subneto $days $unitsServ $pax;
  1990.                             $data_supplier['service'][$i] = array(
  1991.                                 'id' => $item->getId(),
  1992.                                 'serviceCatId' => $item->getServiceCatId(),
  1993.                                 'serviceName' => $item->getName(),
  1994.                                 'serviceType' => 'Tecnología',
  1995.                                 'date' => $dateServ,
  1996.                                 'qty' => $unitsServ,
  1997.                                 'iva' => $item->getIva(),
  1998.                                 'pax' => $item->getPax(),
  1999.                                 'precioUnit' => $subnetoUnit,
  2000.                                 'subneto' => $subneto,
  2001.                                 'subtotal' => $subtotal,
  2002.                             );
  2003.                             break;
  2004.                         case 15//Assisstant
  2005.                             $pax $item->getPax();
  2006.                             if (empty($pax) or $pax == "0") {
  2007.                                 $pax 1;
  2008.                             }
  2009.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2010.                             if ($days 1) {
  2011.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2012.                             } else {
  2013.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2014.                             }
  2015.                             $unitsServ $item->getUnits();
  2016.                             if (empty($unitsServ) or $unitsServ == "0") {
  2017.                                 $unitsServ 1;
  2018.                             }
  2019.                             $subtotal $subtotalService $days $unitsServ $pax;
  2020.                             $subnetoUnit $subneto;
  2021.                             $subneto $subneto $days $unitsServ $pax;
  2022.                             $data_supplier['service'][$i] = array(
  2023.                                 'id' => $item->getId(),
  2024.                                 'serviceCatId' => $item->getServiceCatId(),
  2025.                                 'serviceName' => $item->getName(),
  2026.                                 'serviceType' => 'Asistente',
  2027.                                 'date' => $dateServ,
  2028.                                 'qty' => $unitsServ,
  2029.                                 'iva' => $item->getIva(),
  2030.                                 'pax' => $item->getPax(),
  2031.                                 'precioUnit' => $subnetoUnit,
  2032.                                 'subneto' => $subneto,
  2033.                                 'subtotal' => $subtotal,
  2034.                             );
  2035.                             break;
  2036.                         case 16//DDR
  2037.                             $pax $item->getPax();
  2038.                             if (empty($pax) or $pax == "0") {
  2039.                                 $pax 1;
  2040.                             }
  2041.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2042.                             if ($days 1) {
  2043.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  2044.                             } else {
  2045.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2046.                             }
  2047.                             $unitsServ $item->getUnits();
  2048.                             if (empty($unitsServ) or $unitsServ == "0") {
  2049.                                 $unitsServ 1;
  2050.                             }
  2051.                             $subtotal $subtotalService $days $unitsServ $pax;
  2052.                             $subnetoUnit $subneto;
  2053.                             $subneto $subneto $days $unitsServ $pax;
  2054.                             $data_supplier['service'][$i] = array(
  2055.                                 'id' => $item->getId(),
  2056.                                 'serviceCatId' => $item->getServiceCatId(),
  2057.                                 'serviceName' => $item->getName(),
  2058.                                 'serviceType' => 'DDR',
  2059.                                 'date' => $dateServ,
  2060.                                 'qty' => $unitsServ,
  2061.                                 'iva' => $item->getIva(),
  2062.                                 'pax' => $item->getPax(),
  2063.                                 'precioUnit' => $subnetoUnit,
  2064.                                 'subneto' => $subneto,
  2065.                                 'subtotal' => $subtotal,
  2066.                             );
  2067.                             break;
  2068.                         default:
  2069.                             break;
  2070.                     }
  2071.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2072.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  2073.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  2074.                     $arrayItems[] = array(
  2075.                         'type' => 'Service',
  2076.                         'name' => $item->getName(),
  2077.                         'amount' => $neto,
  2078.                         'iva' => $item->getIva(),
  2079.                         'total' => $subtotal,
  2080.                     );
  2081.                 }
  2082.                 switch ($item->getIva()) {
  2083.                     // Acumula IVA
  2084.                     case 21:
  2085.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  2086.                         break;
  2087.                     case 10:
  2088.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  2089.                         break;
  2090.                     case 0:
  2091.                         break;
  2092.                     default:
  2093.                         break;
  2094.                 }
  2095.             }
  2096.             $totales_neto_all $totales_neto_all $neto;
  2097.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2098.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  2099.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  2100.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  2101.             // Acumula netos totales e IVA
  2102.             $service['neto'] = $service['neto'] + $neto;
  2103.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  2104.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2105.             $service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
  2106.             $service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
  2107.             $i++;
  2108.         }
  2109.         $data_supplier['serviceSubTotal'] = array(
  2110.             'neto' => $service['neto'],
  2111.             'sumSubT' => $service['sumSubT'],
  2112.         );
  2113.         $currency '€';
  2114.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  2115.         if (!empty($payments)) {
  2116.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  2117.         } else {
  2118.             $amount_pay 0;
  2119.         }
  2120.         $totales_all $totales_total $amount_pay;
  2121.         if (empty($dateDocument)){
  2122.             $dateDocument = new DateTime('now');
  2123.         }
  2124.         $data = array(
  2125.             'id' => $fileId,
  2126.             'type' => $type,
  2127. //            'type' => '',
  2128.             'number' => $number,
  2129. //            'prefix' => $prefix,
  2130.             'prefix' => 'MDV-'.(new DateTime('now'))->format('dmy').'-'.$invoiceId,
  2131.             'date' => $dateDocument,
  2132.             'file' => $file,
  2133.             'token' => $file->getAccessKey(),
  2134.             'company' => $company,
  2135.             'clients' => $client,
  2136.             'arrayItems' => $arrayItems,
  2137.             'datasupplier' => $data_supplier,
  2138.             'currency' => $currency,
  2139.             'totales_neto' => $totales_neto_all,
  2140.             'bases_imponibles' => $data_iva,
  2141.             'totales' => $totales_total,
  2142.             'balance' => $totales_all,
  2143.             'paymentInvoice' => $amount_pay,
  2144.         );
  2145.         return $data;
  2146.     }
  2147.     // Replicar cambios entre FileController y ProductsFilesController
  2148.     private function calculosFile($id$arrayBools$number$type)
  2149.     {
  2150.         // $id Id del Expediente (File)
  2151.         // $arrayBool arreglo de logicos
  2152.         // $number  *********************
  2153.         // $type tipo de calculos a realizar (edicion de expediente, factura, factura de deposito, proforma)
  2154.         $em $this->getDoctrine()->getManager();
  2155.         $file $em->getRepository(MdvFiles::class)->findOneById($id);
  2156.         $items $em->getRepository(MdvProductFile::class)->findByFileId($file->getId());
  2157.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
  2158.         $client $em->getRepository(Client::class)->findById($file->getClient());
  2159.         if (!empty($client)){
  2160.             $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2161.             $client[0]->setPopulation($city);
  2162.             $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2163.             $client[0]->setRegion($region);
  2164.             $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2165.             $client[0]->setCountry($country);
  2166.         } else {
  2167.             $client[0] = new Client();
  2168.             $client[0]->setName('');
  2169.             $client[0]->setTitle('');
  2170.             $client[0]->setIdDocument('');
  2171.             $client[0]->setPopulation('');
  2172.             $client[0]->setRegion('');
  2173.             $client[0]->setCountry('');
  2174.         }
  2175.         // Acumuladores de los calculos
  2176.         $totales_neto_all 0;
  2177.         $data_iva = array(
  2178.             'iva' => 21,
  2179.             'ivaMontoVeintiUno' => 0,
  2180.             'ivaMontoDiez' => 0,
  2181.             'ivaMontoCero' => 0,
  2182.         );
  2183.         //INICIO: Determinamos el numero de factura o proforma
  2184.         if (substr($number,0,1) == 'I'){
  2185.             // Es una Factura
  2186.             $numberInvoiceOrProforma substr($number,1);
  2187.             $number $numberInvoiceOrProforma;
  2188. //            $number = $em->getRepository('DevelupBundle:FileInvoice')->findOneById($number);
  2189. //            $number = $number->getNumber();
  2190.             $type 'Invoice';
  2191.         } else {
  2192.             // Es una Proforma
  2193.             $numberInvoiceOrProforma substr($number,1);
  2194.             $number $numberInvoiceOrProforma;
  2195. //            $number = $em->getRepository('DevelupBundle:FileProforma')->findOneById($number);
  2196. //            $number = $number->getPrefix().$number->getReservationId();
  2197.             $type 'Proforma';
  2198.         }
  2199.         //FIN: Determinamos el numero de factura o proforma
  2200.         // Buscamos las salas reservadas, pagos y servicios para el evento
  2201.         $arrayItems = array();
  2202.         $fileProducts = array();
  2203.         if (!empty($arrayBools['lounge'])) {
  2204.             foreach ($arrayBools['lounge'] as $key => $item) {
  2205.                 if ($item == 'true') {
  2206. //                    $fileProducts[] = $em->getRepository('DevelupBundle:ReservationLoungeSimple')->findOneById($key);
  2207.                 }
  2208.             }
  2209.         }
  2210.         $payments = array();
  2211.         if (!empty($arrayBools['payment'])) {
  2212.             foreach ($arrayBools['payment'] as $key => $item) {
  2213.                 if ($item == 'true') {
  2214. //                    $payments[] = $em->getRepository('DevelupBundle:ReservationPaymentsClient')->findOneById($key);
  2215.                 }
  2216.             }
  2217.         }
  2218.         $services = array();
  2219.         if (!empty($arrayBools['service'])) {
  2220.             foreach ($arrayBools['service'] as $key => $item) {
  2221.                 if ($item == 'true') {
  2222. //                    $services[] = $em->getRepository('DevelupBundle:ReservationService')->findOneById($key);
  2223.                 }
  2224.             }
  2225.         }
  2226.         $data_supplier = array();
  2227.         $i 0;
  2228.         $iva '21';            // Esteban Rincon: "Por Ley de localización del impuesto, siempre será un 21%"
  2229.         $pax '-';
  2230.         $qty '1';
  2231.         $product = array(
  2232.             'neto' => 0,
  2233.             'sumSubT' => 0,
  2234.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  2235.         $service = array(
  2236.             'neto' => 0,
  2237.             'sumSubT' => 0,
  2238.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  2239.         if (empty($items)){
  2240.             $data_supplier['product'][0] = null;
  2241.         }
  2242.         foreach ($items as $item){
  2243.             $days '1';
  2244.             if (!empty($item->getUnits())){
  2245.                 $qty $item->getUnits();
  2246.             }
  2247.             if (!empty($item->getDays())){
  2248.                 $days $item->getDays();
  2249.             }
  2250.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
  2251.                 $subtotal 0;
  2252.                 $neto 0;
  2253.                 $subtotalProduct 0;
  2254.             } else {
  2255. //                $subtotalProduct = $item->getServicePrice() * 1.21;
  2256.                 $subtotalProduct $item->getSubTotalPrice() * 1.21;
  2257. //                $subneto = $item->getServicePrice();
  2258.                 $subneto $item->getSubTotalPrice();
  2259.                 $subtotal =  $subtotalProduct;
  2260.                 $neto =  $subneto;
  2261.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2262.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  2263.                 $neto round($neto,2,PHP_ROUND_HALF_UP);
  2264.                 $arrayItems[] = array(
  2265.                     'type' => 'Product',
  2266.                     'name' => $item->getProductName(),
  2267.                     'amount' => $neto,
  2268.                     'iva' => '21',
  2269.                     'total' => $subtotal,
  2270.                 );
  2271.             }
  2272.             // Acumula netos totales e IVA
  2273.             $totales_neto_all $totales_neto_all $neto;
  2274.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  2275.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2276.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  2277.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  2278.             // Acumula netos totales e IVA
  2279.             $product['neto'] = $product['neto'] + $neto;
  2280.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  2281.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2282.             $product['neto'] = round($product['neto'],2,PHP_ROUND_HALF_UP);
  2283.             $product['sumSubT'] = round($product['sumSubT'],2,PHP_ROUND_HALF_UP);
  2284.             $data_supplier['product'][$i] = array (
  2285.                 'id' => $item->getId(),
  2286.                 'productName' => $item->getProductName(),
  2287.                 'description' => $item->getDescription(),
  2288.                 'productId' => $item->getProductId(),
  2289.                 'dateStart' => $item->getDateStart(),
  2290.                 'dateEnd' => $item->getDateEnd(),
  2291.                 'servicePrice' => $item->getServicePrice(),
  2292.                 'subTotalPrice' => $item->getSubTotalPrice(),
  2293.                 'subtotalProduct' => $subtotalProduct,
  2294.                 'iva' => $iva,
  2295.                 'pax' => $pax,
  2296.                 'qty' => $qty,
  2297.                 'days' => $days,
  2298.                 'type' => $item->getType(),
  2299.                 'subtotal' => $subtotal,
  2300.             );
  2301.             $i++;
  2302.         }
  2303.         $data_supplier['productSubTotal'] = array(
  2304.             'neto' => $product['neto'],
  2305.             'sumSubT' => $product['sumSubT'],
  2306.         );
  2307.         $payment = array(
  2308.             'sumSubT' => 0,
  2309.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  2310.         $i 0;
  2311.         foreach ($payments as $item){
  2312.             $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  2313.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2314.             $payment['sumSubT'] = round($payment['sumSubT'],2,PHP_ROUND_HALF_UP);
  2315.             $data_supplier['payment'][$i] = array (
  2316.                 'id' => $item->getId(),
  2317.                 'amount' => $item->getAmount(),
  2318.                 'amountTotal' => $item->getAmountTotal(),
  2319.                 'vat' => $item->getVat(),
  2320.                 'datePayAt' => $item->getDatePayAt(),
  2321.                 'wayToPay' => $item->getWayToPay(),
  2322.             );
  2323.             $arrayItems[] = array(
  2324.                 'type' => 'Payment',
  2325.                 'name' => $item->getWayToPay(),
  2326.                 'amount' => $item->getAmount(),
  2327.                 'total' => $item->getAmountTotal(),
  2328.                 'iva' => $item->getVat(),
  2329. //                    'iva' => '',
  2330. //                    'total' => $item->getAmount(),
  2331.             );
  2332.             $i++;
  2333.         }
  2334.         if (!empty($payments)) {
  2335.             $data_supplier['paymentSubTotal'] = array(
  2336.                 'sumSubT' => $payment['sumSubT'],
  2337.             );
  2338.         }
  2339.         foreach ($services as $item){
  2340.             if (is_null($item->getPrice()) or empty($item->getPrice())){
  2341.                 $subtotal 0;
  2342.                 $neto 0;
  2343.                 $subtotalService 0;
  2344.             } else {
  2345.                 $subtotalService $item->getPrice();
  2346.                 $subneto $item->getPrice();
  2347.                 // Commission
  2348.                 if ($item->getOpCommission()=='1'){
  2349.                     $subtotalService $subtotalService * (+ ($item->getCommission()/100));
  2350.                     $subneto $subneto  * (+ ($item->getCommission()/100));
  2351.                 } else {
  2352.                     $subtotalService $subtotalService * (- ($item->getCommission()/100));
  2353.                     $subneto $subneto * (- ($item->getCommission()/100));
  2354.                 }
  2355.                 // Over
  2356.                 if ($item->getOpOver()=='1'){
  2357.                     $subtotalService $subtotalService $item->getOver();
  2358.                     $subneto $subneto $item->getOver();
  2359.                 } else {
  2360.                     $subtotalService $subtotalService $item->getOver();
  2361.                     $subneto $subneto $item->getOver();
  2362.                 }
  2363.                 // IVA
  2364.                 if ($item->getOpIva()=='1'){
  2365.                     $subtotalService $subtotalService * (+ ($item->getIva()/100));
  2366.                 } else {
  2367.                     $subtotalService $item->getPrice();
  2368.                     $subneto = ($subneto 100) / (100 $item->getIva());
  2369.                 }
  2370.                 switch ($item->getServiceCatId()){
  2371.                     case 1// Alojamiento
  2372.                         // el numero de noches $numNoches; precio unitario $subneto
  2373.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  2374.                         // La personas no afectan este calculo
  2375.                         $subtotal $subtotalService $numNoches $item->getUnits();
  2376.                         $subnetoUnit $subneto;
  2377.                         $subneto $subneto $numNoches $item->getUnits();
  2378.                         $data_supplier['service'][$i] = array (
  2379.                             'id' => $item->getId(),
  2380.                             'serviceCatId' => $item->getServiceCatId(),
  2381.                             'serviceName' => $item->getName(),
  2382.                             'serviceType' => 'Hotel',
  2383.                             'date' => ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y'),
  2384.                             'qty' => $item->getUnits(),
  2385.                             'iva' => $item->getIva(),
  2386.                             'pax' => '-',
  2387.                             'precioUnit' => $subnetoUnit,
  2388.                             'subneto' => $subneto,
  2389.                             'subtotal' => $subtotal,
  2390.                         );
  2391.                         break;
  2392.                     case 2//Actividades
  2393.                         // El número de personas es considerado en el calculo
  2394.                         $pax $item->getPax();
  2395.                         if (empty($pax) or $pax == "0") {
  2396.                             $pax 1;
  2397.                         }
  2398.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2399.                         if ($days 1){
  2400.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2401.                         } else {
  2402.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2403.                         }
  2404.                         $subtotal $subtotalService $days $item->getUnits();
  2405.                         $subnetoUnit $subneto;
  2406.                         $subneto $subneto $days $item->getUnits();
  2407.                         $data_supplier['service'][$i] = array (
  2408.                             'id' => $item->getId(),
  2409.                             'serviceCatId' => $item->getServiceCatId(),
  2410.                             'serviceName' => $item->getName(),
  2411.                             'serviceType' => 'Actividad',
  2412.                             'date' => $dateServ,
  2413.                             'qty' => $item->getUnits(),
  2414.                             'iva' => $item->getIva(),
  2415.                             'pax' => $item->getPax(),
  2416.                             'precioUnit' => $subnetoUnit,
  2417.                             'subneto' => $subneto,
  2418.                             'subtotal' => $subtotal,
  2419.                         );
  2420.                         break;
  2421.                     case 3// AV
  2422.                         $pax $item->getPax();
  2423.                         if (empty($pax) or $pax == "0") {
  2424.                             $pax 1;
  2425.                         }
  2426.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2427.                         if ($days 1){
  2428.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2429.                         } else {
  2430.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2431.                         }
  2432.                         $unitsServ $item->getUnits();
  2433.                         if (empty($unitsServ) or $unitsServ == "0") {
  2434.                             $unitsServ 1;
  2435.                         }
  2436.                         $subtotal $subtotalService $days $unitsServ $pax;
  2437.                         $subnetoUnit $subneto;
  2438.                         $subneto $subneto $days $unitsServ $pax;
  2439.                         $data_supplier['service'][$i] = array (
  2440.                             'id' => $item->getId(),
  2441.                             'serviceCatId' => $item->getServiceCatId(),
  2442.                             'serviceName' => $item->getName(),
  2443.                             'serviceType' => 'AV',
  2444.                             'date' => $dateServ,
  2445.                             'qty' => $unitsServ,
  2446.                             'iva' => $item->getIva(),
  2447.                             'pax' => $item->getPax(),
  2448.                             'precioUnit' => $subnetoUnit,
  2449.                             'subneto' => $subneto,
  2450.                             'subtotal' => $subtotal,
  2451.                         );
  2452.                         break;
  2453.                     case 4//Creative
  2454.                         $pax $item->getPax();
  2455.                         if (empty($pax) or $pax == "0") {
  2456.                             $pax 1;
  2457.                         }
  2458.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2459.                         if ($days 1){
  2460.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2461.                         } else {
  2462.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2463.                         }
  2464.                         $unitsServ $item->getUnits();
  2465.                         if (empty($unitsServ) or $unitsServ == "0") {
  2466.                             $unitsServ 1;
  2467.                         }
  2468.                         $subtotal $subtotalService $days $unitsServ $pax;
  2469.                         $subnetoUnit $subneto;
  2470.                         $subneto $subneto $days $unitsServ $pax;
  2471.                         $data_supplier['service'][$i] = array (
  2472.                             'id' => $item->getId(),
  2473.                             'serviceCatId' => $item->getServiceCatId(),
  2474.                             'serviceName' => $item->getName(),
  2475.                             'serviceType' => 'Creativo',
  2476.                             'date' => $dateServ,
  2477.                             'qty' => $unitsServ,
  2478.                             'iva' => $item->getIva(),
  2479.                             'pax' => $item->getPax(),
  2480.                             'precioUnit' => $subnetoUnit,
  2481.                             'subneto' => $subneto,
  2482.                             'subtotal' => $subtotal,
  2483.                         );
  2484.                         break;
  2485.                     case 5//Cruise
  2486.                         $pax $item->getPax();
  2487.                         if (empty($pax) or $pax == "0") {
  2488.                             $pax 1;
  2489.                         }
  2490.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  2491.                         if ($days 1){
  2492.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2493.                         } else {
  2494.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2495.                         }
  2496.                         $unitsServ $item->getUnits();
  2497.                         if (empty($unitsServ) or $unitsServ == "0") {
  2498.                             $unitsServ 1;
  2499.                         }
  2500.                         $subtotal $subtotalService $days $unitsServ $pax;
  2501.                         $subnetoUnit $subneto;
  2502.                         $subneto $subneto $days $unitsServ $pax;
  2503.                         $data_supplier['service'][$i] = array (
  2504.                             'id' => $item->getId(),
  2505.                             'serviceCatId' => $item->getServiceCatId(),
  2506.                             'serviceName' => $item->getName(),
  2507.                             'serviceType' => 'Crucero',
  2508.                             'date' => $dateServ,
  2509.                             'qty' => $unitsServ,
  2510.                             'iva' => $item->getIva(),
  2511.                             'pax' => $item->getPax(),
  2512.                             'precioUnit' => $subnetoUnit,
  2513.                             'subneto' => $subneto,
  2514.                             'subtotal' => $subtotal,
  2515.                         );
  2516.                         break;
  2517.                     case 6//Entertaiment
  2518.                         $pax $item->getPax();
  2519.                         if (empty($pax) or $pax == "0") {
  2520.                             $pax 1;
  2521.                         }
  2522.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2523.                         if ($days 1){
  2524.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2525.                         } else {
  2526.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2527.                         }
  2528.                         $unitsServ $item->getUnits();
  2529.                         if (empty($unitsServ) or $unitsServ == "0") {
  2530.                             $unitsServ 1;
  2531.                         }
  2532.                         $subtotal $subtotalService $days $unitsServ $pax;
  2533.                         $subnetoUnit $subneto;
  2534.                         $subneto $subneto $days $unitsServ $pax;
  2535.                         $data_supplier['service'][$i] = array (
  2536.                             'id' => $item->getId(),
  2537.                             'serviceCatId' => $item->getServiceCatId(),
  2538.                             'serviceName' => $item->getName(),
  2539.                             'serviceType' => 'Entretenimiento',
  2540.                             'date' => $dateServ,
  2541.                             'qty' => $unitsServ,
  2542.                             'iva' => $item->getIva(),
  2543.                             'pax' => $item->getPax(),
  2544.                             'precioUnit' => $subnetoUnit,
  2545.                             'subneto' => $subneto,
  2546.                             'subtotal' => $subtotal,
  2547.                         );
  2548.                         break;
  2549.                     case 7// Gifts
  2550.                         $pax $item->getPax();
  2551.                         if (empty($pax) or $pax == "0") {
  2552.                             $pax 1;
  2553.                         }
  2554. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  2555.                         $days 1;
  2556.                         if ($days 1){
  2557.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2558.                         } else {
  2559.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2560.                         }
  2561.                         $unitsServ $item->getUnits();
  2562.                         if (empty($unitsServ) or $unitsServ == "0") {
  2563.                             $unitsServ 1;
  2564.                         }
  2565.                         $subtotal $subtotalService $days $unitsServ $pax;
  2566.                         $subnetoUnit $subneto;
  2567.                         $subneto $subneto $days $unitsServ $pax;
  2568.                         $data_supplier['service'][$i] = array (
  2569.                             'id' => $item->getId(),
  2570.                             'serviceCatId' => $item->getServiceCatId(),
  2571.                             'serviceName' => $item->getName(),
  2572.                             'serviceType' => 'Regalos',
  2573.                             'date' => $dateServ,
  2574.                             'qty' => $unitsServ,
  2575.                             'iva' => $item->getIva(),
  2576.                             'pax' => $item->getPax(),
  2577.                             'precioUnit' => $subnetoUnit,
  2578.                             'subneto' => $subneto,
  2579.                             'subtotal' => $subtotal,
  2580.                         );
  2581.                         break;
  2582.                     case 8//Guide
  2583.                         $pax $item->getPax();
  2584.                         if (empty($pax) or $pax == "0") {
  2585.                             $pax 1;
  2586.                         }
  2587.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2588.                         if ($days 1){
  2589.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2590.                         } else {
  2591.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2592.                         }
  2593.                         $unitsServ $item->getUnits();
  2594.                         if (empty($unitsServ) or $unitsServ == "0") {
  2595.                             $unitsServ 1;
  2596.                         }
  2597.                         $subtotal $subtotalService $days $unitsServ $pax;
  2598.                         $subnetoUnit $subneto;
  2599.                         $subneto $subneto $days $unitsServ $pax;
  2600.                         $data_supplier['service'][$i] = array (
  2601.                             'id' => $item->getId(),
  2602.                             'serviceCatId' => $item->getServiceCatId(),
  2603.                             'serviceName' => $item->getName(),
  2604.                             'serviceType' => 'Regalos',
  2605.                             'date' => $dateServ,
  2606.                             'qty' => $unitsServ,
  2607.                             'iva' => $item->getIva(),
  2608.                             'pax' => $item->getPax(),
  2609.                             'precioUnit' => $subnetoUnit,
  2610.                             'subneto' => $subneto,
  2611.                             'subtotal' => $subtotal,
  2612.                         );
  2613.                         break;
  2614.                     case 9//Itineraries
  2615.                         $pax $item->getPax();
  2616.                         if (empty($pax) or $pax == "0") {
  2617.                             $pax 1;
  2618.                         }
  2619.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2620.                         if ($days 1){
  2621.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2622.                         } else {
  2623.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2624.                         }
  2625.                         $unitsServ $item->getUnits();
  2626.                         if (empty($unitsServ) or $unitsServ == "0") {
  2627.                             $unitsServ 1;
  2628.                         }
  2629.                         $subtotal $subtotalService $days $unitsServ $pax;
  2630.                         $subnetoUnit $subneto;
  2631.                         $subneto $subneto $days $unitsServ $pax;
  2632.                         $data_supplier['service'][$i] = array (
  2633.                             'id' => $item->getId(),
  2634.                             'serviceCatId' => $item->getServiceCatId(),
  2635.                             'serviceName' => $item->getName(),
  2636.                             'serviceType' => 'Itinerarios',
  2637.                             'date' => $dateServ,
  2638.                             'qty' => $unitsServ,
  2639.                             'iva' => $item->getIva(),
  2640.                             'pax' => $item->getPax(),
  2641.                             'precioUnit' => $subnetoUnit,
  2642.                             'subneto' => $subneto,
  2643.                             'subtotal' => $subtotal,
  2644.                         );
  2645.                         break;
  2646.                     case 10//Lounge  -- No Aplica
  2647. //                        $pax = $item->getPax();
  2648. //                        if (empty($pax) or $pax == "0") {
  2649. //                            $pax = 1;
  2650. //                        }
  2651. //
  2652. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  2653. //                        if ($days > 1){
  2654. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2655. //                        } else {
  2656. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2657. //                        }
  2658. //
  2659. //                        $unitsServ = $item->getUnits();
  2660. //                        if (empty($unitsServ) or $unitsServ == "0") {
  2661. //                            $unitsServ = 1;
  2662. //                        }
  2663. //
  2664. //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  2665. //                        $subnetoUnit = $subneto;
  2666. //                        $subneto = $subneto * $days * $unitsServ * $pax;
  2667. //
  2668. //                        $data_supplier['service'][$i] = array (
  2669. //                            'id' => $item->getId(),
  2670. //                            'serviceCatId' => $item->getServiceCatId(),
  2671. //                            'serviceName' => $item->getName(),
  2672. //                            'serviceType' => 'Itinerarios',
  2673. //                            'date' => $dateServ,
  2674. //                            'qty' => $unitsServ,
  2675. //                            'iva' => $item->getIva(),
  2676. //                            'pax' => $item->getPax(),
  2677. //                            'precioUnit' => $subnetoUnit,
  2678. //                            'subneto' => $subneto,
  2679. //                            'subtotal' => $subtotal,
  2680. //                        );
  2681.                         break;
  2682.                     case 11//Menu
  2683.                         $pax $item->getPax();
  2684.                         if (empty($pax) or $pax == "0") {
  2685.                             $pax 1;
  2686.                         }
  2687.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2688.                         if ($days 1){
  2689.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2690.                         } else {
  2691.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2692.                         }
  2693.                         $unitsServ $item->getUnits();
  2694.                         if (empty($unitsServ) or $unitsServ == "0") {
  2695.                             $unitsServ 1;
  2696.                         }
  2697.                         $subtotal $subtotalService $days $unitsServ $pax;
  2698.                         $subnetoUnit $subneto;
  2699.                         $subneto $subneto $days $unitsServ $pax;
  2700.                         $data_supplier['service'][$i] = array (
  2701.                             'id' => $item->getId(),
  2702.                             'serviceCatId' => $item->getServiceCatId(),
  2703.                             'serviceName' => $item->getName(),
  2704.                             'serviceType' => 'Menú',
  2705.                             'date' => $dateServ,
  2706.                             'qty' => $unitsServ,
  2707.                             'iva' => $item->getIva(),
  2708.                             'pax' => $item->getPax(),
  2709.                             'precioUnit' => $subnetoUnit,
  2710.                             'subneto' => $subneto,
  2711.                             'subtotal' => $subtotal,
  2712.                         );
  2713.                         break;
  2714.                     case 12//Others
  2715.                         $pax $item->getPax();
  2716.                         if (empty($pax) or $pax == "0") {
  2717.                             $pax 1;
  2718.                         }
  2719.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2720.                         if ($days 1){
  2721.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2722.                         } else {
  2723.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2724.                         }
  2725.                         $unitsServ $item->getUnits();
  2726.                         if (empty($unitsServ) or $unitsServ == "0") {
  2727.                             $unitsServ 1;
  2728.                         }
  2729.                         $subtotal $subtotalService $days $unitsServ $pax;
  2730.                         $subnetoUnit $subneto;
  2731.                         $subneto $subneto $days $unitsServ $pax;
  2732.                         $data_supplier['service'][$i] = array (
  2733.                             'id' => $item->getId(),
  2734.                             'serviceCatId' => $item->getServiceCatId(),
  2735.                             'serviceName' => $item->getName(),
  2736.                             'serviceType' => 'Otros',
  2737.                             'date' => $dateServ,
  2738.                             'qty' => $unitsServ,
  2739.                             'iva' => $item->getIva(),
  2740.                             'pax' => $item->getPax(),
  2741.                             'precioUnit' => $subnetoUnit,
  2742.                             'subneto' => $subneto,
  2743.                             'subtotal' => $subtotal,
  2744.                         );
  2745.                         break;
  2746.                     case 13//Transport
  2747.                         $pax $item->getPax();
  2748.                         if (empty($pax) or $pax == "0") {
  2749.                             $pax 1;
  2750.                         }
  2751.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2752.                         if ($days 1){
  2753.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2754.                         } else {
  2755.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2756.                         }
  2757.                         $unitsServ $item->getUnits();
  2758.                         if (empty($unitsServ) or $unitsServ == "0") {
  2759.                             $unitsServ 1;
  2760.                         }
  2761.                         $subtotal $subtotalService $days $unitsServ $pax;
  2762.                         $subnetoUnit $subneto;
  2763.                         $subneto $subneto $days $unitsServ $pax;
  2764.                         $data_supplier['service'][$i] = array (
  2765.                             'id' => $item->getId(),
  2766.                             'serviceCatId' => $item->getServiceCatId(),
  2767.                             'serviceName' => $item->getName(),
  2768.                             'serviceType' => 'Transporte',
  2769.                             'date' => $dateServ,
  2770.                             'qty' => $unitsServ,
  2771.                             'iva' => $item->getIva(),
  2772.                             'pax' => $item->getPax(),
  2773.                             'precioUnit' => $subnetoUnit,
  2774.                             'subneto' => $subneto,
  2775.                             'subtotal' => $subtotal,
  2776.                         );
  2777.                         break;
  2778.                     case 14//Technology
  2779.                         $pax $item->getPax();
  2780.                         if (empty($pax) or $pax == "0") {
  2781.                             $pax 1;
  2782.                         }
  2783. //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  2784.                         $days 1;
  2785. //                        if ($days > 1){
  2786. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2787. //                        } else {
  2788. //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2789. //                        }
  2790.                         $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2791.                         $unitsServ $item->getUnits();
  2792.                         if (empty($unitsServ) or $unitsServ == "0") {
  2793.                             $unitsServ 1;
  2794.                         }
  2795.                         $subtotal $subtotalService $days $unitsServ $pax;
  2796.                         $subnetoUnit $subneto;
  2797.                         $subneto $subneto $days $unitsServ $pax;
  2798.                         $data_supplier['service'][$i] = array (
  2799.                             'id' => $item->getId(),
  2800.                             'serviceCatId' => $item->getServiceCatId(),
  2801.                             'serviceName' => $item->getName(),
  2802.                             'serviceType' => 'Tecnología',
  2803.                             'date' => $dateServ,
  2804.                             'qty' => $unitsServ,
  2805.                             'iva' => $item->getIva(),
  2806.                             'pax' => $item->getPax(),
  2807.                             'precioUnit' => $subnetoUnit,
  2808.                             'subneto' => $subneto,
  2809.                             'subtotal' => $subtotal,
  2810.                         );
  2811.                         break;
  2812.                     case 15//Assisstant
  2813.                         $pax $item->getPax();
  2814.                         if (empty($pax) or $pax == "0") {
  2815.                             $pax 1;
  2816.                         }
  2817.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2818.                         if ($days 1){
  2819.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2820.                         } else {
  2821.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2822.                         }
  2823.                         $unitsServ $item->getUnits();
  2824.                         if (empty($unitsServ) or $unitsServ == "0") {
  2825.                             $unitsServ 1;
  2826.                         }
  2827.                         $subtotal $subtotalService $days $unitsServ $pax;
  2828.                         $subnetoUnit $subneto;
  2829.                         $subneto $subneto $days $unitsServ $pax;
  2830.                         $data_supplier['service'][$i] = array (
  2831.                             'id' => $item->getId(),
  2832.                             'serviceCatId' => $item->getServiceCatId(),
  2833.                             'serviceName' => $item->getName(),
  2834.                             'serviceType' => 'Asistente',
  2835.                             'date' => $dateServ,
  2836.                             'qty' => $unitsServ,
  2837.                             'iva' => $item->getIva(),
  2838.                             'pax' => $item->getPax(),
  2839.                             'precioUnit' => $subnetoUnit,
  2840.                             'subneto' => $subneto,
  2841.                             'subtotal' => $subtotal,
  2842.                         );
  2843.                         break;
  2844.                     case 16//DDR
  2845.                         $pax $item->getPax();
  2846.                         if (empty($pax) or $pax == "0") {
  2847.                             $pax 1;
  2848.                         }
  2849.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  2850.                         if ($days 1){
  2851.                             $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  2852.                         } else {
  2853.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  2854.                         }
  2855.                         $unitsServ $item->getUnits();
  2856.                         if (empty($unitsServ) or $unitsServ == "0") {
  2857.                             $unitsServ 1;
  2858.                         }
  2859.                         $subtotal $subtotalService $days $unitsServ $pax;
  2860.                         $subnetoUnit $subneto;
  2861.                         $subneto $subneto $days $unitsServ $pax;
  2862.                         $data_supplier['service'][$i] = array (
  2863.                             'id' => $item->getId(),
  2864.                             'serviceCatId' => $item->getServiceCatId(),
  2865.                             'serviceName' => $item->getName(),
  2866.                             'serviceType' => 'DDR',
  2867.                             'date' => $dateServ,
  2868.                             'qty' => $unitsServ,
  2869.                             'iva' => $item->getIva(),
  2870.                             'pax' => $item->getPax(),
  2871.                             'precioUnit' => $subnetoUnit,
  2872.                             'subneto' => $subneto,
  2873.                             'subtotal' => $subtotal,
  2874.                         );
  2875.                         break;
  2876.                     default:
  2877.                         break;
  2878.                 }
  2879.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2880.                 $subtotal round($subtotal,2,PHP_ROUND_HALF_UP);
  2881.                 $neto round($subneto,2,PHP_ROUND_HALF_UP);
  2882.                 $arrayItems[] = array(
  2883.                     'type' => 'Service',
  2884.                     'name' => $item->getName(),
  2885.                     'amount' => $neto,
  2886.                     'iva' => $item->getIva(),
  2887.                     'total' => $subtotal,
  2888.                 );
  2889.             }
  2890.             switch ($item->getIva()){
  2891.                 // Acumula IVA
  2892.                 case 21:
  2893.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva()/100));
  2894.                     break;
  2895.                 case 10:
  2896.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva()/100));
  2897.                     break;
  2898.                 case 0:
  2899.                     break;
  2900.                 default:
  2901.                     break;
  2902.             }
  2903.             $totales_neto_all $totales_neto_all $neto;
  2904.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2905.             $totales_neto_all round($totales_neto_all,2,PHP_ROUND_HALF_UP);
  2906.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
  2907.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
  2908.             // Acumula netos totales e IVA
  2909.             $service['neto'] = $service['neto'] + $neto;
  2910.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  2911.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  2912.             $service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
  2913.             $service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
  2914.             $i++;
  2915.         }
  2916.         $data_supplier['serviceSubTotal'] = array(
  2917.             'neto' => $service['neto'],
  2918.             'sumSubT' => $service['sumSubT'],
  2919.         );
  2920.         $currency '€';
  2921.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  2922.         if (!empty($payments)) {
  2923.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  2924.         } else {
  2925.             $amount_pay 0;
  2926.         }
  2927.         $totales_all $totales_total $amount_pay;
  2928.         if ($type == 'Invoice'){
  2929.             $em->clear();   // sin este clear se producia error al guardar
  2930.             $newInvoice $em->getRepository(MdvDocInvoice::class)->findOneById($numberInvoiceOrProforma);
  2931.             $newInvoice->setBalance($totales_all);
  2932.             $em->persist($newInvoice);
  2933.             $em->flush();
  2934.         }
  2935.         $data = array(
  2936.             'id' => $id,
  2937.             'type' => $type,
  2938.             'number' => $number,
  2939.             'prefix' => 'MDV-'.(new DateTime('now'))->format('dmy').'-',
  2940.             'date' => new DateTime('now'),
  2941.             'file' => $file,
  2942. //            'token' => $reservation->getAccessKey(),
  2943.             'company' => $company,
  2944.             'clients' => $client,
  2945.             'arrayItems' => $arrayItems,
  2946.             'datasupplier' => $data_supplier,
  2947.             'currency' => $currency,
  2948.             'totales_neto' => $totales_neto_all,
  2949.             'bases_imponibles' => $data_iva,
  2950.             'totales' => $totales_total,
  2951.             'balance' => $totales_all,
  2952.             'paymentInvoice' => $amount_pay,
  2953.         );
  2954.         return $data;
  2955.     }
  2956.     private function sendTelegram $id$text )
  2957.     {
  2958.         $em $this->getDoctrine()->getManager();
  2959.         $telegUser $em->getRepository(MdvTelegramUser::class)->findOneByUserId($id);
  2960.         if (empty($telegUser)){return true;}
  2961.         $parameters = array(
  2962.             'chat_id' => $telegUser->getChatId(),
  2963.             'text' => $text,
  2964.         );
  2965.         $bot_token $telegUser->getBotToken();
  2966.         $url "https://api.telegram.org/bot$bot_token/sendMessage";
  2967.         if (!$curl curl_init()){
  2968.             exit();
  2969.         }
  2970.         curl_setopt($curl,CURLOPT_POST,true);
  2971.         curl_setopt($curl,CURLOPT_POSTFIELDS,$parameters);
  2972.         curl_setopt($curl,CURLOPT_URL,$url);
  2973.         curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  2974.         $output curl_exec($curl);
  2975.         curl_close($curl);
  2976.         return true;
  2977.     }
  2978. };