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

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