src/MDS/AvexpressBundle/Controller/InvoiceController.php line 3025

Open in your IDE?
  1. <?php
  2. namespace App\MDS\AvexpressBundle\Controller;
  3. use App\Entity\Cities;
  4. use App\Entity\Supplier;
  5. use App\MDS\AvexpressBundle\Entity\AveBenefitsPermissions;
  6. use App\MDS\AvexpressBundle\Entity\AveBenefitsInvoiceInvoiceRec;
  7. use App\MDS\GreenPatioBundle\Entity\Reservation;
  8. use App\MDS\GreenPatioBundle\Entity\ReservationInvoice;
  9. use App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice;
  10. use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice;
  11. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems;
  12. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRec;
  13. use App\Service\CommissionEnterprisesService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use DateTime;
  19. use App\MDS\AvexpressBundle\Entity\AveFiles;
  20. use App\MDS\AvexpressBundle\Entity\AveProductFile;
  21. use App\MDS\AvexpressBundle\Entity\AvePaymentsClient;
  22. use App\MDS\AvexpressBundle\Entity\AveDocProformaDeposit;
  23. use App\MDS\AvexpressBundle\Entity\AveDocInvoice;
  24. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRec;
  25. use App\MDS\AvexpressBundle\Entity\AveDocProformaItems;
  26. use App\MDS\AvexpressBundle\Entity\AveDocProforma;
  27. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceItems;
  28. use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRecItems;
  29. use App\MDS\AvexpressBundle\Entity\AveBudgetToProforma;
  30. use App\Entity\Client;
  31. use App\Entity\Configuration;
  32. use App\Entity\Country;
  33. use App\Entity\Regions;
  34. use App\Entity\SettingsCompany;
  35. use App\Entity\User;
  36. use App\MDS\AvexpressBundle\Entity\AveBenefitsSupplier;
  37. use App\MDS\AvexpressBundle\Entity\AveBriefings;
  38. use App\MDS\AvexpressBundle\Entity\AveBudgetPending;
  39. use App\MDS\AvexpressBundle\Entity\AveProduct;
  40. use App\MDS\AvexpressBundle\Entity\AveServices;
  41. use App\MDS\AvexpressBundle\Entity\AveTemplateItems;
  42. use App\MDS\DevelupBundle\Entity\MdvDocProformaItems;
  43. use App\MDS\DevelupBundle\Entity\MdvTelegramUser;
  44. use App\MDS\EventsBundle\Entity\ProposalAgents;
  45. use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
  46. use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRecItems;
  47. use Swift_Mailer;
  48. use Swift_Message;
  49. use Swift_SmtpTransport;
  50. class InvoiceController extends AbstractController
  51. {
  52.     private $commisionEnterpriseService;
  53.     public function __construct(CommissionEnterprisesService $commisionEnterpriseService)
  54.     {
  55.         $this->commisionEnterpriseService $commisionEnterpriseService;
  56.     }
  57.     /**
  58.      * @Route("/listpaydep/{id}",  name="ave_list_payments_deposits")
  59.      * Listar pagos y depositos de un expediente
  60.      */
  61.     public function listPaymentsDespositsAction($idRequest $request)
  62.     {
  63.         $em $this->getDoctrine()->getManager();
  64.         $paymentsInFile $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  65.         $proformaDepositsInFile $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  66.         $proformas = array();
  67.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($id);
  68.         foreach ($allProformas as $item) {
  69.             $data $this->baseInvoiceDoneFileTwo($id$item->getId(), 'P');
  70.             $bases 0;
  71.             if (is_numeric($data['totales']) and is_numeric($data['totales_neto'])) {
  72.                 $bases $data['totales'] - $data['totales_neto'];
  73.             }
  74.             $proformas[] = array(
  75.                 'id' => $data['number'],
  76.                 'date' => $data['date'],
  77.                 'neto' => $data['totales_neto'],
  78.                 'bases_imponibles' => $bases,
  79.                 'total' => $data['totales'],
  80.             );
  81.         }
  82.         return $this->render(
  83.             'MDS/AvexpressBundle/Avexpress/list-payments-deposits.html.twig',
  84.             array(
  85.                 'id' => $id,
  86.                 'proformas' => $proformas,
  87.                 'payments' => $paymentsInFile,
  88.                 'allInvoiceDeposit' => null,
  89.                 'proformaDepositsInFile' => $proformaDepositsInFile,
  90.             )
  91.         );
  92.     }
  93.     /**
  94.      * @Route("/paymentadd/{id}",  name="ave_add_payment")
  95.      * Agregar pago a un expediente
  96.      */
  97.     public function addPaymentsAction($idRequest $request)
  98.     {
  99.         $em $this->getDoctrine()->getManager();
  100.         $newRequest $request->request->get('invoicepay');
  101.         /* Obtengo usuario logueado */
  102.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  103.         $user_id $user_logueado->getId();
  104.         if (!empty($newRequest['amount']) and !empty($newRequest['datePayAt']) and !empty($newRequest['wayToPay'])) {
  105.             if (is_numeric($newRequest['amount'])) {
  106.                 $pay = new AvePaymentsClient();
  107.                 $pay->setAmount($newRequest['amount']);
  108.                 $pay->setConcept($newRequest['concept']);
  109.                 $pay->setDatePayAt(new \DateTime($newRequest['datePayAt']));
  110.                 $pay->setWayToPay($newRequest['wayToPay']);
  111.                 $pay->setFileId($id);
  112.                 $pay->setUpdatedId($user_id);
  113.                 $pay->setUpdatedAt(new \DateTime("now"));
  114.                 $pay->setCreatedId($user_id);
  115.                 $pay->setCreatedAt(new \DateTime("now"));
  116.                 $em->persist($pay);
  117.                 $em->flush();
  118.             }
  119.         }
  120.         return $this->redirectToRoute(
  121.             'ave_list_payments_deposits',
  122.             array(
  123.                 'id' => $id
  124.             )
  125.         );
  126.     }
  127.     /**
  128.      * @Route("/paymentdelete/{id}",  name="ave_delete_payment")
  129.      * Eliminar pago de un expediente
  130.      */
  131.     public function deletePaymentsAction($idRequest $request)
  132.     {
  133.         $em $this->getDoctrine()->getManager();
  134.         $payment $em->getRepository(AvePaymentsClient::class)->findOneById($id);
  135.         $fileId $payment->getFileId();
  136.         $em->remove($payment);
  137.         $em->flush();
  138.         return $this->redirectToRoute(
  139.             'ave_list_payments_deposits',
  140.             array(
  141.                 'id' => $fileId
  142.             )
  143.         );
  144.     }
  145.     /**
  146.      * @Route("/newproformadeposit/{id}",  name="ave_new_proforma_deposit")
  147.      * Crear nueva proforma de deposito en un expediente
  148.      */
  149.     public function newProformaDepositAction($idRequest $request)
  150.     {
  151.         $em $this->getDoctrine()->getManager();
  152.         $newRequest $request->request->get('invoicedep');
  153.         /* Obtengo usuario logueado */
  154.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  155.         $user_id $user_logueado->getId();
  156.         $proforma = new AveDocProformaDeposit();
  157.         if (!empty($newRequest['amount']) and !empty($newRequest['name']) and !empty($newRequest['iva'])) {
  158.             if (is_numeric($newRequest['amount']) and is_numeric($newRequest['iva'])) {
  159.                 $proforma->setAmount($newRequest['amount']);
  160.                 $proforma->setName($newRequest['name']);
  161.                 $proforma->setFileId($id);
  162.                 $proforma->setIva($newRequest['iva']);
  163.                 $proforma->setTotal($newRequest['amount'] + ($newRequest['amount'] * ($newRequest['iva'] / 100)));
  164.                 $proforma->setUpdatedId($user_id);
  165.                 $proforma->setUpdatedAt(new \DateTime("now"));
  166.                 $proforma->setCreatedId($user_id);
  167.                 $proforma->setCreatedAt(new \DateTime("now"));
  168.                 $em->persist($proforma);
  169.                 $em->flush();
  170.             }
  171.         } else {
  172.             // Falta algun dato
  173.             return $this->redirectToRoute('ave_list_payments_deposits', array('id' => $id));
  174.         }
  175.         return $this->redirectToRoute(
  176.             'ave_view_proforma_deposit',
  177.             array(
  178.                 'id' => $proforma->getId()
  179.             )
  180.         );
  181.     }
  182.     /**
  183.      * @Route("/viewproformadeposit/{id}",  name="ave_view_proforma_deposit")
  184.      * Ver una proforma de deposito
  185.      */
  186.     public function viewProformaDepositAction($idRequest $request)
  187.     {
  188.         $docType 'Proforma de Deposito';
  189.         $em $this->getDoctrine()->getManager();
  190.         $proforma =  $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
  191.         $id $proforma->getFileId();
  192.         /* Obtengo usuario logueado */
  193.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  194.         $user_id $user_logueado->getId();
  195.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  196.         // Buscamos el cliente
  197.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  198.         $client $em->getRepository(Client::class)->findById($file->getClient());
  199.         if (empty($client)) {
  200.             $client[0] = new Client();
  201.             $client[0]->setName('');
  202.             $client[0]->setTitle('');
  203.             $client[0]->setIdDocument('');
  204.             $client[0]->setPopulation('');
  205.             $client[0]->setRegion('');
  206.             $client[0]->setCountry('');
  207.         } else {
  208.             if (is_numeric($client[0]->getPopulation())) {
  209.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  210. //                $client[0]->setPopulation($city->getCity());
  211.             }
  212.             if (is_numeric($client[0]->getRegion())) {
  213.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  214. //                $client[0]->setRegion($region->getRegion());
  215.             }
  216.             if (is_numeric($client[0]->getCountry())) {
  217.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  218. //                $client[0]->setCountry($country->getCountry());
  219.             }
  220.         }
  221.         if (empty($client)) {
  222.             $client[0] = new Client();
  223.             $client[0]->setName('');
  224.             $client[0]->setTitle('');
  225.             $client[0]->setIdDocument('');
  226.             $client[0]->setPopulation('');
  227.             $client[0]->setRegion('');
  228.             $client[0]->setCountry('');
  229.             $clientNew = array(
  230.                 'name' => '',
  231.                 'title' => '',
  232.                 'idDocument' => '',
  233.                 'population' => '',
  234.                 'region' => '',
  235.                 'country' => '',
  236.                 'address' => '',
  237.                 'addressNumber' => '',
  238.                 'zipCode' => '',
  239.                 'typeDocument' => '',
  240.             );
  241.         } else {
  242.             $clientNew = array(
  243.                 'name' => $client[0]->getName(),
  244.                 'title' => $client[0]->getTitle(),
  245.                 'idDocument' => $client[0]->getIdDocument(),
  246.                 'population' => '',
  247.                 'region' => '',
  248.                 'country' => '',
  249.                 'address' => $client[0]->getAddress(),
  250.                 'addressNumber' => $client[0]->getAddressNumber(),
  251.                 'zipCode' => $client[0]->getZipCode(),
  252.                 'typeDocument' => $client[0]->getTypeDocument(),
  253.             );
  254.             if (is_numeric($client[0]->getPopulation())) {
  255.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  256.                 $clientNew['population'] = $city->getCity();
  257.             }
  258.             if (is_numeric($client[0]->getRegion())) {
  259.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  260.                 $clientNew['region'] = $region->getRegion();
  261.             }
  262.             if (is_numeric($client[0]->getCountry())) {
  263.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  264.                 $clientNew['country'] = $country->getCountry();
  265.             }
  266.         }
  267.         // Buscamos el cliente
  268.         $bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
  269.         $allProformas =  $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  270.         // Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito  //6*6*6
  271.         $commentsBool false;
  272.         $comments null;
  273.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  274.         if ($fileAv->getCommentsInPro()) {
  275.             $commentsBool true;
  276.         }
  277.         if ($commentsBool) {
  278.             $comments $fileAv->getComments();
  279.         }
  280.         // Obtengo usuario logueado
  281.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  282.         $user_id $user_logueado->getId();
  283.         return $this->render(
  284.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  285.             array(
  286.                 'id' => $id,
  287.                 'docType' => $docType,
  288.                 'proforma' => $proforma,
  289.                 'company' => $company,
  290.                 'clients' => $clientNew,
  291.                 'date' => $proforma->getCreatedAt(),
  292.                 'number' => $proforma->getId(),
  293.                 'invoice' => null,
  294.                 'fid' => $proforma->getId(),
  295.                 'boolToRec' => false,
  296.                 'proformas' => $allProformas,
  297.                 'currency' => '€',
  298.                 'totales_neto' => $proforma->getAmount(),
  299.                 'totales' => $proforma->getTotal(),
  300.                 'balance' => $proforma->getTotal(),
  301.                 'bases_imponibles' => $bases_imponibles,
  302.                 'file' => $fileAv,
  303.                 'user' => $user_logueado,
  304.                 'services' => null,
  305.                 'facturas' => null,
  306.                 'paymentNotIvoiced' => null,
  307.                 'paymentsAll' => null,
  308.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  309.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  310.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  311.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  312.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  313.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  314.                 'comments' => $comments,
  315.             )
  316.         );
  317.     }
  318.     /**
  319.      * @Route("/avexternal/printproformadeposit/{id}",  name="ave_print_proforma_deposit")
  320.      * Imprimir una proforma de deposito
  321.      */
  322.     public function printProformaDepositAction($idRequest $request)
  323.     {
  324.         $docType 'Proforma de Deposito';
  325.         $em $this->getDoctrine()->getManager();
  326.         $proforma =  $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
  327.         $id $proforma->getFileId();
  328.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  329.         // Buscamos el cliente
  330.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  331.         $client $em->getRepository(Client::class)->findById($file->getClient());
  332.         if (empty($client)) {
  333.             $client[0] = new Client();
  334.             $client[0]->setName('');
  335.             $client[0]->setTitle('');
  336.             $client[0]->setIdDocument('');
  337.             $client[0]->setPopulation('');
  338.             $client[0]->setRegion('');
  339.             $client[0]->setCountry('');
  340.         } else {
  341.             if (is_numeric($client[0]->getPopulation())) {
  342.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  343. //                $client[0]->setPopulation($city->getCity());
  344.             }
  345.             if (is_numeric($client[0]->getRegion())) {
  346.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  347. //                $client[0]->setRegion($region->getRegion());
  348.             }
  349.             if (is_numeric($client[0]->getCountry())) {
  350.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  351. //                $client[0]->setCountry($country->getCountry());
  352.             }
  353.         }
  354.         if (empty($client)) {
  355.             $client[0] = new Client();
  356.             $client[0]->setName('');
  357.             $client[0]->setTitle('');
  358.             $client[0]->setIdDocument('');
  359.             $client[0]->setPopulation('');
  360.             $client[0]->setRegion('');
  361.             $client[0]->setCountry('');
  362.             $clientNew = array(
  363.                 'name' => '',
  364.                 'title' => '',
  365.                 'idDocument' => '',
  366.                 'population' => '',
  367.                 'region' => '',
  368.                 'country' => '',
  369.                 'address' => '',
  370.                 'addressNumber' => '',
  371.                 'zipCode' => '',
  372.                 'typeDocument' => '',
  373.             );
  374.         } else {
  375.             $clientNew = array(
  376.                 'name' => $client[0]->getName(),
  377.                 'title' => $client[0]->getTitle(),
  378.                 'idDocument' => $client[0]->getIdDocument(),
  379.                 'population' => '',
  380.                 'region' => '',
  381.                 'country' => '',
  382.                 'address' => $client[0]->getAddress(),
  383.                 'addressNumber' => $client[0]->getAddressNumber(),
  384.                 'zipCode' => $client[0]->getZipCode(),
  385.                 'typeDocument' => $client[0]->getTypeDocument(),
  386.             );
  387.             if (is_numeric($client[0]->getPopulation())) {
  388.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  389.                 $clientNew['population'] = $city->getCity();
  390.             }
  391.             if (is_numeric($client[0]->getRegion())) {
  392.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  393.                 $clientNew['region'] = $region->getRegion();
  394.             }
  395.             if (is_numeric($client[0]->getCountry())) {
  396.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  397.                 $clientNew['country'] = $country->getCountry();
  398.             }
  399.         }
  400.         // Buscamos el cliente
  401.         $bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
  402.         $allProformas =  $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  403.         // Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito  //6*6*6
  404.         $commentsBool false;
  405.         $comments null;
  406.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  407.         if ($fileAv->getCommentsInPro()) {
  408.             $commentsBool true;
  409.         }
  410.         if ($commentsBool) {
  411.             $comments $fileAv->getComments();
  412.         }
  413.         return $this->render(
  414.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  415.             array(
  416.                 'id' => $id,
  417.                 'docType' => $docType,
  418.                 'proforma' => $proforma,
  419.                 'company' => $company,
  420.                 'clients' => $clientNew,
  421.                 'date' => $proforma->getCreatedAt(),
  422.                 'number' => $proforma->getId(),
  423.                 'invoice' => null,
  424.                 'fid' => $proforma->getId(),
  425.                 'boolToRec' => false,
  426.                 'proformas' => $allProformas,
  427.                 'currency' => '€',
  428.                 'totales_neto' => $proforma->getAmount(),
  429.                 'totales' => $proforma->getTotal(),
  430.                 'balance' => $proforma->getTotal(),
  431.                 'bases_imponibles' => $bases_imponibles,
  432.                 'comments' => $comments,
  433.                 'file' => $fileAv,
  434.                 'services' => null,
  435.                 'facturas' => null,
  436.                 'paymentNotIvoiced' => null,
  437.                 'paymentsAll' => null,
  438.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  439.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  440.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  441.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  442.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  443.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  444.             )
  445.         );
  446.     }
  447.     /**
  448.      * @Route("/newinvoicedeposit/{id}",  name="ave_new_invoice_deposit")
  449.      * Crear nueva factura de deposito en un expediente
  450.      */
  451.     public function newInvoiceDepositAction($idRequest $request)
  452.     {
  453.         $docType 'Factura de Deposito';
  454.         $em $this->getDoctrine()->getManager();
  455.         $proforma =  $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
  456.         $id $proforma->getFileId();
  457.         /* Obtengo usuario logueado */
  458.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  459.         $user_id $user_logueado->getId();
  460.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  461.         // Buscamos el cliente
  462.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  463.         $client $em->getRepository(Client::class)->findById($file->getClient());
  464.         if (empty($client)) {
  465.             $client[0] = new Client();
  466.             $client[0]->setName('');
  467.             $client[0]->setTitle('');
  468.             $client[0]->setIdDocument('');
  469.             $client[0]->setPopulation('');
  470.             $client[0]->setRegion('');
  471.             $client[0]->setCountry('');
  472.         }
  473.         // Buscamos el cliente
  474.         // Generamos la factura con la proforma especificada
  475.         $invoice = new AveDocInvoice();
  476.         $invoice->setAccessKey(md5(rand() * time()));
  477.         $invoice->setFileId($proforma->getFileId());
  478.         $invoice->setDateAt(new \DateTime("now"));
  479.         $invoice->setName($proforma->getName());
  480.         $invoice->setTotalNet($proforma->getAmount());
  481.         $invoice->setIva($proforma->getIva());
  482.         $invoice->setVat(($proforma->getAmount() * $proforma->getIva()) / 100);
  483.         $totalInv $invoice->getTotalNet() + $invoice->getVat();
  484.         $invoice->setTotal($totalInv);
  485.         $invoice->setMaster(null);
  486.         $invoice->setNumber(null);
  487.         $invoice->setPrefix(null);
  488.         $invoice->setBalance($totalInv * (-1));
  489.         $invoice->setType('Factura de Deposito');
  490.         $invoice->setUpdatedId($user_id);
  491.         $invoice->setUpdatedAt(new \DateTime("now"));
  492.         $invoice->setCreatedId($user_id);
  493.         $invoice->setCreatedAt(new \DateTime("now"));
  494.         $em->persist($invoice);
  495.         $em->flush();
  496.         $bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
  497.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  498.         $allProformas null;
  499.         // Una factura solo se puede rectificar una vez
  500.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
  501.         $boolToRec = empty($rectf);
  502.         return $this->redirectToRoute(
  503.             'ave_view_invoice_deposit',
  504.             array(
  505.                 'id' => $invoice->getId()
  506.             )
  507.         );
  508.     }
  509.     /**
  510.      * @Route("/viewinvoicedeposit/{id}",  name="ave_view_invoice_deposit")
  511.      * Ver una factura de deposito en un expediente
  512.      */
  513.     public function viewInvoiceDepositAction($idRequest $request)
  514.     {
  515.         $docType 'Factura de Deposito';
  516.         $em $this->getDoctrine()->getManager();
  517.         $invoice =  $em->getRepository(AveDocInvoice::class)->findOneById($id);
  518.         $id $invoice->getFileId();
  519.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  520.         // Buscamos el cliente
  521.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  522.         $client $em->getRepository(Client::class)->findById($file->getClient());
  523.         if (empty($client)) {
  524.             $client[0] = new Client();
  525.             $client[0]->setName('');
  526.             $client[0]->setTitle('');
  527.             $client[0]->setIdDocument('');
  528.             $client[0]->setPopulation('');
  529.             $client[0]->setRegion('');
  530.             $client[0]->setCountry('');
  531.         } else {
  532.             if (is_numeric($client[0]->getPopulation())) {
  533.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  534. //                $client[0]->setPopulation($city->getCity());
  535.             }
  536.             if (is_numeric($client[0]->getRegion())) {
  537.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  538. //                $client[0]->setRegion($region->getRegion());
  539.             }
  540.             if (is_numeric($client[0]->getCountry())) {
  541.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  542. //                $client[0]->setCountry($country->getCountry());
  543.             }
  544.         }
  545.         if (empty($client)) {
  546.             $client[0] = new Client();
  547.             $client[0]->setName('');
  548.             $client[0]->setTitle('');
  549.             $client[0]->setIdDocument('');
  550.             $client[0]->setPopulation('');
  551.             $client[0]->setRegion('');
  552.             $client[0]->setCountry('');
  553.             $clientNew = array(
  554.                 'name' => '',
  555.                 'title' => '',
  556.                 'idDocument' => '',
  557.                 'population' => '',
  558.                 'region' => '',
  559.                 'country' => '',
  560.                 'address' => '',
  561.                 'addressNumber' => '',
  562.                 'zipCode' => '',
  563.                 'typeDocument' => '',
  564.             );
  565.         } else {
  566.             $clientNew = array(
  567.                 'name' => $client[0]->getName(),
  568.                 'title' => $client[0]->getTitle(),
  569.                 'idDocument' => $client[0]->getIdDocument(),
  570.                 'population' => '',
  571.                 'region' => '',
  572.                 'country' => '',
  573.                 'address' => $client[0]->getAddress(),
  574.                 'addressNumber' => $client[0]->getAddressNumber(),
  575.                 'zipCode' => $client[0]->getZipCode(),
  576.                 'typeDocument' => $client[0]->getTypeDocument(),
  577.             );
  578.             if (is_numeric($client[0]->getPopulation())) {
  579.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  580.                 $clientNew['population'] = $city->getCity();
  581.             }
  582.             if (is_numeric($client[0]->getRegion())) {
  583.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  584.                 $clientNew['region'] = $region->getRegion();
  585.             }
  586.             if (is_numeric($client[0]->getCountry())) {
  587.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  588.                 $clientNew['country'] = $country->getCountry();
  589.             }
  590.         }
  591.         // Buscamos el cliente
  592.         // Obtengo usuario logueado
  593.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  594.         $user_id $user_logueado->getId();
  595.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  596.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  597.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
  598.         foreach ($allInvoicesRec as $item) {
  599.             array_push($allInvoices$item);
  600.         }
  601.         $allProformas null;
  602.         // Una factura solo se puede rectificar una vez
  603.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
  604.         $boolToRec = empty($rectf);
  605.         $commentsBool false;
  606.         $comments null;
  607.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  608.         if ($fileAv->getCommentsInInv()) {
  609.             $commentsBool true;
  610.         }
  611.         if ($commentsBool) {
  612.             $comments $fileAv->getComments();
  613.         }
  614.         return $this->render(
  615.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  616.             array(
  617.                 'id' => $id,
  618.                 'docType' => $docType,
  619.                 'proforma' => null,
  620.                 'company' => $company,
  621.                 'clients' => $clientNew,
  622.                 'file' => $file,
  623.                 'date' => $invoice->getDateAt(),
  624.                 'number' => $invoice->getId(),
  625.                 'invoice' => $invoice,
  626.                 'fid' => $invoice->getId(),
  627.                 'boolToRec' => $boolToRec,
  628.                 'proformas' => $allProformas,
  629.                 'facturas' => $allInvoices,
  630.                 'currency' => '€',
  631.                 'user' => $user_logueado,
  632.                 'totales_neto' => $invoice->getTotalNet(),
  633.                 'totales' => $invoice->getTotal(),
  634.                 'balance' => $invoice->getTotal(),
  635.                 'bases_imponibles' => $bases_imponibles,
  636.                 'services' => null,
  637.                 //                'facturas' => null,
  638.                 'paymentNotIvoiced' => null,
  639.                 'paymentsAll' => null,
  640.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  641.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  642.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  643.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  644.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  645.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  646.                 'comments' => $comments,
  647.             )
  648.         );
  649.     }
  650.     /**
  651.      * @Route("/avexternal/printinvoicedeposit/{id}",  name="ave_print_invoice_deposit")
  652.      * Imprimir una factura de deposito
  653.      */
  654.     public function printInvoiceDepositAction($idRequest $request)
  655.     {
  656.         $docType 'Factura de Deposito';
  657.         $em $this->getDoctrine()->getManager();
  658.         $invoice =  $em->getRepository(AveDocInvoice::class)->findOneById($id);
  659.         $id $invoice->getFileId();
  660.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  661.         // Buscamos el cliente
  662.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  663.         $client $em->getRepository(Client::class)->findById($file->getClient());
  664.         if (empty($client)) {
  665.             $client[0] = new Client();
  666.             $client[0]->setName('');
  667.             $client[0]->setTitle('');
  668.             $client[0]->setIdDocument('');
  669.             $client[0]->setPopulation('');
  670.             $client[0]->setRegion('');
  671.             $client[0]->setCountry('');
  672.         } else {
  673.             if (is_numeric($client[0]->getPopulation())) {
  674.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  675. //                $client[0]->setPopulation($city->getCity());
  676.             }
  677.             if (is_numeric($client[0]->getRegion())) {
  678.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  679. //                $client[0]->setRegion($region->getRegion());
  680.             }
  681.             if (is_numeric($client[0]->getCountry())) {
  682.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  683. //                $client[0]->setCountry($country->getCountry());
  684.             }
  685.         }
  686.         if (empty($client)) {
  687.             $client[0] = new Client();
  688.             $client[0]->setName('');
  689.             $client[0]->setTitle('');
  690.             $client[0]->setIdDocument('');
  691.             $client[0]->setPopulation('');
  692.             $client[0]->setRegion('');
  693.             $client[0]->setCountry('');
  694.             $clientNew = array(
  695.                 'name' => '',
  696.                 'title' => '',
  697.                 'idDocument' => '',
  698.                 'population' => '',
  699.                 'region' => '',
  700.                 'country' => '',
  701.                 'address' => '',
  702.                 'addressNumber' => '',
  703.                 'zipCode' => '',
  704.                 'typeDocument' => '',
  705.             );
  706.         } else {
  707.             $clientNew = array(
  708.                 'name' => $client[0]->getName(),
  709.                 'title' => $client[0]->getTitle(),
  710.                 'idDocument' => $client[0]->getIdDocument(),
  711.                 'population' => '',
  712.                 'region' => '',
  713.                 'country' => '',
  714.                 'address' => $client[0]->getAddress(),
  715.                 'addressNumber' => $client[0]->getAddressNumber(),
  716.                 'zipCode' => $client[0]->getZipCode(),
  717.                 'typeDocument' => $client[0]->getTypeDocument(),
  718.             );
  719.             if (is_numeric($client[0]->getPopulation())) {
  720.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  721.                 $clientNew['population'] = $city->getCity();
  722.             }
  723.             if (is_numeric($client[0]->getRegion())) {
  724.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  725.                 $clientNew['region'] = $region->getRegion();
  726.             }
  727.             if (is_numeric($client[0]->getCountry())) {
  728.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  729.                 $clientNew['country'] = $country->getCountry();
  730.             }
  731.         }
  732.         // Buscamos el cliente
  733.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  734.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  735.         $allProformas null;
  736.         // Una factura solo se puede rectificar una vez
  737.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
  738.         $boolToRec = empty($rectf);
  739.         $commentsBool false;
  740.         $comments null;
  741.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  742.         if ($fileAv->getCommentsInPro()) {
  743.             $commentsBool true;
  744.         }
  745.         if ($commentsBool) {
  746.             $comments $fileAv->getComments();
  747.         }
  748.         return $this->render(
  749.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  750.             array(
  751.                 'id' => $id,
  752.                 'docType' => $docType,
  753.                 'proforma' => null,
  754.                 'company' => $company,
  755.                 'clients' => $clientNew,
  756.                 'file' => $file,
  757.                 'date' => $invoice->getDateAt(),
  758.                 'number' => $invoice->getId(),
  759.                 'invoice' => $invoice,
  760.                 'fid' => $invoice->getId(),
  761.                 'boolToRec' => $boolToRec,
  762.                 'proformas' => $allProformas,
  763.                 'facturas' => $allInvoices,
  764.                 'currency' => '€',
  765.                 'totales_neto' => $invoice->getTotalNet(),
  766.                 'totales' => $invoice->getTotal(),
  767.                 'balance' => $invoice->getTotal(),
  768.                 'bases_imponibles' => $bases_imponibles,
  769.                 'services' => null,
  770.                 'paymentNotIvoiced' => null,
  771.                 'paymentsAll' => null,
  772.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  773.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  774.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  775.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  776.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  777.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  778.                 'comments' => $comments,
  779.             )
  780.         );
  781.     }
  782.     /**
  783.      * @Route("/newinvoicedepositrec/{id}",  name="ave_invoice_deposit_rec")
  784.      * Crear nueva factura rectificativa de deposito
  785.      */
  786.     public function newInvoiceDepositRecAction($idRequest $request)
  787.     {
  788.         $docType 'Factura Rectificativa de Deposito';
  789.         $em $this->getDoctrine()->getManager();
  790.          // Verificamos que no exista una factura rectificativa previa sobre la misma factura
  791.         $previusInvoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneByInvoiceToRec($id);
  792.         if (!empty($previusInvoiceRec)) {
  793.             return $this->redirectToRoute('ave_view_invoice_deposit_rec', array('id' => $previusInvoiceRec->getId()));
  794.         }
  795.         $invoice =  $em->getRepository(AveDocInvoice::class)->findOneById($id);
  796.         $id $invoice->getFileId();
  797.         /* Obtengo usuario logueado */
  798.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  799.         $user_id $user_logueado->getId();
  800.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  801.         // Buscamos el cliente
  802.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  803.         $client $em->getRepository(Client::class)->findById($file->getClient());
  804.         if (empty($client)) {
  805.             $client[0] = new Client();
  806.             $client[0]->setName('');
  807.             $client[0]->setTitle('');
  808.             $client[0]->setIdDocument('');
  809.             $client[0]->setPopulation('');
  810.             $client[0]->setRegion('');
  811.             $client[0]->setCountry('');
  812.         } else {
  813.             if (is_numeric($client[0]->getPopulation())) {
  814.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  815. //                $client[0]->setPopulation($city->getCity());
  816.             }
  817.             if (is_numeric($client[0]->getRegion())) {
  818.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  819. //                $client[0]->setRegion($region->getRegion());
  820.             }
  821.             if (is_numeric($client[0]->getCountry())) {
  822.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  823. //                $client[0]->setCountry($country->getCountry());
  824.             }
  825.         }
  826.         if (empty($client)) {
  827.             $client[0] = new Client();
  828.             $client[0]->setName('');
  829.             $client[0]->setTitle('');
  830.             $client[0]->setIdDocument('');
  831.             $client[0]->setPopulation('');
  832.             $client[0]->setRegion('');
  833.             $client[0]->setCountry('');
  834.             $clientNew = array(
  835.                 'name' => '',
  836.                 'title' => '',
  837.                 'idDocument' => '',
  838.                 'population' => '',
  839.                 'region' => '',
  840.                 'country' => '',
  841.                 'address' => '',
  842.                 'addressNumber' => '',
  843.                 'zipCode' => '',
  844.                 'typeDocument' => '',
  845.             );
  846.         } else {
  847.             $clientNew = array(
  848.                 'name' => $client[0]->getName(),
  849.                 'title' => $client[0]->getTitle(),
  850.                 'idDocument' => $client[0]->getIdDocument(),
  851.                 'population' => '',
  852.                 'region' => '',
  853.                 'country' => '',
  854.                 'address' => $client[0]->getAddress(),
  855.                 'addressNumber' => $client[0]->getAddressNumber(),
  856.                 'zipCode' => $client[0]->getZipCode(),
  857.                 'typeDocument' => $client[0]->getTypeDocument(),
  858.             );
  859.             if (is_numeric($client[0]->getPopulation())) {
  860.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  861.                 $clientNew['population'] = $city->getCity();
  862.             }
  863.             if (is_numeric($client[0]->getRegion())) {
  864.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  865.                 $clientNew['region'] = $region->getRegion();
  866.             }
  867.             if (is_numeric($client[0]->getCountry())) {
  868.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  869.                 $clientNew['country'] = $country->getCountry();
  870.             }
  871.         }
  872.         // Buscamos el cliente
  873.         // Generamos la factura con la proforma especificada
  874.         $invoiceRec = new AveDocInvoiceRec();
  875.         $invoiceRec->setFileId($invoice->getFileId());
  876.         $invoiceRec->setInvoiceToRec($invoice->getId());
  877.         $invoiceRec->setDateAt(new \DateTime("now"));
  878.         $invoiceRec->setName($invoice->getName());
  879.         $invoiceRec->setTotalNet($invoice->getTotalNet() * (-1));
  880.         $invoiceRec->setIva($invoice->getIva());
  881.         $invoiceRec->setVat((($invoice->getTotalNet() * $invoice->getIva()) / 100) * (-1));
  882.         $totalInv $invoice->getTotalNet() + $invoice->getVat();
  883.         $invoiceRec->setTotal($totalInv * (-1));
  884.         $invoiceRec->setMaster(null);
  885.         $invoiceRec->setNumber(null);
  886.         //        $invoiceRec->setPrefix(null);
  887.         $invoiceRec->setPrefix('R');
  888.         $invoiceRec->setBalance($totalInv);
  889.         $invoiceRec->setType('Factura Rectificativa de Deposito');
  890.         $invoiceRec->setUpdatedId($user_id);
  891.         $invoiceRec->setUpdatedAt(new \DateTime("now"));
  892.         $invoiceRec->setCreatedId($user_id);
  893.         $invoiceRec->setCreatedAt(new \DateTime("now"));
  894.         $em->persist($invoiceRec);
  895.         $em->flush();
  896.         return $this->redirectToRoute('ave_view_invoice_deposit_rec', array('id' => $invoiceRec->getId()));
  897.     }
  898.     /**
  899.      * @Route("/viewinvoicedepositrec/{id}",  name="ave_view_invoice_deposit_rec")
  900.      * Ver una factura rectificativa de deposito
  901.      */
  902.     public function viewInvoiceDepositRecAction($idRequest $request)
  903.     {
  904.         $docType 'Factura Rectificativa de Deposito';
  905.         $em $this->getDoctrine()->getManager();
  906.         $invoice =  $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  907.         $id $invoice->getFileId();
  908.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  909.         // Buscamos el cliente
  910.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  911.         $client $em->getRepository(Client::class)->findById($file->getClient());
  912.         if (empty($client)) {
  913.             $client[0] = new Client();
  914.             $client[0]->setName('');
  915.             $client[0]->setTitle('');
  916.             $client[0]->setIdDocument('');
  917.             $client[0]->setPopulation('');
  918.             $client[0]->setRegion('');
  919.             $client[0]->setCountry('');
  920.         } else {
  921.             if (is_numeric($client[0]->getPopulation())) {
  922.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  923. //                $client[0]->setPopulation($city->getCity());
  924.             }
  925.             if (is_numeric($client[0]->getRegion())) {
  926.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  927. //                $client[0]->setRegion($region->getRegion());
  928.             }
  929.             if (is_numeric($client[0]->getCountry())) {
  930.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  931. //                $client[0]->setCountry($country->getCountry());
  932.             }
  933.         }
  934.         if (empty($client)) {
  935.             $client[0] = new Client();
  936.             $client[0]->setName('');
  937.             $client[0]->setTitle('');
  938.             $client[0]->setIdDocument('');
  939.             $client[0]->setPopulation('');
  940.             $client[0]->setRegion('');
  941.             $client[0]->setCountry('');
  942.             $clientNew = array(
  943.                 'name' => '',
  944.                 'title' => '',
  945.                 'idDocument' => '',
  946.                 'population' => '',
  947.                 'region' => '',
  948.                 'country' => '',
  949.                 'address' => '',
  950.                 'addressNumber' => '',
  951.                 'zipCode' => '',
  952.                 'typeDocument' => '',
  953.             );
  954.         } else {
  955.             $clientNew = array(
  956.                 'name' => $client[0]->getName(),
  957.                 'title' => $client[0]->getTitle(),
  958.                 'idDocument' => $client[0]->getIdDocument(),
  959.                 'population' => '',
  960.                 'region' => '',
  961.                 'country' => '',
  962.                 'address' => $client[0]->getAddress(),
  963.                 'addressNumber' => $client[0]->getAddressNumber(),
  964.                 'zipCode' => $client[0]->getZipCode(),
  965.                 'typeDocument' => $client[0]->getTypeDocument(),
  966.             );
  967.             if (is_numeric($client[0]->getPopulation())) {
  968.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  969.                 $clientNew['population'] = $city->getCity();
  970.             }
  971.             if (is_numeric($client[0]->getRegion())) {
  972.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  973.                 $clientNew['region'] = $region->getRegion();
  974.             }
  975.             if (is_numeric($client[0]->getCountry())) {
  976.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  977.                 $clientNew['country'] = $country->getCountry();
  978.             }
  979.         }
  980.         // Buscamos el cliente
  981.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  982.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  983.         $allProformas null;
  984.         // Una factura solo se puede rectificar una vez
  985.         //        $rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
  986.         $boolToRec false;
  987.         $commentsBool false;
  988.         $comments null;
  989.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  990.         if ($fileAv->getCommentsInInv()) {
  991.             $commentsBool true;
  992.         }
  993.         if ($commentsBool) {
  994.             $comments $fileAv->getComments();
  995.         }
  996.         // Obtengo usuario logueado
  997.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  998.         $user_id $user_logueado->getId();
  999.         return $this->render(
  1000.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  1001.             array(
  1002.                 'id' => $id,
  1003.                 'docType' => $docType,
  1004.                 'proforma' => null,
  1005.                 'company' => $company,
  1006.                 'clients' => $clientNew,
  1007.                 'file' => $file,
  1008.                 'date' => $invoice->getDateAt(),
  1009.                 'number' => $invoice->getId(),
  1010.                 'invoice' => $invoice,
  1011.                 'fid' => $invoice->getId(),
  1012.                 'boolToRec' => $boolToRec,
  1013.                 'proformas' => $allProformas,
  1014.                 'facturas' => $allInvoices,
  1015.                 'currency' => '€',
  1016.                 'totales_neto' => $invoice->getTotalNet(),
  1017.                 'totales' => $invoice->getTotal(),
  1018.                 'balance' => $invoice->getTotal(),
  1019.                 'bases_imponibles' => $bases_imponibles,
  1020.                 'user' => $user_logueado,
  1021.                 'services' => null,
  1022.                 //                'facturas' => null,
  1023.                 'paymentNotIvoiced' => null,
  1024.                 'paymentsAll' => null,
  1025.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  1026.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  1027.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  1028.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  1029.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  1030.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  1031.                 'comments' => $comments,
  1032.             )
  1033.         );
  1034.     }
  1035.     /**
  1036.      * @Route("/avexternal/printinvoicedepositrec/{id}",  name="ave_print_invoice_deposit_rec")
  1037.      * Imprimir una factura rectificativa de deposito
  1038.      */
  1039.     public function printInvoiceDepositRecAction($idRequest $request)
  1040.     {
  1041.         $docType 'Factura Rectificativa de Deposito';
  1042.         $em $this->getDoctrine()->getManager();
  1043.         $invoice =  $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  1044.         $id $invoice->getFileId();
  1045.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  1046.         // Buscamos el cliente
  1047.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  1048.         $client $em->getRepository(Client::class)->findById($file->getClient());
  1049.         if (empty($client)) {
  1050.             $client[0] = new Client();
  1051.             $client[0]->setName('');
  1052.             $client[0]->setTitle('');
  1053.             $client[0]->setIdDocument('');
  1054.             $client[0]->setPopulation('');
  1055.             $client[0]->setRegion('');
  1056.             $client[0]->setCountry('');
  1057.         } else {
  1058.             if (is_numeric($client[0]->getPopulation())) {
  1059.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  1060. //                $client[0]->setPopulation($city->getCity());
  1061.             }
  1062.             if (is_numeric($client[0]->getRegion())) {
  1063.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  1064. //                $client[0]->setRegion($region->getRegion());
  1065.             }
  1066.             if (is_numeric($client[0]->getCountry())) {
  1067.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  1068. //                $client[0]->setCountry($country->getCountry());
  1069.             }
  1070.         }
  1071.         if (empty($client)) {
  1072.             $client[0] = new Client();
  1073.             $client[0]->setName('');
  1074.             $client[0]->setTitle('');
  1075.             $client[0]->setIdDocument('');
  1076.             $client[0]->setPopulation('');
  1077.             $client[0]->setRegion('');
  1078.             $client[0]->setCountry('');
  1079.             $clientNew = array(
  1080.                 'name' => '',
  1081.                 'title' => '',
  1082.                 'idDocument' => '',
  1083.                 'population' => '',
  1084.                 'region' => '',
  1085.                 'country' => '',
  1086.                 'address' => '',
  1087.                 'addressNumber' => '',
  1088.                 'zipCode' => '',
  1089.                 'typeDocument' => '',
  1090.             );
  1091.         } else {
  1092.             $clientNew = array(
  1093.                 'name' => $client[0]->getName(),
  1094.                 'title' => $client[0]->getTitle(),
  1095.                 'idDocument' => $client[0]->getIdDocument(),
  1096.                 'population' => '',
  1097.                 'region' => '',
  1098.                 'country' => '',
  1099.                 'address' => $client[0]->getAddress(),
  1100.                 'addressNumber' => $client[0]->getAddressNumber(),
  1101.                 'zipCode' => $client[0]->getZipCode(),
  1102.                 'typeDocument' => $client[0]->getTypeDocument(),
  1103.             );
  1104.             if (is_numeric($client[0]->getPopulation())) {
  1105.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  1106.                 $clientNew['population'] = $city->getCity();
  1107.             }
  1108.             if (is_numeric($client[0]->getRegion())) {
  1109.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  1110.                 $clientNew['region'] = $region->getRegion();
  1111.             }
  1112.             if (is_numeric($client[0]->getCountry())) {
  1113.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  1114.                 $clientNew['country'] = $country->getCountry();
  1115.             }
  1116.         }
  1117.         // Buscamos el cliente
  1118.         $bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
  1119.         $allInvoices =  $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  1120.         $allProformas null;
  1121.         // Una factura solo se puede rectificar una vez
  1122.         //        $rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
  1123.         $boolToRec false;
  1124.         $commentsBool false;
  1125.         $comments null;
  1126.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  1127.         if ($fileAv->getCommentsInPro()) {
  1128.             $commentsBool true;
  1129.         }
  1130.         if ($commentsBool) {
  1131.             $comments $fileAv->getComments();
  1132.         }
  1133.         return $this->render(
  1134.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  1135.             array(
  1136.                 'id' => $id,
  1137.                 'docType' => $docType,
  1138.                 'proforma' => null,
  1139.                 'company' => $company,
  1140.                 'clients' => $clientNew,
  1141.                 'file' => $file,
  1142.                 'date' => $invoice->getDateAt(),
  1143.                 'number' => $invoice->getId(),
  1144.                 'invoice' => $invoice,
  1145.                 'fid' => $invoice->getId(),
  1146.                 'boolToRec' => $boolToRec,
  1147.                 'proformas' => $allProformas,
  1148.                 'facturas' => $allInvoices,
  1149.                 'currency' => '€',
  1150.                 'totales_neto' => $invoice->getTotalNet(),
  1151.                 'totales' => $invoice->getTotal(),
  1152.                 'balance' => $invoice->getTotal(),
  1153.                 'bases_imponibles' => $bases_imponibles,
  1154.                 'services' => null,
  1155.                 'paymentNotIvoiced' => null,
  1156.                 'paymentsAll' => null,
  1157.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  1158.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  1159.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  1160.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  1161.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  1162.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  1163.                 'comments' => $comments,
  1164.             )
  1165.         );
  1166.     }
  1167.     /**
  1168.      * @Route("/selinvoice/{id}",  name="ave_select_invoice")
  1169.      * Seleccionar los items que pasaran a la proforma o factura
  1170.      */
  1171.     public function selectItemsInvoiceAction($idEntityManagerInterface $emRequest $request)
  1172.     {
  1173.         $paymentsClient = new AvePaymentsClient();
  1174.         $paymentsClient->setFileId($id);
  1175.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  1176.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  1177.         $allProformas $em->getRepository(AveDocProforma::class)->findAll();
  1178.         $number = (!empty($allProformas)) ? (end($allProformas)->getId() + 1) : 1;
  1179.         $type 'Proforma';
  1180.         $docType 'Proforma';
  1181.         $date = new DateTime('now');
  1182.         $prefix "AVE-" $date->format('dmy') . "-";
  1183.         $fileInv = new AveDocInvoice();
  1184.         $fileInv->setAccessKey(md5(rand() * time()));
  1185.         $fileInv->setFileId($id);
  1186.         $data $this->baseInvoiceFile($id$type$number$prefix$date);
  1187.         $token $data['token'];
  1188.         $idProducts = array();
  1189.         if (array_key_exists('product'$data['datasupplier'])) {
  1190.             foreach ($data['datasupplier']['product'] as $key => $item) {
  1191.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPrdControlId($item['id']);
  1192.                 if (empty($existe)) {
  1193.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = true;
  1194.                 } else {
  1195.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = false;
  1196.                 }
  1197.             }
  1198.         }
  1199.         if (array_key_exists('service'$data['datasupplier'])) {
  1200.             foreach ($data['datasupplier']['service'] as $key => $item) {
  1201.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneBySrvControlId($item['id']);
  1202.                 if (empty($existe)) {
  1203.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
  1204.                 } else {
  1205.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
  1206.                 }
  1207.             }
  1208.         }
  1209.         $idPayments = array();
  1210.         if (array_key_exists('payment'$data['datasupplier'])) {
  1211.             foreach ($data['datasupplier']['payment'] as $key => $item) {
  1212.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPayControlId($item['id']);
  1213.                 if (empty($existe)) {
  1214.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
  1215.                 } else {
  1216.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
  1217.                 }
  1218.             }
  1219.         }
  1220.         /* Obtengo usuario logueado */
  1221.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1222.         $user_id $user_logueado->getId();
  1223.         return $this->render(
  1224.             'MDS/AvexpressBundle/Avexpress/invoice-select-items.html.twig',
  1225.             array(
  1226.                 'id' => $id,
  1227.                 'idLounges' => $idProducts,
  1228.                 'file' => $file,
  1229.                 'idPayments' => $idPayments,
  1230.                 'type' => $data['type'],
  1231.                 'docType' => $docType,
  1232.                 'number' => $data['number'],
  1233.                 'prefix' => $data['prefix'],
  1234.                 'date' => $data['date'],
  1235.                 'token' => $token,
  1236.                 'company' => $data['company'],
  1237.                 'clients' => $data['clients'],
  1238.                 'datasupplier' => $data['datasupplier'],
  1239.                 'currency' => $data['currency'],
  1240.                 'totales_neto' => $data['totales_neto'],
  1241.                 'bases_imponibles' => $data['bases_imponibles'],
  1242.                 'totales' => $data['totales'],
  1243.                 'balance' => $data['balance'],
  1244.                 'paymentInvoice' => $data['paymentInvoice'],
  1245.                 'payments' => $payments,
  1246.                 'user_id' => $user_id,
  1247.             )
  1248.         );
  1249.     }
  1250.     /**
  1251.      * @Route("/selproforma/{id}",  name="ave_select_proforma")
  1252.      * Seleccionar los items que pasaran a la proforma o factura a partir de los datos de una proforma
  1253.      */
  1254.     public function selectItemsProformaAction($idRequest $request)
  1255.     {
  1256.         $em $this->getDoctrine()->getManager();
  1257.         //Se cambia el ID de proforma a ID file
  1258.         $proforma $em->getRepository(AveDocProforma::class)->findOneById($id);
  1259.         $id $proforma->getFileId();
  1260.         $proformaId $proforma->getId();
  1261.         $paymentsClient = new AvePaymentsClient();
  1262.         $paymentsClient->setFileId($id);
  1263.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  1264.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  1265.         $allProformas $em->getRepository(AveDocProforma::class)->findAll();
  1266.         if (!empty($allProformas)) {
  1267.             $number end($allProformas)->getId() + 1;
  1268.         } else {
  1269.             // Primer registro de proformas
  1270.             $number 1;
  1271.         }
  1272.         $type 'Proforma';
  1273.         $docType 'Proforma';
  1274.         $date = new DateTime('now');
  1275.         $prefix "AVE-" $date->format('dmy') . "-";
  1276.         $fileInv = new AveDocInvoice();
  1277.         $fileInv->setAccessKey(md5(rand() * time()));
  1278.         $fileInv->setFileId($id);
  1279.         $data $this->baseProformaSelect($id$type$number$prefix$date$proformaId);
  1280.         $token $data['token'];
  1281.         $idProducts = array();
  1282.         if (array_key_exists('product'$data['datasupplier'])) {
  1283.             foreach ($data['datasupplier']['product'] as $key => $item) {
  1284.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPrdControlId($item['id']);
  1285.                 if (empty($existe)) {
  1286.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = true;
  1287.                 } else {
  1288.                     $data['datasupplier']['product'][$key]['enabledToInvoice'] = false;
  1289.                 }
  1290.             }
  1291.         }
  1292.         if (array_key_exists('service'$data['datasupplier'])) {
  1293.             foreach ($data['datasupplier']['service'] as $key => $item) {
  1294.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneBySrvControlId($item['id']);
  1295.                 if (empty($existe)) {
  1296.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
  1297.                 } else {
  1298.                     $data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
  1299.                 }
  1300.             }
  1301.         }
  1302.         $idPayments = array();
  1303.         if (array_key_exists('payment'$data['datasupplier'])) {
  1304.             foreach ($data['datasupplier']['payment'] as $key => $item) {
  1305.                 $existe $em->getRepository(AveDocInvoiceItems::class)->findOneByPayControlId($item['id']);
  1306.                 if (empty($existe)) {
  1307.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
  1308.                 } else {
  1309.                     $data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
  1310.                 }
  1311.             }
  1312.         }
  1313.         /* Obtengo usuario logueado */
  1314.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1315.         $user_id $user_logueado->getId();
  1316.         return $this->render(
  1317.             'MDS/AvexpressBundle/Avexpress/invoice-select-items.html.twig',
  1318.             array(
  1319.                 'id' => $id,
  1320.                 'idLounges' => $idProducts,
  1321.                 'file' => $file,
  1322.                 'idPayments' => $idPayments,
  1323.                 'type' => $data['type'],
  1324.                 'docType' => $docType,
  1325.                 'number' => $data['number'],
  1326.                 'prefix' => $data['prefix'],
  1327.                 'date' => $data['date'],
  1328.                 'token' => $token,
  1329.                 'company' => $data['company'],
  1330.                 'clients' => $data['clients'],
  1331.                 'datasupplier' => $data['datasupplier'],
  1332.                 'currency' => $data['currency'],
  1333.                 'totales_neto' => $data['totales_neto'],
  1334.                 'bases_imponibles' => $data['bases_imponibles'],
  1335.                 'totales' => $data['totales'],
  1336.                 'balance' => $data['balance'],
  1337.                 'paymentInvoice' => $data['paymentInvoice'],
  1338.                 'payments' => $payments,
  1339.                 'user_id' => $user_id,
  1340.             )
  1341.         );
  1342.     }
  1343.     /**
  1344.      * @Route("/newmultiproforma/", name="ave_new_multi_proforma")
  1345.      * Crear nueva proforma con los elementos seleccionados y retornar al selector
  1346.      */
  1347.     public function generateNewMultiProformaAction(Request $request)
  1348.     {
  1349.         $em $this->getDoctrine()->getManager();
  1350.         // Se genera y muestra en nueva pantalla la nueva proforma
  1351.         $arrayBools = array(
  1352.             'product' => null,
  1353.             'service' => null,
  1354.             'payment' => null,
  1355.         );
  1356.         $arrayBools['product'] = $request->request->get('multi_lounge_hidden_bool');
  1357.         $arrayBools['service'] = $request->request->get('multi_service_hidden_bool');
  1358.         $arrayBools['payment'] = $request->request->get('multi_payment_hidden_bool');
  1359.         $id $request->request->get('multi_file_id');
  1360.         $proforma_number $request->request->get('multi_proforma_number');
  1361.         $proforma_prefix $request->request->get('multi_proforma_prefix') . $proforma_number '-' $id;
  1362.         //INICIO: buscamos el ID de la factura
  1363.         $boolMakeInvoice false;  // Control para verificar si se debe hacer (PROFORMA) o todos los indicadores (sala, servicios y pagos) estaban en falso
  1364.         //FIN: buscamos el ID de la factura
  1365.         /* Obtengo usuario logueado */
  1366.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1367.         $user_id $user_logueado->getId();
  1368.         //Acumuladores de datos globales de la factura
  1369.         $valorTotalNet 0;
  1370.         $valorVat 0;
  1371.         //INICIO: Creamos los items de la proforma
  1372.         if (!empty($arrayBools['product'])) {
  1373.             foreach ($arrayBools['product'] as $key => $item) {
  1374.                 if ($item == 'true') {
  1375.                     $boolMakeInvoice true;
  1376.                     $product $em->getRepository(AveProductFile::class)->findOneById($key);
  1377.                     $boolKeyChange false;
  1378.                     //INICIO: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  1379.                     // Si el producto esta contenido en una proforma debemos crear un nuevo porducto
  1380.                     $productInProforma $em->getRepository(AveDocProformaItems::class)->findOneByControlId($key);
  1381.                     if (!empty($productInProforma)) {
  1382.                         //INICIO: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  1383.                         $boolKeyChange true;
  1384.                         $newProductFile = new AveProductFile();
  1385.                         //INICIO: Duplicamos en Eventos
  1386.                         if (!empty($product->getOriginId())) {
  1387.                             $serviceEvent $em->getRepository(ProposalSupplierServices::class)->findOneById($product->getOriginId());
  1388.                             if (!empty($serviceEvent)) {
  1389.                                 $newServiceEvent = new ProposalSupplierServices();
  1390.                                 $newServiceEvent->setServiceIdFather($serviceEvent->getServiceIdFather());
  1391.                                 $newServiceEvent->setControlId($serviceEvent->getControlId());
  1392.                                 $newServiceEvent->setProposalId($serviceEvent->getProposalId());
  1393.                                 $newServiceEvent->setDestinationId($serviceEvent->getDestinationId());
  1394.                                 $newServiceEvent->setSupplierId($serviceEvent->getSupplierId());
  1395.                                 $newServiceEvent->setIdeaId($serviceEvent->getIdeaId());
  1396.                                 $newServiceEvent->setActivityId($serviceEvent->getActivityId());
  1397.                                 $newServiceEvent->setServiceId($serviceEvent->getServiceId());
  1398.                                 $newServiceEvent->setServiceCatId($serviceEvent->getServiceCatId());
  1399.                                 $newServiceEvent->setServiceCatName($serviceEvent->getServiceCatName());
  1400.                                 $newServiceEvent->setName($serviceEvent->getName());
  1401.                                 $newServiceEvent->setPrice($serviceEvent->getPrice());
  1402.                                 $newServiceEvent->setCurrency($serviceEvent->getCurrency());
  1403.                                 $newServiceEvent->setUnits($serviceEvent->getUnits());
  1404.                                 $newServiceEvent->setCommission($serviceEvent->getCommission());
  1405.                                 $newServiceEvent->setOver($serviceEvent->getOver());
  1406.                                 $newServiceEvent->setIva($serviceEvent->getIva());
  1407.                                 $newServiceEvent->setPax($serviceEvent->getPax());
  1408.                                 $newServiceEvent->setHour($serviceEvent->getHour());
  1409.                                 $newServiceEvent->setDateInAt($serviceEvent->getDateInAt());
  1410.                                 $newServiceEvent->setDateOutAt($serviceEvent->getDateOutAt());
  1411.                                 $newServiceEvent->setDirectPayment($serviceEvent->getDirectPayment());
  1412.                                 $newServiceEvent->setStatus($serviceEvent->getStatus());
  1413.                                 $newServiceEvent->setCreatedAt(new DateTime('now'));
  1414.                                 $newServiceEvent->setCreatedId($user_id);
  1415.                                 $newServiceEvent->setUpdatedAt(new DateTime('now'));
  1416.                                 $newServiceEvent->setUpdatedId($user_id);
  1417.                                 $newServiceEvent->setStatusinternal($serviceEvent->getStatusinternal());
  1418.                                 $newServiceEvent->setPreCommission($serviceEvent->getPreCommission());
  1419.                                 $newServiceEvent->setPreIva($serviceEvent->getPreIva());
  1420.                                 $newServiceEvent->setDateBlockLimit($serviceEvent->getDateBlockLimit());
  1421.                                 $newServiceEvent->setOpCommission($serviceEvent->getOpCommission());
  1422.                                 $newServiceEvent->setOpOver($serviceEvent->getOpOver());
  1423.                                 $newServiceEvent->setOpIva($serviceEvent->getOpIva());
  1424.                                 $newServiceEvent->setBreakdown($serviceEvent->getBreakdown());
  1425.                                 $newServiceEvent->setIsFather($serviceEvent->getIsFather());
  1426.                                 $newServiceEvent->setRank($serviceEvent->getRank());
  1427.                                 $newServiceEvent->setOriginalopIva($serviceEvent->getOriginalopIva());
  1428.                                 $newServiceEvent->setOriginalIva($serviceEvent->getOriginalIva());
  1429.                                 $newServiceEvent->setOriginalPrice($serviceEvent->getOriginalPrice());
  1430.                                 $newServiceEvent->setStatusRec($serviceEvent->getStatusRec());   //setStatusRecommended
  1431.                                 $newServiceEvent->setAssistantId($serviceEvent->getAssistantId());
  1432.                                 $em->persist($newServiceEvent);
  1433.                                 $em->flush();
  1434.                             }
  1435.                             if (!empty($serviceEvent)) {
  1436.                                 $newProductFile->setOriginId($newServiceEvent->getId());
  1437.                             } else {
  1438.                                 $newProductFile->setOriginId(null);
  1439.                             }
  1440.                         }
  1441.                         //FIN: Duplicamos en Eventos
  1442.                         //FIN: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  1443.                         $newProductFile->setProductName($product->getProductName());
  1444.                         $newProductFile->setProductId($product->getProductId());
  1445.                         $newProductFile->setDateStart($product->getDateStart());
  1446.                         $newProductFile->setDateEnd($product->getDateEnd());
  1447.                         $newProductFile->setServicePrice($product->getServicePrice());
  1448.                         $newProductFile->setFileId($product->getFileId());
  1449.                         $newProductFile->setPax($product->getPax());
  1450.                         $newProductFile->setType($product->getType());
  1451.                         $newProductFile->setHourStart($product->getHourStart());
  1452.                         $newProductFile->setMinStart($product->getMinStart());
  1453.                         $newProductFile->setHourEnd($product->getHourEnd());
  1454.                         $newProductFile->setMinEnd($product->getMinEnd());
  1455.                         $newProductFile->setDescription($product->getDescription());
  1456.                         $newProductFile->setServiceIdProposal($product->getServiceIdProposal());
  1457.                         $newProductFile->setServiceIdFather($product->getServiceIdFather());
  1458.                         $newProductFile->setControlId($product->getControlId());
  1459.                         $newProductFile->setProposalId($product->getProposalId());
  1460.                         $newProductFile->setDestinationId($product->getDestinationId());
  1461.                         $newProductFile->setIdeaId($product->getIdeaId());
  1462.                         $newProductFile->setActivityId($product->getActivityId());
  1463.                         $newProductFile->setSupplierId($product->getSupplierId());
  1464.                         $newProductFile->setAssistantId($product->getAssistantId());
  1465.                         $newProductFile->setServiceId($product->getServiceId());
  1466.                         $newProductFile->setServiceCatId($product->getServiceCatId());
  1467.                         $newProductFile->setServiceCatName($product->getServiceCatName());
  1468.                         $newProductFile->setName($product->getName());
  1469.                         $newProductFile->setPrice($product->getPrice());
  1470.                         $newProductFile->setCurrency($product->getCurrency());
  1471.                         $newProductFile->setUnits($product->getUnits());
  1472.                         $newProductFile->setOpCommission($product->getOpCommission());
  1473.                         $newProductFile->setCommission($product->getCommission());
  1474.                         $newProductFile->setOpOver($product->getOpOver());
  1475.                         $newProductFile->setOver($product->getOver());
  1476.                         $newProductFile->setOpIva($product->getOpIva());
  1477.                         $newProductFile->setIva($product->getIva());
  1478.                         $newProductFile->setHour($product->getHour());
  1479.                         $newProductFile->setDateInAt($product->getDateInAt());
  1480.                         $newProductFile->setDateOutAt($product->getDateOutAt());
  1481.                         $newProductFile->setContcolor($product->getContcolor());
  1482.                         $newProductFile->setRank($product->getRank());
  1483.                         $newProductFile->setRenovate($product->getRenovate());
  1484.                         $newProductFile->setPay($product->getPay());
  1485.                         $newProductFile->setSubTotalPrice($product->getSubTotalPrice());
  1486.                         $newProductFile->setDays($product->getDays());
  1487.                         $newProductFile->setCreatedAt(new DateTime('now'));
  1488.                         $newProductFile->setCreatedId($user_id);
  1489.                         $newProductFile->setUpdatedAt(new DateTime('now'));
  1490.                         $newProductFile->setUpdatedId($user_id);
  1491.                         $em->persist($newProductFile);
  1492.                         $em->flush();
  1493.                     }
  1494.                     //FIN: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  1495.                     $itemProforma = new AveDocProformaItems();
  1496.                     $itemProforma->setType('PRODUCT');
  1497.                     $itemProforma->setFileId($id);
  1498.                     $itemProforma->setProformaId($proforma_number);
  1499.                     if ($boolKeyChange) {
  1500.                         $itemProforma->setControlId($newProductFile->getId());
  1501.                     } else {
  1502.                         $itemProforma->setControlId($key);
  1503.                     }
  1504.                     $em->persist($itemProforma);
  1505.                     $em->flush();
  1506.                     //Acumulamos neto e iva para la factura (PROFORMA)
  1507.                     //                    $valorTotalNet = $valorTotalNet + $product->getServicePrice();
  1508.                     $valorTotalNet $valorTotalNet $product->getSubTotalPrice();
  1509.                     //                    $valorVat = $valorVat + round(($product->getServicePrice() * 0.21), 2, PHP_ROUND_HALF_UP);
  1510.                     $valorVat $valorVat round(($product->getSubTotalPrice() * 0.21), 2PHP_ROUND_HALF_UP);
  1511.                 }
  1512.             }
  1513.         }
  1514.         if (!empty($arrayBools['service'])) {
  1515.             foreach ($arrayBools['service'] as $key => $item) {
  1516.                 if ($item == 'true') {
  1517.                     $boolMakeInvoice true;
  1518.                     $servicio $em->getRepository(AveServices::class)->findOneById($key);
  1519.                     $itemProforma = new AveDocProformaItems();
  1520.                     $itemProforma->setType('SERVICE');
  1521.                     $itemProforma->setFileId($id);
  1522.                     $itemProforma->setProformaId($proforma_number);
  1523.                     $itemProforma->setControlId($key);
  1524.                     $em->persist($itemProforma);
  1525.                     $em->flush();
  1526.                     //Acumulamos neto e iva para la factura
  1527.                     if (is_null($servicio->getPrice()) or empty($servicio->getPrice())) {
  1528.                         $subtotal 0;
  1529.                         $neto 0;
  1530.                         $subtotalService 0;
  1531.                     } else {
  1532.                         $subtotalService $servicio->getPrice();
  1533.                         $subneto $servicio->getPrice();
  1534.                         // Commission
  1535.                         if ($servicio->getOpCommission() == '1') {
  1536.                             $subtotalService $subtotalService * (+ ($servicio->getCommission() / 100));
  1537.                             $subneto $subneto * (+ ($servicio->getCommission() / 100));
  1538.                         } else {
  1539.                             $subtotalService $subtotalService * (- ($servicio->getCommission() / 100));
  1540.                             $subneto $subneto * (- ($servicio->getCommission() / 100));
  1541.                         }
  1542.                         // Over
  1543.                         if ($servicio->getOpOver() == '1') {
  1544.                             $subtotalService $subtotalService $servicio->getOver();
  1545.                             $subneto $subneto $servicio->getOver();
  1546.                         } else {
  1547.                             $subtotalService $subtotalService $servicio->getOver();
  1548.                             $subneto $subneto $servicio->getOver();
  1549.                         }
  1550.                         // IVA
  1551.                         if ($servicio->getOpIva() == '1') {
  1552.                             $subtotalService $subtotalService * (+ ($servicio->getIva() / 100));
  1553.                         } else {
  1554.                             $subtotalService $servicio->getPrice();
  1555.                             $subneto = ($subneto 100) / (100 $servicio->getIva());
  1556.                         }
  1557.                         switch ($servicio->getServiceCatId()) {
  1558.                             case 1// Alojamiento
  1559.                                 // el numero de noches $numNoches; precio unitario $subneto
  1560.                                 $numNoches = (($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days;
  1561.                                 // La personas no afectan este calculo
  1562.                                 $subtotal $subtotalService $numNoches $servicio->getUnits();
  1563.                                 $subnetoUnit $subneto;
  1564.                                 $subneto $subneto $numNoches $servicio->getUnits();
  1565.                                 break;
  1566.                             case 2//Actividades
  1567.                                 // El nĂºmero de personas es considerado en el calculo
  1568.                                 $pax $servicio->getPax();
  1569.                                 if (empty($pax) or $pax == "0") {
  1570.                                     $pax 1;
  1571.                                 }
  1572.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1573.                                 if ($days 1) {
  1574.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1575.                                 } else {
  1576.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1577.                                 }
  1578.                                 $subtotal $subtotalService $days $servicio->getUnits();
  1579.                                 $subnetoUnit $subneto;
  1580.                                 $subneto $subneto $days $servicio->getUnits();
  1581.                                 break;
  1582.                             case 3// AV
  1583.                                 $pax $servicio->getPax();
  1584.                                 if (empty($pax) or $pax == "0") {
  1585.                                     $pax 1;
  1586.                                 }
  1587.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1588.                                 if ($days 1) {
  1589.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1590.                                 } else {
  1591.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1592.                                 }
  1593.                                 $unitsServ $servicio->getUnits();
  1594.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1595.                                     $unitsServ 1;
  1596.                                 }
  1597.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1598.                                 $subnetoUnit $subneto;
  1599.                                 $subneto $subneto $days $unitsServ $pax;
  1600.                                 break;
  1601.                             case 4//Creative
  1602.                                 $pax $servicio->getPax();
  1603.                                 if (empty($pax) or $pax == "0") {
  1604.                                     $pax 1;
  1605.                                 }
  1606.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1607.                                 if ($days 1) {
  1608.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1609.                                 } else {
  1610.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1611.                                 }
  1612.                                 $unitsServ $servicio->getUnits();
  1613.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1614.                                     $unitsServ 1;
  1615.                                 }
  1616.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1617.                                 $subnetoUnit $subneto;
  1618.                                 $subneto $subneto $days $unitsServ $pax;
  1619.                                 break;
  1620.                             case 5//Cruise
  1621.                                 $pax $servicio->getPax();
  1622.                                 if (empty($pax) or $pax == "0") {
  1623.                                     $pax 1;
  1624.                                 }
  1625.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days);
  1626.                                 if ($days 1) {
  1627.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1628.                                 } else {
  1629.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1630.                                 }
  1631.                                 $unitsServ $servicio->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.                                 break;
  1639.                             case 6//Entertaiment
  1640.                                 $pax $servicio->getPax();
  1641.                                 if (empty($pax) or $pax == "0") {
  1642.                                     $pax 1;
  1643.                                 }
  1644.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1645.                                 if ($days 1) {
  1646.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1647.                                 } else {
  1648.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1649.                                 }
  1650.                                 $unitsServ $servicio->getUnits();
  1651.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1652.                                     $unitsServ 1;
  1653.                                 }
  1654.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1655.                                 $subnetoUnit $subneto;
  1656.                                 $subneto $subneto $days $unitsServ $pax;
  1657.                                 break;
  1658.                             case 7// Gifts
  1659.                                 $pax $servicio->getPax();
  1660.                                 if (empty($pax) or $pax == "0") {
  1661.                                     $pax 1;
  1662.                                 }
  1663.                                 $days 1;
  1664.                                 if ($days 1) {
  1665.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1666.                                 } else {
  1667.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1668.                                 }
  1669.                                 $unitsServ $servicio->getUnits();
  1670.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1671.                                     $unitsServ 1;
  1672.                                 }
  1673.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1674.                                 $subnetoUnit $subneto;
  1675.                                 $subneto $subneto $days $unitsServ $pax;
  1676.                                 break;
  1677.                             case 8//Guide
  1678.                                 $pax $servicio->getPax();
  1679.                                 if (empty($pax) or $pax == "0") {
  1680.                                     $pax 1;
  1681.                                 }
  1682.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1683.                                 if ($days 1) {
  1684.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1685.                                 } else {
  1686.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1687.                                 }
  1688.                                 $unitsServ $servicio->getUnits();
  1689.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1690.                                     $unitsServ 1;
  1691.                                 }
  1692.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1693.                                 $subnetoUnit $subneto;
  1694.                                 $subneto $subneto $days $unitsServ $pax;
  1695.                                 break;
  1696.                             case 9//Itineraries
  1697.                                 $pax $servicio->getPax();
  1698.                                 if (empty($pax) or $pax == "0") {
  1699.                                     $pax 1;
  1700.                                 }
  1701.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1702.                                 if ($days 1) {
  1703.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1704.                                 } else {
  1705.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1706.                                 }
  1707.                                 $unitsServ $servicio->getUnits();
  1708.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1709.                                     $unitsServ 1;
  1710.                                 }
  1711.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1712.                                 $subnetoUnit $subneto;
  1713.                                 $subneto $subneto $days $unitsServ $pax;
  1714.                                 break;
  1715.                             case 10//Lounge  -- No Aplica  6*6*6 en GreenPatio no, pero en Develup ???
  1716.                                 break;
  1717.                             case 11//Menu
  1718.                                 $pax $servicio->getPax();
  1719.                                 if (empty($pax) or $pax == "0") {
  1720.                                     $pax 1;
  1721.                                 }
  1722.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1723.                                 if ($days 1) {
  1724.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1725.                                 } else {
  1726.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1727.                                 }
  1728.                                 $unitsServ $servicio->getUnits();
  1729.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1730.                                     $unitsServ 1;
  1731.                                 }
  1732.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1733.                                 $subnetoUnit $subneto;
  1734.                                 $subneto $subneto $days $unitsServ $pax;
  1735.                                 break;
  1736.                             case 12//Others
  1737.                                 $pax $servicio->getPax();
  1738.                                 if (empty($pax) or $pax == "0") {
  1739.                                     $pax 1;
  1740.                                 }
  1741.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1742.                                 if ($days 1) {
  1743.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1744.                                 } else {
  1745.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1746.                                 }
  1747.                                 $unitsServ $servicio->getUnits();
  1748.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1749.                                     $unitsServ 1;
  1750.                                 }
  1751.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1752.                                 $subnetoUnit $subneto;
  1753.                                 $subneto $subneto $days $unitsServ $pax;
  1754.                                 break;
  1755.                             case 13//Transport
  1756.                                 $pax $servicio->getPax();
  1757.                                 if (empty($pax) or $pax == "0") {
  1758.                                     $pax 1;
  1759.                                 }
  1760.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1761.                                 if ($days 1) {
  1762.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1763.                                 } else {
  1764.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1765.                                 }
  1766.                                 $unitsServ $servicio->getUnits();
  1767.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1768.                                     $unitsServ 1;
  1769.                                 }
  1770.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1771.                                 $subnetoUnit $subneto;
  1772.                                 $subneto $subneto $days $unitsServ $pax;
  1773.                                 break;
  1774.                             case 14//Technology
  1775.                                 $pax $servicio->getPax();
  1776.                                 if (empty($pax) or $pax == "0") {
  1777.                                     $pax 1;
  1778.                                 }
  1779.                                 $days 1;
  1780.                                 $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1781.                                 $unitsServ $servicio->getUnits();
  1782.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1783.                                     $unitsServ 1;
  1784.                                 }
  1785.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1786.                                 $subnetoUnit $subneto;
  1787.                                 $subneto $subneto $days $unitsServ $pax;
  1788.                                 break;
  1789.                             case 15//Assisstant
  1790.                                 $pax $servicio->getPax();
  1791.                                 if (empty($pax) or $pax == "0") {
  1792.                                     $pax 1;
  1793.                                 }
  1794.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1795.                                 if ($days 1) {
  1796.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1797.                                 } else {
  1798.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1799.                                 }
  1800.                                 $unitsServ $servicio->getUnits();
  1801.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1802.                                     $unitsServ 1;
  1803.                                 }
  1804.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1805.                                 $subnetoUnit $subneto;
  1806.                                 $subneto $subneto $days $unitsServ $pax;
  1807.                                 break;
  1808.                             case 16//DDR
  1809.                                 $pax $servicio->getPax();
  1810.                                 if (empty($pax) or $pax == "0") {
  1811.                                     $pax 1;
  1812.                                 }
  1813.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  1814.                                 if ($days 1) {
  1815.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  1816.                                 } else {
  1817.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  1818.                                 }
  1819.                                 $unitsServ $servicio->getUnits();
  1820.                                 if (empty($unitsServ) or $unitsServ == "0") {
  1821.                                     $unitsServ 1;
  1822.                                 }
  1823.                                 $subtotal $subtotalService $days $unitsServ $pax;
  1824.                                 $subnetoUnit $subneto;
  1825.                                 $subneto $subneto $days $unitsServ $pax;
  1826.                                 break;
  1827.                             default:
  1828.                                 break;
  1829.                         }
  1830.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  1831.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  1832.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  1833.                         $valorTotalNet $valorTotalNet $neto;
  1834.                         $valorVat $valorVat + ($subtotal $neto);
  1835.                     }
  1836.                 }
  1837.             }
  1838.         }
  1839.         if (!empty($arrayBools['payment'])) {
  1840.             foreach ($arrayBools['payment'] as $key => $item) {
  1841.                 if ($item == 'true') {
  1842.                     $boolMakeInvoice true;
  1843.                     $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  1844.                     $itemProforma = new AveDocProformaItems();
  1845.                     $itemProforma->setType('PAYMENT');
  1846.                     $itemProforma->setFileId($id);
  1847.                     $itemProforma->setProformaId($proforma_number);
  1848.                     $itemProforma->setControlId($key);
  1849.                     $em->persist($itemProforma);
  1850.                     $em->flush();
  1851.                 }
  1852.             }
  1853.         }
  1854.         //FIN: Creamos los items de la proforma
  1855.         $valorTotal $valorTotalNet $valorVat;
  1856.         //INICIO: Creamos la proforma
  1857.         $newProforma = new AveDocProforma();
  1858.         $newProforma->setPrefix($proforma_prefix);
  1859.         $newProforma->setDateAt(new DateTime('now'));
  1860.         $newProforma->setFileId($id);
  1861.         $newProforma->setCreatedAt(new DateTime('now'));
  1862.         $newProforma->setCreatedId($user_id);
  1863.         $newProforma->setUpdatedAt(new DateTime('now'));
  1864.         $newProforma->setUpdatedId($user_id);
  1865.         $newProforma->setItems(null);
  1866.         $newProforma->setAccessKey(null);
  1867.         if ($boolMakeInvoice) {
  1868.             // Solo se debe crear proforma si hay un elemento
  1869.             $em->persist($newProforma);
  1870.             $em->flush();
  1871.         } else {
  1872.             // Se llama a la vista de editar el expediente
  1873.             return $this->redirectToRoute('ave_edit_file', array('id' => $id));
  1874.         }
  1875.         //FIN: Creamos la proforma
  1876.         return $this->redirectToRoute('ave_select_invoice', array('id' => $id));
  1877.     }
  1878.     /**
  1879.      * @Route("/newproforma/", name="ave_new_proforma")
  1880.      * Crear nueva proforma con los elementos seleccionados
  1881.      */
  1882.     public function generateNewProformaAction(Request $request)
  1883.     {
  1884.         $em $this->getDoctrine()->getManager();
  1885.         // Se genera y muestra en nueva pantalla la nueva proforma
  1886.         $arrayBools = array(
  1887.             'product' => null,
  1888.             'service' => null,
  1889.             'payment' => null,
  1890.         );
  1891.         $arrayBools['product'] = $request->request->get('lounge_hidden_bool');
  1892.         $arrayBools['service'] = $request->request->get('service_hidden_bool');
  1893.         $arrayBools['payment'] = $request->request->get('payment_hidden_bool');
  1894.         $id $request->request->get('file_id');
  1895.         $proforma_number $request->request->get('proforma_number');
  1896.         $proforma_prefix $request->request->get('proforma_prefix') . $proforma_number '-' $id;
  1897.         //INICIO: buscamos el ID de la factura
  1898.         $boolMakeInvoice false;  // Control para verificar si se debe hacer (PROFORMA) o todos los indicadores (sala, servicios y pagos) estaban en falso
  1899.         //FIN: buscamos el ID de la factura
  1900.         /* Obtengo usuario logueado */
  1901.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1902.         $user_id $user_logueado->getId();
  1903.         //Acumuladores de datos globales de la factura
  1904.         $valorTotalNet 0;
  1905.         $valorVat 0;
  1906.         //INICIO: Creamos los items de la proforma
  1907.         if (!empty($arrayBools['product'])) {
  1908.             foreach ($arrayBools['product'] as $key => $item) {
  1909.                 if ($item == 'true') {
  1910.                     $boolMakeInvoice true;
  1911.                     $product $em->getRepository(AveProductFile::class)->findOneById($key);
  1912.                     $boolKeyChange false;
  1913.                     //INICIO: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  1914.                     // Si el producto esta contenido en una proforma debemos crear un nuevo porducto
  1915.                     $productInProforma $em->getRepository(AveDocProformaItems::class)->findOneByControlId($key);
  1916.                     $productInProforma null;                  // Duplicacion innecesaria
  1917.                     if (!empty($productInProforma)) {
  1918.                         //INICIO: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  1919.                         $boolKeyChange true;
  1920.                         $newProductFile = new AveProductFile();
  1921.                         //INICIO: Duplicamos en Eventos
  1922.                         if (!empty($product->getOriginId())) {
  1923.                             $serviceEvent $em->getRepository(ProposalSupplierServices::class)->findOneById($product->getOriginId());
  1924.                             if (!empty($serviceEvent)) {
  1925.                                 $newServiceEvent = new ProposalSupplierServices();
  1926.                                 $newServiceEvent->setServiceIdFather($serviceEvent->getServiceIdFather());
  1927.                                 $newServiceEvent->setControlId($serviceEvent->getControlId());
  1928.                                 $newServiceEvent->setProposalId($serviceEvent->getProposalId());
  1929.                                 $newServiceEvent->setDestinationId($serviceEvent->getDestinationId());
  1930.                                 $newServiceEvent->setSupplierId($serviceEvent->getSupplierId());
  1931.                                 $newServiceEvent->setIdeaId($serviceEvent->getIdeaId());
  1932.                                 $newServiceEvent->setActivityId($serviceEvent->getActivityId());
  1933.                                 $newServiceEvent->setServiceId($serviceEvent->getServiceId());
  1934.                                 $newServiceEvent->setServiceCatId($serviceEvent->getServiceCatId());
  1935.                                 $newServiceEvent->setServiceCatName($serviceEvent->getServiceCatName());
  1936.                                 $newServiceEvent->setName($serviceEvent->getName());
  1937.                                 $newServiceEvent->setPrice($serviceEvent->getPrice());
  1938.                                 $newServiceEvent->setCurrency($serviceEvent->getCurrency());
  1939.                                 $newServiceEvent->setUnits($serviceEvent->getUnits());
  1940.                                 $newServiceEvent->setCommission($serviceEvent->getCommission());
  1941.                                 $newServiceEvent->setOver($serviceEvent->getOver());
  1942.                                 $newServiceEvent->setIva($serviceEvent->getIva());
  1943.                                 $newServiceEvent->setPax($serviceEvent->getPax());
  1944.                                 $newServiceEvent->setHour($serviceEvent->getHour());
  1945.                                 $newServiceEvent->setDateInAt($serviceEvent->getDateInAt());
  1946.                                 $newServiceEvent->setDateOutAt($serviceEvent->getDateOutAt());
  1947.                                 $newServiceEvent->setDirectPayment($serviceEvent->getDirectPayment());
  1948.                                 $newServiceEvent->setStatus($serviceEvent->getStatus());
  1949.                                 $newServiceEvent->setCreatedAt(new DateTime('now'));
  1950.                                 $newServiceEvent->setCreatedId($user_id);
  1951.                                 $newServiceEvent->setUpdatedAt(new DateTime('now'));
  1952.                                 $newServiceEvent->setUpdatedId($user_id);
  1953.                                 $newServiceEvent->setStatusinternal($serviceEvent->getStatusinternal());
  1954.                                 $newServiceEvent->setPreCommission($serviceEvent->getPreCommission());
  1955.                                 $newServiceEvent->setPreIva($serviceEvent->getPreIva());
  1956.                                 $newServiceEvent->setDateBlockLimit($serviceEvent->getDateBlockLimit());
  1957.                                 $newServiceEvent->setOpCommission($serviceEvent->getOpCommission());
  1958.                                 $newServiceEvent->setOpOver($serviceEvent->getOpOver());
  1959.                                 $newServiceEvent->setOpIva($serviceEvent->getOpIva());
  1960.                                 $newServiceEvent->setBreakdown($serviceEvent->getBreakdown());
  1961.                                 $newServiceEvent->setIsFather($serviceEvent->getIsFather());
  1962.                                 $newServiceEvent->setRank($serviceEvent->getRank());
  1963.                                 $newServiceEvent->setOriginalopIva($serviceEvent->getOriginalopIva());
  1964.                                 $newServiceEvent->setOriginalIva($serviceEvent->getOriginalIva());
  1965.                                 $newServiceEvent->setOriginalPrice($serviceEvent->getOriginalPrice());
  1966.                                 $newServiceEvent->setStatusRec($serviceEvent->getStatusRec());   //setStatusRecommended
  1967.                                 $newServiceEvent->setAssistantId($serviceEvent->getAssistantId());
  1968.                                 $em->persist($newServiceEvent);
  1969.                                 $em->flush();
  1970.                             }
  1971.                             if (!empty($serviceEvent)) {
  1972.                                 $newProductFile->setOriginId($newServiceEvent->getId());
  1973.                             } else {
  1974.                                 $newProductFile->setOriginId(null);
  1975.                             }
  1976.                         }
  1977.                         //FIN: Duplicamos en Eventos
  1978.                         //FIN: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
  1979.                         $newProductFile->setProductName($product->getProductName());
  1980.                         $newProductFile->setProductId($product->getProductId());
  1981.                         $newProductFile->setDateStart($product->getDateStart());
  1982.                         $newProductFile->setDateEnd($product->getDateEnd());
  1983.                         $newProductFile->setServicePrice($product->getServicePrice());
  1984.                         $newProductFile->setFileId($product->getFileId());
  1985.                         $newProductFile->setPax($product->getPax());
  1986.                         $newProductFile->setType($product->getType());
  1987.                         $newProductFile->setHourStart($product->getHourStart());
  1988.                         $newProductFile->setMinStart($product->getMinStart());
  1989.                         $newProductFile->setHourEnd($product->getHourEnd());
  1990.                         $newProductFile->setMinEnd($product->getMinEnd());
  1991.                         $newProductFile->setDescription($product->getDescription());
  1992.                         $newProductFile->setServiceIdProposal($product->getServiceIdProposal());
  1993.                         $newProductFile->setServiceIdFather($product->getServiceIdFather());
  1994.                         $newProductFile->setControlId($product->getControlId());
  1995.                         $newProductFile->setProposalId($product->getProposalId());
  1996.                         $newProductFile->setDestinationId($product->getDestinationId());
  1997.                         $newProductFile->setIdeaId($product->getIdeaId());
  1998.                         $newProductFile->setActivityId($product->getActivityId());
  1999.                         $newProductFile->setSupplierId($product->getSupplierId());
  2000.                         $newProductFile->setAssistantId($product->getAssistantId());
  2001.                         $newProductFile->setServiceId($product->getServiceId());
  2002.                         $newProductFile->setServiceCatId($product->getServiceCatId());
  2003.                         $newProductFile->setServiceCatName($product->getServiceCatName());
  2004.                         $newProductFile->setName($product->getName());
  2005.                         $newProductFile->setPrice($product->getPrice());
  2006.                         $newProductFile->setCurrency($product->getCurrency());
  2007.                         $newProductFile->setUnits($product->getUnits());
  2008.                         $newProductFile->setOpCommission($product->getOpCommission());
  2009.                         $newProductFile->setCommission($product->getCommission());
  2010.                         $newProductFile->setOpOver($product->getOpOver());
  2011.                         $newProductFile->setOver($product->getOver());
  2012.                         $newProductFile->setOpIva($product->getOpIva());
  2013.                         $newProductFile->setIva($product->getIva());
  2014.                         $newProductFile->setHour($product->getHour());
  2015.                         $newProductFile->setDateInAt($product->getDateInAt());
  2016.                         $newProductFile->setDateOutAt($product->getDateOutAt());
  2017.                         $newProductFile->setContcolor($product->getContcolor());
  2018.                         $newProductFile->setRank($product->getRank());
  2019.                         $newProductFile->setRenovate($product->getRenovate());
  2020.                         $newProductFile->setPay($product->getPay());
  2021.                         $newProductFile->setSubTotalPrice($product->getSubTotalPrice());
  2022.                         $newProductFile->setDays($product->getDays());
  2023.                         $newProductFile->setCreatedAt(new DateTime('now'));
  2024.                         $newProductFile->setCreatedId($user_id);
  2025.                         $newProductFile->setUpdatedAt(new DateTime('now'));
  2026.                         $newProductFile->setUpdatedId($user_id);
  2027.                         $em->persist($newProductFile);
  2028.                         $em->flush();
  2029.                     }
  2030.                     //FIN: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
  2031.                     $itemProforma = new AveDocProformaItems();
  2032.                     $itemProforma->setType('PRODUCT');
  2033.                     $itemProforma->setFileId($id);
  2034.                     $itemProforma->setProformaId($proforma_number);
  2035.                     if ($boolKeyChange) {
  2036.                         $itemProforma->setControlId($newProductFile->getId());
  2037.                     } else {
  2038.                         $itemProforma->setControlId($key);
  2039.                     }
  2040.                     $em->persist($itemProforma);
  2041.                     $em->flush();
  2042.                     //Acumulamos neto e iva para la factura (PROFORMA)
  2043.                     //                    $valorTotalNet = $valorTotalNet + $product->getServicePrice();
  2044.                     $valorTotalNet $valorTotalNet $product->getSubTotalPrice();
  2045.                     if ($product->getIva() == '21') {
  2046.                         $valorVat $valorVat round(($product->getSubTotalPrice() * 0.21), 2PHP_ROUND_HALF_UP);
  2047.                     }
  2048.                     if ($product->getIva() == '10') {
  2049.                         $valorVat $valorVat round(($product->getSubTotalPrice() * 0.1), 2PHP_ROUND_HALF_UP);
  2050.                     }
  2051.                     if ($product->getIva() == '0') {
  2052.                         $valorVat $valorVat round(($product->getSubTotalPrice() * 0), 2PHP_ROUND_HALF_UP);
  2053.                     }
  2054.                 }
  2055.             }
  2056.         }
  2057.         if (!empty($arrayBools['service'])) {
  2058.             foreach ($arrayBools['service'] as $key => $item) {
  2059.                 if ($item == 'true') {
  2060.                     $boolMakeInvoice true;
  2061.                     $servicio $em->getRepository(AveServices::class)->findOneById($key);
  2062.                     $itemProforma = new AveDocProformaItems();
  2063.                     $itemProforma->setType('SERVICE');
  2064.                     $itemProforma->setFileId($id);
  2065.                     $itemProforma->setProformaId($proforma_number);
  2066.                     $itemProforma->setControlId($key);
  2067.                     $em->persist($itemProforma);
  2068.                     $em->flush();
  2069.                     //Acumulamos neto e iva para la factura
  2070.                     if (is_null($servicio->getPrice()) or empty($servicio->getPrice())) {
  2071.                         $subtotal 0;
  2072.                         $neto 0;
  2073.                         $subtotalService 0;
  2074.                     } else {
  2075.                         $subtotalService $servicio->getPrice();
  2076.                         $subneto $servicio->getPrice();
  2077.                         // Commission
  2078.                         if ($servicio->getOpCommission() == '1') {
  2079.                             $subtotalService $subtotalService * (+ ($servicio->getCommission() / 100));
  2080.                             $subneto $subneto * (+ ($servicio->getCommission() / 100));
  2081.                         } else {
  2082.                             $subtotalService $subtotalService * (- ($servicio->getCommission() / 100));
  2083.                             $subneto $subneto * (- ($servicio->getCommission() / 100));
  2084.                         }
  2085.                         // Over
  2086.                         if ($servicio->getOpOver() == '1') {
  2087.                             $subtotalService $subtotalService $servicio->getOver();
  2088.                             $subneto $subneto $servicio->getOver();
  2089.                         } else {
  2090.                             $subtotalService $subtotalService $servicio->getOver();
  2091.                             $subneto $subneto $servicio->getOver();
  2092.                         }
  2093.                         // IVA
  2094.                         if ($servicio->getOpIva() == '1') {
  2095.                             $subtotalService $subtotalService * (+ ($servicio->getIva() / 100));
  2096.                         } else {
  2097.                             $subtotalService $servicio->getPrice();
  2098.                             $subneto = ($subneto 100) / (100 $servicio->getIva());
  2099.                         }
  2100.                         switch ($servicio->getServiceCatId()) {
  2101.                             case 1// Alojamiento
  2102.                                 // el numero de noches $numNoches; precio unitario $subneto
  2103.                                 $numNoches = (($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days;
  2104.                                 // La personas no afectan este calculo
  2105.                                 $subtotal $subtotalService $numNoches $servicio->getUnits();
  2106.                                 $subnetoUnit $subneto;
  2107.                                 $subneto $subneto $numNoches $servicio->getUnits();
  2108.                                 break;
  2109.                             case 2//Actividades
  2110.                                 // El nĂºmero de personas es considerado en el calculo
  2111.                                 $pax $servicio->getPax();
  2112.                                 if (empty($pax) or $pax == "0") {
  2113.                                     $pax 1;
  2114.                                 }
  2115.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2116.                                 if ($days 1) {
  2117.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2118.                                 } else {
  2119.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2120.                                 }
  2121.                                 $subtotal $subtotalService $days $servicio->getUnits();
  2122.                                 $subnetoUnit $subneto;
  2123.                                 $subneto $subneto $days $servicio->getUnits();
  2124.                                 break;
  2125.                             case 3// AV
  2126.                                 $pax $servicio->getPax();
  2127.                                 if (empty($pax) or $pax == "0") {
  2128.                                     $pax 1;
  2129.                                 }
  2130.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2131.                                 if ($days 1) {
  2132.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2133.                                 } else {
  2134.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2135.                                 }
  2136.                                 $unitsServ $servicio->getUnits();
  2137.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2138.                                     $unitsServ 1;
  2139.                                 }
  2140.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2141.                                 $subnetoUnit $subneto;
  2142.                                 $subneto $subneto $days $unitsServ $pax;
  2143.                                 break;
  2144.                             case 4//Creative
  2145.                                 $pax $servicio->getPax();
  2146.                                 if (empty($pax) or $pax == "0") {
  2147.                                     $pax 1;
  2148.                                 }
  2149.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2150.                                 if ($days 1) {
  2151.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2152.                                 } else {
  2153.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2154.                                 }
  2155.                                 $unitsServ $servicio->getUnits();
  2156.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2157.                                     $unitsServ 1;
  2158.                                 }
  2159.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2160.                                 $subnetoUnit $subneto;
  2161.                                 $subneto $subneto $days $unitsServ $pax;
  2162.                                 break;
  2163.                             case 5//Cruise
  2164.                                 $pax $servicio->getPax();
  2165.                                 if (empty($pax) or $pax == "0") {
  2166.                                     $pax 1;
  2167.                                 }
  2168.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days);
  2169.                                 if ($days 1) {
  2170.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2171.                                 } else {
  2172.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2173.                                 }
  2174.                                 $unitsServ $servicio->getUnits();
  2175.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2176.                                     $unitsServ 1;
  2177.                                 }
  2178.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2179.                                 $subnetoUnit $subneto;
  2180.                                 $subneto $subneto $days $unitsServ $pax;
  2181.                                 break;
  2182.                             case 6//Entertaiment
  2183.                                 $pax $servicio->getPax();
  2184.                                 if (empty($pax) or $pax == "0") {
  2185.                                     $pax 1;
  2186.                                 }
  2187.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2188.                                 if ($days 1) {
  2189.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2190.                                 } else {
  2191.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2192.                                 }
  2193.                                 $unitsServ $servicio->getUnits();
  2194.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2195.                                     $unitsServ 1;
  2196.                                 }
  2197.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2198.                                 $subnetoUnit $subneto;
  2199.                                 $subneto $subneto $days $unitsServ $pax;
  2200.                                 break;
  2201.                             case 7// Gifts
  2202.                                 $pax $servicio->getPax();
  2203.                                 if (empty($pax) or $pax == "0") {
  2204.                                     $pax 1;
  2205.                                 }
  2206.                                 $days 1;
  2207.                                 if ($days 1) {
  2208.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2209.                                 } else {
  2210.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2211.                                 }
  2212.                                 $unitsServ $servicio->getUnits();
  2213.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2214.                                     $unitsServ 1;
  2215.                                 }
  2216.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2217.                                 $subnetoUnit $subneto;
  2218.                                 $subneto $subneto $days $unitsServ $pax;
  2219.                                 break;
  2220.                             case 8//Guide
  2221.                                 $pax $servicio->getPax();
  2222.                                 if (empty($pax) or $pax == "0") {
  2223.                                     $pax 1;
  2224.                                 }
  2225.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2226.                                 if ($days 1) {
  2227.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2228.                                 } else {
  2229.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2230.                                 }
  2231.                                 $unitsServ $servicio->getUnits();
  2232.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2233.                                     $unitsServ 1;
  2234.                                 }
  2235.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2236.                                 $subnetoUnit $subneto;
  2237.                                 $subneto $subneto $days $unitsServ $pax;
  2238.                                 break;
  2239.                             case 9//Itineraries
  2240.                                 $pax $servicio->getPax();
  2241.                                 if (empty($pax) or $pax == "0") {
  2242.                                     $pax 1;
  2243.                                 }
  2244.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2245.                                 if ($days 1) {
  2246.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2247.                                 } else {
  2248.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2249.                                 }
  2250.                                 $unitsServ $servicio->getUnits();
  2251.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2252.                                     $unitsServ 1;
  2253.                                 }
  2254.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2255.                                 $subnetoUnit $subneto;
  2256.                                 $subneto $subneto $days $unitsServ $pax;
  2257.                                 break;
  2258.                             case 10//Lounge  -- No Aplica  6*6*6 en GreenPatio no, pero en Develup ???
  2259.                                 break;
  2260.                             case 11//Menu
  2261.                                 $pax $servicio->getPax();
  2262.                                 if (empty($pax) or $pax == "0") {
  2263.                                     $pax 1;
  2264.                                 }
  2265.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2266.                                 if ($days 1) {
  2267.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2268.                                 } else {
  2269.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2270.                                 }
  2271.                                 $unitsServ $servicio->getUnits();
  2272.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2273.                                     $unitsServ 1;
  2274.                                 }
  2275.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2276.                                 $subnetoUnit $subneto;
  2277.                                 $subneto $subneto $days $unitsServ $pax;
  2278.                                 break;
  2279.                             case 12//Others
  2280.                                 $pax $servicio->getPax();
  2281.                                 if (empty($pax) or $pax == "0") {
  2282.                                     $pax 1;
  2283.                                 }
  2284.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2285.                                 if ($days 1) {
  2286.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2287.                                 } else {
  2288.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2289.                                 }
  2290.                                 $unitsServ $servicio->getUnits();
  2291.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2292.                                     $unitsServ 1;
  2293.                                 }
  2294.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2295.                                 $subnetoUnit $subneto;
  2296.                                 $subneto $subneto $days $unitsServ $pax;
  2297.                                 break;
  2298.                             case 13//Transport
  2299.                                 $pax $servicio->getPax();
  2300.                                 if (empty($pax) or $pax == "0") {
  2301.                                     $pax 1;
  2302.                                 }
  2303.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2304.                                 if ($days 1) {
  2305.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2306.                                 } else {
  2307.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2308.                                 }
  2309.                                 $unitsServ $servicio->getUnits();
  2310.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2311.                                     $unitsServ 1;
  2312.                                 }
  2313.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2314.                                 $subnetoUnit $subneto;
  2315.                                 $subneto $subneto $days $unitsServ $pax;
  2316.                                 break;
  2317.                             case 14//Technology
  2318.                                 $pax $servicio->getPax();
  2319.                                 if (empty($pax) or $pax == "0") {
  2320.                                     $pax 1;
  2321.                                 }
  2322.                                 $days 1;
  2323.                                 $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2324.                                 $unitsServ $servicio->getUnits();
  2325.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2326.                                     $unitsServ 1;
  2327.                                 }
  2328.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2329.                                 $subnetoUnit $subneto;
  2330.                                 $subneto $subneto $days $unitsServ $pax;
  2331.                                 break;
  2332.                             case 15//Assisstant
  2333.                                 $pax $servicio->getPax();
  2334.                                 if (empty($pax) or $pax == "0") {
  2335.                                     $pax 1;
  2336.                                 }
  2337.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2338.                                 if ($days 1) {
  2339.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2340.                                 } else {
  2341.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2342.                                 }
  2343.                                 $unitsServ $servicio->getUnits();
  2344.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2345.                                     $unitsServ 1;
  2346.                                 }
  2347.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2348.                                 $subnetoUnit $subneto;
  2349.                                 $subneto $subneto $days $unitsServ $pax;
  2350.                                 break;
  2351.                             case 16//DDR
  2352.                                 $pax $servicio->getPax();
  2353.                                 if (empty($pax) or $pax == "0") {
  2354.                                     $pax 1;
  2355.                                 }
  2356.                                 $days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days 1);
  2357.                                 if ($days 1) {
  2358.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
  2359.                                 } else {
  2360.                                     $dateServ = ($servicio->getDateInAt())->format('d/m/Y');
  2361.                                 }
  2362.                                 $unitsServ $servicio->getUnits();
  2363.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2364.                                     $unitsServ 1;
  2365.                                 }
  2366.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2367.                                 $subnetoUnit $subneto;
  2368.                                 $subneto $subneto $days $unitsServ $pax;
  2369.                                 break;
  2370.                             default:
  2371.                                 break;
  2372.                         }
  2373.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  2374.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  2375.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  2376.                         $valorTotalNet $valorTotalNet $neto;
  2377.                         $valorVat $valorVat + ($subtotal $neto);
  2378.                     }
  2379.                 }
  2380.             }
  2381.         }
  2382.         if (!empty($arrayBools['payment'])) {
  2383.             foreach ($arrayBools['payment'] as $key => $item) {
  2384.                 if ($item == 'true') {
  2385.                     $boolMakeInvoice true;
  2386.                     $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  2387.                     $itemProforma = new AveDocProformaItems();
  2388.                     $itemProforma->setType('PAYMENT');
  2389.                     $itemProforma->setFileId($id);
  2390.                     $itemProforma->setProformaId($proforma_number);
  2391.                     $itemProforma->setControlId($key);
  2392.                     $em->persist($itemProforma);
  2393.                     $em->flush();
  2394.                 }
  2395.             }
  2396.         }
  2397.         //FIN: Creamos los items de la proforma
  2398.         $valorTotal $valorTotalNet $valorVat;
  2399.         //INICIO: Creamos la proforma
  2400.         $newProforma = new AveDocProforma();
  2401.         //        $newProforma->setPrefix("GPP-".date('dmy')."-".$id);
  2402.         $newProforma->setPrefix($proforma_prefix);
  2403.         $newProforma->setDateAt(new DateTime('now'));
  2404.         $newProforma->setFileId($id);
  2405.         $newProforma->setCreatedAt(new DateTime('now'));
  2406.         $newProforma->setCreatedId($user_id);
  2407.         $newProforma->setUpdatedAt(new DateTime('now'));
  2408.         $newProforma->setUpdatedId($user_id);
  2409.         $newProforma->setItems(null);
  2410.         $newProforma->setAccessKey(null);
  2411.         if ($boolMakeInvoice) {
  2412.             // Solo se debe crear proforma si hay un elemento
  2413.             $em->persist($newProforma);
  2414.             $em->flush();
  2415.         } else {
  2416.             // Se llama a la vista de editar el expediente
  2417.             return $this->redirectToRoute('ave_edit_file', array('id' => $id));
  2418.         }
  2419.         //FIN: Creamos la proforma
  2420.         return $this->redirectToRoute('ave_view_proforma', array('id' => $newProforma->getId()));
  2421.     }
  2422.     /**
  2423.      * @Route("/discardproforma/{id}",  name="ave_discard_proforma")
  2424.      * Descartar la proforma especificada en el ID
  2425.      */
  2426.     public function discardProformaAction($idRequest $request)
  2427.     {
  2428.         $em $this->getDoctrine()->getManager();
  2429.         $proforma =  $em->getRepository(AveDocProforma::class)->findOneById($id);
  2430.         $fileId $proforma->getFileId();
  2431.         //Buscamos en la tabla de proformas a enviar
  2432.         $budToPro =  $em->getRepository(AveBudgetToProforma::class)->findOneByProformaId($id);
  2433.         if (!empty($budToPro)) {
  2434.             $em->remove($budToPro);
  2435.             $em->flush();
  2436.         }
  2437.         //Eliminamos los productos dentro de la proforma
  2438.         $proformaItems =  $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
  2439.         foreach ($proformaItems as $item) {
  2440.             $em->remove($item);
  2441.             $em->flush();
  2442.         }
  2443.         //No se puede eliminar el registro porque es necesario mantener la numeraciĂ³n de las proformas si se desean generar correctamente
  2444.         $proforma->setFileId(0);
  2445.         $em->persist($proforma);
  2446.         $em->flush();
  2447.         return $this->redirectToRoute('ave_edit_file', array('id' => $fileId));
  2448.     }
  2449.     /**
  2450.      * @Route("/viewproforma/{id}",  name="ave_view_proforma")
  2451.      * Ver una proforma
  2452.      */
  2453.     public function viewProformaAction($idRequest $request)
  2454.     {
  2455.         $docType 'Proforma';
  2456.         $em $this->getDoctrine()->getManager();
  2457.         $proforma =  $em->getRepository(AveDocProforma::class)->findOneById($id);
  2458.         $id $proforma->getFileId();
  2459.         /* Obtengo usuario logueado */
  2460.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2461.         $user_id $user_logueado->getId();
  2462.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  2463.         // Buscamos el cliente
  2464.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  2465.         $client $em->getRepository(Client::class)->findById($file->getClient());
  2466.         if (empty($client)) {
  2467.             $client[0] = new Client();
  2468.             $client[0]->setName('');
  2469.             $client[0]->setTitle('');
  2470.             $client[0]->setIdDocument('');
  2471.             $client[0]->setPopulation('');
  2472.             $client[0]->setRegion('');
  2473.             $client[0]->setCountry('');
  2474.         } else {
  2475.             if (is_numeric($client[0]->getPopulation())) {
  2476.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2477. //                $client[0]->setPopulation($city->getCity());
  2478.             }
  2479.             if (is_numeric($client[0]->getRegion())) {
  2480.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2481. //                $client[0]->setRegion($region->getRegion());
  2482.             }
  2483.             if (is_numeric($client[0]->getCountry())) {
  2484.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2485. //                $client[0]->setCountry($country->getCountry());
  2486.             }
  2487.         }
  2488.         if (empty($client)) {
  2489.             $client[0] = new Client();
  2490.             $client[0]->setName('');
  2491.             $client[0]->setTitle('');
  2492.             $client[0]->setIdDocument('');
  2493.             $client[0]->setPopulation('');
  2494.             $client[0]->setRegion('');
  2495.             $client[0]->setCountry('');
  2496.             $clientNew = array(
  2497.                 'name' => '',
  2498.                 'title' => '',
  2499.                 'idDocument' => '',
  2500.                 'population' => '',
  2501.                 'region' => '',
  2502.                 'country' => '',
  2503.                 'address' => '',
  2504.                 'addressNumber' => '',
  2505.                 'zipCode' => '',
  2506.                 'typeDocument' => '',
  2507.             );
  2508.         } else {
  2509.             $clientNew = array(
  2510.                 'name' => $client[0]->getName(),
  2511.                 'title' => $client[0]->getTitle(),
  2512.                 'idDocument' => $client[0]->getIdDocument(),
  2513.                 'population' => '',
  2514.                 'region' => '',
  2515.                 'country' => '',
  2516.                 'address' => $client[0]->getAddress(),
  2517.                 'addressNumber' => $client[0]->getAddressNumber(),
  2518.                 'zipCode' => $client[0]->getZipCode(),
  2519.                 'typeDocument' => $client[0]->getTypeDocument(),
  2520.             );
  2521.             if (is_numeric($client[0]->getPopulation())) {
  2522.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2523.                 $clientNew['population'] = $city->getCity();
  2524.             }
  2525.             if (is_numeric($client[0]->getRegion())) {
  2526.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2527.                 $clientNew['region'] = $region->getRegion();
  2528.             }
  2529.             if (is_numeric($client[0]->getCountry())) {
  2530.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2531.                 $clientNew['country'] = $country->getCountry();
  2532.             }
  2533.         }
  2534.         // Buscamos el cliente
  2535.         $data $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
  2536.         $allProformas =  $em->getRepository(AveDocProforma::class)->findByFileId($id);
  2537.         // Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito  //6*6*6
  2538.         $commentsBool false;
  2539.         $comments null;
  2540.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  2541.         if ($fileAv->getCommentsInPro()) {
  2542.             $commentsBool true;
  2543.         }
  2544.         if ($commentsBool) {
  2545.             $comments $fileAv->getComments();
  2546.         }
  2547.         // Obtengo usuario logueado
  2548.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2549.         $user_id $user_logueado->getId();
  2550. //dd(
  2551. //
  2552. //    'id', $id,
  2553. //                'docType', $docType,
  2554. //                'proforma', $proforma,
  2555. //                'company', $company,
  2556. //                'clients', $clientNew,
  2557. //                'file', $file,
  2558. //                'date', $proforma->getDateAt(),
  2559. //                'number', $proforma->getId(),
  2560. //                'invoice', null,
  2561. //                'fid', $proforma->getId(),
  2562. //                'boolToRec', false,
  2563. //                'proformas', $allProformas,
  2564. //                'currency', '€',
  2565. //                'user', $user_logueado,
  2566. //                'totales_neto', $data['totales_neto'],
  2567. //                'totales', $data['totales'],
  2568. //                'balance', $data['balance'],
  2569. //                'bases_imponibles', $data['bases_imponibles'],
  2570. //                'datasupplier', $data['datasupplier']
  2571. //
  2572. //);
  2573.         return $this->render(
  2574.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  2575.             array(
  2576.                 'id' => $id,
  2577.                 'docType' => $docType,
  2578.                 'proforma' => $proforma,
  2579.                 'company' => $company,
  2580.                 'clients' => $clientNew,
  2581.                 'file' => $file,
  2582.                 'date' => $proforma->getDateAt(),
  2583.                 'number' => $proforma->getId(),
  2584.                 'invoice' => null,
  2585.                 'fid' => $proforma->getId(),
  2586.                 'boolToRec' => false,
  2587.                 'proformas' => $allProformas,
  2588.                 'currency' => '€',
  2589.                 'user' => $user_logueado,
  2590.                 'totales_neto' => $data['totales_neto'],
  2591.                 'totales' => $data['totales'],
  2592.                 'balance' => $data['balance'],
  2593.                 'bases_imponibles' => $data['bases_imponibles'],
  2594.                 'datasupplier' => $data['datasupplier'],
  2595.                 'services' => null,
  2596.                 'facturas' => null,
  2597.                 'paymentNotIvoiced' => null,
  2598.                 'paymentsAll' => null,
  2599.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  2600.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  2601.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  2602.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  2603.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  2604.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  2605.                 'comments' => $comments,
  2606.             )
  2607.         );
  2608.     }
  2609.     /**
  2610.      * @Route("/avexternal/printproforma/{id}",  name="ave_print_proforma")
  2611.      * Imprimir una proforma
  2612.      */
  2613.     public function printProformaAction($idRequest $request)
  2614.     {
  2615.         $docType 'Proforma';
  2616.         $em $this->getDoctrine()->getManager();
  2617.         $proforma =  $em->getRepository(AveDocProforma::class)->findOneById($id);
  2618.         $id $proforma->getFileId();
  2619.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  2620.         if ($id == 0) {
  2621.             // La proforma ha sido descartada o eliminada desde AV
  2622.             d('La proforma ha sido descartada o eliminada desde AV');
  2623.             exit();
  2624.         }
  2625.         // Buscamos el cliente
  2626.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  2627.         $client $em->getRepository(Client::class)->findById($file->getClient());
  2628.         if (empty($client)) {
  2629.             $client[0] = new Client();
  2630.             $client[0]->setName('');
  2631.             $client[0]->setTitle('');
  2632.             $client[0]->setIdDocument('');
  2633.             $client[0]->setPopulation('');
  2634.             $client[0]->setRegion('');
  2635.             $client[0]->setCountry('');
  2636.         } else {
  2637.             if (is_numeric($client[0]->getPopulation())) {
  2638.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2639. //                $client[0]->setPopulation($city->getCity());
  2640.             }
  2641.             if (is_numeric($client[0]->getRegion())) {
  2642.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2643. //                $client[0]->setRegion($region->getRegion());
  2644.             }
  2645.             if (is_numeric($client[0]->getCountry())) {
  2646.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2647. //                $client[0]->setCountry($country->getCountry());
  2648.             }
  2649.         }
  2650.         if (empty($client)) {
  2651.             $client[0] = new Client();
  2652.             $client[0]->setName('');
  2653.             $client[0]->setTitle('');
  2654.             $client[0]->setIdDocument('');
  2655.             $client[0]->setPopulation('');
  2656.             $client[0]->setRegion('');
  2657.             $client[0]->setCountry('');
  2658.             $clientNew = array(
  2659.                 'name' => '',
  2660.                 'title' => '',
  2661.                 'idDocument' => '',
  2662.                 'population' => '',
  2663.                 'region' => '',
  2664.                 'country' => '',
  2665.                 'address' => '',
  2666.                 'addressNumber' => '',
  2667.                 'zipCode' => '',
  2668.                 'typeDocument' => '',
  2669.             );
  2670.         } else {
  2671.             $clientNew = array(
  2672.                 'name' => $client[0]->getName(),
  2673.                 'title' => $client[0]->getTitle(),
  2674.                 'idDocument' => $client[0]->getIdDocument(),
  2675.                 'population' => '',
  2676.                 'region' => '',
  2677.                 'country' => '',
  2678.                 'address' => $client[0]->getAddress(),
  2679.                 'addressNumber' => $client[0]->getAddressNumber(),
  2680.                 'zipCode' => $client[0]->getZipCode(),
  2681.                 'typeDocument' => $client[0]->getTypeDocument(),
  2682.             );
  2683.             if (is_numeric($client[0]->getPopulation())) {
  2684.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  2685.                 $clientNew['population'] = $city->getCity();
  2686.             }
  2687.             if (is_numeric($client[0]->getRegion())) {
  2688.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  2689.                 $clientNew['region'] = $region->getRegion();
  2690.             }
  2691.             if (is_numeric($client[0]->getCountry())) {
  2692.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  2693.                 $clientNew['country'] = $country->getCountry();
  2694.             }
  2695.         }
  2696.         // Buscamos el cliente
  2697.         $data $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
  2698.         $allProformas =  $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
  2699.         $commentsBool false;
  2700.         $comments null;
  2701.         $fileAv $em->getRepository(AveFiles::class)->findOneById($id);
  2702.         if ($fileAv->getCommentsInPro()) {
  2703.             $commentsBool true;
  2704.         }
  2705.         if ($commentsBool) {
  2706.             $comments $fileAv->getComments();
  2707.         }
  2708.         return $this->render(
  2709.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  2710.             array(
  2711.                 'id' => $id,
  2712.                 'docType' => $docType,
  2713.                 'proforma' => $proforma,
  2714.                 'company' => $company,
  2715.                 'clients' => $clientNew,
  2716.                 'file' => $file,
  2717.                 'date' => $proforma->getDateAt(),
  2718.                 'number' => $proforma->getId(),
  2719.                 'invoice' => null,
  2720.                 'fid' => $proforma->getId(),
  2721.                 'boolToRec' => false,
  2722.                 'proformas' => $allProformas,
  2723.                 'currency' => '€',
  2724.                 'totales_neto' => $data['totales_neto'],
  2725.                 'totales' => $data['totales'],
  2726.                 'balance' => $data['balance'],
  2727.                 'bases_imponibles' => $data['bases_imponibles'],
  2728.                 'datasupplier' => $data['datasupplier'],
  2729.                 'services' => null,
  2730.                 'facturas' => null,
  2731.                 'paymentNotIvoiced' => null,
  2732.                 'paymentsAll' => null,
  2733.                 'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  2734.                 'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  2735.                 'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  2736.                 'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  2737.                 'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  2738.                 'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  2739.                 'comments' => $comments,
  2740.             )
  2741.         );
  2742.     }
  2743.     /**
  2744.      * @Route("/newinvoice/", name="ave_new_invoice")
  2745.      * Crear nueva factura con los elementos seleccionados
  2746.      */
  2747.     public function generateNewInvoiceAction(Request $request)
  2748.     {
  2749.         $em $this->getDoctrine()->getManager();
  2750.         // Se genera y muestra en nueva pantalla la nueva proforma
  2751.         $arrayBools = array(
  2752.             'product' => null,
  2753.             'service' => null,
  2754.             'payment' => null,
  2755.         );
  2756.         $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  2757.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  2758.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  2759.         $id $request->request->get('inv_file_id');
  2760.         //INICIO: buscamos el ID de la factura
  2761.         $allFacturas $em->getRepository(AveDocInvoice::class)->findAll();
  2762.         if (!empty($allFacturas)) {
  2763.             $invoiceId end($allFacturas)->getId() + 1;
  2764.         } else {
  2765.             $invoiceId 1;
  2766.             //            $invoiceId = 10;    //La primera factura de AV en el sistema serĂ¡ la 10, se cambia el numero de serie a A1, A2,...
  2767.         }
  2768.         $boolMakeInvoice false;  // Control para verificar si se debe hacer factura o todos los indicadores (sala, servicios y pagos) estaban en falso
  2769.         //FIN: buscamos el ID de la factura
  2770.         /* Obtengo usuario logueado */
  2771.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2772.         $user_id $user_logueado->getId();
  2773.         //Acumuladores de datos globales de la factura
  2774.         $valorTotalNet 0;
  2775.         $valorVat 0;
  2776.         //INICIO: Creamos los items de la factura
  2777.         if (!empty($arrayBools['product'])) {
  2778.             foreach ($arrayBools['product'] as $key => $item) {
  2779.                 if ($item == 'true') {
  2780.                     $boolMakeInvoice true;
  2781.                     $sala $em->getRepository(AveProductFile::class)->findOneById($key);
  2782.                     $itemInvoice = new AveDocInvoiceItems();
  2783.                     $itemInvoice->setFileId($id);
  2784.                     $itemInvoice->setInvoiceId($invoiceId);
  2785.                     $itemInvoice->setItemType('PRODUCT');
  2786.                     $itemInvoice->setPrdControlId($key);
  2787.                     $itemInvoice->setPrdName($sala->getProductName());
  2788.                     $itemInvoice->setPrdProductId($sala->getProductId());
  2789.                     $itemInvoice->setPrdType($sala->getType());
  2790.                     $itemInvoice->setPrdDateStart($sala->getDateStart());
  2791.                     $itemInvoice->setPrdDateEnd($sala->getDateEnd());
  2792.                     $itemInvoice->setPrdServicePrice($sala->getServicePrice());
  2793.                     $itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
  2794.                     $itemInvoice->setPrdQty($sala->getUnits());
  2795.                     $itemInvoice->setPrdDays($sala->getDays());
  2796.                     $itemInvoice->setPrdPax($sala->getPax());
  2797.                     $itemInvoice->setCreatedId($user_id);
  2798.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  2799.                     $itemInvoice->setUpdatedId($user_id);
  2800.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  2801.                     $itemInvoice->setPrdHourStart($sala->getHourStart());
  2802.                     $itemInvoice->setPrdMinStart($sala->getMinStart());
  2803.                     $itemInvoice->setPrdHourEnd($sala->getHourEnd());
  2804.                     $itemInvoice->setPrdMinEnd($sala->getMinEnd());
  2805.                     if (empty($sala->getLocation())) {
  2806.                         $itemInvoice->setLocation(null);
  2807.                     } else {
  2808.                         $itemInvoice->setLocation($sala->getLocation());
  2809.                     }
  2810.                     $itemInvoice->setRankAv($sala->getRankAv());
  2811.                     $itemInvoice->setPrdIva($sala->getIva());
  2812.                     $itemInvoice->setPrdOpIva($sala->getOpIva());
  2813.                     $em->persist($itemInvoice);
  2814.                     $em->flush();
  2815.                     //Acumulamos neto e iva para la factura
  2816.                     //                    $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
  2817.                     $valorTotalNet $valorTotalNet $itemInvoice->getPrdSubTotalPrice();
  2818.                     //                    $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  2819.                     $valorVat $valorVat round(($itemInvoice->getPrdSubTotalPrice() * ($sala->getIva() / 100)), 2PHP_ROUND_HALF_UP);
  2820.                 }
  2821.             }
  2822.         }
  2823.         if (!empty($arrayBools['service'])) {
  2824.             foreach ($arrayBools['service'] as $key => $item) {
  2825.                 if ($item == 'true') {
  2826.                     $boolMakeInvoice true;
  2827.                     $servicio $em->getRepository(AveServices::class)->findOneById($key);
  2828.                     $itemInvoice = new AveDocInvoiceItems();
  2829.                     $itemInvoice->setFileId($id);
  2830.                     $itemInvoice->setInvoiceId($invoiceId);
  2831.                     $itemInvoice->setItemType('SERVICE');
  2832.                     $itemInvoice->setSrvControlId($key);
  2833.                     $itemInvoice->setSrvSupplierId($servicio->getSupplierId());
  2834.                     $itemInvoice->setSrvServiceId($servicio->getServiceId());
  2835.                     $itemInvoice->setSrvServiceCatId($servicio->getServiceCatId());
  2836.                     $itemInvoice->setSrvServiceCatName($servicio->getServiceCatName());
  2837.                     $itemInvoice->setSrvPrice($servicio->getPrice());
  2838.                     $itemInvoice->setSrvCurrency($servicio->getCurrency());
  2839.                     $itemInvoice->setSrvUnits($servicio->getUnits());
  2840.                     $itemInvoice->setSrvOpCommission($servicio->getOpCommission());
  2841.                     $itemInvoice->setSrvCommission($servicio->getCommission());
  2842.                     $itemInvoice->setSrvOpOver($servicio->getOpOver());
  2843.                     $itemInvoice->setSrvOver($servicio->getOver());
  2844.                     $itemInvoice->setSrvOpIva($servicio->getOpIva());
  2845.                     $itemInvoice->setSrvIva($servicio->getIva());
  2846.                     $itemInvoice->setSrvPax($servicio->getPax());
  2847.                     $itemInvoice->setSrvHour($servicio->getHour());
  2848.                     $itemInvoice->setSrvDateInAt($servicio->getDateInAt());
  2849.                     $itemInvoice->setSrvDateOutAt($servicio->getDateOutAt());
  2850.                     $itemInvoice->setSrvContcolor($servicio->getContcolor());
  2851.                     $itemInvoice->setSrvRank($servicio->getRank());
  2852.                     $itemInvoice->setSrvAssistantId($servicio->getAssistantId());
  2853.                     $itemInvoice->setSrvActivityId($servicio->getActivityId());
  2854.                     $itemInvoice->setSrvPay($servicio->getPay());
  2855.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  2856.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  2857.                     $itemInvoice->setCreatedId($user_id);
  2858.                     $itemInvoice->setUpdatedId($user_id);
  2859.                     $em->persist($itemInvoice);
  2860.                     $em->flush();
  2861.                     //Acumulamos neto e iva para la factura
  2862.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  2863.                         $subtotal 0;
  2864.                         $neto 0;
  2865.                         $subtotalService 0;
  2866.                     } else {
  2867.                         $subtotalService $itemInvoice->getSrvPrice();
  2868.                         $subneto $itemInvoice->getSrvPrice();
  2869.                         // Commission
  2870.                         if ($itemInvoice->getSrvOpCommission() == '1') {
  2871.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  2872.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission() / 100));
  2873.                         } else {
  2874.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  2875.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  2876.                         }
  2877.                         // Over
  2878.                         if ($itemInvoice->getSrvOpOver() == '1') {
  2879.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  2880.                             $subneto $subneto $itemInvoice->getSrvOver();
  2881.                         } else {
  2882.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  2883.                             $subneto $subneto $itemInvoice->getSrvOver();
  2884.                         }
  2885.                         // IVA
  2886.                         if ($itemInvoice->getSrvOpIva() == '1') {
  2887.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  2888.                         } else {
  2889.                             $subtotalService $itemInvoice->getSrvPrice();
  2890.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  2891.                         }
  2892.                         switch ($itemInvoice->getSrvServiceCatId()) {
  2893.                             case 1// Alojamiento
  2894.                                 // el numero de noches $numNoches; precio unitario $subneto
  2895.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  2896.                                 // La personas no afectan este calculo
  2897.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  2898.                                 $subnetoUnit $subneto;
  2899.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  2900.                                 break;
  2901.                             case 2//Actividades
  2902.                                 // El nĂºmero de personas es considerado en el calculo
  2903.                                 $pax $itemInvoice->getSrvPax();
  2904.                                 if (empty($pax) or $pax == "0") {
  2905.                                     $pax 1;
  2906.                                 }
  2907.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2908.                                 if ($days 1) {
  2909.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2910.                                 } else {
  2911.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2912.                                 }
  2913.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  2914.                                 $subnetoUnit $subneto;
  2915.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  2916.                                 break;
  2917.                             case 3// AV
  2918.                                 $pax $itemInvoice->getSrvPax();
  2919.                                 if (empty($pax) or $pax == "0") {
  2920.                                     $pax 1;
  2921.                                 }
  2922.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2923.                                 if ($days 1) {
  2924.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2925.                                 } else {
  2926.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2927.                                 }
  2928.                                 $unitsServ $itemInvoice->getSrvUnits();
  2929.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2930.                                     $unitsServ 1;
  2931.                                 }
  2932.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2933.                                 $subnetoUnit $subneto;
  2934.                                 $subneto $subneto $days $unitsServ $pax;
  2935.                                 break;
  2936.                             case 4//Creative
  2937.                                 $pax $itemInvoice->getSrvPax();
  2938.                                 if (empty($pax) or $pax == "0") {
  2939.                                     $pax 1;
  2940.                                 }
  2941.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2942.                                 if ($days 1) {
  2943.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2944.                                 } else {
  2945.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2946.                                 }
  2947.                                 $unitsServ $itemInvoice->getSrvUnits();
  2948.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2949.                                     $unitsServ 1;
  2950.                                 }
  2951.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2952.                                 $subnetoUnit $subneto;
  2953.                                 $subneto $subneto $days $unitsServ $pax;
  2954.                                 break;
  2955.                             case 5//Cruise
  2956.                                 $pax $itemInvoice->getSrvPax();
  2957.                                 if (empty($pax) or $pax == "0") {
  2958.                                     $pax 1;
  2959.                                 }
  2960.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  2961.                                 if ($days 1) {
  2962.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2963.                                 } else {
  2964.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2965.                                 }
  2966.                                 $unitsServ $itemInvoice->getSrvUnits();
  2967.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2968.                                     $unitsServ 1;
  2969.                                 }
  2970.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2971.                                 $subnetoUnit $subneto;
  2972.                                 $subneto $subneto $days $unitsServ $pax;
  2973.                                 break;
  2974.                             case 6//Entertaiment
  2975.                                 $pax $itemInvoice->getSrvPax();
  2976.                                 if (empty($pax) or $pax == "0") {
  2977.                                     $pax 1;
  2978.                                 }
  2979.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  2980.                                 if ($days 1) {
  2981.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  2982.                                 } else {
  2983.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  2984.                                 }
  2985.                                 $unitsServ $itemInvoice->getSrvUnits();
  2986.                                 if (empty($unitsServ) or $unitsServ == "0") {
  2987.                                     $unitsServ 1;
  2988.                                 }
  2989.                                 $subtotal $subtotalService $days $unitsServ $pax;
  2990.                                 $subnetoUnit $subneto;
  2991.                                 $subneto $subneto $days $unitsServ $pax;
  2992.                                 break;
  2993.                             case 7// Gifts
  2994.                                 $pax $itemInvoice->getSrvPax();
  2995.                                 if (empty($pax) or $pax == "0") {
  2996.                                     $pax 1;
  2997.                                 }
  2998.                                 $days 1;
  2999.                                 if ($days 1) {
  3000.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3001.                                 } else {
  3002.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3003.                                 }
  3004.                                 $unitsServ $itemInvoice->getSrvUnits();
  3005.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3006.                                     $unitsServ 1;
  3007.                                 }
  3008.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3009.                                 $subnetoUnit $subneto;
  3010.                                 $subneto $subneto $days $unitsServ $pax;
  3011.                                 break;
  3012.                             case 8//Guide
  3013.                                 $pax $itemInvoice->getSrvPax();
  3014.                                 if (empty($pax) or $pax == "0") {
  3015.                                     $pax 1;
  3016.                                 }
  3017.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3018.                                 if ($days 1) {
  3019.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3020.                                 } else {
  3021.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3022.                                 }
  3023.                                 $unitsServ $itemInvoice->getSrvUnits();
  3024.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3025.                                     $unitsServ 1;
  3026.                                 }
  3027.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3028.                                 $subnetoUnit $subneto;
  3029.                                 $subneto $subneto $days $unitsServ $pax;
  3030.                                 break;
  3031.                             case 9//Itineraries
  3032.                                 $pax $itemInvoice->getSrvPax();
  3033.                                 if (empty($pax) or $pax == "0") {
  3034.                                     $pax 1;
  3035.                                 }
  3036.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3037.                                 if ($days 1) {
  3038.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3039.                                 } else {
  3040.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3041.                                 }
  3042.                                 $unitsServ $itemInvoice->getSrvUnits();
  3043.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3044.                                     $unitsServ 1;
  3045.                                 }
  3046.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3047.                                 $subnetoUnit $subneto;
  3048.                                 $subneto $subneto $days $unitsServ $pax;
  3049.                                 break;
  3050.                             case 10//Lounge  -- No Aplica
  3051.                                 break;
  3052.                             case 11//Menu
  3053.                                 $pax $itemInvoice->getSrvPax();
  3054.                                 if (empty($pax) or $pax == "0") {
  3055.                                     $pax 1;
  3056.                                 }
  3057.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3058.                                 if ($days 1) {
  3059.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3060.                                 } else {
  3061.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3062.                                 }
  3063.                                 $unitsServ $itemInvoice->getSrvUnits();
  3064.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3065.                                     $unitsServ 1;
  3066.                                 }
  3067.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3068.                                 $subnetoUnit $subneto;
  3069.                                 $subneto $subneto $days $unitsServ $pax;
  3070.                                 break;
  3071.                             case 12//Others
  3072.                                 $pax $itemInvoice->getSrvPax();
  3073.                                 if (empty($pax) or $pax == "0") {
  3074.                                     $pax 1;
  3075.                                 }
  3076.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3077.                                 if ($days 1) {
  3078.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3079.                                 } else {
  3080.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3081.                                 }
  3082.                                 $unitsServ $itemInvoice->getSrvUnits();
  3083.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3084.                                     $unitsServ 1;
  3085.                                 }
  3086.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3087.                                 $subnetoUnit $subneto;
  3088.                                 $subneto $subneto $days $unitsServ $pax;
  3089.                                 break;
  3090.                             case 13//Transport
  3091.                                 $pax $itemInvoice->getSrvPax();
  3092.                                 if (empty($pax) or $pax == "0") {
  3093.                                     $pax 1;
  3094.                                 }
  3095.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3096.                                 if ($days 1) {
  3097.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3098.                                 } else {
  3099.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3100.                                 }
  3101.                                 $unitsServ $itemInvoice->getSrvUnits();
  3102.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3103.                                     $unitsServ 1;
  3104.                                 }
  3105.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3106.                                 $subnetoUnit $subneto;
  3107.                                 $subneto $subneto $days $unitsServ $pax;
  3108.                                 break;
  3109.                             case 14//Technology
  3110.                                 $pax $itemInvoice->getSrvPax();
  3111.                                 if (empty($pax) or $pax == "0") {
  3112.                                     $pax 1;
  3113.                                 }
  3114.                                 $days 1;
  3115.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3116.                                 $unitsServ $itemInvoice->getSrvUnits();
  3117.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3118.                                     $unitsServ 1;
  3119.                                 }
  3120.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3121.                                 $subnetoUnit $subneto;
  3122.                                 $subneto $subneto $days $unitsServ $pax;
  3123.                                 break;
  3124.                             case 15//Assisstant
  3125.                                 $pax $itemInvoice->getSrvPax();
  3126.                                 if (empty($pax) or $pax == "0") {
  3127.                                     $pax 1;
  3128.                                 }
  3129.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3130.                                 if ($days 1) {
  3131.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3132.                                 } else {
  3133.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3134.                                 }
  3135.                                 $unitsServ $itemInvoice->getSrvUnits();
  3136.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3137.                                     $unitsServ 1;
  3138.                                 }
  3139.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3140.                                 $subnetoUnit $subneto;
  3141.                                 $subneto $subneto $days $unitsServ $pax;
  3142.                                 break;
  3143.                             case 16//DDR
  3144.                                 $pax $itemInvoice->getSrvPax();
  3145.                                 if (empty($pax) or $pax == "0") {
  3146.                                     $pax 1;
  3147.                                 }
  3148.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3149.                                 if ($days 1) {
  3150.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3151.                                 } else {
  3152.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3153.                                 }
  3154.                                 $unitsServ $itemInvoice->getSrvUnits();
  3155.                                 if (empty($unitsServ) or $unitsServ == "0") {
  3156.                                     $unitsServ 1;
  3157.                                 }
  3158.                                 $subtotal $subtotalService $days $unitsServ $pax;
  3159.                                 $subnetoUnit $subneto;
  3160.                                 $subneto $subneto $days $unitsServ $pax;
  3161.                                 break;
  3162.                             default:
  3163.                                 break;
  3164.                         }
  3165.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  3166.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  3167.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  3168.                         $valorTotalNet $valorTotalNet $neto;
  3169.                         $valorVat $valorVat + ($subtotal $neto);
  3170.                     }
  3171.                 }
  3172.             }
  3173.         }
  3174.         if (!empty($arrayBools['payment'])) {
  3175.             foreach ($arrayBools['payment'] as $key => $item) {
  3176.                 if ($item == 'true') {
  3177.                     $boolMakeInvoice true;
  3178.                     $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  3179.                     $itemInvoice = new AveDocInvoiceItems();
  3180.                     $itemInvoice->setFileId($id);
  3181.                     $itemInvoice->setInvoiceId($invoiceId);
  3182.                     $itemInvoice->setItemType('PAYMENT');
  3183.                     $itemInvoice->setPayControlId($key);
  3184.                     $itemInvoice->setPayAmount($pago->getAmount());
  3185.                     $itemInvoice->setPayVat($pago->getVat());
  3186.                     $itemInvoice->setPayAmountTotal($pago->getAmountTotal());
  3187.                     $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  3188.                     $itemInvoice->setPayWayToPay($pago->getWayToPay());
  3189.                     $itemInvoice->setCreatedAt(new DateTime('now'));
  3190.                     $itemInvoice->setUpdatedAt(new DateTime('now'));
  3191.                     $itemInvoice->setCreatedId($user_id);
  3192.                     $itemInvoice->setUpdatedId($user_id);
  3193.                     $em->persist($itemInvoice);
  3194.                     $em->flush();
  3195.                     //Acumulamos neto e iva para la factura
  3196.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  3197.                 }
  3198.             }
  3199.         }
  3200.         //FIN: Creamos los items de la factura
  3201.         $valorTotal $valorTotalNet $valorVat;
  3202.         //INICIO: Creamos la factura
  3203.         $newInvoice = new AveDocInvoice();
  3204.         $newInvoice->setAccessKey(md5(rand() * time()));
  3205.         $newInvoice->setNumber('AVE-' date('dmy') . "-" $id);
  3206.         $newInvoice->setDateAt(new DateTime('now'));
  3207.         $newInvoice->setType('Invoice');
  3208.         $newInvoice->setFileId($id);
  3209.         $newInvoice->setTotalNet($valorTotalNet);
  3210.         $newInvoice->setVat($valorVat);
  3211.         $newInvoice->setTotal($valorTotal);
  3212.         $newInvoice->setCreatedAt(new DateTime('now'));
  3213.         $newInvoice->setCreatedId($user_id);
  3214.         $newInvoice->setUpdatedAt(new DateTime('now'));
  3215.         $newInvoice->setUpdatedId($user_id);
  3216.         $newInvoice->setMaster('master');
  3217.         if ($boolMakeInvoice) {
  3218.             // Solo se debe crear factura si hay un elemento
  3219.             $em->persist($newInvoice);
  3220.             $em->flush();
  3221.             $newInvoice->setNumber($newInvoice->getNumber() . '-' $newInvoice->getId());
  3222.             $em->persist($newInvoice);
  3223.             $em->flush();
  3224.         } else {
  3225.             // Se llama a la vista de facturas del expediente
  3226.             return $this->redirectToRoute('ave_view_invoice', array('id' => $id));
  3227.         }
  3228.         //FIN: Creamos la factura
  3229.         $data = array();
  3230.         $data $this->baseInvoiceSelectedFile($id$arrayBools'I' $newInvoice->getId());
  3231.         $paymentsClient = new AvePaymentsClient();
  3232.         $paymentsClient->setFileId($id);
  3233.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  3234.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  3235.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  3236.         $proforma $em->getRepository(AveDocProforma::class)->findOneByFileId($id);
  3237.         $reservaInv = new AveDocInvoice();
  3238.         $reservaInv->setAccessKey(md5(rand() * time()));
  3239.         $reservaInv->setFileId($id);
  3240.         $idProducts = array();
  3241.         $productsBoolToInvoice = array();
  3242.         if (array_key_exists('lounge'$data['datasupplier'])) {
  3243.             foreach ($data['datasupplier']['lounge'] as $item) {
  3244.                 $idProducts[] = $item['id'];
  3245.                 $productsBoolToInvoice[] = 1;
  3246.             }
  3247.             $idProducts implode(','$idProducts);
  3248.             $productsBoolToInvoice implode(','$productsBoolToInvoice);
  3249.         } else {
  3250.             $idProducts '0';
  3251.             $productsBoolToInvoice '0';
  3252.         }
  3253.         $idPayments = array();
  3254.         $paymentsBoolToInvoice = array();
  3255.         if (array_key_exists('payment'$data['datasupplier'])) {
  3256.             foreach ($data['datasupplier']['payment'] as $item) {
  3257.                 $idPayments[] = $item['id'];
  3258.                 $paymentsBoolToInvoice[] = 1;
  3259.             }
  3260.             $idPayments implode(','$idPayments);
  3261.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  3262.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  3263.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  3264.             // Para manipularlos entre la vista y el JS
  3265.         } else {
  3266.             $idPayments '0';
  3267.             $paymentsBoolToInvoice '0';
  3268.         }
  3269.         // Una factura solo se puede rectificar una vez
  3270.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  3271.         $boolToRec = empty($rectf);
  3272.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  3273.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
  3274.         foreach ($allInvoicesRec as $item) {
  3275.             array_push($allInvoices$item);
  3276.         }
  3277.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($id);
  3278.         if (empty($data['type'])) {
  3279.             $data['type'] = 'Invoice';
  3280.         }
  3281.         if (array_key_exists('paymentSubTotal'$data['datasupplier'])) {
  3282.             $paymentInvoice $data['datasupplier']['paymentSubTotal']['sumSubT'];
  3283.         } else {
  3284.             $paymentInvoice 0;
  3285.         }
  3286.         $this->calculoBeneficiosDocumento($newInvoice->getId(), 'Invoice');
  3287.         return $this->redirectToRoute(
  3288.             'ave_view_invoice',
  3289.             array(
  3290.                 'id' => $newInvoice->getId()
  3291.             )
  3292.         );
  3293.     }
  3294.     /**
  3295.      * @Route("/newinvoicefromproforma/{id}", name="ave_new_invoice_from_proforma")
  3296.      * Crear nueva factura con los elementos seleccionados en una proforma
  3297.      */
  3298.     public function generateNewInvoiceFromProformaAction($idRequest $request)
  3299.     {
  3300.         $em $this->getDoctrine()->getManager();
  3301.         $proformaOrigen $em->getRepository(AveDocProforma::class)->findOneById($id);
  3302.         //INICIO: Buscamos los elementos de la proforma y verificamos disponibilidad
  3303.         $proformaOrigenItems $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
  3304.         $algunItemEstaFacturado false;
  3305.         foreach ($proformaOrigenItems as $item) {
  3306.             if ($item->getType() == 'PRODUCT') {
  3307.                 $estaFacturado $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getControlId());
  3308.                 if (!empty($estaFacturado)) {
  3309.                     $algunItemEstaFacturado true;
  3310.                 }
  3311.             }
  3312.             if ($item->getType() == 'PAYMENT') {
  3313.                 $estaFacturado $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getControlId());
  3314.                 if (!empty($estaFacturado)) {
  3315.                     $algunItemEstaFacturado true;
  3316.                 }
  3317.             }
  3318.             if ($item->getType() == 'SERVICE') {
  3319.                 $estaFacturado $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getControlId());
  3320.                 if (!empty($estaFacturado)) {
  3321.                     $algunItemEstaFacturado true;
  3322.                 }
  3323.             }
  3324.         }
  3325.         //FIN: Buscamos los elementos de la proforma y verificamos disponibilidad
  3326.         // Obtengo usuario logueado
  3327.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3328.         $user_id $user_logueado->getId();
  3329.         if ($algunItemEstaFacturado) {
  3330.             $id $proformaOrigen->getFileId();
  3331.             return $this->render(
  3332.                 'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  3333.                 array(
  3334.                     'id' => $id,
  3335.                     'docType' => 'Error Elementos ya Facturados',
  3336.                     'proforma' => '',
  3337.                     'company' => '',
  3338.                     'clients' => '',
  3339.                     'date' => '',
  3340.                     'number' => '',
  3341.                     'invoice' => null,
  3342.                     'fid' => '',
  3343.                     'boolToRec' => false,
  3344.                     'proformas' => '',
  3345.                     'currency' => '',
  3346.                     'totales_neto' => '',
  3347.                     'totales' => '',
  3348.                     'balance' => '',
  3349.                     'bases_imponibles' => '',
  3350.                     'user' => $user_logueado,
  3351.                     'comments' => null,
  3352.                     'services' => null,
  3353.                     'facturas' => null,
  3354.                     'paymentNotIvoiced' => null,
  3355.                     'paymentsAll' => null,
  3356.                     'totales_global_servicios_con_iva' => 0//$data['totales_global_servicios_con_iva'],
  3357.                     'totales_global_servicios_neto' => 0//$data['totales_global_servicios_neto'],
  3358.                     'totales_global_servicios_iva' => 0//$data['totales_global_servicios_iva'],
  3359.                     'sumatoria_totales_global_con_iva' => 0//$data['sumatoria_totales_global_con_iva'],
  3360.                     'sumatoria_totales_global_neto' => 0//$data['sumatoria_totales_global_neto'],
  3361.                     'sumatoria_totales_global_iva' => 0//$data['sumatoria_totales_global_iva'],
  3362.                 )
  3363.             );
  3364.         } else {
  3365.             // Se genera y muestra en nueva pantalla la nueva proforma
  3366.             $arrayBools = array(
  3367.                 'product' => null,
  3368.                 'service' => null,
  3369.                 'payment' => null,
  3370.             );
  3371.             foreach ($proformaOrigenItems as $item) {
  3372.                 if ($item->getType() == 'PRODUCT') {
  3373.                     $arrayBools['product'][$item->getControlId()] = 'true';
  3374.                 }
  3375.                 if ($item->getType() == 'SERVICE') {
  3376.                     $arrayBools['service'][$item->getControlId()] = 'true';
  3377.                 }
  3378.                 if ($item->getType() == 'PAYMENT') {
  3379.                     $arrayBools['payment'][$item->getControlId()] = 'true';
  3380.                 }
  3381.             }
  3382.             //            $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  3383.             //            $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  3384.             //            $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  3385.             $id $proformaOrigen->getFileId();
  3386.             //INICIO: buscamos el ID de la factura
  3387.             $allFacturas $em->getRepository(AveDocInvoice::class)->findAll();
  3388.             if (!empty($allFacturas)) {
  3389.                 $invoiceId end($allFacturas)->getId() + 1;
  3390.             } else {
  3391.                 $invoiceId 1;
  3392.                 //                $invoiceId = 10;    //La primera factura de AV en el sistema serĂ¡ la 10, se cambia el numero de serie a A1, A2,...
  3393.             }
  3394.             $boolMakeInvoice false;  // Control para verificar si se debe hacer factura o todos los indicadores (sala, servicios y pagos) estaban en falso
  3395.             //FIN: buscamos el ID de la factura
  3396.             /* Obtengo usuario logueado */
  3397.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3398.             $user_id $user_logueado->getId();
  3399.             //Acumuladores de datos globales de la factura
  3400.             $valorTotalNet 0;
  3401.             $valorVat 0;
  3402.             //INICIO: Creamos los items de la factura
  3403.             if (!empty($arrayBools['product'])) {
  3404.                 foreach ($arrayBools['product'] as $key => $item) {
  3405.                     if ($item == 'true') {
  3406.                         $boolMakeInvoice true;
  3407.                         $sala $em->getRepository(AveProductFile::class)->findOneById($key);
  3408.                         $itemInvoice = new AveDocInvoiceItems();
  3409.                         $itemInvoice->setFileId($id);
  3410.                         $itemInvoice->setInvoiceId($invoiceId);
  3411.                         $itemInvoice->setItemType('PRODUCT');
  3412.                         $itemInvoice->setPrdControlId($key);
  3413.                         $itemInvoice->setPrdName($sala->getProductName());
  3414.                         $itemInvoice->setPrdProductId($sala->getProductId());
  3415.                         $itemInvoice->setPrdProductId($sala->getProductId());
  3416.                         $itemInvoice->setPrdDateStart($sala->getDateStart());
  3417.                         $itemInvoice->setPrdType($sala->getType());
  3418.                         if (empty($sala->getLocation())) {
  3419.                             $itemInvoice->setLocation(null);
  3420.                         } else {
  3421.                             $itemInvoice->setLocation($sala->getLocation());
  3422.                         }
  3423.                         $itemInvoice->setRankAv($sala->getRankAv());
  3424.                         $itemInvoice->setPrdDateEnd($sala->getDateEnd());
  3425.                         $itemInvoice->setPrdServicePrice($sala->getServicePrice());
  3426.                         $itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
  3427.                         $itemInvoice->setPrdQty($sala->getUnits());
  3428.                         $itemInvoice->setPrdPax($sala->getPax());
  3429.                         $itemInvoice->setPrdDays($sala->getDays());
  3430.                         $itemInvoice->setCreatedId($user_id);
  3431.                         $itemInvoice->setCreatedAt(new DateTime('now'));
  3432.                         $itemInvoice->setUpdatedId($user_id);
  3433.                         $itemInvoice->setUpdatedAt(new DateTime('now'));
  3434.                         $itemInvoice->setPrdHourStart($sala->getHourStart());
  3435.                         $itemInvoice->setPrdMinStart($sala->getMinStart());
  3436.                         $itemInvoice->setPrdHourEnd($sala->getHourEnd());
  3437.                         $itemInvoice->setPrdMinEnd($sala->getMinEnd());
  3438.                         $itemInvoice->setPrdIva($sala->getIva());
  3439.                         $itemInvoice->setPrdOpIva($sala->getOpIva());
  3440.                         $em->persist($itemInvoice);
  3441.                         $em->flush();
  3442.                         //Acumulamos neto e iva para la factura
  3443.                         //                        $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
  3444.                         $valorTotalNet $valorTotalNet $itemInvoice->getPrdSubTotalPrice();
  3445.                         //                        $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21), 2, PHP_ROUND_HALF_UP);
  3446.                         $valorVat $valorVat round(($itemInvoice->getPrdSubTotalPrice() * 0.21), 2PHP_ROUND_HALF_UP);
  3447.                     }
  3448.                 }
  3449.             }
  3450.             if (!empty($arrayBools['service'])) {
  3451.                 foreach ($arrayBools['service'] as $key => $item) {
  3452.                     if ($item == 'true') {
  3453.                         $boolMakeInvoice true;
  3454.                         $servicio $em->getRepository(AveServices::class)->findOneById($key);
  3455.                         $itemInvoice = new AveDocInvoiceItems();
  3456.                         $itemInvoice->setFileId($id);
  3457.                         $itemInvoice->setInvoiceId($invoiceId);
  3458.                         $itemInvoice->setItemType('SERVICE');
  3459.                         $itemInvoice->setSrvControlId($key);
  3460.                         $itemInvoice->setSrvSupplierId($servicio->getSupplierId());
  3461.                         $itemInvoice->setSrvServiceId($servicio->getServiceId());
  3462.                         $itemInvoice->setSrvServiceCatId($servicio->getServiceCatId());
  3463.                         $itemInvoice->setSrvServiceCatName($servicio->getServiceCatName());
  3464.                         $itemInvoice->setSrvPrice($servicio->getPrice());
  3465.                         $itemInvoice->setSrvCurrency($servicio->getCurrency());
  3466.                         $itemInvoice->setSrvUnits($servicio->getUnits());
  3467.                         $itemInvoice->setSrvOpCommission($servicio->getOpCommission());
  3468.                         $itemInvoice->setSrvCommission($servicio->getCommission());
  3469.                         $itemInvoice->setSrvOpOver($servicio->getOpOver());
  3470.                         $itemInvoice->setSrvOver($servicio->getOver());
  3471.                         $itemInvoice->setSrvOpIva($servicio->getOpIva());
  3472.                         $itemInvoice->setSrvIva($servicio->getIva());
  3473.                         $itemInvoice->setSrvPax($servicio->getPax());
  3474.                         $itemInvoice->setSrvHour($servicio->getHour());
  3475.                         $itemInvoice->setSrvDateInAt($servicio->getDateInAt());
  3476.                         $itemInvoice->setSrvDateOutAt($servicio->getDateOutAt());
  3477.                         $itemInvoice->setSrvContcolor($servicio->getContcolor());
  3478.                         $itemInvoice->setSrvRank($servicio->getRank());
  3479.                         $itemInvoice->setSrvAssistantId($servicio->getAssistantId());
  3480.                         $itemInvoice->setSrvActivityId($servicio->getActivityId());
  3481.                         $itemInvoice->setSrvPay($servicio->getPay());
  3482.                         $itemInvoice->setCreatedAt(new DateTime('now'));
  3483.                         $itemInvoice->setUpdatedAt(new DateTime('now'));
  3484.                         $itemInvoice->setCreatedId($user_id);
  3485.                         $itemInvoice->setUpdatedId($user_id);
  3486.                         $em->persist($itemInvoice);
  3487.                         $em->flush();
  3488.                         //Acumulamos neto e iva para la factura
  3489.                         if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  3490.                             $subtotal 0;
  3491.                             $neto 0;
  3492.                             $subtotalService 0;
  3493.                         } else {
  3494.                             $subtotalService $itemInvoice->getSrvPrice();
  3495.                             $subneto $itemInvoice->getSrvPrice();
  3496.                             // Commission
  3497.                             if ($itemInvoice->getSrvOpCommission() == '1') {
  3498.                                 $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  3499.                                 $subneto $subneto * (+ ($itemInvoice->getSrvCommission() / 100));
  3500.                             } else {
  3501.                                 $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  3502.                                 $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  3503.                             }
  3504.                             // Over
  3505.                             if ($itemInvoice->getSrvOpOver() == '1') {
  3506.                                 $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3507.                                 $subneto $subneto $itemInvoice->getSrvOver();
  3508.                             } else {
  3509.                                 $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3510.                                 $subneto $subneto $itemInvoice->getSrvOver();
  3511.                             }
  3512.                             // IVA
  3513.                             if ($itemInvoice->getSrvOpIva() == '1') {
  3514.                                 $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  3515.                             } else {
  3516.                                 $subtotalService $itemInvoice->getSrvPrice();
  3517.                                 $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  3518.                             }
  3519.                             switch ($itemInvoice->getSrvServiceCatId()) {
  3520.                                 case 1// Alojamiento
  3521.                                     // el numero de noches $numNoches; precio unitario $subneto
  3522.                                     $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  3523.                                     // La personas no afectan este calculo
  3524.                                     $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  3525.                                     $subnetoUnit $subneto;
  3526.                                     $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  3527.                                     break;
  3528.                                 case 2//Actividades
  3529.                                     // El nĂºmero de personas es considerado en el calculo
  3530.                                     $pax $itemInvoice->getSrvPax();
  3531.                                     if (empty($pax) or $pax == "0") {
  3532.                                         $pax 1;
  3533.                                     }
  3534.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3535.                                     if ($days 1) {
  3536.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3537.                                     } else {
  3538.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3539.                                     }
  3540.                                     $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  3541.                                     $subnetoUnit $subneto;
  3542.                                     $subneto $subneto $days $itemInvoice->getSrvUnits();
  3543.                                     break;
  3544.                                 case 3// AV
  3545.                                     $pax $itemInvoice->getSrvPax();
  3546.                                     if (empty($pax) or $pax == "0") {
  3547.                                         $pax 1;
  3548.                                     }
  3549.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3550.                                     if ($days 1) {
  3551.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3552.                                     } else {
  3553.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3554.                                     }
  3555.                                     $unitsServ $itemInvoice->getSrvUnits();
  3556.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3557.                                         $unitsServ 1;
  3558.                                     }
  3559.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3560.                                     $subnetoUnit $subneto;
  3561.                                     $subneto $subneto $days $unitsServ $pax;
  3562.                                     break;
  3563.                                 case 4//Creative
  3564.                                     $pax $itemInvoice->getSrvPax();
  3565.                                     if (empty($pax) or $pax == "0") {
  3566.                                         $pax 1;
  3567.                                     }
  3568.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3569.                                     if ($days 1) {
  3570.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3571.                                     } else {
  3572.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3573.                                     }
  3574.                                     $unitsServ $itemInvoice->getSrvUnits();
  3575.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3576.                                         $unitsServ 1;
  3577.                                     }
  3578.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3579.                                     $subnetoUnit $subneto;
  3580.                                     $subneto $subneto $days $unitsServ $pax;
  3581.                                     break;
  3582.                                 case 5//Cruise
  3583.                                     $pax $itemInvoice->getSrvPax();
  3584.                                     if (empty($pax) or $pax == "0") {
  3585.                                         $pax 1;
  3586.                                     }
  3587.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  3588.                                     if ($days 1) {
  3589.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3590.                                     } else {
  3591.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3592.                                     }
  3593.                                     $unitsServ $itemInvoice->getSrvUnits();
  3594.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3595.                                         $unitsServ 1;
  3596.                                     }
  3597.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3598.                                     $subnetoUnit $subneto;
  3599.                                     $subneto $subneto $days $unitsServ $pax;
  3600.                                     break;
  3601.                                 case 6//Entertaiment
  3602.                                     $pax $itemInvoice->getSrvPax();
  3603.                                     if (empty($pax) or $pax == "0") {
  3604.                                         $pax 1;
  3605.                                     }
  3606.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3607.                                     if ($days 1) {
  3608.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3609.                                     } else {
  3610.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3611.                                     }
  3612.                                     $unitsServ $itemInvoice->getSrvUnits();
  3613.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3614.                                         $unitsServ 1;
  3615.                                     }
  3616.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3617.                                     $subnetoUnit $subneto;
  3618.                                     $subneto $subneto $days $unitsServ $pax;
  3619.                                     break;
  3620.                                 case 7// Gifts
  3621.                                     $pax $itemInvoice->getSrvPax();
  3622.                                     if (empty($pax) or $pax == "0") {
  3623.                                         $pax 1;
  3624.                                     }
  3625.                                     $days 1;
  3626.                                     if ($days 1) {
  3627.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3628.                                     } else {
  3629.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3630.                                     }
  3631.                                     $unitsServ $itemInvoice->getSrvUnits();
  3632.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3633.                                         $unitsServ 1;
  3634.                                     }
  3635.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3636.                                     $subnetoUnit $subneto;
  3637.                                     $subneto $subneto $days $unitsServ $pax;
  3638.                                     break;
  3639.                                 case 8//Guide
  3640.                                     $pax $itemInvoice->getSrvPax();
  3641.                                     if (empty($pax) or $pax == "0") {
  3642.                                         $pax 1;
  3643.                                     }
  3644.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3645.                                     if ($days 1) {
  3646.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3647.                                     } else {
  3648.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3649.                                     }
  3650.                                     $unitsServ $itemInvoice->getSrvUnits();
  3651.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3652.                                         $unitsServ 1;
  3653.                                     }
  3654.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3655.                                     $subnetoUnit $subneto;
  3656.                                     $subneto $subneto $days $unitsServ $pax;
  3657.                                     break;
  3658.                                 case 9//Itineraries
  3659.                                     $pax $itemInvoice->getSrvPax();
  3660.                                     if (empty($pax) or $pax == "0") {
  3661.                                         $pax 1;
  3662.                                     }
  3663.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3664.                                     if ($days 1) {
  3665.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3666.                                     } else {
  3667.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3668.                                     }
  3669.                                     $unitsServ $itemInvoice->getSrvUnits();
  3670.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3671.                                         $unitsServ 1;
  3672.                                     }
  3673.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3674.                                     $subnetoUnit $subneto;
  3675.                                     $subneto $subneto $days $unitsServ $pax;
  3676.                                     break;
  3677.                                 case 10//Lounge  -- No Aplica
  3678.                                     break;
  3679.                                 case 11//Menu
  3680.                                     $pax $itemInvoice->getSrvPax();
  3681.                                     if (empty($pax) or $pax == "0") {
  3682.                                         $pax 1;
  3683.                                     }
  3684.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3685.                                     if ($days 1) {
  3686.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3687.                                     } else {
  3688.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3689.                                     }
  3690.                                     $unitsServ $itemInvoice->getSrvUnits();
  3691.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3692.                                         $unitsServ 1;
  3693.                                     }
  3694.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3695.                                     $subnetoUnit $subneto;
  3696.                                     $subneto $subneto $days $unitsServ $pax;
  3697.                                     break;
  3698.                                 case 12//Others
  3699.                                     $pax $itemInvoice->getSrvPax();
  3700.                                     if (empty($pax) or $pax == "0") {
  3701.                                         $pax 1;
  3702.                                     }
  3703.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3704.                                     if ($days 1) {
  3705.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3706.                                     } else {
  3707.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3708.                                     }
  3709.                                     $unitsServ $itemInvoice->getSrvUnits();
  3710.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3711.                                         $unitsServ 1;
  3712.                                     }
  3713.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3714.                                     $subnetoUnit $subneto;
  3715.                                     $subneto $subneto $days $unitsServ $pax;
  3716.                                     break;
  3717.                                 case 13//Transport
  3718.                                     $pax $itemInvoice->getSrvPax();
  3719.                                     if (empty($pax) or $pax == "0") {
  3720.                                         $pax 1;
  3721.                                     }
  3722.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3723.                                     if ($days 1) {
  3724.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3725.                                     } else {
  3726.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3727.                                     }
  3728.                                     $unitsServ $itemInvoice->getSrvUnits();
  3729.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3730.                                         $unitsServ 1;
  3731.                                     }
  3732.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3733.                                     $subnetoUnit $subneto;
  3734.                                     $subneto $subneto $days $unitsServ $pax;
  3735.                                     break;
  3736.                                 case 14//Technology
  3737.                                     $pax $itemInvoice->getSrvPax();
  3738.                                     if (empty($pax) or $pax == "0") {
  3739.                                         $pax 1;
  3740.                                     }
  3741.                                     $days 1;
  3742.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3743.                                     $unitsServ $itemInvoice->getSrvUnits();
  3744.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3745.                                         $unitsServ 1;
  3746.                                     }
  3747.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3748.                                     $subnetoUnit $subneto;
  3749.                                     $subneto $subneto $days $unitsServ $pax;
  3750.                                     break;
  3751.                                 case 15//Assisstant
  3752.                                     $pax $itemInvoice->getSrvPax();
  3753.                                     if (empty($pax) or $pax == "0") {
  3754.                                         $pax 1;
  3755.                                     }
  3756.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3757.                                     if ($days 1) {
  3758.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3759.                                     } else {
  3760.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3761.                                     }
  3762.                                     $unitsServ $itemInvoice->getSrvUnits();
  3763.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3764.                                         $unitsServ 1;
  3765.                                     }
  3766.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3767.                                     $subnetoUnit $subneto;
  3768.                                     $subneto $subneto $days $unitsServ $pax;
  3769.                                     break;
  3770.                                 case 16//DDR
  3771.                                     $pax $itemInvoice->getSrvPax();
  3772.                                     if (empty($pax) or $pax == "0") {
  3773.                                         $pax 1;
  3774.                                     }
  3775.                                     $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  3776.                                     if ($days 1) {
  3777.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  3778.                                     } else {
  3779.                                         $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  3780.                                     }
  3781.                                     $unitsServ $itemInvoice->getSrvUnits();
  3782.                                     if (empty($unitsServ) or $unitsServ == "0") {
  3783.                                         $unitsServ 1;
  3784.                                     }
  3785.                                     $subtotal $subtotalService $days $unitsServ $pax;
  3786.                                     $subnetoUnit $subneto;
  3787.                                     $subneto $subneto $days $unitsServ $pax;
  3788.                                     break;
  3789.                                 default:
  3790.                                     break;
  3791.                             }
  3792.                             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  3793.                             $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  3794.                             $neto round($subneto2PHP_ROUND_HALF_UP);
  3795.                             $valorTotalNet $valorTotalNet $neto;
  3796.                             $valorVat $valorVat + ($subtotal $neto);
  3797.                         }
  3798.                     }
  3799.                 }
  3800.             }
  3801.             if (!empty($arrayBools['payment'])) {
  3802.                 foreach ($arrayBools['payment'] as $key => $item) {
  3803.                     if ($item == 'true') {
  3804.                         $boolMakeInvoice true;
  3805.                         $pago $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  3806.                         $itemInvoice = new AveDocInvoiceItems();
  3807.                         $itemInvoice->setFileId($id);
  3808.                         $itemInvoice->setInvoiceId($invoiceId);
  3809.                         $itemInvoice->setItemType('PAYMENT');
  3810.                         $itemInvoice->setPayControlId($key);
  3811.                         $itemInvoice->setPayAmount($pago->getAmount());
  3812.                         $itemInvoice->setPayVat($pago->getVat());
  3813.                         $itemInvoice->setPayAmountTotal($pago->getAmountTotal());
  3814.                         $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  3815.                         $itemInvoice->setPayWayToPay($pago->getWayToPay());
  3816.                         $itemInvoice->setCreatedAt(new DateTime('now'));
  3817.                         $itemInvoice->setUpdatedAt(new DateTime('now'));
  3818.                         $itemInvoice->setCreatedId($user_id);
  3819.                         $itemInvoice->setUpdatedId($user_id);
  3820.                         $em->persist($itemInvoice);
  3821.                         $em->flush();
  3822.                         //Acumulamos neto e iva para la factura
  3823.                         //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  3824.                     }
  3825.                 }
  3826.             }
  3827.             //FIN: Creamos los items de la factura
  3828.             $valorTotal $valorTotalNet $valorVat;
  3829.             //INICIO: Creamos la factura
  3830.             $newInvoice = new AveDocInvoice();
  3831.             $newInvoice->setAccessKey(md5(rand() * time()));
  3832.             $newInvoice->setNumber('AVE-' date('dmy') . "-" $id);
  3833.             $newInvoice->setDateAt(new DateTime('now'));
  3834.             $newInvoice->setType('Invoice');
  3835.             $newInvoice->setFileId($id);
  3836.             $newInvoice->setTotalNet($valorTotalNet);
  3837.             $newInvoice->setVat($valorVat);
  3838.             $newInvoice->setTotal($valorTotal);
  3839.             $newInvoice->setCreatedAt(new DateTime('now'));
  3840.             $newInvoice->setCreatedId($user_id);
  3841.             $newInvoice->setUpdatedAt(new DateTime('now'));
  3842.             $newInvoice->setUpdatedId($user_id);
  3843.             $newInvoice->setMaster('master');
  3844.             if ($boolMakeInvoice) {
  3845.                 // Solo se debe crear factura si hay un elemento
  3846.                 $em->persist($newInvoice);
  3847.                 $em->flush();
  3848.                 $newInvoice->setNumber($newInvoice->getNumber() . '-' $newInvoice->getId());
  3849.                 $em->persist($newInvoice);
  3850.                 $em->flush();
  3851.             } else {
  3852.                 // Se llama a la vista de facturas del expediente
  3853.                 return $this->redirectToRoute('ave_view_invoice', array('id' => $id));
  3854.             }
  3855.             //FIN: Creamos la factura
  3856.             $data = array();
  3857.             $data $this->baseInvoiceSelectedFile($id$arrayBools'I' $newInvoice->getId());
  3858.             $paymentsClient = new AvePaymentsClient();
  3859.             $paymentsClient->setFileId($id);
  3860.             $file $em->getRepository(AveFiles::class)->findOneById($id);
  3861.             $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  3862.             $services $em->getRepository(AveServices::class)->findByFileId($id);
  3863.             $proforma $em->getRepository(AveDocProforma::class)->findOneByFileId($id);
  3864.             $reservaInv = new AveDocInvoice();
  3865.             $reservaInv->setAccessKey(md5(rand() * time()));
  3866.             $reservaInv->setFileId($id);
  3867.             $idProducts = array();
  3868.             $productsBoolToInvoice = array();
  3869.             if (array_key_exists('lounge'$data['datasupplier'])) {
  3870.                 foreach ($data['datasupplier']['lounge'] as $item) {
  3871.                     $idProducts[] = $item['id'];
  3872.                     $productsBoolToInvoice[] = 1;
  3873.                 }
  3874.                 $idProducts implode(','$idProducts);
  3875.                 $productsBoolToInvoice implode(','$productsBoolToInvoice);
  3876.             } else {
  3877.                 $idProducts '0';
  3878.                 $productsBoolToInvoice '0';
  3879.             }
  3880.             $idPayments = array();
  3881.             $paymentsBoolToInvoice = array();
  3882.             if (array_key_exists('payment'$data['datasupplier'])) {
  3883.                 foreach ($data['datasupplier']['payment'] as $item) {
  3884.                     $idPayments[] = $item['id'];
  3885.                     $paymentsBoolToInvoice[] = 1;
  3886.                 }
  3887.                 $idPayments implode(','$idPayments);
  3888.                 $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  3889.                 // Se han generado dos arreglos, cada uno dividido en 2 strings
  3890.                 // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  3891.                 // Para manipularlos entre la vista y el JS
  3892.             } else {
  3893.                 $idPayments '0';
  3894.                 $paymentsBoolToInvoice '0';
  3895.             }
  3896.             // Una factura solo se puede rectificar una vez
  3897.             $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  3898.             $boolToRec = empty($rectf);
  3899.             $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($id);
  3900.             $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
  3901.             foreach ($allInvoicesRec as $item) {
  3902.                 array_push($allInvoices$item);
  3903.             }
  3904.             $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($id);
  3905.             if (empty($data['type'])) {
  3906.                 $data['type'] = 'Invoice';
  3907.             }
  3908.             if (array_key_exists('paymentSubTotal'$data['datasupplier'])) {
  3909.                 $paymentInvoice $data['datasupplier']['paymentSubTotal']['sumSubT'];
  3910.             } else {
  3911.                 $paymentInvoice 0;
  3912.             }
  3913.             return $this->redirectToRoute(
  3914.                 'ave_view_invoice',
  3915.                 array(
  3916.                     'id' => $newInvoice->getId()
  3917.                 )
  3918.             );
  3919.         }
  3920.     }
  3921.     /**
  3922.      * @Route("/viewinvoice/{id}",  name="ave_view_invoice")
  3923.      * Ver una factura
  3924.      */
  3925.     public function viewNewInvoiceAction($idRequest $request)
  3926.     {
  3927.         $em $this->getDoctrine()->getManager();
  3928.         // Se genera y muestra en nueva pantalla la nueva proforma
  3929.         $arrayBools = array(
  3930.             'product' => null,
  3931.             'service' => null,
  3932.             'payment' => null,
  3933.         );
  3934.         $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  3935.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  3936.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  3937.         /* Obtengo usuario logueado */
  3938.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3939.         $user_id $user_logueado->getId();
  3940.         //Acumuladores de datos globales de la factura
  3941.         $valorTotalNet 0;
  3942.         $valorVat 0;
  3943.         //INICIO: Creamos los items de la factura
  3944.         $arrayInvoicedItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  3945.         if (!empty($arrayInvoicedItems)) {
  3946.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3947.                 if ($itemInvoice->getItemType() == 'PRODUCT') {
  3948.                     //Buscamos el iva
  3949.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($itemInvoice->getPrdControlId());
  3950.                     if (empty($zProductFile)) {
  3951.                         $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $itemInvoice->getPrdControlId());
  3952.                     }
  3953.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  3954.                     if (!empty($itemInvoice->getPrdIva()) or ($itemInvoice->getPrdIva() == 0)) {
  3955.                         $ivaFactor = ($itemInvoice->getPrdIva()) / 100;
  3956.                     }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  3957.                     //Acumulamos neto e iva para la factura
  3958.                     //                    $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
  3959.                     $valorTotalNet $valorTotalNet $itemInvoice->getPrdSubTotalPrice();
  3960.                     //                    $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
  3961.                     $valorVat $valorVat round(($itemInvoice->getPrdSubTotalPrice() * $ivaFactor), 2PHP_ROUND_HALF_UP);
  3962.                 }
  3963.             }
  3964.         }
  3965.         if (!empty($arrayInvoicedItems)) {
  3966.             foreach ($arrayInvoicedItems as $itemInvoice) {
  3967.                 if ($itemInvoice->getItemType() == 'SERVICE') {
  3968.                     //Acumulamos neto e iva para la factura
  3969.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  3970.                         $subtotal 0;
  3971.                         $neto 0;
  3972.                         $subtotalService 0;
  3973.                     } else {
  3974.                         $subtotalService $itemInvoice->getSrvPrice();
  3975.                         $subneto $itemInvoice->getSrvPrice();
  3976.                         // Commission
  3977.                         if ($itemInvoice->getSrvOpCommission() == '1') {
  3978.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  3979.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission() / 100));
  3980.                         } else {
  3981.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  3982.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  3983.                         }
  3984.                         // Over
  3985.                         if ($itemInvoice->getSrvOpOver() == '1') {
  3986.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3987.                             $subneto $subneto $itemInvoice->getSrvOver();
  3988.                         } else {
  3989.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  3990.                             $subneto $subneto $itemInvoice->getSrvOver();
  3991.                         }
  3992.                         // IVA
  3993.                         if ($itemInvoice->getSrvOpIva() == '1') {
  3994.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  3995.                         } else {
  3996.                             $subtotalService $itemInvoice->getSrvPrice();
  3997.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  3998.                         }
  3999.                         switch ($itemInvoice->getSrvServiceCatId()) {
  4000.                             case 1// Alojamiento
  4001.                                 // el numero de noches $numNoches; precio unitario $subneto
  4002.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  4003.                                 // La personas no afectan este calculo
  4004.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  4005.                                 $subnetoUnit $subneto;
  4006.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  4007.                                 break;
  4008.                             case 2//Actividades
  4009.                                 // El nĂºmero de personas es considerado en el calculo
  4010.                                 $pax $itemInvoice->getSrvPax();
  4011.                                 if (empty($pax) or $pax == "0") {
  4012.                                     $pax 1;
  4013.                                 }
  4014.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4015.                                 if ($days 1) {
  4016.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4017.                                 } else {
  4018.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4019.                                 }
  4020.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  4021.                                 $subnetoUnit $subneto;
  4022.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  4023.                                 break;
  4024.                             case 3// AV
  4025.                                 $pax $itemInvoice->getSrvPax();
  4026.                                 if (empty($pax) or $pax == "0") {
  4027.                                     $pax 1;
  4028.                                 }
  4029.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4030.                                 if ($days 1) {
  4031.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4032.                                 } else {
  4033.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4034.                                 }
  4035.                                 $unitsServ $itemInvoice->getSrvUnits();
  4036.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4037.                                     $unitsServ 1;
  4038.                                 }
  4039.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4040.                                 $subnetoUnit $subneto;
  4041.                                 $subneto $subneto $days $unitsServ $pax;
  4042.                                 break;
  4043.                             case 4//Creative
  4044.                                 $pax $itemInvoice->getSrvPax();
  4045.                                 if (empty($pax) or $pax == "0") {
  4046.                                     $pax 1;
  4047.                                 }
  4048.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4049.                                 if ($days 1) {
  4050.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4051.                                 } else {
  4052.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4053.                                 }
  4054.                                 $unitsServ $itemInvoice->getSrvUnits();
  4055.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4056.                                     $unitsServ 1;
  4057.                                 }
  4058.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4059.                                 $subnetoUnit $subneto;
  4060.                                 $subneto $subneto $days $unitsServ $pax;
  4061.                                 break;
  4062.                             case 5//Cruise
  4063.                                 $pax $itemInvoice->getSrvPax();
  4064.                                 if (empty($pax) or $pax == "0") {
  4065.                                     $pax 1;
  4066.                                 }
  4067.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  4068.                                 if ($days 1) {
  4069.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4070.                                 } else {
  4071.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4072.                                 }
  4073.                                 $unitsServ $itemInvoice->getSrvUnits();
  4074.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4075.                                     $unitsServ 1;
  4076.                                 }
  4077.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4078.                                 $subnetoUnit $subneto;
  4079.                                 $subneto $subneto $days $unitsServ $pax;
  4080.                                 break;
  4081.                             case 6//Entertaiment
  4082.                                 $pax $itemInvoice->getSrvPax();
  4083.                                 if (empty($pax) or $pax == "0") {
  4084.                                     $pax 1;
  4085.                                 }
  4086.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4087.                                 if ($days 1) {
  4088.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4089.                                 } else {
  4090.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4091.                                 }
  4092.                                 $unitsServ $itemInvoice->getSrvUnits();
  4093.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4094.                                     $unitsServ 1;
  4095.                                 }
  4096.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4097.                                 $subnetoUnit $subneto;
  4098.                                 $subneto $subneto $days $unitsServ $pax;
  4099.                                 break;
  4100.                             case 7// Gifts
  4101.                                 $pax $itemInvoice->getSrvPax();
  4102.                                 if (empty($pax) or $pax == "0") {
  4103.                                     $pax 1;
  4104.                                 }
  4105.                                 $days 1;
  4106.                                 if ($days 1) {
  4107.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4108.                                 } else {
  4109.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4110.                                 }
  4111.                                 $unitsServ $itemInvoice->getSrvUnits();
  4112.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4113.                                     $unitsServ 1;
  4114.                                 }
  4115.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4116.                                 $subnetoUnit $subneto;
  4117.                                 $subneto $subneto $days $unitsServ $pax;
  4118.                                 break;
  4119.                             case 8//Guide
  4120.                                 $pax $itemInvoice->getSrvPax();
  4121.                                 if (empty($pax) or $pax == "0") {
  4122.                                     $pax 1;
  4123.                                 }
  4124.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4125.                                 if ($days 1) {
  4126.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4127.                                 } else {
  4128.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4129.                                 }
  4130.                                 $unitsServ $itemInvoice->getSrvUnits();
  4131.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4132.                                     $unitsServ 1;
  4133.                                 }
  4134.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4135.                                 $subnetoUnit $subneto;
  4136.                                 $subneto $subneto $days $unitsServ $pax;
  4137.                                 break;
  4138.                             case 9//Itineraries
  4139.                                 $pax $itemInvoice->getSrvPax();
  4140.                                 if (empty($pax) or $pax == "0") {
  4141.                                     $pax 1;
  4142.                                 }
  4143.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4144.                                 if ($days 1) {
  4145.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4146.                                 } else {
  4147.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4148.                                 }
  4149.                                 $unitsServ $itemInvoice->getSrvUnits();
  4150.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4151.                                     $unitsServ 1;
  4152.                                 }
  4153.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4154.                                 $subnetoUnit $subneto;
  4155.                                 $subneto $subneto $days $unitsServ $pax;
  4156.                                 break;
  4157.                             case 10//Lounge  -- No Aplica
  4158.                                 break;
  4159.                             case 11//Menu
  4160.                                 $pax $itemInvoice->getSrvPax();
  4161.                                 if (empty($pax) or $pax == "0") {
  4162.                                     $pax 1;
  4163.                                 }
  4164.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4165.                                 if ($days 1) {
  4166.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4167.                                 } else {
  4168.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4169.                                 }
  4170.                                 $unitsServ $itemInvoice->getSrvUnits();
  4171.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4172.                                     $unitsServ 1;
  4173.                                 }
  4174.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4175.                                 $subnetoUnit $subneto;
  4176.                                 $subneto $subneto $days $unitsServ $pax;
  4177.                                 break;
  4178.                             case 12//Others
  4179.                                 $pax $itemInvoice->getSrvPax();
  4180.                                 if (empty($pax) or $pax == "0") {
  4181.                                     $pax 1;
  4182.                                 }
  4183.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4184.                                 if ($days 1) {
  4185.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4186.                                 } else {
  4187.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4188.                                 }
  4189.                                 $unitsServ $itemInvoice->getSrvUnits();
  4190.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4191.                                     $unitsServ 1;
  4192.                                 }
  4193.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4194.                                 $subnetoUnit $subneto;
  4195.                                 $subneto $subneto $days $unitsServ $pax;
  4196.                                 break;
  4197.                             case 13//Transport
  4198.                                 $pax $itemInvoice->getSrvPax();
  4199.                                 if (empty($pax) or $pax == "0") {
  4200.                                     $pax 1;
  4201.                                 }
  4202.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4203.                                 if ($days 1) {
  4204.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4205.                                 } else {
  4206.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4207.                                 }
  4208.                                 $unitsServ $itemInvoice->getSrvUnits();
  4209.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4210.                                     $unitsServ 1;
  4211.                                 }
  4212.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4213.                                 $subnetoUnit $subneto;
  4214.                                 $subneto $subneto $days $unitsServ $pax;
  4215.                                 break;
  4216.                             case 14//Technology
  4217.                                 $pax $itemInvoice->getSrvPax();
  4218.                                 if (empty($pax) or $pax == "0") {
  4219.                                     $pax 1;
  4220.                                 }
  4221.                                 $days 1;
  4222.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4223.                                 $unitsServ $itemInvoice->getSrvUnits();
  4224.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4225.                                     $unitsServ 1;
  4226.                                 }
  4227.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4228.                                 $subnetoUnit $subneto;
  4229.                                 $subneto $subneto $days $unitsServ $pax;
  4230.                                 break;
  4231.                             case 15//Assisstant
  4232.                                 $pax $itemInvoice->getSrvPax();
  4233.                                 if (empty($pax) or $pax == "0") {
  4234.                                     $pax 1;
  4235.                                 }
  4236.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4237.                                 if ($days 1) {
  4238.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4239.                                 } else {
  4240.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4241.                                 }
  4242.                                 $unitsServ $itemInvoice->getSrvUnits();
  4243.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4244.                                     $unitsServ 1;
  4245.                                 }
  4246.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4247.                                 $subnetoUnit $subneto;
  4248.                                 $subneto $subneto $days $unitsServ $pax;
  4249.                                 break;
  4250.                             case 16//DDR
  4251.                                 $pax $itemInvoice->getSrvPax();
  4252.                                 if (empty($pax) or $pax == "0") {
  4253.                                     $pax 1;
  4254.                                 }
  4255.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4256.                                 if ($days 1) {
  4257.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4258.                                 } else {
  4259.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4260.                                 }
  4261.                                 $unitsServ $itemInvoice->getSrvUnits();
  4262.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4263.                                     $unitsServ 1;
  4264.                                 }
  4265.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4266.                                 $subnetoUnit $subneto;
  4267.                                 $subneto $subneto $days $unitsServ $pax;
  4268.                                 break;
  4269.                             default:
  4270.                                 break;
  4271.                         }
  4272.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  4273.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  4274.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  4275.                         $valorTotalNet $valorTotalNet $neto;
  4276.                         $valorVat $valorVat + ($subtotal $neto);
  4277.                     }
  4278.                 }
  4279.             }
  4280.         }
  4281.         if (!empty($arrayInvoicedItems)) {
  4282.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4283.                 if ($itemInvoice->getItemType() == 'PAYMENT') {
  4284.                     //                    $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  4285.                     //
  4286.                     //                    $itemInvoice = new ReservationInvoiceItems();
  4287.                     //                    $itemInvoice->setReservationId($id);
  4288.                     //                    $itemInvoice->setInvoiceId($invoiceId);
  4289.                     //                    $itemInvoice->setItemType('PAYMENT');
  4290.                     //                    $itemInvoice->setPayControlId($key);
  4291.                     //                    $itemInvoice->setPayAmount($pago->getAmount());
  4292.                     //                    $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  4293.                     //                    $itemInvoice->setPayWayToPay($pago->getWayToPay());
  4294.                     //                    $itemInvoice->setCreatedAt(new DateTime('now'));
  4295.                     //                    $itemInvoice->setUpdatedAt(new DateTime('now'));
  4296.                     //                    $itemInvoice->setCreatedId($user_id);
  4297.                     //                    $itemInvoice->setUpdatedId($user_id);
  4298.                     //
  4299.                     //                    $em->persist($itemInvoice);
  4300.                     //                    $em->flush();
  4301.                     //Acumulamos neto e iva para la factura
  4302.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  4303.                 }
  4304.             }
  4305.         }
  4306.         //FIN: Creamos los items de la factura
  4307.         $valorTotal $valorTotalNet $valorVat;
  4308.         //INICIO: Buscamos la factura
  4309.         $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  4310.         //FIN: Buscamos la factura
  4311.         $data = array();
  4312.         $data $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id'I');
  4313.         $paymentsClient = new AvePaymentsClient();
  4314.         $paymentsClient->setFileId($id);
  4315.         $fileInv = new AveDocInvoice();
  4316.         $fileInv->setAccessKey(md5(rand() * time()));
  4317.         $fileInv->setFileId($id);
  4318.         $idProducts = array();
  4319.         $productsBoolToInvoice = array();
  4320.         if (array_key_exists('product'$data['datasupplier'])) {
  4321.             foreach ($data['datasupplier']['product'] as $item) {
  4322.                 $idProducts[] = $item['id'];
  4323.                 $productsBoolToInvoice[] = 1;
  4324.             }
  4325.             $idProducts implode(','$idProducts);
  4326.             $productsBoolToInvoice implode(','$productsBoolToInvoice);
  4327.         } else {
  4328.             $idProducts '0';
  4329.             $productsBoolToInvoice '0';
  4330.         }
  4331.         $idPayments = array();
  4332.         $paymentsBoolToInvoice = array();
  4333.         if (array_key_exists('payment'$data['datasupplier'])) {
  4334.             foreach ($data['datasupplier']['payment'] as $item) {
  4335.                 $idPayments[] = $item['id'];
  4336.                 $paymentsBoolToInvoice[] = 1;
  4337.             }
  4338.             $idPayments implode(','$idPayments);
  4339.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  4340.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  4341.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  4342.             // Para manipularlos entre la vista y el JS
  4343.         } else {
  4344.             $idPayments '0';
  4345.             $paymentsBoolToInvoice '0';
  4346.         }
  4347.         // Una factura solo se puede rectificar una vez
  4348.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  4349.         $boolToRec = empty($rectf);
  4350.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($newInvoice->getFileId());
  4351.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
  4352.         foreach ($allInvoicesRec as $item) {
  4353.             array_push($allInvoices$item);
  4354.         }
  4355.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($newInvoice->getFileId());
  4356.         if (empty($data['type'])) {
  4357.             $data['type'] = 'Invoice';
  4358.         }
  4359.         $commentsBool false;
  4360.         $comments null;
  4361.         $fileAv $em->getRepository(AveFiles::class)->findOneById($newInvoice->getFileId());
  4362.         if ($fileAv->getCommentsInInv()) {
  4363.             $commentsBool true;
  4364.         }
  4365.         if ($commentsBool) {
  4366.             $comments $fileAv->getComments();
  4367.         }
  4368.         return $this->render(
  4369.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  4370.             array(
  4371.                 'id' => $newInvoice->getFileId(),
  4372.                 'cid' => '',
  4373.                 'fid' => $id,
  4374.                 'invoice' => $newInvoice,
  4375.                 'facturas' => $allInvoices,
  4376.                 'proformas' => $allProformas,
  4377.                 'boolToRec' => $boolToRec,
  4378.                 'numberadmin' => '',
  4379.                 'type' => $data['type'],
  4380.                 'docType' => 'Factura',
  4381.                 'number' => $newInvoice->getId(),
  4382.                 'prefix' => $data['prefix'],
  4383.                 'date' => $data['date'],
  4384.                 'token' =>  $data['token'],
  4385.                 'file' => $data['file'],
  4386.                 'company' => $data['company'],
  4387.                 'clients' => $data['clients'],
  4388.                 'user' => $user_logueado,
  4389.                 'invoicedeposititems' => '',
  4390.                 'arrayItems' => $data['arrayItems'],
  4391.                 'datasupplier' => $data['datasupplier'],
  4392.                 'totales_neto' => $data['totales_neto'],
  4393.                 'totales_iva' => '',
  4394.                 'totales' => $data['totales'],
  4395.                 'bases_imponibles' => $data['bases_imponibles'],
  4396.                 'balance' => $data['balance'],
  4397.                 'paymentInvoice' => $data['paymentInvoice'],
  4398.                 'currency' => $data['currency'],
  4399.                 'comments' => $comments,
  4400.             )
  4401.         );
  4402.     }
  4403.     /**
  4404.      * @Route("/avexternal/printinvoice/{id}",  name="ave_print_invoice")
  4405.      * Imprimir una factura
  4406.      */
  4407.     public function printInvoiceAction($idRequest $request)
  4408.     {
  4409.         $em $this->getDoctrine()->getManager();
  4410.         // Se genera y muestra en nueva pantalla la nueva proforma
  4411.         $arrayBools = array(
  4412.             'product' => null,
  4413.             'service' => null,
  4414.             'payment' => null,
  4415.         );
  4416.         $arrayBools['product'] = $request->request->get('inv_lounge_hidden_bool');
  4417.         $arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
  4418.         $arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
  4419.         //Acumuladores de datos globales de la factura
  4420.         $valorTotalNet 0;
  4421.         $valorVat 0;
  4422.         //INICIO: Creamos los items de la factura
  4423.         $arrayInvoicedItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  4424.         if (!empty($arrayInvoicedItems)) {
  4425.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4426.                 if ($itemInvoice->getItemType() == 'PRODUCT') {
  4427.                     //Acumulamos neto e iva para la factura
  4428.                     $valorTotalNet $valorTotalNet $itemInvoice->getPrdServicePrice();
  4429.                     $valorVat $valorVat round(($itemInvoice->getPrdServicePrice() * 0.21), 2PHP_ROUND_HALF_UP);
  4430.                 }
  4431.             }
  4432.         }
  4433.         if (!empty($arrayInvoicedItems)) {
  4434.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4435.                 if ($itemInvoice->getItemType() == 'SERVICE') {
  4436.                     //Acumulamos neto e iva para la factura
  4437.                     if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())) {
  4438.                         $subtotal 0;
  4439.                         $neto 0;
  4440.                         $subtotalService 0;
  4441.                     } else {
  4442.                         $subtotalService $itemInvoice->getSrvPrice();
  4443.                         $subneto $itemInvoice->getSrvPrice();
  4444.                         // Commission
  4445.                         if ($itemInvoice->getSrvOpCommission() == '1') {
  4446.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvCommission() / 100));
  4447.                             $subneto $subneto  * (+ ($itemInvoice->getSrvCommission() / 100));
  4448.                         } else {
  4449.                             $subtotalService $subtotalService * (- ($itemInvoice->getSrvCommission() / 100));
  4450.                             $subneto $subneto * (- ($itemInvoice->getSrvCommission() / 100));
  4451.                         }
  4452.                         // Over
  4453.                         if ($itemInvoice->getSrvOpOver() == '1') {
  4454.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4455.                             $subneto $subneto $itemInvoice->getSrvOver();
  4456.                         } else {
  4457.                             $subtotalService $subtotalService $itemInvoice->getSrvOver();
  4458.                             $subneto $subneto $itemInvoice->getSrvOver();
  4459.                         }
  4460.                         // IVA
  4461.                         if ($itemInvoice->getSrvOpIva() == '1') {
  4462.                             $subtotalService $subtotalService * (+ ($itemInvoice->getSrvIva() / 100));
  4463.                         } else {
  4464.                             $subtotalService $itemInvoice->getSrvPrice();
  4465.                             $subneto = ($subneto 100) / (100 $itemInvoice->getSrvIva());
  4466.                         }
  4467.                         switch ($itemInvoice->getSrvServiceCatId()) {
  4468.                             case 1// Alojamiento
  4469.                                 // el numero de noches $numNoches; precio unitario $subneto
  4470.                                 $numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
  4471.                                 // La personas no afectan este calculo
  4472.                                 $subtotal $subtotalService $numNoches $itemInvoice->getSrvUnits();
  4473.                                 $subnetoUnit $subneto;
  4474.                                 $subneto $subneto $numNoches $itemInvoice->getSrvUnits();
  4475.                                 break;
  4476.                             case 2//Actividades
  4477.                                 // El nĂºmero de personas es considerado en el calculo
  4478.                                 $pax $itemInvoice->getSrvPax();
  4479.                                 if (empty($pax) or $pax == "0") {
  4480.                                     $pax 1;
  4481.                                 }
  4482.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4483.                                 if ($days 1) {
  4484.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4485.                                 } else {
  4486.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4487.                                 }
  4488.                                 $subtotal $subtotalService $days $itemInvoice->getSrvUnits();
  4489.                                 $subnetoUnit $subneto;
  4490.                                 $subneto $subneto $days $itemInvoice->getSrvUnits();
  4491.                                 break;
  4492.                             case 3// AV
  4493.                                 $pax $itemInvoice->getSrvPax();
  4494.                                 if (empty($pax) or $pax == "0") {
  4495.                                     $pax 1;
  4496.                                 }
  4497.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4498.                                 if ($days 1) {
  4499.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4500.                                 } else {
  4501.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4502.                                 }
  4503.                                 $unitsServ $itemInvoice->getSrvUnits();
  4504.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4505.                                     $unitsServ 1;
  4506.                                 }
  4507.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4508.                                 $subnetoUnit $subneto;
  4509.                                 $subneto $subneto $days $unitsServ $pax;
  4510.                                 break;
  4511.                             case 4//Creative
  4512.                                 $pax $itemInvoice->getSrvPax();
  4513.                                 if (empty($pax) or $pax == "0") {
  4514.                                     $pax 1;
  4515.                                 }
  4516.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4517.                                 if ($days 1) {
  4518.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4519.                                 } else {
  4520.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4521.                                 }
  4522.                                 $unitsServ $itemInvoice->getSrvUnits();
  4523.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4524.                                     $unitsServ 1;
  4525.                                 }
  4526.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4527.                                 $subnetoUnit $subneto;
  4528.                                 $subneto $subneto $days $unitsServ $pax;
  4529.                                 break;
  4530.                             case 5//Cruise
  4531.                                 $pax $itemInvoice->getSrvPax();
  4532.                                 if (empty($pax) or $pax == "0") {
  4533.                                     $pax 1;
  4534.                                 }
  4535.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
  4536.                                 if ($days 1) {
  4537.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4538.                                 } else {
  4539.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4540.                                 }
  4541.                                 $unitsServ $itemInvoice->getSrvUnits();
  4542.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4543.                                     $unitsServ 1;
  4544.                                 }
  4545.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4546.                                 $subnetoUnit $subneto;
  4547.                                 $subneto $subneto $days $unitsServ $pax;
  4548.                                 break;
  4549.                             case 6//Entertaiment
  4550.                                 $pax $itemInvoice->getSrvPax();
  4551.                                 if (empty($pax) or $pax == "0") {
  4552.                                     $pax 1;
  4553.                                 }
  4554.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4555.                                 if ($days 1) {
  4556.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4557.                                 } else {
  4558.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4559.                                 }
  4560.                                 $unitsServ $itemInvoice->getSrvUnits();
  4561.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4562.                                     $unitsServ 1;
  4563.                                 }
  4564.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4565.                                 $subnetoUnit $subneto;
  4566.                                 $subneto $subneto $days $unitsServ $pax;
  4567.                                 break;
  4568.                             case 7// Gifts
  4569.                                 $pax $itemInvoice->getSrvPax();
  4570.                                 if (empty($pax) or $pax == "0") {
  4571.                                     $pax 1;
  4572.                                 }
  4573.                                 $days 1;
  4574.                                 if ($days 1) {
  4575.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4576.                                 } else {
  4577.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4578.                                 }
  4579.                                 $unitsServ $itemInvoice->getSrvUnits();
  4580.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4581.                                     $unitsServ 1;
  4582.                                 }
  4583.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4584.                                 $subnetoUnit $subneto;
  4585.                                 $subneto $subneto $days $unitsServ $pax;
  4586.                                 break;
  4587.                             case 8//Guide
  4588.                                 $pax $itemInvoice->getSrvPax();
  4589.                                 if (empty($pax) or $pax == "0") {
  4590.                                     $pax 1;
  4591.                                 }
  4592.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4593.                                 if ($days 1) {
  4594.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4595.                                 } else {
  4596.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4597.                                 }
  4598.                                 $unitsServ $itemInvoice->getSrvUnits();
  4599.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4600.                                     $unitsServ 1;
  4601.                                 }
  4602.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4603.                                 $subnetoUnit $subneto;
  4604.                                 $subneto $subneto $days $unitsServ $pax;
  4605.                                 break;
  4606.                             case 9//Itineraries
  4607.                                 $pax $itemInvoice->getSrvPax();
  4608.                                 if (empty($pax) or $pax == "0") {
  4609.                                     $pax 1;
  4610.                                 }
  4611.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4612.                                 if ($days 1) {
  4613.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4614.                                 } else {
  4615.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4616.                                 }
  4617.                                 $unitsServ $itemInvoice->getSrvUnits();
  4618.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4619.                                     $unitsServ 1;
  4620.                                 }
  4621.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4622.                                 $subnetoUnit $subneto;
  4623.                                 $subneto $subneto $days $unitsServ $pax;
  4624.                                 break;
  4625.                             case 10//Lounge  -- No Aplica
  4626.                                 break;
  4627.                             case 11//Menu
  4628.                                 $pax $itemInvoice->getSrvPax();
  4629.                                 if (empty($pax) or $pax == "0") {
  4630.                                     $pax 1;
  4631.                                 }
  4632.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4633.                                 if ($days 1) {
  4634.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4635.                                 } else {
  4636.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4637.                                 }
  4638.                                 $unitsServ $itemInvoice->getSrvUnits();
  4639.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4640.                                     $unitsServ 1;
  4641.                                 }
  4642.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4643.                                 $subnetoUnit $subneto;
  4644.                                 $subneto $subneto $days $unitsServ $pax;
  4645.                                 break;
  4646.                             case 12//Others
  4647.                                 $pax $itemInvoice->getSrvPax();
  4648.                                 if (empty($pax) or $pax == "0") {
  4649.                                     $pax 1;
  4650.                                 }
  4651.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4652.                                 if ($days 1) {
  4653.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4654.                                 } else {
  4655.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4656.                                 }
  4657.                                 $unitsServ $itemInvoice->getSrvUnits();
  4658.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4659.                                     $unitsServ 1;
  4660.                                 }
  4661.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4662.                                 $subnetoUnit $subneto;
  4663.                                 $subneto $subneto $days $unitsServ $pax;
  4664.                                 break;
  4665.                             case 13//Transport
  4666.                                 $pax $itemInvoice->getSrvPax();
  4667.                                 if (empty($pax) or $pax == "0") {
  4668.                                     $pax 1;
  4669.                                 }
  4670.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4671.                                 if ($days 1) {
  4672.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4673.                                 } else {
  4674.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4675.                                 }
  4676.                                 $unitsServ $itemInvoice->getSrvUnits();
  4677.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4678.                                     $unitsServ 1;
  4679.                                 }
  4680.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4681.                                 $subnetoUnit $subneto;
  4682.                                 $subneto $subneto $days $unitsServ $pax;
  4683.                                 break;
  4684.                             case 14//Technology
  4685.                                 $pax $itemInvoice->getSrvPax();
  4686.                                 if (empty($pax) or $pax == "0") {
  4687.                                     $pax 1;
  4688.                                 }
  4689.                                 $days 1;
  4690.                                 $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4691.                                 $unitsServ $itemInvoice->getSrvUnits();
  4692.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4693.                                     $unitsServ 1;
  4694.                                 }
  4695.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4696.                                 $subnetoUnit $subneto;
  4697.                                 $subneto $subneto $days $unitsServ $pax;
  4698.                                 break;
  4699.                             case 15//Assisstant
  4700.                                 $pax $itemInvoice->getSrvPax();
  4701.                                 if (empty($pax) or $pax == "0") {
  4702.                                     $pax 1;
  4703.                                 }
  4704.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4705.                                 if ($days 1) {
  4706.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4707.                                 } else {
  4708.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4709.                                 }
  4710.                                 $unitsServ $itemInvoice->getSrvUnits();
  4711.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4712.                                     $unitsServ 1;
  4713.                                 }
  4714.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4715.                                 $subnetoUnit $subneto;
  4716.                                 $subneto $subneto $days $unitsServ $pax;
  4717.                                 break;
  4718.                             case 16//DDR
  4719.                                 $pax $itemInvoice->getSrvPax();
  4720.                                 if (empty($pax) or $pax == "0") {
  4721.                                     $pax 1;
  4722.                                 }
  4723.                                 $days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days 1);
  4724.                                 if ($days 1) {
  4725.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
  4726.                                 } else {
  4727.                                     $dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
  4728.                                 }
  4729.                                 $unitsServ $itemInvoice->getSrvUnits();
  4730.                                 if (empty($unitsServ) or $unitsServ == "0") {
  4731.                                     $unitsServ 1;
  4732.                                 }
  4733.                                 $subtotal $subtotalService $days $unitsServ $pax;
  4734.                                 $subnetoUnit $subneto;
  4735.                                 $subneto $subneto $days $unitsServ $pax;
  4736.                                 break;
  4737.                             default:
  4738.                                 break;
  4739.                         }
  4740.                         // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  4741.                         $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  4742.                         $neto round($subneto2PHP_ROUND_HALF_UP);
  4743.                         $valorTotalNet $valorTotalNet $neto;
  4744.                         $valorVat $valorVat + ($subtotal $neto);
  4745.                     }
  4746.                 }
  4747.             }
  4748.         }
  4749.         if (!empty($arrayInvoicedItems)) {
  4750.             foreach ($arrayInvoicedItems as $itemInvoice) {
  4751.                 if ($itemInvoice->getItemType() == 'PAYMENT') {
  4752.                     //                    $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
  4753.                     //
  4754.                     //                    $itemInvoice = new ReservationInvoiceItems();
  4755.                     //                    $itemInvoice->setReservationId($id);
  4756.                     //                    $itemInvoice->setInvoiceId($invoiceId);
  4757.                     //                    $itemInvoice->setItemType('PAYMENT');
  4758.                     //                    $itemInvoice->setPayControlId($key);
  4759.                     //                    $itemInvoice->setPayAmount($pago->getAmount());
  4760.                     //                    $itemInvoice->setPayDatePayAt($pago->getDatePayAt());
  4761.                     //                    $itemInvoice->setPayWayToPay($pago->getWayToPay());
  4762.                     //                    $itemInvoice->setCreatedAt(new DateTime('now'));
  4763.                     //                    $itemInvoice->setUpdatedAt(new DateTime('now'));
  4764.                     //                    $itemInvoice->setCreatedId($user_id);
  4765.                     //                    $itemInvoice->setUpdatedId($user_id);
  4766.                     //
  4767.                     //                    $em->persist($itemInvoice);
  4768.                     //                    $em->flush();
  4769.                     //Acumulamos neto e iva para la factura
  4770.                     //$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();    // El pago no puede afectar el neto de la factura
  4771.                 }
  4772.             }
  4773.         }
  4774.         //FIN: Creamos los items de la factura
  4775.         $valorTotal $valorTotalNet $valorVat;
  4776.         //INICIO: Buscamos la factura
  4777.         $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  4778.         //FIN: Buscamos la factura
  4779.         $data = array();
  4780.         $data $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id'I');
  4781.         $paymentsClient = new AvePaymentsClient();
  4782.         $paymentsClient->setFileId($id);
  4783.         $fileInv = new AveDocInvoice();
  4784.         $fileInv->setAccessKey(md5(rand() * time()));
  4785.         $fileInv->setFileId($id);
  4786.         $idProducts = array();
  4787.         $productsBoolToInvoice = array();
  4788.         if (array_key_exists('product'$data['datasupplier'])) {
  4789.             foreach ($data['datasupplier']['product'] as $item) {
  4790.                 $idProducts[] = $item['id'];
  4791.                 $productsBoolToInvoice[] = 1;
  4792.             }
  4793.             $idProducts implode(','$idProducts);
  4794.             $productsBoolToInvoice implode(','$productsBoolToInvoice);
  4795.         } else {
  4796.             $idProducts '0';
  4797.             $productsBoolToInvoice '0';
  4798.         }
  4799.         $idPayments = array();
  4800.         $paymentsBoolToInvoice = array();
  4801.         if (array_key_exists('payment'$data['datasupplier'])) {
  4802.             foreach ($data['datasupplier']['payment'] as $item) {
  4803.                 $idPayments[] = $item['id'];
  4804.                 $paymentsBoolToInvoice[] = 1;
  4805.             }
  4806.             $idPayments implode(','$idPayments);
  4807.             $paymentsBoolToInvoice implode(','$paymentsBoolToInvoice);
  4808.             // Se han generado dos arreglos, cada uno dividido en 2 strings
  4809.             // array( [5]=>0, [8]=>1, [10]=>0)  ==>> '5,8,10' y '0,1,0'
  4810.             // Para manipularlos entre la vista y el JS
  4811.         } else {
  4812.             $idPayments '0';
  4813.             $paymentsBoolToInvoice '0';
  4814.         }
  4815.         // Una factura solo se puede rectificar una vez
  4816.         $rectf $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' $newInvoice->getNumber()));
  4817.         $boolToRec = empty($rectf);
  4818.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($newInvoice->getFileId());
  4819.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
  4820.         foreach ($allInvoicesRec as $item) {
  4821.             array_push($allInvoices$item);
  4822.         }
  4823.         $allProformas $em->getRepository(AveDocProforma::class)->findByFileId($newInvoice->getFileId());
  4824.         if (empty($data['type'])) {
  4825.             $data['type'] = 'Invoice';
  4826.         }
  4827.         $commentsBool false;
  4828.         $comments null;
  4829.         $fileAv $em->getRepository(AveFiles::class)->findOneById($newInvoice->getFileId());
  4830.         if ($fileAv->getCommentsInInv()) {
  4831.             $commentsBool true;
  4832.         }
  4833.         if ($commentsBool) {
  4834.             $comments $fileAv->getComments();
  4835.         }
  4836.         return $this->render(
  4837.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  4838.             array(
  4839.                 'id' => $newInvoice->getFileId(),
  4840.                 'cid' => '',
  4841.                 'fid' => $id,
  4842.                 'invoice' => $newInvoice,
  4843.                 'facturas' => $allInvoices,
  4844.                 'proformas' => $allProformas,
  4845.                 'boolToRec' => $boolToRec,
  4846.                 'numberadmin' => '',
  4847.                 'type' => $data['type'],
  4848.                 'docType' => 'Factura',
  4849.                 'number' => $newInvoice->getId(),
  4850.                 'prefix' => $data['prefix'],
  4851.                 'date' => $data['date'],
  4852.                 'token' =>  $data['token'],
  4853.                 'file' => $data['file'],
  4854.                 'company' => $data['company'],
  4855.                 'clients' => $data['clients'],
  4856.                 'user' => '',
  4857.                 'invoicedeposititems' => '',
  4858.                 'arrayItems' => $data['arrayItems'],
  4859.                 'datasupplier' => $data['datasupplier'],
  4860.                 'totales_neto' => $data['totales_neto'],
  4861.                 'totales_iva' => '',
  4862.                 'totales' => $data['totales'],
  4863.                 'bases_imponibles' => $data['bases_imponibles'],
  4864.                 'balance' => $data['balance'],
  4865.                 'paymentInvoice' => $data['paymentInvoice'],
  4866.                 'currency' => $data['currency'],
  4867.                 'comments' => $comments,
  4868.             )
  4869.         );
  4870.     }
  4871.     /**
  4872.      * @Route("/newinvoicerec/{id}", name="ave_new_invoice_rec")
  4873.      * Crear una factura rectificativa
  4874.      */
  4875.     public function generateNewInvoiceRecAction($idRequest $request)
  4876.     {
  4877.         $em $this->getDoctrine()->getManager();
  4878.         $invoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  4879.         $invoiceComAvGp $em->getRepository(ReservationInvoice::class)->findOneByNumber('GPF-Automatic commission invoice-Av_File-'.$invoice->getFileId().'-Invoice-'.$invoice->getId());
  4880.         if (empty($invoiceComAvGp)){
  4881.             $invoiceComAvGp $em->getRepository(CvrReservationInvoice::class)->findOneByNumber('GPF-Automatic commission invoice-Av_File-'.$invoice->getFileId().'-Invoice-'.$invoice->getId());
  4882.             if (empty($invoiceComAvGp)) {
  4883.                 $invoiceComAvGp $em->getRepository(BlvReservationInvoice::class)->findOneByNumber('GPF-Automatic commission invoice-Av_File-' $invoice->getFileId() . '-Invoice-' $invoice->getId());
  4884.             }
  4885.         }
  4886. //dd('$invoiceComAvGp', $invoiceComAvGp, 'id', $id,
  4887. //
  4888. //    'GPF-Automatic commission invoice-Av_File-'.$invoice->getFileId().'-Invoice-'.$invoice->getId()
  4889. //);
  4890.         // Verificamos que no exista una factura rectificativa previa sobre la misma factura
  4891.         $previusInvoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneByInvoiceToRec($id);
  4892.         if (!empty($previusInvoiceRec)) { return $this->redirectToRoute('ave_view_invoice_rec', array('id' => $previusInvoiceRec->getId())); }
  4893.         $now = new DateTime();
  4894.         /* Obtengo usuario logueado */
  4895.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  4896.         $user_id $user_logueado->getId();
  4897.         $invoiceRec = new AveDocInvoiceRec();
  4898.         $invoiceRec->setInvoiceToRec($id);
  4899.         $invoiceRec->setCreatedAt($now);
  4900.         $invoiceRec->setUpdatedAt($now);
  4901.         $invoiceRec->setCreatedId($user_id);
  4902.         $invoiceRec->setUpdatedId($user_id);
  4903.         $invoiceRec->setDateAt($now);
  4904.         $invoiceRec->setMaster($invoice->getMaster());
  4905.         $invoiceRec->setNumber('REC-' $invoice->getNumber());
  4906.         $invoiceRec->setPrefix('R');
  4907.         $invoiceRec->setFileId($invoice->getFileId());
  4908.         $invoiceRec->setTotal($invoice->getTotal() * (-1));
  4909.         $invoiceRec->setTotalNet($invoice->getTotalNet() * (-1));
  4910.         $invoiceRec->setType('Invoice Rec');
  4911.         $invoiceRec->setVat($invoice->getVat() * (-1));
  4912.         $invoiceRec->setBalance($invoice->getBalance() * (-1));
  4913.         $em->persist($invoiceRec);
  4914.         $em->flush();
  4915.         $invoiceItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  4916.         // Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
  4917.         foreach ($invoiceItems as $item) {
  4918.             $itemRec = new AveDocInvoiceRecItems();
  4919.             $itemRec->setFileId($item->getFileId());
  4920.             $itemRec->setInvoiceId($item->getInvoiceId());
  4921.             $itemRec->setItemType($item->getItemType());
  4922.             $itemRec->setInvoiceRecId($invoiceRec->getId());
  4923.             $itemRec->setLocation($item->getLocation());
  4924.             $itemRec->setRankAv($item->getRankAv());
  4925.             $itemRec->setPrdControlId($item->getPrdControlId());
  4926.             $itemRec->setPrdName($item->getPrdName());
  4927.             $itemRec->setPrdProductId($item->getPrdProductId());
  4928.             $itemRec->setPrdDateStart($item->getPrdDateStart());
  4929.             $itemRec->setPrdDateEnd($item->getPrdDateEnd());
  4930.             $itemRec->setPrdServicePrice($item->getPrdServicePrice() * (-1));
  4931.             $itemRec->setPrdSubTotalPrice($item->getPrdSubTotalPrice() * (-1));
  4932.             $itemRec->setPrdQty($item->getPrdQty());
  4933.             $itemRec->setPrdDays($item->getPrdDays());
  4934.             $itemRec->setPrdPax($item->getPrdPax());
  4935.             $itemRec->setPrdType($item->getPrdType());
  4936.             $itemRec->setPrdHourStart($item->getPrdHourStart());
  4937.             $itemRec->setPrdMinStart($item->getPrdMinStart());
  4938.             $itemRec->setPrdHourEnd($item->getPrdHourEnd());
  4939.             $itemRec->setPrdMinEnd($item->getPrdMinEnd());
  4940.             $itemRec->setPrdIva($item->getPrdIva());
  4941.             $itemRec->setPrdOpIva($item->getPrdOpIva());
  4942.             $itemRec->setSrvControlId($item->getSrvControlId());
  4943.             $itemRec->setSrvSupplierId($item->getSrvSupplierId());
  4944.             $itemRec->setSrvServiceId($item->getSrvServiceId());
  4945.             $itemRec->setSrvServiceCatId($item->getSrvServiceCatId());
  4946.             $itemRec->setSrvServiceCatName($item->getSrvServiceCatName());
  4947.             $itemRec->setSrvPrice($item->getSrvPrice() * (-1));
  4948.             $itemRec->setSrvCurrency($item->getSrvCurrency());
  4949.             $itemRec->setSrvUnits($item->getSrvUnits());
  4950.             $itemRec->setSrvOpCommission($item->getSrvOpCommission());
  4951.             $itemRec->setSrvCommission($item->getSrvCommission());
  4952.             $itemRec->setSrvOpOver($item->getSrvOpOver());
  4953.             $itemRec->setSrvOver($item->getSrvOver());
  4954.             $itemRec->setSrvOpIva($item->getSrvOpIva());
  4955.             $itemRec->setSrvIva($item->getSrvIva());
  4956.             $itemRec->setSrvPax($item->getSrvPax());
  4957.             $itemRec->setSrvHour($item->getSrvHour());
  4958.             $itemRec->setSrvDateInAt($item->getSrvDateInAt());
  4959.             $itemRec->setSrvDateOutAt($item->getSrvDateOutAt());
  4960.             $itemRec->setSrvContcolor($item->getSrvContcolor());
  4961.             $itemRec->setSrvRank($item->getSrvRank());
  4962.             $itemRec->setSrvAssistantId($item->getSrvAssistantId());
  4963.             $itemRec->setSrvActivityId($item->getSrvActivityId());
  4964.             $itemRec->setSrvPay($item->getSrvPay());
  4965.             $itemRec->setPayControlId($item->getPayControlId());
  4966.             $itemRec->setPayAmount($item->getPayAmount() * (-1));
  4967.             $itemRec->setPayDatePayAt($item->getPayDatePayAt());
  4968.             $itemRec->setPayWayToPay($item->getPayWayToPay());
  4969.             $itemRec->setPayAmountTotal($item->getPayAmountTotal() * (-1));
  4970.             $itemRec->setPayVat($item->getPayVat());
  4971.             $itemRec->setCreatedId($user_id);
  4972.             $itemRec->setCreatedAt(new DateTime('now'));
  4973.             $itemRec->setUpdatedId($user_id);
  4974.             $itemRec->setUpdatedAt(new DateTime('now'));
  4975.             $em->persist($itemRec);
  4976.             $em->flush();
  4977.             $item->setPrdControlId((-1) * $item->getPrdControlId());
  4978.             $item->setSrvControlId((-1) * $item->getSrvControlId());
  4979.             $item->setPayControlId((-1) * $item->getPayControlId());
  4980.             $em->persist($item);
  4981.             $em->flush();
  4982.         }
  4983.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($invoice->getFileId());
  4984.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoice->getFileId());
  4985.         foreach ($allInvoicesRec as $item) { array_push($allInvoices$item); }
  4986.         $file $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  4987.         $client $em->getRepository(Client::class)->findOneById($file->getClient());
  4988.         $data = array();
  4989.         $data $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $invoiceRec->getId(), 'R');
  4990.         $data['clients'][0] = $client;
  4991.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  4992.         // Se elimina la ComisiĂ³n de AV a GreenPatio y la factura de comision
  4993.         $aveFile $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  4994.         $reserva $em->getRepository(Reservation::class)->findOneById($aveFile->getReservation());
  4995.         $description $id.' - ComisiĂ³n MANTE de Green Patio (Generado automaticamente)';
  4996.         $benSup $em->getRepository(AveBenefitsSupplier::class)->findOneByDescription($description);     // Beneficio de Green Patio sobre una factura
  4997.         if(!empty($benSup)){
  4998.             $em->remove($benSup);
  4999.             $em->flush();
  5000.         }
  5001.         if(!empty($invoiceComAvGp)){
  5002.             $dataService $this->commisionEnterpriseService->rectCommissionAvExpressGreenPatio($invoice->getId(), $user_id);
  5003.         }
  5004.         $this->calculoBeneficiosDocumento($invoiceRec->getId(), 'Invoice Rec');
  5005.         return $this->redirectToRoute'ave_view_invoice_rec', array('id' => $invoiceRec->getId()));
  5006.     }
  5007.     /**
  5008.      * @Route("/viewinvoicerec/{id}",  name="ave_view_invoice_rec")
  5009.      * Ver una factura rectificativa
  5010.      */
  5011.     public function viewInvoiceRecAction($idRequest $request)
  5012.     {
  5013.         $em $this->getDoctrine()->getManager();
  5014.         $invoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  5015.         /* Obtengo usuario logueado */
  5016.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5017.         $user_id $user_logueado->getId();
  5018.         $invoiceItems $em->getRepository(AveDocInvoiceRecItems::class)->findByInvoiceId($id);
  5019.         // Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
  5020.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($invoiceRec->getFileId());
  5021.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
  5022.         foreach ($allInvoicesRec as $item) { array_push($allInvoices$item); }
  5023.         $file $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5024.         $client $em->getRepository(Client::class)->findById($file->getClient());
  5025.         if (empty($client)) {
  5026.             $client[0] = new Client();
  5027.             $client[0]->setName('');
  5028.             $client[0]->setTitle('');
  5029.             $client[0]->setIdDocument('');
  5030.             $client[0]->setPopulation('');
  5031.             $client[0]->setRegion('');
  5032.             $client[0]->setCountry('');
  5033.             $clientNew = array(
  5034.                 'name' => '',
  5035.                 'title' => '',
  5036.                 'idDocument' => '',
  5037.                 'population' => '',
  5038.                 'region' => '',
  5039.                 'country' => '',
  5040.                 'address' => '',
  5041.                 'addressNumber' => '',
  5042.                 'zipCode' => '',
  5043.                 'typeDocument' => '',
  5044.             );
  5045.         } else {
  5046.             $clientNew = array(
  5047.                 'name' => $client[0]->getName(),
  5048.                 'title' => $client[0]->getTitle(),
  5049.                 'idDocument' => $client[0]->getIdDocument(),
  5050.                 'population' => '',
  5051.                 'region' => '',
  5052.                 'country' => '',
  5053.                 'address' => $client[0]->getAddress(),
  5054.                 'addressNumber' => $client[0]->getAddressNumber(),
  5055.                 'zipCode' => $client[0]->getZipCode(),
  5056.                 'typeDocument' => $client[0]->getTypeDocument(),
  5057.             );
  5058.             if (is_numeric($client[0]->getPopulation())) {
  5059.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  5060.                 $clientNew['population'] = $city->getCity();
  5061.             }
  5062.             if (is_numeric($client[0]->getRegion())) {
  5063.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  5064.                 $clientNew['region'] = $region->getRegion();
  5065.             }
  5066.             if (is_numeric($client[0]->getCountry())) {
  5067.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  5068.                 $clientNew['country'] = $country->getCountry();
  5069.             }
  5070.         }
  5071.         $data = array();
  5072.         $data $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $id'R');
  5073.         $data['clients'] = $client;
  5074.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  5075.         // Una factura solo se puede rectificar una vez
  5076.         //        $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
  5077.         $boolToRec false;
  5078.         $commentsBool false;
  5079.         $comments null;
  5080.         $fileAv $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5081.         if ($fileAv->getCommentsInInv()) { $commentsBool true; }
  5082.         if ($commentsBool) { $comments $fileAv->getComments(); }
  5083.         return $this->render(
  5084.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
  5085.             array(
  5086.                 'id' => $invoiceRec->getFileId(),
  5087.                 'cid' => '',
  5088.                 'fid' => $invoiceRec->getId(),
  5089.                 'invoice' => $invoiceRec,
  5090.                 'facturas' => $allInvoices,
  5091.                 'boolToRec' => $boolToRec,
  5092.                 'numberadmin' => '',
  5093.                 'type' => 'Invoice Rec',
  5094.                 'docType' => 'Factura Rectificativa',
  5095.                 'number' => $invoiceRec->getId(),
  5096.                 'prefix' => '',
  5097.                 'date' => $invoiceRec->getDateAt(),
  5098.                 'invoiceIdToRec' => $invoiceRec->getInvoiceToRec(),
  5099.                 'token' => '',
  5100.                 'file' => $file,
  5101.                 'company' => $data['company'],
  5102.                 'clients' => $clientNew,
  5103.                 'user' => $user_logueado,
  5104.                 'invoicedeposititems' => '',
  5105.                 'datasupplier' => $data['datasupplier'],
  5106.                 'totales_neto' => $data['totales_neto'],
  5107.                 'totales_iva' => '',
  5108.                 'totales' => $data['totales'],
  5109.                 'bases_imponibles' => $data['bases_imponibles'],
  5110.                 'balance' => $data['balance'],
  5111.                 'paymentInvoice' => $data['paymentInvoice'],
  5112.                 'currency' => $data['currency'],
  5113.                 'comments' => $comments,
  5114.             )
  5115.         );
  5116.     }
  5117.     /**
  5118.      * @Route("/avexternal/printinvoicerec/{id}",  name="ave_print_invoice_rec")
  5119.      * Imprimir una factura rectificativa
  5120.      */
  5121.     public function printInvoiceRecAction($idRequest $request)
  5122.     {
  5123.         $em $this->getDoctrine()->getManager();
  5124.         $invoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  5125.         $invoiceItems $em->getRepository(AveDocInvoiceRecItems::class)->findByInvoiceId($id);
  5126.         $allInvoices $em->getRepository(AveDocInvoice::class)->findByFileId($invoiceRec->getFileId());
  5127.         $allInvoicesRec $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
  5128.         foreach ($allInvoicesRec as $item) {
  5129.             array_push($allInvoices$item);
  5130.         }
  5131.         $file $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5132.         $client $em->getRepository(Client::class)->findOneById($file->getClient());
  5133.         $data = array();
  5134.         $data $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $invoiceRec->getId(), 'R');
  5135.         $data['clients'][0] = $client;
  5136.         $data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  5137.         // Una factura solo se puede rectificar una vez
  5138.         //        $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
  5139.         $boolToRec false;
  5140.         $commentsBool false;
  5141.         $comments null;
  5142.         $fileAv $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
  5143.         if ($fileAv->getCommentsInPro()) {
  5144.             $commentsBool true;
  5145.         }
  5146.         if ($commentsBool) {
  5147.             $comments $fileAv->getComments();
  5148.         }
  5149.         return $this->render(
  5150.             'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
  5151.             array(
  5152.                 'id' => $invoiceRec->getFileId(),
  5153.                 'cid' => '',
  5154.                 'fid' => $invoiceRec->getId(),
  5155.                 'invoice' => $invoiceRec,
  5156.                 'facturas' => $allInvoices,
  5157.                 'boolToRec' => $boolToRec,
  5158.                 'numberadmin' => '',
  5159.                 'type' => 'Invoice Rec',
  5160.                 'docType' => 'Factura Rectificativa',
  5161.                 'number' => $invoiceRec->getId(),
  5162.                 'prefix' => '',
  5163.                 'date' => $invoiceRec->getDateAt(),
  5164.                 'invoiceIdToRec' => $invoiceRec->getInvoiceToRec(),
  5165.                 'token' => '',
  5166.                 'file' => $file,
  5167.                 'company' => $data['company'],
  5168.                 'clients' => $data['clients'],
  5169.                 'user' => '',
  5170.                 'invoicedeposititems' => '',
  5171.                 'datasupplier' => $data['datasupplier'],
  5172.                 'totales_neto' => $data['totales_neto'],
  5173.                 'totales_iva' => '',
  5174.                 'totales' => $data['totales'],
  5175.                 'bases_imponibles' => $data['bases_imponibles'],
  5176.                 'balance' => $data['balance'],
  5177.                 'paymentInvoice' => $data['paymentInvoice'],
  5178.                 'currency' => $data['currency'],
  5179.                 'comments' => $comments,
  5180.             )
  5181.         );
  5182.     }
  5183.     /**
  5184.      * @Route("/listinvoice/",  name="ave_list_invoices")
  5185.      * Listar facturas
  5186.      */
  5187.     public function listInvoicesAction(Request $request)
  5188.     {
  5189.         $em $this->getDoctrine()->getManager();
  5190.         $invoiced $em->getRepository(AveDocInvoice::class)->findAll();
  5191.         $invoicedRec $em->getRepository(AveDocInvoiceRec::class)->findAll();
  5192.         // Agregamos las rectificativas al arreglo de facturas con el indice "R(id)"
  5193.         foreach ($invoicedRec as $idRecArray => $item) {
  5194.             $invoiced['R' $item->getId()] = $item;
  5195.         }
  5196.         $sumatoriaTotalNet 0;
  5197.         $sumatoriaTotalVat 0;
  5198.         $sumatoriaTotal 0;
  5199.         foreach ($invoiced as $idArray => $item) {
  5200.             $file $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
  5201.             $invoiced[$idArray]->setNumber(is_null($file) ? $file->getTitle());
  5202.             $client is_null($file) ? '' $em->getRepository(Client::class)->findOneById($file->getClient());
  5203.             if (!empty($client)) {
  5204.                 $invoiced[$idArray]->setPrefix($client->getName());
  5205.             } else {
  5206.                 $invoiced[$idArray]->setPrefix('');
  5207.             }
  5208.             $estaEnFactura false;
  5209.             $estaEnFacturaRectificativa false;
  5210.             if ($item->getType() == 'Invoice Deposit') {
  5211.                 // Si la factura de deposito se encuentra en una factura sumara 0
  5212.                 // INICIO: Verificamos factura de deposito dentro de alguna factura
  5213.                 $payOfInvoiceDeposit $em->getRepository(AvePaymentsClient::class)->findOneByInvoiceId($item->getId());
  5214.                 if (!empty($payOfInvoiceDeposit)) {
  5215.                     // Verificamos si el deposito esta dentro de una factura
  5216.                     $itemInvoiceOfInvoiceDeposit $em->getRepository(AveDocInvoiceItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
  5217.                 }
  5218.                 if (!empty($itemInvoiceOfInvoiceDeposit)) {
  5219.                     $estaEnFactura true;
  5220.                 } else {
  5221.                     // Verificamos que el control Id no haya sido seteado a 0 por rectificar la factura
  5222.                     if (!empty($payOfInvoiceDeposit)) {
  5223.                         $itemInvoiceOfInvoiceDeposit $em->getRepository(AveDocInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
  5224.                         if (!empty($itemInvoiceOfInvoiceDeposit)) {
  5225.                             $estaEnFactura true;
  5226.                         }
  5227.                     }
  5228.                 }
  5229.                 if (!empty($payOfInvoiceDeposit)) {
  5230.                     // Verificamos si el deposito esta dentro de una factura rectificativa
  5231.                     $itemInvoiceOfInvoiceDepositRec $em->getRepository(AveDocInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
  5232.                 }
  5233.                 if (!empty($itemInvoiceOfInvoiceDepositRec)) {
  5234.                     $estaEnFacturaRectificativa true;
  5235.                 }
  5236.                 // FIN: Verificamos factura de deposito dentro de alguna factura
  5237.                 $invoicedDepositItems $em->getRepository(AveDocInvoiceItems::class)->findByControlId($item->getMaster());
  5238.                 foreach ($invoicedDepositItems as $itemDep) {
  5239.                     $invoiced[$idArray]->setTotalNet($invoiced[$idArray]->getTotalNet() + $itemDep->getAmount());
  5240.                     $invoiced[$idArray]->setVat($invoiced[$idArray]->getVat() + (($itemDep->getAmount() * $itemDep->getIva()) / 100));
  5241.                     $invoiced[$idArray]->setTotal($invoiced[$idArray]->getTotal() + ($itemDep->getAmount() + (($itemDep->getAmount() * $itemDep->getIva()) / 100)));
  5242.                 }
  5243.             }
  5244.             // Sumara cuando ambos esten en false (no esta en factura ni en fact rect) o en true en ambas (fue facturado pero luego rectificado)
  5245.             if ((!$estaEnFactura and !$estaEnFacturaRectificativa) or ($estaEnFactura and $estaEnFacturaRectificativa)) {
  5246.                 $sumatoriaTotalNet $sumatoriaTotalNet $item->getTotalNet();
  5247.                 $sumatoriaTotalVat $sumatoriaTotalVat $item->getVat();
  5248.                 $sumatoriaTotal $sumatoriaTotal $item->getTotal();
  5249.             }
  5250.         }
  5251.         return $this->render(
  5252.             'MDS/AvexpressBundle/Avexpress/invoice-list.html.twig',
  5253.             array(
  5254.                 'invocied' => $invoiced,
  5255.                 'sumatoriaTotalNet' => $sumatoriaTotalNet,
  5256.                 'sumatoriaTotalVat' => $sumatoriaTotalVat,
  5257.                 'sumatoriaTotal' => $sumatoriaTotal,
  5258.             )
  5259.         );
  5260.     }
  5261.     /**
  5262.      * @Route("/listpendingbud/", name="ave_list_pending_bud")
  5263.      * Listar presupuestos pendientes para aprobar y los pendientes por facturar
  5264.      */
  5265.     public function listPendingBudgetsAction(Request $request)
  5266.     {
  5267.         $em $this->getDoctrine()->getManager();
  5268.         $pendingBuds $em->getRepository(AveBudgetPending::class)->findAll();
  5269.         $pBuds = array();
  5270.         $budInPro = array();
  5271.         // Creamos la agrupacion por proposal
  5272.         foreach ($pendingBuds as $item) {
  5273.             if (!(array_key_exists($item->getProposalId(), $pBuds))) {
  5274.                 if (!empty($item->getOriginId())) {    // Los vacios solo contienen briefings
  5275.                     $pBuds[$item->getProposalId()] = null;
  5276.                 }
  5277.             }
  5278.         }
  5279.         // Metemos los items en el arreglo clasificado por proposal
  5280.         foreach ($pendingBuds as $item) {
  5281.             if (!empty($item->getOriginId())) {    // Los vacios solo contienen briefings
  5282.                 $pBuds[$item->getProposalId()][] = $item;
  5283.             }
  5284.         }
  5285.         ksort($pBuds);
  5286.         $keysPbuds array_keys($pBuds);
  5287.         $budToProforma $em->getRepository(AveBudgetToProforma::class)->findBy(
  5288.             array(
  5289.                 'status' => 'Confirmed',                                         // Pending -> Tosend -> Confirmed -> Invoiced
  5290.             )
  5291.         );
  5292.         $budToInvoice = array();
  5293.         foreach ($budToProforma as $item) {
  5294.             if (!array_key_exists($item->getFileId(), $budToInvoice)) {
  5295.                 $budToInvoice[$item->getFileId()] = null;
  5296.             }
  5297.         }
  5298.         foreach ($budToProforma as $item) {
  5299.             $budToInvoice[$item->getFileId()]['file'] = $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
  5300.             // INICIO: Agrupamos las proformas y dentro ponemos los items de cada una
  5301.             //Obtenemos el Id de la proforma que contiene el producto
  5302.             $idPro =  $em->getRepository(AveDocProformaItems::class)->findOneByControlId($item->getProductFileId());
  5303.             $idPro $idPro->getProformaId();
  5304.             // Guardamos la info del agente
  5305.             $budToInvoice[$item->getFileId()]['agente'] = $item->getUserConfirmedFullName();
  5306.             $budToInvoice[$item->getFileId()]['idAgente'] = $item->getUserConfirmedId();
  5307.             //Buscamos el elemento que va dentro de la proforma
  5308.             $elemento $em->getRepository(AveProductFile::class)->findOneById($item->getProductFileId());
  5309.             $budToInvoice[$item->getFileId()]['proformas'][$idPro][] = $elemento;
  5310.             // FIN: Agrupamos las proformas y dentro ponemos los items de cada una
  5311.         }
  5312.         ksort($budToInvoice);
  5313.         //INICIO: Buscamos los budgets que ya se han metido en proformas
  5314.         $budInProforma $em->getRepository(AveBudgetToProforma::class)->findBy(
  5315.             array(
  5316.                 'status' => 'Tosend',                                         // Pending -> Tosend -> Confirmed -> Invoiced
  5317.             )
  5318.         );
  5319.         $budInPro = array();
  5320.         foreach ($budInProforma as $item) {
  5321.             $budInPro[$item->getFileId()]['file'] = $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
  5322.             // INICIO: Agrupamos las proformas y dentro ponemos los items de cada una
  5323.             //Obtenemos el Id de la proforma que contiene el producto
  5324.             $idPro =  $em->getRepository(AveDocProformaItems::class)->findOneByControlId($item->getProductFileId());
  5325.             $idPro $idPro->getProformaId();
  5326.             // Guardamos la info del agente
  5327.             $budInPro[$item->getFileId()]['agente'] = $item->getUserConfirmedFullName();
  5328.             $budInPro[$item->getFileId()]['idAgente'] = $item->getUserConfirmedId();
  5329.             //Buscamos el elemento que va dentro de la proforma
  5330.             $elemento $em->getRepository(AveProductFile::class)->findOneById($item->getProductFileId());
  5331.             if (!empty($elemento)) {
  5332.                 $budInPro[$item->getFileId()]['proformas'][$idPro][] = $elemento;
  5333.                 if (empty($budInPro[$item->getFileId()]['proformasMontos'][$idPro])) {
  5334.                     $budInPro[$item->getFileId()]['proformasMontos'][$idPro] = $elemento->getServicePrice() * 1.21;
  5335.                 } else {
  5336.                     $budInPro[$item->getFileId()]['proformasMontos'][$idPro] = $budInPro[$item->getFileId()]['proformasMontos'][$idPro] + $elemento->getServicePrice() * 1.21;
  5337.                 }
  5338.             }
  5339.             // FIN: Agrupamos las proformas y dentro ponemos los items de cada una
  5340.         }
  5341.         ksort($budInPro);
  5342.         //Verificamos que no haya expedientes sin elementos (proformas)
  5343.         foreach ($budInPro as $key => $item) {
  5344.             if (!array_key_exists('proformas'$item)) {
  5345.                 if (sizeof($budInPro) == 1) {
  5346.                     unset($budInPro$key);
  5347.                     $budInPro = array();
  5348.                 } else {
  5349.                     unset($budInPro$key);
  5350.                 }
  5351.             }
  5352.         }
  5353.         //FIN: Buscamos los budgets que ya se han metido en proformas
  5354.         //Buscamos los budgets que solo contienen Briefing
  5355.         $briefings $em->getRepository(AveBudgetPending::class)->findBy(
  5356.             array(
  5357.                 'serviceId' => null,                                         // Pending -> Tosend -> Confirmed -> Invoiced
  5358.             )
  5359.         );
  5360.         return $this->render(
  5361.             'MDS/AvexpressBundle/Avexpress/list-budgets-pending.html.twig',
  5362.             array(
  5363.                 'pendingBudgets' => $pBuds,
  5364.                 'keysPendingBudgets' => $keysPbuds,
  5365.                 'budToInvoice' => $budToInvoice,
  5366.                 'budInProforma' => $budInPro,
  5367.                 'briefings' => $briefings,
  5368.             )
  5369.         );
  5370.     }
  5371.     /**
  5372.      * @Route("/budgetadd/", name="ave_list_budget_add")
  5373.      * Crear los presupuestos (proformas) y los expedientes (si es necesario)
  5374.      */
  5375.     public function budgetsAddAction(Request $request)
  5376.     {
  5377.         $services $request->request->get('services_hidden');
  5378.         $backToEditFile $request->request->get('backToEditFile');
  5379.         $logTelegram false;
  5380.         //Modificar precios en Eventos (si es necesario)
  5381.         foreach ($services as $item) {
  5382.             $em $this->getDoctrine()->getManager();
  5383.             $pendingBud $em->getRepository(AveBudgetPending::class)->findOneById($item['id']);
  5384.             //INICIO: Creamos el expediente de AVEXPRESS (en caso de ser necesario)
  5385.             $file $em->getRepository(AveFiles::class)->findOneByIdProposal($pendingBud->getProposalId());
  5386.             if (empty($file)) {
  5387.                 $file = new AveFiles();
  5388.                 if (array_key_exists('proposalTitle'$item)) {
  5389.                     $file->setTitle($pendingBud->getProposalId() . ' -- ' $item['proposalTitle']);
  5390.                 } else {
  5391.                     if (array_key_exists('title'$item)) {
  5392.                         $file->setTitle($item['title']);
  5393.                     } else {
  5394.                         $file->setTitle($pendingBud->getProposalId() . ' - ');
  5395.                     }
  5396.                 }
  5397.                 $file->setClient('262');                                            // 262 es In Out Travel & Events
  5398.                 $file->setPriority(null);
  5399.                 $file->setSupplier(null);
  5400.                 $file->setStatus('Confirmed');
  5401.                 $file->setDaysBlock(null);
  5402.                 $file->setAdvancePayment(null);
  5403.                 $file->setIdProposal($pendingBud->getProposalId());
  5404.                 $file->setCateringName(null);
  5405.                 $file->setBoolCatering(null);
  5406.                 $file->setDateStart(null);
  5407.                 $file->setDateEnd(null);
  5408.                 $file->setPax(null);
  5409.                 $file->setDeposit(null);
  5410.                 $file->setAccessKey(null);
  5411.                 $file->setDescription(null);
  5412.                 $file->setCreatedAt(new DateTime('now'));
  5413.                 $file->setCreatedId(14);                                             // Usuario de Salvador Guerrero
  5414.                 $file->setUpdatedAt(new DateTime('now'));
  5415.                 $file->setUpdatedId(14);                                             // Usuario de Salvador Guerrero
  5416.                 $em->persist($file);
  5417.                 $em->flush();
  5418.                 //Actualizamos los Briefings que esten en FileId null con el recien generado fileId en base al proposalId
  5419.                 $allBriefings $em->getRepository(AveBriefings::class)->findByProposalId($file->getIdProposal());
  5420.                 foreach ($allBriefings as $itemBrief) {
  5421.                     if (empty($itemBrief->getFileId())) {
  5422.                         $itemBrief->setFileId($file->getId());
  5423.                         $em->persist($itemBrief);
  5424.                         $em->flush();
  5425.                     }
  5426.                 }
  5427.             }
  5428.             //FIN: Creamos el expediente de AVEXPRESS (en caso de ser necesario)
  5429.             //INICIO: Creamos el producto dentro del expediente
  5430.             /* Obtengo usuario logueado */
  5431.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5432.             $user_id $user_logueado->getId();
  5433.             $newProductFile = new AveProductFile();
  5434.             if (!($pendingBud->getStatusinternal() == 'AV TEMPLATE')) {
  5435.                 $aveProductSelected $em->getRepository(AveProduct::class)->findOneById($pendingBud->getServiceId());
  5436.                 $newProductFile->setProductName($aveProductSelected->getName());
  5437.                 if (!empty($item['price'])) {
  5438.                     $newProductFile->setServicePrice($item['price']);
  5439.                     if (!($item['price'] == $aveProductSelected->getPrice())) {
  5440.                         // Se ha modificado el precio en el presupuesto y se debe cambiar en el origen (Proposal de eventos)
  5441.                         $itemOrigin $em->getRepository(ProposalSupplierServices::class)->findOneById($pendingBud->getOriginId());
  5442.                         if (!empty($itemOrigin)) {
  5443.                             $itemOrigin->setPrice($item['price']);
  5444.                             $em->persist($itemOrigin);
  5445.                             $em->flush();
  5446.                         }
  5447.                     }
  5448.                 } else {
  5449.                     // Si el precio viene vacio tomamos el valor por defecto del producto
  5450.                     $newProductFile->setServicePrice($aveProductSelected->getPrice());
  5451.                 }
  5452.                 //Unidades
  5453.                 if (!empty($item['units'])) {
  5454.                     $newProductFile->setUnits($item['units']);
  5455.                     if (!($item['units'] == 1)) {
  5456.                         // Se ha modificado el numero de unidades en el presupuesto y se debe cambiar en el origen (Proposal de eventos)
  5457.                         $itemOrigin $em->getRepository(ProposalSupplierServices::class)->findOneById($pendingBud->getOriginId());
  5458.                         if (!empty($itemOrigin)) {
  5459.                             $itemOrigin->setUnits($item['units']);
  5460.                             $itemOrigin->setUnits(1);
  5461.                             $em->persist($itemOrigin);
  5462.                             $em->flush();
  5463.                         }
  5464.                     }
  5465.                 } else {
  5466.                     // Si las unidades viene vacio tomamos el valor por defecto del producto
  5467.                     $newProductFile->setUnits('1');
  5468.                 }
  5469.                 $newProductFile->setSubTotalPrice($newProductFile->getServicePrice() * $newProductFile->getUnits());
  5470.             } else {
  5471.                 // Es un Template
  5472.                 $aveProductSelected $em->getRepository(AveTemplateItems::class)->findOneById($pendingBud->getServiceId());
  5473.                 //                d($pendingBud,$pendingBud->getServiceId(),$aveProductSelected);
  5474.                 $newProductFile->setProductName($aveProductSelected->getProductName());
  5475.                 $newProductFile->setServicePrice($aveProductSelected->getServicePrice());
  5476.                 $newProductFile->setUnits($aveProductSelected->getUnits());
  5477.                 $newProductFile->setSubTotalPrice($aveProductSelected->getSubTotalPrice());
  5478.                 $newProductFile->setSupplierExt($aveProductSelected->getSupplierExt());
  5479.                 $newProductFile->setSupplierExtId($aveProductSelected->getSupplierExtId());
  5480.                 $newProductFile->setUnits($aveProductSelected->getUnits());
  5481.                 $newProductFile->setOpCommission($aveProductSelected->getOpCommission());
  5482.                 $newProductFile->setCommission($aveProductSelected->getCommission());
  5483.                 $newProductFile->setOpOver($aveProductSelected->getOpOver());
  5484.                 $newProductFile->setOver($aveProductSelected->getOver());
  5485.                 $newProductFile->setOpIva($aveProductSelected->getOpIva());
  5486.                 $newProductFile->setIva($aveProductSelected->getIva());
  5487.                 $newProductFile->setDays($aveProductSelected->getDays());
  5488.             }
  5489.             $newProductFile->setProductId($aveProductSelected->getId());
  5490.             $newProductFile->setOriginId($pendingBud->getOriginId());
  5491.             $newProductFile->setDescription($aveProductSelected->getDescription());
  5492.             $newProductFile->setFileId($file->getId());
  5493.             if (true) { // No recibimos fechas // (!empty($newRequest['dateStart'])) {
  5494.                 $newProductFile->setDateStart(new DateTime('now')); //$newRequest['dateStart'].' '.$newRequest['hourStart']));
  5495.             }
  5496.             if (true) { // No recibimos fechas // (!empty($newRequest['dateEnd'])) {
  5497.                 $newProductFile->setDateEnd(new DateTime('now')); // (new \DateTime($newRequest['dateStart'].' '.$newRequest['hourEnd']));
  5498.             }
  5499.             $newProductFile->setCreatedId($user_id);
  5500.             $newProductFile->setUpdatedId($user_id);
  5501.             $newProductFile->setCreatedAt(new DateTime('now'));
  5502.             $newProductFile->setUpdatedAt(new DateTime('now'));
  5503.             $em->persist($newProductFile);
  5504.             $em->flush();
  5505.             $logTelegram true;
  5506.             //FIN: Creamos el producto dentro del expediente
  5507.             //INICIO: Creamos una orden de hacer proforma
  5508.             $order = new AveBudgetToProforma();
  5509.             $order->setStatus('Pending');
  5510.             $order->setFileId($file->getId());
  5511.             $order->setProductFileId($newProductFile->getId());
  5512.             $order->setUserConfirmedId($pendingBud->getUserConfirmedId());
  5513.             $order->setUserConfirmedFullName($pendingBud->getUserConfirmedFullName());
  5514.             $order->setProposalTitle($pendingBud->getProposalTitle());
  5515.             $em->persist($order);
  5516.             $em->flush();
  5517.             //FIN: Creamos una orden de hacer proforma
  5518.             // Se elimina el presupuesto pendiente
  5519.             $em->remove($pendingBud);
  5520.             $em->flush();
  5521.         }
  5522.         //INICIO: Creamos el presupuesto (proforma)
  5523.         $budToPro $em->getRepository(AveBudgetToProforma::class)->findByStatus('Pending');
  5524.         /* Obtengo usuario logueado */
  5525.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5526.         $user_id $user_logueado->getId();
  5527.         //        $arrayIdPro = array();          // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5528.         //INICIO: Se agrupan por expediente (fileId)
  5529.         $proformas = array();
  5530.         foreach ($budToPro as $item) {
  5531.             $proformas[$item->getFileId()][] = $item;
  5532.         }
  5533.         //FIN: Se agrupan por expediente (fileId)
  5534.         if (empty($backToEditFile)) {                   // Las proforma no se creara si venimos de editar file
  5535.             if (!empty($budToPro)) {
  5536.                 foreach ($proformas as $key => $elemento) {
  5537.                     //INICIO: Creamos las proformas
  5538.                     //INICIO: Calculamos el ID de la proforma
  5539.                     $numberToPrefix $em->getRepository(AveDocProforma::class)->findAll();
  5540.                     if (empty($numberToPrefix)) {
  5541.                         $numberToPrefix 0;
  5542.                     } else {
  5543.                         $numberToPrefix end($numberToPrefix)->getId();
  5544.                     }
  5545.                     $numberToPrefix++;
  5546.                     //FIN: Calculamos el ID de la proforma
  5547.                     $newProforma = new AveDocProforma();
  5548.                     $newProforma->setPrefix('AVE-' . (new DateTime('now'))->format('dmy') . '-' $numberToPrefix '-' $key);
  5549.                     $newProforma->setDateAt(new DateTime('now'));
  5550.                     $newProforma->setFileId($key);
  5551.                     $newProforma->setCreatedId($user_id);
  5552.                     $newProforma->setUpdatedId($user_id);
  5553.                     $newProforma->setCreatedAt(new DateTime('now'));
  5554.                     $newProforma->setUpdatedAt(new DateTime('now'));
  5555.                     $em->persist($newProforma);
  5556.                     $em->flush();
  5557.                     //FIN: Creamos las proformas
  5558.                     foreach ($elemento as $item) {
  5559.                         //$key es el id del expediente
  5560.                         //                    $arrayIdPro[$numberToPrefix] = $item->getUserConfirmedId();             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5561.                         //INICIO: Creamos los elemento que iran dentro de las proformas
  5562.                         $itemProforma = new AveDocProformaItems();
  5563.                         $itemProforma->setType('PRODUCT');
  5564.                         $itemProforma->setFileId($key);
  5565.                         $itemProforma->setProformaId($newProforma->getId());
  5566.                         $itemProforma->setControlId($item->getProductFileId());
  5567.                         $em->persist($itemProforma);
  5568.                         $em->flush();
  5569.                         //INICIO: Confirmamos el BudToProforma
  5570.                         $item->setStatus('Tosend');              // El elemento se ha pasado a la proforma, solo falta enviar
  5571.                         $item->setProformaId($newProforma->getId());
  5572.                         $em->persist($item);
  5573.                         $em->flush();
  5574.                         //FIN: Confirmamos el BudToProforma
  5575.                         //FIN: Creamos los elemento que iran dentro de las proformas
  5576.                     }
  5577.                 }
  5578.             }
  5579.         }
  5580.         //INICIO: Notificamos al agente por Telegram
  5581.         if ($logTelegram) {
  5582.             //Buscamos todos los agentes del proposal
  5583.             $proposalAgents $em->getRepository(ProposalAgents::class)->findOneByIdProp($file->getIdProposal());
  5584.             //Buscamos el Destino
  5585.             //            $proposalDestino = $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
  5586.             //Buscamos el agente de Develup
  5587.             $userData $em->getRepository(User::class)->findOneById($user_id);
  5588.             if (!empty($proposalAgents)) {
  5589.                 if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))) {
  5590.                     $this->sendTelegram($proposalAgents->getAgOne(), '1. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5591.                 }
  5592.                 if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))) {
  5593.                     $this->sendTelegram($proposalAgents->getAgTwo(), '2. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5594.                 }
  5595.                 if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))) {
  5596.                     $this->sendTelegram($proposalAgents->getAgThree(), '3. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5597.                 }
  5598.                 if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))) {
  5599.                     $this->sendTelegram($proposalAgents->getAgFour(), '4. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5600.                 }
  5601.             }
  5602.         }
  5603.         //FIN: Notificamos al agente por Telegram
  5604.         //FIN: Creamos el presupuesto (proforma)
  5605.         if (!empty($backToEditFile)) {
  5606.             return $this->redirectToRoute('ave_edit_file', array('id' => $backToEditFile));
  5607.         }
  5608.         return $this->redirectToRoute('ave_list_pending_bud');
  5609.     }
  5610.     /**
  5611.      * @Route("/budgetsend/", name="ave_budget_send")
  5612.      * Envio automatico de los presupuestos forzado por usuario
  5613.      */
  5614.     public function budgetSendAction(Request $request)
  5615.     {
  5616.         $em $this->getDoctrine()->getManager();
  5617.         $budToPro $em->getRepository(AveBudgetToProforma::class)->findByStatus('Tosend');
  5618.         $logTelegram false;
  5619.         /* Obtengo usuario logueado */
  5620.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5621.         $user_id $user_logueado->getId();
  5622.         $arrayIdPro = array();          // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5623.         //INICIO: Se agrupan por expediente (fileId)
  5624.         $proformas = array();
  5625.         foreach ($budToPro as $item) {
  5626.             $proformas[$item->getFileId()][] = $item;
  5627.             //            $fileDevelup = $item->getFileId();
  5628.         }
  5629.         //FIN: Se agrupan por expediente (fileId)
  5630.         if (!empty($budToPro)) {
  5631.             foreach ($proformas as $key => $elemento) {
  5632.                 //INICIO: Creamos las proformas
  5633.                 foreach ($elemento as $item) {
  5634.                     //$key es el id del expediente
  5635.                     if (!empty($item->getProformaId())) {
  5636.                         $arrayIdPro[$item->getProformaId()] = $item->getUserConfirmedId();             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5637.                     }
  5638.                     //INICIO: Confirmamos el BudToProforma
  5639.                     $item->setStatus('Confirmed');              // El elemento se ha pasado a confirmado porque se enviara por correo
  5640.                     $em->persist($item);
  5641.                     $em->flush();
  5642.                     //FIN: Confirmamos el BudToProforma
  5643.                     //FIN: Creamos los elemento que iran dentro de las proformas
  5644.                 }
  5645.             }
  5646.         }
  5647.         //INICIO: Notificamos de todos los presupuestos (proformas) que se han creado
  5648.         foreach ($arrayIdPro as $key => $item) {
  5649.             $logTelegram true;
  5650.             //Buscamos los agentes a notificar
  5651.             // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
  5652.             $agent $em->getRepository(User::class)->findOneById($item);
  5653.             $agentMail $agent->getEmail();
  5654.             $mailAgent $agentMail;
  5655.             //            $mailAgent = 'gustavo.ayala@develup.solutions';
  5656.             //Se prepara el correo con los agentes a notificar
  5657.             $firmGmail $agent->getFirmGmail();
  5658.             $data = array(
  5659.                 'body' => 'Presupuesto AvExpress #' $key  ', ' '<br><a href="http://' $request->server->get('HTTP_HOST') . '/pdf/avexpressproforma/' $key '">Ver el PDF del presupuesto</a><br><br>NotificaciĂ³n de nuevo presupuesto: Este presupuesto ha sido creado de forma automatica.' '<br><br>',
  5660.                 'firm' => $firmGmail,
  5661.             );
  5662.             // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  5663.             $transporter = new Swift_SmtpTransport();
  5664.             $transporter->setHost('smtp.gmail.com')
  5665.                 ->setEncryption('ssl'//ssl / tls
  5666.                 ->setPort(465// 465 / 587
  5667.                 ->setUsername('desarrollo@develup.solutions')
  5668.                 ->setPassword('utvh hzoi wfdo ztjs');
  5669.             $mailer = new Swift_Mailer($transporter);
  5670.             $message = new Swift_Message();
  5671.             $message->setSubject('Presupuesto #' $key ', NotificaciĂ³n de nuevo presupuesto')
  5672.                 ->setSender($agentMail)
  5673.                 ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  5674.                 ->setReplyTo($agentMail)
  5675.                 ->setTo($mailAgent)
  5676.                 ->setBody(
  5677.                     $this->renderView(
  5678.                         'mail/structure-mail.html.twig',
  5679.                         array('data' => $data)
  5680.                     ),
  5681.                     'text/html'
  5682.                 );
  5683.             $mailer->send($message);
  5684.             //INICIO: Notificamos al agente por Telegram
  5685.             if ($logTelegram) {
  5686.                 //Buscamos el id proposal a partir del id de la proforma
  5687.                 $prof $em->getRepository(AveDocProforma::class)->findOneById($key);
  5688.                 $file $em->getRepository(AveFiles::class)->findOneById($prof->getFileId());
  5689.                 //Buscamos todos los agentes del proposal
  5690.                 $proposalAgents $em->getRepository(ProposalAgents::class)->findOneByIdProp($file->getIdProposal());
  5691.                 //Buscamos el Destino
  5692.                 //            $proposalDestino = $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
  5693.                 //Buscamos el agente de AvExpress
  5694.                 $userData $em->getRepository(User::class)->findOneById($user_id);
  5695.                 if (!empty($proposalAgents)) {
  5696.                     if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))) {
  5697.                         $this->sendTelegram($proposalAgents->getAgOne(), '1. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5698.                     }
  5699.                     if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))) {
  5700.                         $this->sendTelegram($proposalAgents->getAgTwo(), '2. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5701.                     }
  5702.                     if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))) {
  5703.                         $this->sendTelegram($proposalAgents->getAgThree(), '3. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5704.                     }
  5705.                     if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))) {
  5706.                         $this->sendTelegram($proposalAgents->getAgFour(), '4. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' $userData->getName() . ' ' $userData->getLastName());
  5707.                     }
  5708.                 }
  5709.             }
  5710.             //FIN: Notificamos al agente por Telegram
  5711.         }
  5712.         //FIN: Notificamos de todos los presupuestos (proformas) que se han creado
  5713.         return $this->redirectToRoute('ave_list_pending_bud');
  5714.     }
  5715.     /**
  5716.      * @Route("/budgetdel/{id}", name="ave_list_budget_del")
  5717.      * Eliminar el producto de la solicitud de presupuesto
  5718.      */
  5719.     public function budgetsDeleteAction($idRequest $request)
  5720.     {
  5721.         $em $this->getDoctrine()->getManager();
  5722.         $budget $em->getRepository(AveBudgetPending::class)->findOneById($id);
  5723.         $proposal_services_supplier $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getOriginId());
  5724.         // Se elimina el servicio de In Out
  5725.         if (!empty($proposal_services_supplier)) {
  5726.             $em->remove($proposal_services_supplier);
  5727.             $em->flush();
  5728.         }
  5729.         // Se elimina el servicio del presupuesto
  5730.         $em->remove($budget);
  5731.         $em->flush();
  5732.         return $this->redirectToRoute('ave_list_pending_bud');
  5733.     }
  5734.     /**
  5735.      * @Route("/newinvoicefrombudget/{id}", name="ave_new_invoice_from_budget")
  5736.      * Crear nueva factura desde un presupuesto (proforma)
  5737.      */
  5738.     public function generateNewInvoiceFromBudgetAction($idRequest $request)
  5739.     {
  5740.         // Antes de redirigir a la funcion que crea presupuesto a partir de proformas se deben modificar las tablas de los presupuestos
  5741.         $em $this->getDoctrine()->getManager();
  5742.         //  Buscamos los elementos de la proforma
  5743.         $elemProf $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
  5744.         $fileId $elemProf[0]->getFileId();
  5745.         //  Buscamos los elementos de budgetToProforma para cambiar su status a Invoiced
  5746.         // los que pertenezcan a la proforma y a Discard los que pertenezcan a otra proforma
  5747.         $elemBudToProf $em->getRepository(AveBudgetToProforma::class)->findByFileId($fileId);
  5748.         foreach ($elemBudToProf as $key => $item) {
  5749.             //con los $item busco en $elemBudToProf para poner invoiced
  5750.             foreach ($elemProf as $elem) {
  5751.                 if ($elem->getControlId() == $item->getProductFileId()) {
  5752.                     // Se debe poner en Invoiced
  5753.                     $item->setStatus('Invoiced');
  5754.                 }
  5755.             }
  5756.             // Si al terminar de revisar el status sigue en Confirmado, lo pasaremos
  5757.             // a descartado, es un elemento de un presupuesto que no fue aprobado
  5758.             // mientras que otro presupuesto si fue aprobado y paso a facturacion.
  5759.             // Al estar descartado no se muestra mas el presupuesto en los listados
  5760.             // aunque la proforma sigue existiendo.
  5761.             if ($item->getStatus() == 'Confirmed') {
  5762.                 $item->setStatus('Discarded');
  5763.             }
  5764.             $em->persist($item);
  5765.             $em->flush();
  5766.         }
  5767.         return $this->redirectToRoute('ave_new_invoice_from_proforma', array('id' => $id));
  5768.     }
  5769.     /**
  5770.      * @Route("/budgetdiscard/{id}", name="ave_budget_discard")
  5771.      * Crear nueva factura desde un presupuesto (proforma)
  5772.      */
  5773.     public function discardBudgetAction($idRequest $request)
  5774.     {
  5775.         $em $this->getDoctrine()->getManager();
  5776.         //  Buscamos los elementos de la proforma
  5777.         $elemProf $em->getRepository(MdvDocProformaItems::class)->findByProformaId($id);
  5778.         foreach ($elemProf as $item) {
  5779.             //  Buscamos los elementos de budgetToProforma para cambiar su status a Discarded
  5780.             $elemBudToProf $em->getRepository(AveBudgetToProforma::class)->findOneByProductFileId($item->getControlId());
  5781.             $elemBudToProf->setStatus('Discarded');
  5782.             $em->persist($item);
  5783.             $em->flush();
  5784.         }
  5785.         return $this->redirectToRoute('ave_list_pending_bud');
  5786.     }
  5787.     /**
  5788.      * @Route("/updateinvoicedate/", name="ave_update_invoice_date")
  5789.      * Actualizar servicios develup desde inout events (Controlador inaccesible)
  5790.      */
  5791.     public function updateInvoiceDateAction(Request $request)
  5792.     {
  5793.         $em $this->getDoctrine()->getManager();
  5794.         $invoiceId $request->request->get('invoice_id');
  5795.         $invoiceNewDate $request->request->get('new_invoice_date');
  5796.         /* Obtengo usuario logueado */
  5797.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5798.         $user_id $user_logueado->getId();
  5799.         $invoice $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  5800.         $newDate = new DateTime($invoiceNewDate);
  5801.         $invoice->setDateAt($newDate);
  5802.         // Modificamos el number para que se adapte a la nueva fecha
  5803.         $invoice->setNumber('AVE-' $newDate->format('dmy') . substr($invoice->getNumber(), 10));
  5804.         $invoice->setUpdatedId($user_id);
  5805.         $invoice->setUpdatedAt(new DateTime('now'));
  5806.         $em->persist($invoice);
  5807.         $em->flush();
  5808.         return $this->redirectToRoute('ave_list_invoices');
  5809.     }
  5810.     /**
  5811.      * @Route("/budgetbriefdiscard/{id}", name="ave_budget_briefing_discard")
  5812.      * Eliminar un budget que es de tipo Briefing
  5813.      */
  5814.     public function budgetBriefDiscardAction($idRequest $request)
  5815.     {
  5816.         $em $this->getDoctrine()->getManager();
  5817.         $pendingBud $em->getRepository(AveBudgetPending::class)->findOneById($id);
  5818.         // Se elimina el presupuesto pendiente
  5819.         $em->remove($pendingBud);
  5820.         $em->flush();
  5821.         return $this->redirectToRoute('ave_list_pending_bud');
  5822.     }
  5823.     /**
  5824.      * @Route("/sendinvoicemail/", name="ave_send_invoice_mail")
  5825.      * Enviar enlace de la factura al cliente con copia
  5826.      */
  5827.     public function sendInvoiceMailAction(Request $request)
  5828.     {
  5829.         $fileId $request->request->get('fileId');
  5830.         $invoiceId $request->request->get('invoiceId');
  5831.         $ccToMail $request->request->get('ccToMail');
  5832.         /* Obtengo usuario logueado */
  5833.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5834.         $user_id $user_logueado->getId();
  5835.         $mailArrayTo = array();
  5836.         $mailArrayTo['salvador@avexpress.tv'] = 'salvador@avexpress.tv';
  5837.         $em $this->getDoctrine()->getManager();
  5838.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  5839.         $invoice $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  5840.         if (!empty($file->getClient())) {
  5841.             $client $em->getRepository(Client::class)->findOneById($file->getClient());
  5842.             if (!empty($client->getEmail())) {
  5843.                 $mailArrayTo[$client->getEmail()] = $client->getEmail();
  5844.             }
  5845.         }
  5846.         if (!empty($ccToMail)) {
  5847.             $mailArrayTo[$ccToMail] = $ccToMail;
  5848.         }
  5849.         $agente $em->getRepository(User::class)->findOneById($user_id);
  5850.         $mailAddressFrom $agente->getEmail();
  5851.         $mailSubject 'Factura del expediente: ' $file->getTitle();
  5852.         $mailBody 'Estimado cliente,' .
  5853.             '<br><br> En el siguiente enlace ponemos a su disposiciĂ³n la factura del expediente: ' .
  5854.             '<br><br><a href="https://inout.mante.solutions/pdf/avexpressinvoiceext/' $invoice->getAccessKey() . '">Ver la factura</a>' .
  5855.             '<br><br>Muchas gracias por confiar en nuestros servicios.<br><br>';
  5856.         $this->sendMailLot($mailAddressFrom$mailArrayTo$mailSubject$mailBody);
  5857.         return $this->redirectToRoute('ave_edit_file', array('id' => $fileId));
  5858.     }
  5859.     /**
  5860.      * @Route("/filltokens/", name="ave_fill_tokens")
  5861.      * Llenar el campo token
  5862.      */
  5863.     public function fillTokensAction(Request $request)
  5864.     {
  5865.         $em $this->getDoctrine()->getManager();
  5866.         $invoices $em->getRepository(AveDocInvoice::class)->findAll();
  5867.         foreach ($invoices as $item) {
  5868.             if (empty($item->getAccessKey())) {
  5869.                 $item->setAccessKey(md5(rand() * time()));
  5870.                 $em->persist($item);
  5871.                 $em->flush();
  5872.             }
  5873.         }
  5874.         exit();
  5875.     }
  5876.     /**
  5877.      * @Route("/sendatch/", name="ave_sendatch")
  5878.      * prueba de envio de correo con datos adjuntos
  5879.      */
  5880.     public function sendAtchAction(Request $request)
  5881.     {
  5882.         $em $this->getDoctrine()->getManager();
  5883.         $mailBody 'Mensaje del correo';
  5884.         $mailArrayTo = array();
  5885.         $mailAddressFrom 'gustavo.ayala@develup.solutions';
  5886.         $mailSubject 'Asunto del correo';
  5887.         $agent $em->getRepository(User::class)->findOneByEmail($mailAddressFrom);
  5888.         $replyTo = array();
  5889.         foreach ($mailArrayTo as $item) {
  5890.             // Verificamos que los correos sean validos
  5891.             if (filter_var($itemFILTER_VALIDATE_EMAIL)) {
  5892.                 $replyTo[$item] = $item;
  5893.             }
  5894.         }
  5895.         $agentMail $mailAddressFrom;
  5896.         $mailAgent $agentMail;
  5897.         //Se prepara el correo con los agentes a notificar
  5898.         $firmGmail $agent->getFirmGmail();
  5899.         $data = array(
  5900.             'body' => $mailBody,
  5901.             'firm' => $firmGmail,
  5902.         );
  5903.         // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  5904.         $transporter = new Swift_SmtpTransport();
  5905.         $transporter->setHost('smtp.gmail.com')
  5906.             ->setEncryption('ssl'//ssl / tls
  5907.             ->setPort(465// 465 / 587
  5908.             ->setUsername('desarrollo@develup.solutions')
  5909.             ->setPassword('utvh hzoi wfdo ztjs');
  5910.         $mailer = new Swift_Mailer($transporter);
  5911.         $message = new Swift_Message();
  5912.         $message->setSubject($mailSubject)
  5913.             ->setSender($agentMail)
  5914.             ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  5915.             ->setReplyTo($agentMail)
  5916.             ->setTo($replyTo)
  5917.             ->setBody(
  5918.                 $this->renderView(
  5919.                     'mail/structure-mail.html.twig',
  5920.                     array('data' => $data)
  5921.                 ),
  5922.                 'text/html'
  5923.             );
  5924.         $message->attach(Swift_Attachment::fromPath('http://site.tld/logo.png'));
  5925.         $mailer->send($message);
  5926.         exit();
  5927.     }
  5928.     /**
  5929.      * @Route("/maketableinfo/", name="ave_make_table_info")
  5930.      * crea la info de la tabla AveBenefitsInvoiceInvoiceRec
  5931.      */
  5932.     public function aveBenefitsAction(Request $request)
  5933.     {
  5934.         $em $this->getDoctrine()->getManager();
  5935.         if (true) {
  5936.             //Buscamos todas las facturas
  5937.             $invoices $em->getRepository(AveDocInvoice::class)->findAll();
  5938.             foreach ($invoices as $invoice) {
  5939.                 // Verificamos si esta ya en la tabla
  5940.                 $isInTable $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneBy(array('docId' => $invoice->getId(), 'docType' => 'Invoice'));
  5941.                 // Solo se hace en facturas, se descartan facturas de deposito ya que estas no se consideran ventas reales (Isa)
  5942.                 if ($invoice->getType() == 'Invoice') {
  5943.                     // Solo creamos si no existe en la tabla
  5944.                     if (empty($isInTable)) {
  5945.                         $this->calculoBeneficiosDocumento($invoice->getId(), 'Invoice');
  5946.                     }
  5947.                 }
  5948.             }
  5949.         }
  5950.         if (true) {
  5951.             //Buscamos todas las facturas rectificativas
  5952.             $invoices $em->getRepository(AveDocInvoiceRec::class)->findAll();
  5953.             foreach ($invoices as $invoice) {
  5954.                 // Verificamos si esta ya en la tabla
  5955.                 //                $isInTable = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByDocId($invoice->getId());
  5956.                 $isInTable $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneBy(array('docId' => $invoice->getId(), 'docType' => 'Invoice Rec'));
  5957.                 // Solo se hace en facturas, se descartan facturas de deposito ya que estas no se consideran ventas reales (Isa)
  5958.                 if ($invoice->getType() == 'Invoice Rec') {
  5959.                     // Solo creamos si no existe en la tabla
  5960.                     if (empty($isInTable)) {
  5961.                         $this->calculoBeneficiosDocumento($invoice->getId(), 'Invoice Rec');
  5962.                     }
  5963.                 }
  5964.             }
  5965.         }
  5966.         d('Fin del procesamiento');
  5967.         exit();
  5968.     }
  5969.     /**
  5970.      * @Route("/openbenefitssuppliers/{id}", name="ave_open_benefits_suppliers")
  5971.      * abre el expediente para permitir escritura AveBenefitsInvoiceInvoiceRec
  5972.      */
  5973.     public function aveOpenBenefitsSuppliersAction($idRequest $request)
  5974.     {
  5975.         $em $this->getDoctrine()->getManager();
  5976.         /* Obtengo usuario logueado */
  5977.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  5978.         $user_id $user_logueado->getId();
  5979.         $benefits $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByFileId($id);
  5980.         if (!empty($benefits)) {
  5981.             $benefits->setBenefitEuro(0);
  5982.             $benefits->setBenefitPerc(0);
  5983.             $em->persist($benefits);
  5984.             $em->flush();
  5985.         }
  5986.         $benefitsPer $em->getRepository(AveBenefitsPermissions::class)->findOneByFileId($id);
  5987.         if (empty($benefitsPer)) {
  5988.             $benefitsPer = new AveBenefitsPermissions();
  5989.             $benefitsPer->setCreatedId($user_id);
  5990.             $benefitsPer->setCreatedAt(new \DateTime("now"));
  5991.         }
  5992.         $benefitsPer->setStatus('Open');
  5993.         $benefitsPer->setFileId($id);
  5994.         $benefitsPer->setUpdatedId($user_id);
  5995.         $benefitsPer->setUpdatedAt(new \DateTime("now"));
  5996.         $em->persist($benefitsPer);
  5997.         $em->flush();
  5998.         return $this->redirectToRoute('ave_supplier_list', array('id' => $id));
  5999.     }
  6000.     /**
  6001.      * @Route("/closebenefitssuppliers/{id}", name="ave_close_benefits_suppliers")
  6002.      * cierra el expediente para crear su AveBenefitsInvoiceInvoiceRec
  6003.      */
  6004.     public function aveCloseBenefitsSuppliersAction($idRequest $request)
  6005.     {
  6006.         $em $this->getDoctrine()->getManager();
  6007.         /* Obtengo usuario logueado */
  6008.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  6009.         $user_id $user_logueado->getId();
  6010.         $benefitsOLD $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findBy(
  6011.             array(
  6012.                 'fileId' => $id,
  6013.                 'docType' => 'Invoice',
  6014.             )
  6015.         );
  6016.         if (!empty($benefitsOLD)) {
  6017.             if (!(($benefitsOLD[0]->getClientName() == 'Green Patio') and ($benefitsOLD[0]->getClientId() == 2556))) {
  6018.                 $this->calculoBeneficiosDocumento($benefitsOLD[0]->getDocId(), $benefitsOLD[0]->getDocType());
  6019.                 $em->remove($benefitsOLD[0]);
  6020.                 $em->flush();
  6021.             }
  6022.         }
  6023.         $benefitsPer $em->getRepository(AveBenefitsPermissions::class)->findOneByFileId($id);
  6024.         if (!empty($benefitsPer)) {
  6025.             $benefitsPer->setStatus('Close');
  6026.             $benefitsPer->setUpdatedId($user_id);
  6027.             $benefitsPer->setUpdatedAt(new \DateTime("now"));
  6028.             $em->persist($benefitsPer);
  6029.             $em->flush();
  6030.         }
  6031.         return $this->redirectToRoute('ave_supplier_list', array('id' => $id));
  6032.     }
  6033.     private function baseInvoiceFile($id$type$number$prefix$date)
  6034.     {
  6035.         $em $this->getDoctrine()->getManager();
  6036.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  6037.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  6038.         $client $em->getRepository(Client::class)->findById($file->getClient());
  6039.         if (empty($client)) {
  6040.             $client[0] = new Client();
  6041.             $client[0]->setName('');
  6042.             $client[0]->setTitle('');
  6043.             $client[0]->setIdDocument('');
  6044.             $client[0]->setPopulation('');
  6045.             $client[0]->setRegion('');
  6046.             $client[0]->setCountry('');
  6047.         } else {
  6048.             if (is_numeric($client[0]->getPopulation())) {
  6049.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  6050. //                $client[0]->setPopulation($city->getCity());
  6051.             }
  6052.             if (is_numeric($client[0]->getRegion())) {
  6053.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  6054. //                $client[0]->setRegion($region->getRegion());
  6055.             }
  6056.             if (is_numeric($client[0]->getCountry())) {
  6057.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  6058. //                $client[0]->setCountry($country->getCountry());
  6059.             }
  6060.         }
  6061.         if (empty($client)) {
  6062.             $client[0] = new Client();
  6063.             $client[0]->setName('');
  6064.             $client[0]->setTitle('');
  6065.             $client[0]->setIdDocument('');
  6066.             $client[0]->setPopulation('');
  6067.             $client[0]->setRegion('');
  6068.             $client[0]->setCountry('');
  6069.             $clientNew = array(
  6070.                 'name' => '',
  6071.                 'title' => '',
  6072.                 'idDocument' => '',
  6073.                 'population' => '',
  6074.                 'region' => '',
  6075.                 'country' => '',
  6076.                 'address' => '',
  6077.                 'addressNumber' => '',
  6078.                 'zipCode' => '',
  6079.                 'typeDocument' => '',
  6080.             );
  6081.         } else {
  6082.             $clientNew = array(
  6083.                 'name' => $client[0]->getName(),
  6084.                 'title' => $client[0]->getTitle(),
  6085.                 'idDocument' => $client[0]->getIdDocument(),
  6086.                 'population' => '',
  6087.                 'region' => '',
  6088.                 'country' => '',
  6089.                 'address' => $client[0]->getAddress(),
  6090.                 'addressNumber' => $client[0]->getAddressNumber(),
  6091.                 'zipCode' => $client[0]->getZipCode(),
  6092.                 'typeDocument' => $client[0]->getTypeDocument(),
  6093.             );
  6094.             if (is_numeric($client[0]->getPopulation())) {
  6095.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  6096.                 $clientNew['population'] = $city->getCity();
  6097.             }
  6098.             if (is_numeric($client[0]->getRegion())) {
  6099.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  6100.                 $clientNew['region'] = $region->getRegion();
  6101.             }
  6102.             if (is_numeric($client[0]->getCountry())) {
  6103.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  6104.                 $clientNew['country'] = $country->getCountry();
  6105.             }
  6106.         }
  6107.         // Acumuladores de los calculos
  6108.         $totales_neto_all 0;
  6109.         $data_iva = array(
  6110.             'iva' => 21,
  6111.             'ivaMontoVeintiUno' => 0,
  6112.             'ivaMontoDiez' => 0,
  6113.             'ivaMontoCero' => null,
  6114.         );
  6115.         // Buscamos las salas reservadas, pagos y servicios para el evento
  6116.         // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  6117.         $allProductFile $em->getRepository(AveProductFile::class)->findByFileId($id);
  6118.         $arrayLocation = [];
  6119.         $arrayLocationWithNull false;
  6120.         foreach ($allProductFile as $item) {
  6121.             if (!empty($item->getLocation())) {
  6122.                 $arrayLocation[$item->getLocation()] = $item->getLocation();
  6123.             } else {
  6124.                 $arrayLocationWithNull true;
  6125.             }
  6126.         }
  6127.         if ($arrayLocationWithNull) { $arrayLocation['null'] = 'null'; }
  6128.         $productsInFile = [];
  6129.         foreach ($arrayLocation as $item) {
  6130.             // VIDEO
  6131.             $parameters = array(
  6132.                 'fileId' => $id,
  6133.                 'type' => 'VĂ­deo',
  6134.                 'location' => $item,
  6135.             );
  6136.             $dql 'SELECT i
  6137.                     FROM AvexpressBundle:AveProductFile i
  6138.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6139.                     ORDER BY i.rankAv ASC';
  6140.             $query $em->createQuery($dql)->setParameters($parameters);
  6141.             $productsInFileVid $query->getResult();
  6142.             // SONIDO
  6143.             $parameters = array(
  6144.                 'fileId' => $id,
  6145.                 'type' => 'Sonido',
  6146.                 'location' => $item,
  6147.             );
  6148.             $dql 'SELECT i
  6149.                     FROM AvexpressBundle:AveProductFile i
  6150.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6151.                     ORDER BY i.rankAv ASC';
  6152.             $query $em->createQuery($dql)->setParameters($parameters);
  6153.             $productsInFileSound $query->getResult();
  6154.             // ILUMINACION
  6155.             $parameters = array(
  6156.                 'fileId' => $id,
  6157.                 'type' => 'IluminaciĂ³n',
  6158.                 'location' => $item,
  6159.             );
  6160.             $dql 'SELECT i
  6161.                     FROM AvexpressBundle:AveProductFile i
  6162.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6163.                     ORDER BY i.rankAv ASC';
  6164.             $query $em->createQuery($dql)->setParameters($parameters);
  6165.             $productsInFileLights $query->getResult();
  6166.             // PAQUETE
  6167.             $parameters = array(
  6168.                 'fileId' => $id,
  6169.                 'type' => 'Paquete',
  6170.                 'location' => $item,
  6171.             );
  6172.             $dql 'SELECT i
  6173.                     FROM AvexpressBundle:AveProductFile i
  6174.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
  6175.                     ORDER BY i.rankAv ASC';
  6176.             $query $em->createQuery($dql)->setParameters($parameters);
  6177.             $productsInFilePackage $query->getResult();
  6178.             // OTROS
  6179.             $parameters = array(
  6180.                 'fileId' => $id,
  6181.                 'typeV' => 'VĂ­deo',
  6182.                 'typeS' => 'Sonido',
  6183.                 'typeI' => 'IluminaciĂ³n',
  6184.                 'typeP' => 'Paquete',
  6185.                 'location' => $item,
  6186.             );
  6187.             $dql 'SELECT i
  6188.                     FROM AvexpressBundle:AveProductFile i
  6189.                     WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.type != :typeP AND i.location = :location)
  6190.                     ORDER BY i.rankAv ASC';
  6191.             $query $em->createQuery($dql)->setParameters($parameters);
  6192.             $productsInFileOther $query->getResult();
  6193.             // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  6194.             $parameters = array(
  6195.                 'fileId' => $id,
  6196.                 'location' => $item,
  6197.             );
  6198.             $dql 'SELECT i
  6199.                     FROM AvexpressBundle:AveProductFile i
  6200.                     WHERE (i.fileId = :fileId AND i.type IS NULL AND i.location = :location)
  6201.                     ORDER BY i.rankAv ASC';
  6202.             $query $em->createQuery($dql)->setParameters($parameters);
  6203.             $productsInFileNull $query->getResult();
  6204.             // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  6205.             if ($item == 'null') {
  6206.                 // VIDEO
  6207.                 $parameters = array(
  6208.                     'fileId' => $id,
  6209.                     'type' => 'VĂ­deo',
  6210.                     'location' => '',
  6211.                 );
  6212.                 $dql 'SELECT i
  6213.                         FROM AvexpressBundle:AveProductFile i
  6214.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  6215.                         ORDER BY i.rankAv ASC';
  6216.                 $query $em->createQuery($dql)->setParameters($parameters);
  6217.                 $productsInFileVid $query->getResult();
  6218.                 // SONIDO
  6219.                 $parameters = array(
  6220.                     'fileId' => $id,
  6221.                     'type' => 'Sonido',
  6222.                     'location' => '',
  6223.                 );
  6224.                 $dql 'SELECT i
  6225.                         FROM AvexpressBundle:AveProductFile i
  6226.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) 
  6227.                         ORDER BY i.rankAv ASC';
  6228.                 $query $em->createQuery($dql)->setParameters($parameters);
  6229.                 $productsInFileSound $query->getResult();
  6230.                 // ILUMINACION
  6231.                 $parameters = array(
  6232.                     'fileId' => $id,
  6233.                     'type' => 'IluminaciĂ³n',
  6234.                     'location' => '',
  6235.                 );
  6236.                 $dql 'SELECT i
  6237.                         FROM AvexpressBundle:AveProductFile i
  6238.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  6239.                         ORDER BY i.rankAv ASC';
  6240.                 $query $em->createQuery($dql)->setParameters($parameters);
  6241.                 $productsInFileLights $query->getResult();
  6242.                 // PAQUETE
  6243. //                $parameters = array(
  6244. //                    'fileId' => $id,
  6245. //                    'type' => 'Paquete',
  6246. //                    'location' => '',
  6247. //                );
  6248. //                $dql = 'SELECT i
  6249. //                        FROM AvexpressBundle:AveProductFile i
  6250. //                        WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
  6251. //                        ORDER BY i.rankAv ASC';
  6252. //                $query = $em->createQuery($dql)->setParameters($parameters);
  6253. //                $productsInFilePackage = $query->getResult();
  6254.                 // OTROS
  6255.                 $parameters = array(
  6256.                     'fileId' => $id,
  6257.                     'typeV' => 'VĂ­deo',
  6258.                     'typeS' => 'Sonido',
  6259.                     'typeI' => 'IluminaciĂ³n',
  6260.                     'location' => '',
  6261.                 );
  6262.                 $dql 'SELECT i
  6263.                         FROM AvexpressBundle:AveProductFile i
  6264.                         WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND (i.location IS NULL OR i.location = :location))
  6265.                         ORDER BY i.rankAv ASC';
  6266.                 $query $em->createQuery($dql)->setParameters($parameters);
  6267.                 $productsInFileOther $query->getResult();
  6268.                 // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  6269.                 $parameters = array(
  6270.                     'fileId' => $id,
  6271.                     'location' => '',
  6272.                 );
  6273.                 $dql 'SELECT i
  6274.                         FROM AvexpressBundle:AveProductFile i
  6275.                         WHERE (i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location))
  6276.                         ORDER BY i.rankAv ASC';
  6277.                 $query $em->createQuery($dql)->setParameters($parameters);
  6278.                 $productsInFileNull $query->getResult();
  6279.             }
  6280.             $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  6281.         }
  6282.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  6283.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  6284.         $data_supplier = [];
  6285.         $i 0;
  6286.         $product = array(
  6287.             'neto' => 0,
  6288.             'sumSubT' => 0,
  6289.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6290.         $service = array(
  6291.             'neto' => 0,
  6292.             'sumSubT' => 0,
  6293.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6294.         foreach ($productsInFile as $item) {
  6295.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  6296.             // Verificamos que el producto no se encuentre ya en una factura
  6297.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
  6298.             $pax $item->getPax();
  6299.             $qty $item->getUnits();
  6300.             if (!empty($item->getDays())) { $days $item->getDays(); }
  6301.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
  6302.                 $subtotal $neto $subtotalProduct 0;
  6303.             } else {
  6304.                 $subtotalProduct 0;
  6305.                 if ($item->getIva() == '21') {
  6306.                     $subtotalProduct $item->getSubTotalPrice() * 1.21;
  6307.                 } // Iva a 21%
  6308.                 if ($item->getIva() == '10') {
  6309.                     $subtotalProduct $item->getSubTotalPrice() * 1.1;
  6310.                 } // Iva a 10%
  6311.                 if ($item->getIva() == '0') {
  6312.                     $subtotalProduct $item->getSubTotalPrice() * 1;
  6313.                 } // Iva a 0%
  6314.                 $subneto $item->getSubTotalPrice();
  6315.                 $subtotal =  $subtotalProduct;
  6316.                 $neto =  $subneto;
  6317.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  6318.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  6319.                 $neto round($neto2PHP_ROUND_HALF_UP);
  6320.             }
  6321.             // Acumula netos totales e IVA
  6322.             $totales_neto_all $totales_neto_all $neto;
  6323.             if ($item->getIva() == '21') {
  6324.                 $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  6325.             } // Iva a 21%
  6326.             if ($item->getIva() == '10') {
  6327.                 $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  6328.             } // Iva a 10%
  6329.             if ($item->getIva() == '0') {
  6330.                 $data_iva['ivaMontoCero'] = $neto 0;
  6331.             } // Iva a 0%, estaba inicializado en null para que aparezca en la factura solo si estĂ¡ a cero
  6332.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6333.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  6334.             if ($item->getIva() == '21') {
  6335.                 $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  6336.             } // Iva a 21%
  6337.             if ($item->getIva() == '10') {
  6338.                 $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  6339.             } // Iva a 10%
  6340.             if ($item->getIva() == '0') {
  6341.                 $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  6342.             } // Iva a 0%
  6343.             // Acumula netos totales e IVA
  6344.             $product['neto'] = $product['neto'] + $neto;
  6345.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  6346.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6347.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  6348.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  6349.             // Calculo del precio unitario despues de aplicar Over y Comision
  6350.             $multiplo = (float)$qty * (float)$days;
  6351.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  6352.             $data_supplier['product'][$i] = array(
  6353.                 'id' => $item->getId(),
  6354.                 'productName' => $item->getProductName(),
  6355.                 'productId' => $item->getProductId(),
  6356.                 'dateStart' => $item->getDateStart(),
  6357.                 'dateEnd' => $item->getDateEnd(),
  6358.                 'location' => $item->getLocation(),
  6359.                 'servicePrice' => $item->getServicePrice(),
  6360.                 'subTotalPrice' => $item->getSubTotalPrice(),
  6361.                 'subtotalProduct' => $subtotalProduct,
  6362.                 'iva' => $item->getIva(),
  6363.                 'pax' => $pax,
  6364.                 'qty' => $qty,
  6365.                 'days' => $days,
  6366.                 'type' => $item->getType(),
  6367.                 'subtotal' => $subtotal,
  6368.             );
  6369.             $i++;
  6370.         }
  6371.         $data_supplier['productSubTotal'] = array(
  6372.             'neto' => $product['neto'],
  6373.             'sumSubT' => $product['sumSubT'],
  6374.         );
  6375.         $payment = array(
  6376.             'sumSubT' => 0,
  6377.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6378.         $i 0;
  6379.         foreach ($payments as $item) {
  6380.             // Verificamos que el pago no se encuentre ya en una factura
  6381.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
  6382.             if (!empty($existe)) {
  6383.                 $payment['sumSubT'] = $payment['sumSubT'] + 0;
  6384.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6385.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  6386.             } else {
  6387.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  6388.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6389.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  6390.             }
  6391.             $data_supplier['payment'][$i] = array(
  6392.                 'id' => $item->getId(),
  6393.                 'amount' => $item->getAmount(),
  6394.                 'datePayAt' => $item->getDatePayAt(),
  6395.                 'wayToPay' => $item->getWayToPay(),
  6396.                 'amountTotal' => $item->getAmountTotal(),
  6397.                 'vat' => $item->getVat(),
  6398.             );
  6399.             $i++;
  6400.         }
  6401.         if (!empty($payments)) {
  6402.             $data_supplier['paymentSubTotal'] = array(
  6403.                 'sumSubT' => $payment['sumSubT'],
  6404.             );
  6405.         }
  6406.         foreach ($services as $item) {
  6407.             // Verificamos que el servicio no se encuentre ya en una factura
  6408.             $existe $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
  6409.             if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
  6410.                 $subtotal 0;
  6411.                 $neto 0;
  6412.                 $subtotalService 0;
  6413.                 $subneto 0;
  6414.                 switch ($item->getServiceCatId()) {
  6415.                     case 1// Alojamiento
  6416.                         // el numero de noches $numNoches; precio unitario $subneto
  6417.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  6418.                         // La personas no afectan este calculo
  6419.                         $subtotal $subtotalService $numNoches $item->getUnits();
  6420.                         $subnetoUnit $subneto;
  6421.                         $subneto $subneto $numNoches $item->getUnits();
  6422.                         $data_supplier['service'][$i] = array(
  6423.                             'id' => $item->getId(),
  6424.                             'serviceCatId' => $item->getServiceCatId(),
  6425.                             'serviceName' => $item->getName(),
  6426.                             'serviceType' => 'Hotel',
  6427.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  6428.                             'qty' => $item->getUnits(),
  6429.                             'iva' => $item->getIva(),
  6430.                             'pax' => '-',
  6431.                             'precioUnit' => $subnetoUnit,
  6432.                             'subneto' => $subneto,
  6433.                             'subtotal' => $subtotal,
  6434.                         );
  6435.                         break;
  6436.                     case 2//Actividades
  6437.                         // El nĂºmero de personas es considerado en el calculo
  6438.                         $pax $item->getPax();
  6439.                         if (empty($pax) or $pax == "0") {
  6440.                             $pax 1;
  6441.                         }
  6442.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6443.                         if ($days 1) {
  6444.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6445.                         } else {
  6446.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6447.                         }
  6448.                         $subtotal $subtotalService $days $item->getUnits();
  6449.                         $subnetoUnit $subneto;
  6450.                         $subneto $subneto $days $item->getUnits();
  6451.                         $data_supplier['service'][$i] = array(
  6452.                             'id' => $item->getId(),
  6453.                             'serviceCatId' => $item->getServiceCatId(),
  6454.                             'serviceName' => $item->getName(),
  6455.                             'serviceType' => 'Actividad',
  6456.                             'date' => $dateServ,
  6457.                             'qty' => $item->getUnits(),
  6458.                             'iva' => $item->getIva(),
  6459.                             'pax' => $item->getPax(),
  6460.                             'precioUnit' => $subnetoUnit,
  6461.                             'subneto' => $subneto,
  6462.                             'subtotal' => $subtotal,
  6463.                         );
  6464.                         break;
  6465.                     case 3// AV
  6466.                         $pax $item->getPax();
  6467.                         if (empty($pax) or $pax == "0") {
  6468.                             $pax 1;
  6469.                         }
  6470.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6471.                         if ($days 1) {
  6472.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6473.                         } else {
  6474.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6475.                         }
  6476.                         $unitsServ $item->getUnits();
  6477.                         if (empty($unitsServ) or $unitsServ == "0") {
  6478.                             $unitsServ 1;
  6479.                         }
  6480.                         $subtotal $subtotalService $days $unitsServ $pax;
  6481.                         $subnetoUnit $subneto;
  6482.                         $subneto $subneto $days $unitsServ $pax;
  6483.                         $data_supplier['service'][$i] = array(
  6484.                             'id' => $item->getId(),
  6485.                             'serviceCatId' => $item->getServiceCatId(),
  6486.                             'serviceName' => $item->getName(),
  6487.                             'serviceType' => 'AV',
  6488.                             'date' => $dateServ,
  6489.                             'qty' => $unitsServ,
  6490.                             'iva' => $item->getIva(),
  6491.                             'pax' => $item->getPax(),
  6492.                             'precioUnit' => $subnetoUnit,
  6493.                             'subneto' => $subneto,
  6494.                             'subtotal' => $subtotal,
  6495.                         );
  6496.                         break;
  6497.                     case 4//Creative
  6498.                         $pax $item->getPax();
  6499.                         if (empty($pax) or $pax == "0") {
  6500.                             $pax 1;
  6501.                         }
  6502.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6503.                         if ($days 1) {
  6504.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6505.                         } else {
  6506.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6507.                         }
  6508.                         $unitsServ $item->getUnits();
  6509.                         if (empty($unitsServ) or $unitsServ == "0") {
  6510.                             $unitsServ 1;
  6511.                         }
  6512.                         $subtotal $subtotalService $days $unitsServ $pax;
  6513.                         $subnetoUnit $subneto;
  6514.                         $subneto $subneto $days $unitsServ $pax;
  6515.                         $data_supplier['service'][$i] = array(
  6516.                             'id' => $item->getId(),
  6517.                             'serviceCatId' => $item->getServiceCatId(),
  6518.                             'serviceName' => $item->getName(),
  6519.                             'serviceType' => 'Creativo',
  6520.                             'date' => $dateServ,
  6521.                             'qty' => $unitsServ,
  6522.                             'iva' => $item->getIva(),
  6523.                             'pax' => $item->getPax(),
  6524.                             'precioUnit' => $subnetoUnit,
  6525.                             'subneto' => $subneto,
  6526.                             'subtotal' => $subtotal,
  6527.                         );
  6528.                         break;
  6529.                     case 5//Cruise
  6530.                         $pax $item->getPax();
  6531.                         if (empty($pax) or $pax == "0") {
  6532.                             $pax 1;
  6533.                         }
  6534.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  6535.                         if ($days 1) {
  6536.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6537.                         } else {
  6538.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6539.                         }
  6540.                         $unitsServ $item->getUnits();
  6541.                         if (empty($unitsServ) or $unitsServ == "0") {
  6542.                             $unitsServ 1;
  6543.                         }
  6544.                         $subtotal $subtotalService $days $unitsServ $pax;
  6545.                         $subnetoUnit $subneto;
  6546.                         $subneto $subneto $days $unitsServ $pax;
  6547.                         $data_supplier['service'][$i] = array(
  6548.                             'id' => $item->getId(),
  6549.                             'serviceCatId' => $item->getServiceCatId(),
  6550.                             'serviceName' => $item->getName(),
  6551.                             'serviceType' => 'Crucero',
  6552.                             'date' => $dateServ,
  6553.                             'qty' => $unitsServ,
  6554.                             'iva' => $item->getIva(),
  6555.                             'pax' => $item->getPax(),
  6556.                             'precioUnit' => $subnetoUnit,
  6557.                             'subneto' => $subneto,
  6558.                             'subtotal' => $subtotal,
  6559.                         );
  6560.                         break;
  6561.                     case 6//Entertaiment
  6562.                         $pax $item->getPax();
  6563.                         if (empty($pax) or $pax == "0") {
  6564.                             $pax 1;
  6565.                         }
  6566.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6567.                         if ($days 1) {
  6568.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6569.                         } else {
  6570.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6571.                         }
  6572.                         $unitsServ $item->getUnits();
  6573.                         if (empty($unitsServ) or $unitsServ == "0") {
  6574.                             $unitsServ 1;
  6575.                         }
  6576.                         $subtotal $subtotalService $days $unitsServ $pax;
  6577.                         $subnetoUnit $subneto;
  6578.                         $subneto $subneto $days $unitsServ $pax;
  6579.                         $data_supplier['service'][$i] = array(
  6580.                             'id' => $item->getId(),
  6581.                             'serviceCatId' => $item->getServiceCatId(),
  6582.                             'serviceName' => $item->getName(),
  6583.                             'serviceType' => 'Entretenimiento',
  6584.                             'date' => $dateServ,
  6585.                             'qty' => $unitsServ,
  6586.                             'iva' => $item->getIva(),
  6587.                             'pax' => $item->getPax(),
  6588.                             'precioUnit' => $subnetoUnit,
  6589.                             'subneto' => $subneto,
  6590.                             'subtotal' => $subtotal,
  6591.                         );
  6592.                         break;
  6593.                     case 7// Gifts
  6594.                         $pax $item->getPax();
  6595.                         if (empty($pax) or $pax == "0") {
  6596.                             $pax 1;
  6597.                         }
  6598.                         $days 1;
  6599.                         if ($days 1) {
  6600.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6601.                         } else {
  6602.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6603.                         }
  6604.                         $unitsServ $item->getUnits();
  6605.                         if (empty($unitsServ) or $unitsServ == "0") {
  6606.                             $unitsServ 1;
  6607.                         }
  6608.                         $subtotal $subtotalService $days $unitsServ $pax;
  6609.                         $subnetoUnit $subneto;
  6610.                         $subneto $subneto $days $unitsServ $pax;
  6611.                         $data_supplier['service'][$i] = array(
  6612.                             'id' => $item->getId(),
  6613.                             'serviceCatId' => $item->getServiceCatId(),
  6614.                             'serviceName' => $item->getName(),
  6615.                             'serviceType' => 'Regalos',
  6616.                             'date' => $dateServ,
  6617.                             'qty' => $unitsServ,
  6618.                             'iva' => $item->getIva(),
  6619.                             'pax' => $item->getPax(),
  6620.                             'precioUnit' => $subnetoUnit,
  6621.                             'subneto' => $subneto,
  6622.                             'subtotal' => $subtotal,
  6623.                         );
  6624.                         break;
  6625.                     case 8//Guide
  6626.                         $pax $item->getPax();
  6627.                         if (empty($pax) or $pax == "0") {
  6628.                             $pax 1;
  6629.                         }
  6630.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6631.                         if ($days 1) {
  6632.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6633.                         } else {
  6634.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6635.                         }
  6636.                         $unitsServ $item->getUnits();
  6637.                         if (empty($unitsServ) or $unitsServ == "0") {
  6638.                             $unitsServ 1;
  6639.                         }
  6640.                         $subtotal $subtotalService $days $unitsServ $pax;
  6641.                         $subnetoUnit $subneto;
  6642.                         $subneto $subneto $days $unitsServ $pax;
  6643.                         $data_supplier['service'][$i] = array(
  6644.                             'id' => $item->getId(),
  6645.                             'serviceCatId' => $item->getServiceCatId(),
  6646.                             'serviceName' => $item->getName(),
  6647.                             'serviceType' => 'Regalos',
  6648.                             'date' => $dateServ,
  6649.                             'qty' => $unitsServ,
  6650.                             'iva' => $item->getIva(),
  6651.                             'pax' => $item->getPax(),
  6652.                             'precioUnit' => $subnetoUnit,
  6653.                             'subneto' => $subneto,
  6654.                             'subtotal' => $subtotal,
  6655.                         );
  6656.                         break;
  6657.                     case 9//Itineraries
  6658.                         $pax $item->getPax();
  6659.                         if (empty($pax) or $pax == "0") {
  6660.                             $pax 1;
  6661.                         }
  6662.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6663.                         if ($days 1) {
  6664.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6665.                         } else {
  6666.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6667.                         }
  6668.                         $unitsServ $item->getUnits();
  6669.                         if (empty($unitsServ) or $unitsServ == "0") {
  6670.                             $unitsServ 1;
  6671.                         }
  6672.                         $subtotal $subtotalService $days $unitsServ $pax;
  6673.                         $subnetoUnit $subneto;
  6674.                         $subneto $subneto $days $unitsServ $pax;
  6675.                         $data_supplier['service'][$i] = array(
  6676.                             'id' => $item->getId(),
  6677.                             'serviceCatId' => $item->getServiceCatId(),
  6678.                             'serviceName' => $item->getName(),
  6679.                             'serviceType' => 'Itinerarios',
  6680.                             'date' => $dateServ,
  6681.                             'qty' => $unitsServ,
  6682.                             'iva' => $item->getIva(),
  6683.                             'pax' => $item->getPax(),
  6684.                             'precioUnit' => $subnetoUnit,
  6685.                             'subneto' => $subneto,
  6686.                             'subtotal' => $subtotal,
  6687.                         );
  6688.                         break;
  6689.                     case 10//Lounge  -- No Aplica
  6690.                         //                        $pax = $item->getPax();
  6691.                         //                        if (empty($pax) or $pax == "0") {
  6692.                         //                            $pax = 1;
  6693.                         //                        }
  6694.                         //
  6695.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  6696.                         //                        if ($days > 1){
  6697.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  6698.                         //                        } else {
  6699.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6700.                         //                        }
  6701.                         //
  6702.                         //                        $unitsServ = $item->getUnits();
  6703.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  6704.                         //                            $unitsServ = 1;
  6705.                         //                        }
  6706.                         //
  6707.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  6708.                         //                        $subnetoUnit = $subneto;
  6709.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  6710.                         //
  6711.                         //                        $data_supplier['service'][$i] = array (
  6712.                         //                            'id' => $item->getId(),
  6713.                         //                            'serviceCatId' => $item->getServiceCatId(),
  6714.                         //                            'serviceName' => $item->getName(),
  6715.                         //                            'serviceType' => 'Itinerarios',
  6716.                         //                            'date' => $dateServ,
  6717.                         //                            'qty' => $unitsServ,
  6718.                         //                            'iva' => $item->getIva(),
  6719.                         //                            'pax' => $item->getPax(),
  6720.                         //                            'precioUnit' => $subnetoUnit,
  6721.                         //                            'subneto' => $subneto,
  6722.                         //                            'subtotal' => $subtotal,
  6723.                         //                        );
  6724.                         break;
  6725.                     case 11//Menu
  6726.                         $pax $item->getPax();
  6727.                         if (empty($pax) or $pax == "0") {
  6728.                             $pax 1;
  6729.                         }
  6730.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6731.                         if ($days 1) {
  6732.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6733.                         } else {
  6734.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6735.                         }
  6736.                         $unitsServ $item->getUnits();
  6737.                         if (empty($unitsServ) or $unitsServ == "0") {
  6738.                             $unitsServ 1;
  6739.                         }
  6740.                         $subtotal $subtotalService $days $unitsServ $pax;
  6741.                         $subnetoUnit $subneto;
  6742.                         $subneto $subneto $days $unitsServ $pax;
  6743.                         $data_supplier['service'][$i] = array(
  6744.                             'id' => $item->getId(),
  6745.                             'serviceCatId' => $item->getServiceCatId(),
  6746.                             'serviceName' => $item->getName(),
  6747.                             'serviceType' => 'MenĂº',
  6748.                             'date' => $dateServ,
  6749.                             'qty' => $unitsServ,
  6750.                             'iva' => $item->getIva(),
  6751.                             'pax' => $item->getPax(),
  6752.                             'precioUnit' => $subnetoUnit,
  6753.                             'subneto' => $subneto,
  6754.                             'subtotal' => $subtotal,
  6755.                         );
  6756.                         break;
  6757.                     case 12//Others
  6758.                         $pax $item->getPax();
  6759.                         if (empty($pax) or $pax == "0") {
  6760.                             $pax 1;
  6761.                         }
  6762.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6763.                         if ($days 1) {
  6764.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6765.                         } else {
  6766.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6767.                         }
  6768.                         $unitsServ $item->getUnits();
  6769.                         if (empty($unitsServ) or $unitsServ == "0") {
  6770.                             $unitsServ 1;
  6771.                         }
  6772.                         $subtotal $subtotalService $days $unitsServ $pax;
  6773.                         $subnetoUnit $subneto;
  6774.                         $subneto $subneto $days $unitsServ $pax;
  6775.                         $data_supplier['service'][$i] = array(
  6776.                             'id' => $item->getId(),
  6777.                             'serviceCatId' => $item->getServiceCatId(),
  6778.                             'serviceName' => $item->getName(),
  6779.                             'serviceType' => 'Otros',
  6780.                             'date' => $dateServ,
  6781.                             'qty' => $unitsServ,
  6782.                             'iva' => $item->getIva(),
  6783.                             'pax' => $item->getPax(),
  6784.                             'precioUnit' => $subnetoUnit,
  6785.                             'subneto' => $subneto,
  6786.                             'subtotal' => $subtotal,
  6787.                         );
  6788.                         break;
  6789.                     case 13//Transport
  6790.                         $pax $item->getPax();
  6791.                         if (empty($pax) or $pax == "0") {
  6792.                             $pax 1;
  6793.                         }
  6794.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6795.                         if ($days 1) {
  6796.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6797.                         } else {
  6798.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6799.                         }
  6800.                         $unitsServ $item->getUnits();
  6801.                         if (empty($unitsServ) or $unitsServ == "0") {
  6802.                             $unitsServ 1;
  6803.                         }
  6804.                         $subtotal $subtotalService $days $unitsServ $pax;
  6805.                         $subnetoUnit $subneto;
  6806.                         $subneto $subneto $days $unitsServ $pax;
  6807.                         $data_supplier['service'][$i] = array(
  6808.                             'id' => $item->getId(),
  6809.                             'serviceCatId' => $item->getServiceCatId(),
  6810.                             'serviceName' => $item->getName(),
  6811.                             'serviceType' => 'Transporte',
  6812.                             'date' => $dateServ,
  6813.                             'qty' => $unitsServ,
  6814.                             'iva' => $item->getIva(),
  6815.                             'pax' => $item->getPax(),
  6816.                             'precioUnit' => $subnetoUnit,
  6817.                             'subneto' => $subneto,
  6818.                             'subtotal' => $subtotal,
  6819.                         );
  6820.                         break;
  6821.                     case 14//Technology
  6822.                         $pax $item->getPax();
  6823.                         if (empty($pax) or $pax == "0") {
  6824.                             $pax 1;
  6825.                         }
  6826.                         $days 1;
  6827.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6828.                         $unitsServ $item->getUnits();
  6829.                         if (empty($unitsServ) or $unitsServ == "0") {
  6830.                             $unitsServ 1;
  6831.                         }
  6832.                         $subtotal $subtotalService $days $unitsServ $pax;
  6833.                         $subnetoUnit $subneto;
  6834.                         $subneto $subneto $days $unitsServ $pax;
  6835.                         $data_supplier['service'][$i] = array(
  6836.                             'id' => $item->getId(),
  6837.                             'serviceCatId' => $item->getServiceCatId(),
  6838.                             'serviceName' => $item->getName(),
  6839.                             'serviceType' => 'TecnologĂ­a',
  6840.                             'date' => $dateServ,
  6841.                             'qty' => $unitsServ,
  6842.                             'iva' => $item->getIva(),
  6843.                             'pax' => $item->getPax(),
  6844.                             'precioUnit' => $subnetoUnit,
  6845.                             'subneto' => $subneto,
  6846.                             'subtotal' => $subtotal,
  6847.                         );
  6848.                         break;
  6849.                     case 15//Assisstant
  6850.                         $pax $item->getPax();
  6851.                         if (empty($pax) or $pax == "0") {
  6852.                             $pax 1;
  6853.                         }
  6854.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6855.                         if ($days 1) {
  6856.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6857.                         } else {
  6858.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6859.                         }
  6860.                         $unitsServ $item->getUnits();
  6861.                         if (empty($unitsServ) or $unitsServ == "0") {
  6862.                             $unitsServ 1;
  6863.                         }
  6864.                         $subtotal $subtotalService $days $unitsServ $pax;
  6865.                         $subnetoUnit $subneto;
  6866.                         $subneto $subneto $days $unitsServ $pax;
  6867.                         $data_supplier['service'][$i] = array(
  6868.                             'id' => $item->getId(),
  6869.                             'serviceCatId' => $item->getServiceCatId(),
  6870.                             'serviceName' => $item->getName(),
  6871.                             'serviceType' => 'Asistente',
  6872.                             'date' => $dateServ,
  6873.                             'qty' => $unitsServ,
  6874.                             'iva' => $item->getIva(),
  6875.                             'pax' => $item->getPax(),
  6876.                             'precioUnit' => $subnetoUnit,
  6877.                             'subneto' => $subneto,
  6878.                             'subtotal' => $subtotal,
  6879.                         );
  6880.                         break;
  6881.                     case 16//DDR
  6882.                         $pax $item->getPax();
  6883.                         if (empty($pax) or $pax == "0") {
  6884.                             $pax 1;
  6885.                         }
  6886.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6887.                         if ($days 1) {
  6888.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6889.                         } else {
  6890.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6891.                         }
  6892.                         $unitsServ $item->getUnits();
  6893.                         if (empty($unitsServ) or $unitsServ == "0") {
  6894.                             $unitsServ 1;
  6895.                         }
  6896.                         $subtotal $subtotalService $days $unitsServ $pax;
  6897.                         $subnetoUnit $subneto;
  6898.                         $subneto $subneto $days $unitsServ $pax;
  6899.                         $data_supplier['service'][$i] = array(
  6900.                             'id' => $item->getId(),
  6901.                             'serviceCatId' => $item->getServiceCatId(),
  6902.                             'serviceName' => $item->getName(),
  6903.                             'serviceType' => 'DDR',
  6904.                             'date' => $dateServ,
  6905.                             'qty' => $unitsServ,
  6906.                             'iva' => $item->getIva(),
  6907.                             'pax' => $item->getPax(),
  6908.                             'precioUnit' => $subnetoUnit,
  6909.                             'subneto' => $subneto,
  6910.                             'subtotal' => $subtotal,
  6911.                         );
  6912.                         break;
  6913.                     default:
  6914.                         break;
  6915.                 }
  6916.             } else {
  6917.                 $subtotalService $item->getPrice();
  6918.                 $subneto $item->getPrice();
  6919.                 // Commission
  6920.                 if ($item->getOpCommission() == '1') {
  6921.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  6922.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  6923.                 } else {
  6924.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  6925.                     $subneto $subneto * (- ($item->getCommission() / 100));
  6926.                 }
  6927.                 // Over
  6928.                 if ($item->getOpOver() == '1') {
  6929.                     $subtotalService $subtotalService $item->getOver();
  6930.                     $subneto $subneto $item->getOver();
  6931.                 } else {
  6932.                     $subtotalService $subtotalService $item->getOver();
  6933.                     $subneto $subneto $item->getOver();
  6934.                 }
  6935.                 // IVA
  6936.                 if ($item->getOpIva() == '1') {
  6937.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  6938.                 } else {
  6939.                     $subtotalService $item->getPrice();
  6940.                     $subneto = ($subneto 100) / (100 $item->getIva());
  6941.                 }
  6942.                 switch ($item->getServiceCatId()) {
  6943.                     case 1// Alojamiento
  6944.                         // el numero de noches $numNoches; precio unitario $subneto
  6945.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  6946.                         // La personas no afectan este calculo
  6947.                         $subtotal $subtotalService $numNoches $item->getUnits();
  6948.                         $subnetoUnit $subneto;
  6949.                         $subneto $subneto $numNoches $item->getUnits();
  6950.                         $data_supplier['service'][$i] = array(
  6951.                             'id' => $item->getId(),
  6952.                             'serviceCatId' => $item->getServiceCatId(),
  6953.                             'serviceName' => $item->getName(),
  6954.                             'serviceType' => 'Hotel',
  6955.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  6956.                             'qty' => $item->getUnits(),
  6957.                             'iva' => $item->getIva(),
  6958.                             'pax' => '-',
  6959.                             'precioUnit' => $subnetoUnit,
  6960.                             'subneto' => $subneto,
  6961.                             'subtotal' => $subtotal,
  6962.                         );
  6963.                         break;
  6964.                     case 2//Actividades
  6965.                         // El nĂºmero de personas es considerado en el calculo
  6966.                         $pax $item->getPax();
  6967.                         if (empty($pax) or $pax == "0") {
  6968.                             $pax 1;
  6969.                         }
  6970.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6971.                         if ($days 1) {
  6972.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6973.                         } else {
  6974.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6975.                         }
  6976.                         $subtotal $subtotalService $days $item->getUnits();
  6977.                         $subnetoUnit $subneto;
  6978.                         $subneto $subneto $days $item->getUnits();
  6979.                         $data_supplier['service'][$i] = array(
  6980.                             'id' => $item->getId(),
  6981.                             'serviceCatId' => $item->getServiceCatId(),
  6982.                             'serviceName' => $item->getName(),
  6983.                             'serviceType' => 'Actividad',
  6984.                             'date' => $dateServ,
  6985.                             'qty' => $item->getUnits(),
  6986.                             'iva' => $item->getIva(),
  6987.                             'pax' => $item->getPax(),
  6988.                             'precioUnit' => $subnetoUnit,
  6989.                             'subneto' => $subneto,
  6990.                             'subtotal' => $subtotal,
  6991.                         );
  6992.                         break;
  6993.                     case 3// AV
  6994.                         $pax $item->getPax();
  6995.                         if (empty($pax) or $pax == "0") {
  6996.                             $pax 1;
  6997.                         }
  6998.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6999.                         if ($days 1) {
  7000.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7001.                         } else {
  7002.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7003.                         }
  7004.                         $unitsServ $item->getUnits();
  7005.                         if (empty($unitsServ) or $unitsServ == "0") {
  7006.                             $unitsServ 1;
  7007.                         }
  7008.                         $subtotal $subtotalService $days $unitsServ $pax;
  7009.                         $subnetoUnit $subneto;
  7010.                         $subneto $subneto $days $unitsServ $pax;
  7011.                         $data_supplier['service'][$i] = array(
  7012.                             'id' => $item->getId(),
  7013.                             'serviceCatId' => $item->getServiceCatId(),
  7014.                             'serviceName' => $item->getName(),
  7015.                             'serviceType' => 'AV',
  7016.                             'date' => $dateServ,
  7017.                             'qty' => $unitsServ,
  7018.                             'iva' => $item->getIva(),
  7019.                             'pax' => $item->getPax(),
  7020.                             'precioUnit' => $subnetoUnit,
  7021.                             'subneto' => $subneto,
  7022.                             'subtotal' => $subtotal,
  7023.                         );
  7024.                         break;
  7025.                     case 4//Creative
  7026.                         $pax $item->getPax();
  7027.                         if (empty($pax) or $pax == "0") {
  7028.                             $pax 1;
  7029.                         }
  7030.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7031.                         if ($days 1) {
  7032.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7033.                         } else {
  7034.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7035.                         }
  7036.                         $unitsServ $item->getUnits();
  7037.                         if (empty($unitsServ) or $unitsServ == "0") {
  7038.                             $unitsServ 1;
  7039.                         }
  7040.                         $subtotal $subtotalService $days $unitsServ $pax;
  7041.                         $subnetoUnit $subneto;
  7042.                         $subneto $subneto $days $unitsServ $pax;
  7043.                         $data_supplier['service'][$i] = array(
  7044.                             'id' => $item->getId(),
  7045.                             'serviceCatId' => $item->getServiceCatId(),
  7046.                             'serviceName' => $item->getName(),
  7047.                             'serviceType' => 'Creativo',
  7048.                             'date' => $dateServ,
  7049.                             'qty' => $unitsServ,
  7050.                             'iva' => $item->getIva(),
  7051.                             'pax' => $item->getPax(),
  7052.                             'precioUnit' => $subnetoUnit,
  7053.                             'subneto' => $subneto,
  7054.                             'subtotal' => $subtotal,
  7055.                         );
  7056.                         break;
  7057.                     case 5//Cruise
  7058.                         $pax $item->getPax();
  7059.                         if (empty($pax) or $pax == "0") {
  7060.                             $pax 1;
  7061.                         }
  7062.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  7063.                         if ($days 1) {
  7064.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7065.                         } else {
  7066.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7067.                         }
  7068.                         $unitsServ $item->getUnits();
  7069.                         if (empty($unitsServ) or $unitsServ == "0") {
  7070.                             $unitsServ 1;
  7071.                         }
  7072.                         $subtotal $subtotalService $days $unitsServ $pax;
  7073.                         $subnetoUnit $subneto;
  7074.                         $subneto $subneto $days $unitsServ $pax;
  7075.                         $data_supplier['service'][$i] = array(
  7076.                             'id' => $item->getId(),
  7077.                             'serviceCatId' => $item->getServiceCatId(),
  7078.                             'serviceName' => $item->getName(),
  7079.                             'serviceType' => 'Crucero',
  7080.                             'date' => $dateServ,
  7081.                             'qty' => $unitsServ,
  7082.                             'iva' => $item->getIva(),
  7083.                             'pax' => $item->getPax(),
  7084.                             'precioUnit' => $subnetoUnit,
  7085.                             'subneto' => $subneto,
  7086.                             'subtotal' => $subtotal,
  7087.                         );
  7088.                         break;
  7089.                     case 6//Entertaiment
  7090.                         $pax $item->getPax();
  7091.                         if (empty($pax) or $pax == "0") {
  7092.                             $pax 1;
  7093.                         }
  7094.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7095.                         if ($days 1) {
  7096.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7097.                         } else {
  7098.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7099.                         }
  7100.                         $unitsServ $item->getUnits();
  7101.                         if (empty($unitsServ) or $unitsServ == "0") {
  7102.                             $unitsServ 1;
  7103.                         }
  7104.                         $subtotal $subtotalService $days $unitsServ $pax;
  7105.                         $subnetoUnit $subneto;
  7106.                         $subneto $subneto $days $unitsServ $pax;
  7107.                         $data_supplier['service'][$i] = array(
  7108.                             'id' => $item->getId(),
  7109.                             'serviceCatId' => $item->getServiceCatId(),
  7110.                             'serviceName' => $item->getName(),
  7111.                             'serviceType' => 'Entretenimiento',
  7112.                             'date' => $dateServ,
  7113.                             'qty' => $unitsServ,
  7114.                             'iva' => $item->getIva(),
  7115.                             'pax' => $item->getPax(),
  7116.                             'precioUnit' => $subnetoUnit,
  7117.                             'subneto' => $subneto,
  7118.                             'subtotal' => $subtotal,
  7119.                         );
  7120.                         break;
  7121.                     case 7// Gifts
  7122.                         $pax $item->getPax();
  7123.                         if (empty($pax) or $pax == "0") {
  7124.                             $pax 1;
  7125.                         }
  7126.                         $days 1;
  7127.                         if ($days 1) {
  7128.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7129.                         } else {
  7130.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7131.                         }
  7132.                         $unitsServ $item->getUnits();
  7133.                         if (empty($unitsServ) or $unitsServ == "0") {
  7134.                             $unitsServ 1;
  7135.                         }
  7136.                         $subtotal $subtotalService $days $unitsServ $pax;
  7137.                         $subnetoUnit $subneto;
  7138.                         $subneto $subneto $days $unitsServ $pax;
  7139.                         $data_supplier['service'][$i] = array(
  7140.                             'id' => $item->getId(),
  7141.                             'serviceCatId' => $item->getServiceCatId(),
  7142.                             'serviceName' => $item->getName(),
  7143.                             'serviceType' => 'Regalos',
  7144.                             'date' => $dateServ,
  7145.                             'qty' => $unitsServ,
  7146.                             'iva' => $item->getIva(),
  7147.                             'pax' => $item->getPax(),
  7148.                             'precioUnit' => $subnetoUnit,
  7149.                             'subneto' => $subneto,
  7150.                             'subtotal' => $subtotal,
  7151.                         );
  7152.                         break;
  7153.                     case 8//Guide
  7154.                         $pax $item->getPax();
  7155.                         if (empty($pax) or $pax == "0") {
  7156.                             $pax 1;
  7157.                         }
  7158.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7159.                         if ($days 1) {
  7160.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7161.                         } else {
  7162.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7163.                         }
  7164.                         $unitsServ $item->getUnits();
  7165.                         if (empty($unitsServ) or $unitsServ == "0") {
  7166.                             $unitsServ 1;
  7167.                         }
  7168.                         $subtotal $subtotalService $days $unitsServ $pax;
  7169.                         $subnetoUnit $subneto;
  7170.                         $subneto $subneto $days $unitsServ $pax;
  7171.                         $data_supplier['service'][$i] = array(
  7172.                             'id' => $item->getId(),
  7173.                             'serviceCatId' => $item->getServiceCatId(),
  7174.                             'serviceName' => $item->getName(),
  7175.                             'serviceType' => 'Regalos',
  7176.                             'date' => $dateServ,
  7177.                             'qty' => $unitsServ,
  7178.                             'iva' => $item->getIva(),
  7179.                             'pax' => $item->getPax(),
  7180.                             'precioUnit' => $subnetoUnit,
  7181.                             'subneto' => $subneto,
  7182.                             'subtotal' => $subtotal,
  7183.                         );
  7184.                         break;
  7185.                     case 9//Itineraries
  7186.                         $pax $item->getPax();
  7187.                         if (empty($pax) or $pax == "0") {
  7188.                             $pax 1;
  7189.                         }
  7190.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7191.                         if ($days 1) {
  7192.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7193.                         } else {
  7194.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7195.                         }
  7196.                         $unitsServ $item->getUnits();
  7197.                         if (empty($unitsServ) or $unitsServ == "0") {
  7198.                             $unitsServ 1;
  7199.                         }
  7200.                         $subtotal $subtotalService $days $unitsServ $pax;
  7201.                         $subnetoUnit $subneto;
  7202.                         $subneto $subneto $days $unitsServ $pax;
  7203.                         $data_supplier['service'][$i] = array(
  7204.                             'id' => $item->getId(),
  7205.                             'serviceCatId' => $item->getServiceCatId(),
  7206.                             'serviceName' => $item->getName(),
  7207.                             'serviceType' => 'Itinerarios',
  7208.                             'date' => $dateServ,
  7209.                             'qty' => $unitsServ,
  7210.                             'iva' => $item->getIva(),
  7211.                             'pax' => $item->getPax(),
  7212.                             'precioUnit' => $subnetoUnit,
  7213.                             'subneto' => $subneto,
  7214.                             'subtotal' => $subtotal,
  7215.                         );
  7216.                         break;
  7217.                     case 10//Lounge  -- No Aplica
  7218.                         //                        $pax = $item->getPax();
  7219.                         //                        if (empty($pax) or $pax == "0") {
  7220.                         //                            $pax = 1;
  7221.                         //                        }
  7222.                         //
  7223.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  7224.                         //                        if ($days > 1){
  7225.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  7226.                         //                        } else {
  7227.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7228.                         //                        }
  7229.                         //
  7230.                         //                        $unitsServ = $item->getUnits();
  7231.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  7232.                         //                            $unitsServ = 1;
  7233.                         //                        }
  7234.                         //
  7235.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  7236.                         //                        $subnetoUnit = $subneto;
  7237.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  7238.                         //
  7239.                         //                        $data_supplier['service'][$i] = array (
  7240.                         //                            'id' => $item->getId(),
  7241.                         //                            'serviceCatId' => $item->getServiceCatId(),
  7242.                         //                            'serviceName' => $item->getName(),
  7243.                         //                            'serviceType' => 'Itinerarios',
  7244.                         //                            'date' => $dateServ,
  7245.                         //                            'qty' => $unitsServ,
  7246.                         //                            'iva' => $item->getIva(),
  7247.                         //                            'pax' => $item->getPax(),
  7248.                         //                            'precioUnit' => $subnetoUnit,
  7249.                         //                            'subneto' => $subneto,
  7250.                         //                            'subtotal' => $subtotal,
  7251.                         //                        );
  7252.                         break;
  7253.                     case 11//Menu
  7254.                         $pax $item->getPax();
  7255.                         if (empty($pax) or $pax == "0") {
  7256.                             $pax 1;
  7257.                         }
  7258.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7259.                         if ($days 1) {
  7260.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7261.                         } else {
  7262.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7263.                         }
  7264.                         $unitsServ $item->getUnits();
  7265.                         if (empty($unitsServ) or $unitsServ == "0") {
  7266.                             $unitsServ 1;
  7267.                         }
  7268.                         $subtotal $subtotalService $days $unitsServ $pax;
  7269.                         $subnetoUnit $subneto;
  7270.                         $subneto $subneto $days $unitsServ $pax;
  7271.                         $data_supplier['service'][$i] = array(
  7272.                             'id' => $item->getId(),
  7273.                             'serviceCatId' => $item->getServiceCatId(),
  7274.                             'serviceName' => $item->getName(),
  7275.                             'serviceType' => 'MenĂº',
  7276.                             'date' => $dateServ,
  7277.                             'qty' => $unitsServ,
  7278.                             'iva' => $item->getIva(),
  7279.                             'pax' => $item->getPax(),
  7280.                             'precioUnit' => $subnetoUnit,
  7281.                             'subneto' => $subneto,
  7282.                             'subtotal' => $subtotal,
  7283.                         );
  7284.                         break;
  7285.                     case 12//Others
  7286.                         $pax $item->getPax();
  7287.                         if (empty($pax) or $pax == "0") {
  7288.                             $pax 1;
  7289.                         }
  7290.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7291.                         if ($days 1) {
  7292.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7293.                         } else {
  7294.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7295.                         }
  7296.                         $unitsServ $item->getUnits();
  7297.                         if (empty($unitsServ) or $unitsServ == "0") {
  7298.                             $unitsServ 1;
  7299.                         }
  7300.                         $subtotal $subtotalService $days $unitsServ $pax;
  7301.                         $subnetoUnit $subneto;
  7302.                         $subneto $subneto $days $unitsServ $pax;
  7303.                         $data_supplier['service'][$i] = array(
  7304.                             'id' => $item->getId(),
  7305.                             'serviceCatId' => $item->getServiceCatId(),
  7306.                             'serviceName' => $item->getName(),
  7307.                             'serviceType' => 'Otros',
  7308.                             'date' => $dateServ,
  7309.                             'qty' => $unitsServ,
  7310.                             'iva' => $item->getIva(),
  7311.                             'pax' => $item->getPax(),
  7312.                             'precioUnit' => $subnetoUnit,
  7313.                             'subneto' => $subneto,
  7314.                             'subtotal' => $subtotal,
  7315.                         );
  7316.                         break;
  7317.                     case 13//Transport
  7318.                         $pax $item->getPax();
  7319.                         if (empty($pax) or $pax == "0") {
  7320.                             $pax 1;
  7321.                         }
  7322.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7323.                         if ($days 1) {
  7324.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7325.                         } else {
  7326.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7327.                         }
  7328.                         $unitsServ $item->getUnits();
  7329.                         if (empty($unitsServ) or $unitsServ == "0") {
  7330.                             $unitsServ 1;
  7331.                         }
  7332.                         $subtotal $subtotalService $days $unitsServ $pax;
  7333.                         $subnetoUnit $subneto;
  7334.                         $subneto $subneto $days $unitsServ $pax;
  7335.                         $data_supplier['service'][$i] = array(
  7336.                             'id' => $item->getId(),
  7337.                             'serviceCatId' => $item->getServiceCatId(),
  7338.                             'serviceName' => $item->getName(),
  7339.                             'serviceType' => 'Transporte',
  7340.                             'date' => $dateServ,
  7341.                             'qty' => $unitsServ,
  7342.                             'iva' => $item->getIva(),
  7343.                             'pax' => $item->getPax(),
  7344.                             'precioUnit' => $subnetoUnit,
  7345.                             'subneto' => $subneto,
  7346.                             'subtotal' => $subtotal,
  7347.                         );
  7348.                         break;
  7349.                     case 14//Technology
  7350.                         $pax $item->getPax();
  7351.                         if (empty($pax) or $pax == "0") {
  7352.                             $pax 1;
  7353.                         }
  7354.                         $days 1;
  7355.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7356.                         $unitsServ $item->getUnits();
  7357.                         if (empty($unitsServ) or $unitsServ == "0") {
  7358.                             $unitsServ 1;
  7359.                         }
  7360.                         $subtotal $subtotalService $days $unitsServ $pax;
  7361.                         $subnetoUnit $subneto;
  7362.                         $subneto $subneto $days $unitsServ $pax;
  7363.                         $data_supplier['service'][$i] = array(
  7364.                             'id' => $item->getId(),
  7365.                             'serviceCatId' => $item->getServiceCatId(),
  7366.                             'serviceName' => $item->getName(),
  7367.                             'serviceType' => 'TecnologĂ­a',
  7368.                             'date' => $dateServ,
  7369.                             'qty' => $unitsServ,
  7370.                             'iva' => $item->getIva(),
  7371.                             'pax' => $item->getPax(),
  7372.                             'precioUnit' => $subnetoUnit,
  7373.                             'subneto' => $subneto,
  7374.                             'subtotal' => $subtotal,
  7375.                         );
  7376.                         break;
  7377.                     case 15//Assisstant
  7378.                         $pax $item->getPax();
  7379.                         if (empty($pax) or $pax == "0") {
  7380.                             $pax 1;
  7381.                         }
  7382.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7383.                         if ($days 1) {
  7384.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7385.                         } else {
  7386.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7387.                         }
  7388.                         $unitsServ $item->getUnits();
  7389.                         if (empty($unitsServ) or $unitsServ == "0") {
  7390.                             $unitsServ 1;
  7391.                         }
  7392.                         $subtotal $subtotalService $days $unitsServ $pax;
  7393.                         $subnetoUnit $subneto;
  7394.                         $subneto $subneto $days $unitsServ $pax;
  7395.                         $data_supplier['service'][$i] = array(
  7396.                             'id' => $item->getId(),
  7397.                             'serviceCatId' => $item->getServiceCatId(),
  7398.                             'serviceName' => $item->getName(),
  7399.                             'serviceType' => 'Asistente',
  7400.                             'date' => $dateServ,
  7401.                             'qty' => $unitsServ,
  7402.                             'iva' => $item->getIva(),
  7403.                             'pax' => $item->getPax(),
  7404.                             'precioUnit' => $subnetoUnit,
  7405.                             'subneto' => $subneto,
  7406.                             'subtotal' => $subtotal,
  7407.                         );
  7408.                         break;
  7409.                     case 16//DDR
  7410.                         $pax $item->getPax();
  7411.                         if (empty($pax) or $pax == "0") {
  7412.                             $pax 1;
  7413.                         }
  7414.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7415.                         if ($days 1) {
  7416.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7417.                         } else {
  7418.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7419.                         }
  7420.                         $unitsServ $item->getUnits();
  7421.                         if (empty($unitsServ) or $unitsServ == "0") {
  7422.                             $unitsServ 1;
  7423.                         }
  7424.                         $subtotal $subtotalService $days $unitsServ $pax;
  7425.                         $subnetoUnit $subneto;
  7426.                         $subneto $subneto $days $unitsServ $pax;
  7427.                         $data_supplier['service'][$i] = array(
  7428.                             'id' => $item->getId(),
  7429.                             'serviceCatId' => $item->getServiceCatId(),
  7430.                             'serviceName' => $item->getName(),
  7431.                             'serviceType' => 'DDR',
  7432.                             'date' => $dateServ,
  7433.                             'qty' => $unitsServ,
  7434.                             'iva' => $item->getIva(),
  7435.                             'pax' => $item->getPax(),
  7436.                             'precioUnit' => $subnetoUnit,
  7437.                             'subneto' => $subneto,
  7438.                             'subtotal' => $subtotal,
  7439.                         );
  7440.                         break;
  7441.                     default:
  7442.                         break;
  7443.                 }
  7444.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7445.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  7446.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  7447.             }
  7448.             switch ($item->getIva()) {
  7449.                     // Acumula IVA
  7450.                 case 21:
  7451.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  7452.                     break;
  7453.                 case 10:
  7454.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  7455.                     break;
  7456.                 case 0:
  7457.                     break;
  7458.                 default:
  7459.                     break;
  7460.             }
  7461.             $totales_neto_all $totales_neto_all $neto;
  7462.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7463.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  7464.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  7465.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  7466.             // Acumula netos totales e IVA
  7467.             $service['neto'] = $service['neto'] + $neto;
  7468.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  7469.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7470.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  7471.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  7472.             $i++;
  7473.         }
  7474.         $data_supplier['serviceSubTotal'] = array(
  7475.             'neto' => $service['neto'],
  7476.             'sumSubT' => $service['sumSubT'],
  7477.         );
  7478.         $currency '€';
  7479.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  7480.         if (!empty($payments)) {
  7481.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  7482.         } else {
  7483.             $amount_pay 0;
  7484.         }
  7485.         $totales_all $totales_total $amount_pay;
  7486.         $data = array(
  7487.             'id' => $id,
  7488.             'type' => $type,
  7489.             'number' => $number,
  7490.             'prefix' => $prefix,
  7491.             'date' => $date,
  7492.             'file' => $file,
  7493.             'token' => ''// $file->getAccessKey(),
  7494.             'company' => $company,
  7495.             'clients' => $clientNew,
  7496.             'datasupplier' => $data_supplier,
  7497.             'currency' => $currency,
  7498.             'totales_neto' => $totales_neto_all,
  7499.             'bases_imponibles' => $data_iva,
  7500.             'totales' => $totales_total,
  7501.             'balance' => $totales_all,
  7502.             'paymentInvoice' => $amount_pay,
  7503.         );
  7504.         return $data;
  7505.     }
  7506.     private function baseInvoiceSelectedFile($id$arrayBools$number)
  7507.     {
  7508.         $em $this->getDoctrine()->getManager();
  7509.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  7510.         $items $em->getRepository(AveDocProformaItems::class)->findByFileId($file->getId());
  7511.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  7512.         $client $em->getRepository(Client::class)->findById($file->getClient());
  7513.         if (empty($client)) {
  7514.             $client[0] = new Client();
  7515.             $client[0]->setName('');
  7516.             $client[0]->setTitle('');
  7517.             $client[0]->setIdDocument('');
  7518.             $client[0]->setPopulation('');
  7519.             $client[0]->setRegion('');
  7520.             $client[0]->setCountry('');
  7521.         } else {
  7522.             if (is_numeric($client[0]->getPopulation())) {
  7523.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  7524. //                $client[0]->setPopulation($city->getCity());
  7525.             }
  7526.             if (is_numeric($client[0]->getRegion())) {
  7527.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  7528. //                $client[0]->setRegion($region->getRegion());
  7529.             }
  7530.             if (is_numeric($client[0]->getCountry())) {
  7531.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  7532. //                $client[0]->setCountry($country->getCountry());
  7533.             }
  7534.         }
  7535.         if (empty($client)) {
  7536.             $client[0] = new Client();
  7537.             $client[0]->setName('');
  7538.             $client[0]->setTitle('');
  7539.             $client[0]->setIdDocument('');
  7540.             $client[0]->setPopulation('');
  7541.             $client[0]->setRegion('');
  7542.             $client[0]->setCountry('');
  7543.             $clientNew = array(
  7544.                 'name' => '',
  7545.                 'title' => '',
  7546.                 'idDocument' => '',
  7547.                 'population' => '',
  7548.                 'region' => '',
  7549.                 'country' => '',
  7550.                 'address' => '',
  7551.                 'addressNumber' => '',
  7552.                 'zipCode' => '',
  7553.                 'typeDocument' => '',
  7554.             );
  7555.         } else {
  7556.             $clientNew = array(
  7557.                 'name' => $client[0]->getName(),
  7558.                 'title' => $client[0]->getTitle(),
  7559.                 'idDocument' => $client[0]->getIdDocument(),
  7560.                 'population' => '',
  7561.                 'region' => '',
  7562.                 'country' => '',
  7563.                 'address' => $client[0]->getAddress(),
  7564.                 'addressNumber' => $client[0]->getAddressNumber(),
  7565.                 'zipCode' => $client[0]->getZipCode(),
  7566.                 'typeDocument' => $client[0]->getTypeDocument(),
  7567.             );
  7568.             if (is_numeric($client[0]->getPopulation())) {
  7569.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  7570.                 $clientNew['population'] = $city->getCity();
  7571.             }
  7572.             if (is_numeric($client[0]->getRegion())) {
  7573.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  7574.                 $clientNew['region'] = $region->getRegion();
  7575.             }
  7576.             if (is_numeric($client[0]->getCountry())) {
  7577.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  7578.                 $clientNew['country'] = $country->getCountry();
  7579.             }
  7580.         }
  7581.         // Acumuladores de los calculos
  7582.         $totales_neto_all 0;
  7583.         $data_iva = array(
  7584.             'iva' => 21,
  7585.             'ivaMontoVeintiUno' => 0,
  7586.             'ivaMontoDiez' => 0,
  7587.             'ivaMontoCero' => null,                                     // Si toma el valor de cero, indica que hay un iva en 0 y se pone en la factura de resto no
  7588.         );
  7589.         //INICIO: Determinamos el numero de factura o proforma
  7590.         if (substr($number01) == 'I') {
  7591.             // Es una Factura
  7592.             $numberInvoiceOrProforma substr($number1);
  7593.             $number $numberInvoiceOrProforma;
  7594.             $number $em->getRepository(AveDocInvoice::class)->findOneById($number);
  7595.             $number $number->getNumber();
  7596.             $type 'Invoice';
  7597.         } else {
  7598.             // Es una Proforma
  7599.             $numberInvoiceOrProforma substr($number1);
  7600.             $number $numberInvoiceOrProforma;
  7601.             $number $em->getRepository(AveDocProforma::class)->findOneById($number);
  7602.             $number $number->getPrefix() . $number->getFileId();
  7603.             $type 'Proforma';
  7604.         }
  7605.         //FIN: Determinamos el numero de factura o proforma
  7606.         // Buscamos las salas reservadas, pagos y servicios para el evento
  7607.         $arrayItems = array();
  7608.         $fileProducts = array();
  7609.         if (!empty($arrayBools['product'])) {
  7610.             foreach ($arrayBools['product'] as $key => $item) {
  7611.                 if ($item == 'true') {
  7612.                     $fileProducts[] = $em->getRepository(AveProductFile::class)->findOneById($key);
  7613.                     ///***---
  7614.                 }
  7615.             }
  7616.         }
  7617.         $payments = array();
  7618.         if (!empty($arrayBools['payment'])) {
  7619.             foreach ($arrayBools['payment'] as $key => $item) {
  7620.                 if ($item == 'true') {
  7621.                     $payments[] = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  7622.                 }
  7623.             }
  7624.         }
  7625.         $services = array();
  7626.         if (!empty($arrayBools['service'])) {
  7627.             foreach ($arrayBools['service'] as $key => $item) {
  7628.                 if ($item == 'true') {
  7629.                     $services[] = $em->getRepository(AveServices::class)->findOneById($key);
  7630.                 }
  7631.             }
  7632.         }
  7633.         $data_supplier = array();
  7634.         $i 0;
  7635.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  7636.         $pax '1';
  7637.         $qty '1';
  7638.         $product = array(
  7639.             'neto' => 0,
  7640.             'sumSubT' => 0,
  7641.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7642.         $service = array(
  7643.             'neto' => 0,
  7644.             'sumSubT' => 0,
  7645.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7646.         foreach ($fileProducts as $item) {
  7647.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  7648.                 $subtotal 0;
  7649.                 $neto 0;
  7650.                 $subtotalProduct 0;
  7651.             } else {
  7652.                 //                $subtotalProduct = $item->getServicePrice() * 1.21;
  7653.                 $subtotalProduct $item->getSubTotalPrice() * (+ ($item->getIva() / 100));
  7654.                 //                $subneto = $item->getServicePrice();
  7655.                 $subneto $item->getSubTotalPrice();
  7656.                 $subtotal =  $subtotalProduct;
  7657.                 $neto =  $subneto;
  7658.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7659.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  7660.                 $neto round($neto2PHP_ROUND_HALF_UP);
  7661.                 $arrayItems[] = array(
  7662.                     'type' => 'Product',
  7663.                     'name' => $item->getProductName(),
  7664.                     'amount' => $neto,
  7665.                     'iva' => $item->getIva(),
  7666.                     'total' => $subtotal,
  7667.                 );
  7668.             }
  7669.             // Acumula netos totales e IVA
  7670.             $totales_neto_all $totales_neto_all $neto;
  7671.             switch ($item->getIva()) {
  7672.                 case 21:
  7673.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  7674.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  7675.                     break;
  7676.                 case 10:
  7677.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  7678.                     $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  7679.                     break;
  7680.                 case 0:
  7681.                     $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  7682.                     $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  7683.                     break;
  7684.                 default:
  7685.                     $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  7686.                     $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  7687.                     break;
  7688.             }
  7689.             //            $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
  7690.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7691.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  7692.             // Acumula netos totales e IVA
  7693.             $product['neto'] = $product['neto'] + $neto;
  7694.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  7695.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7696.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  7697.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  7698.             // Calculo del precio unitario despues de aplicar Over y Comision
  7699.             $multiplo $qty $item->getDays();
  7700.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  7701.             $data_supplier['product'][$i] = array(
  7702.                 'id' => $item->getId(),
  7703.                 'productName' => $item->getProductName(),
  7704.                 'productId' => $item->getProductId(),
  7705.                 'dateStart' => $item->getDateStart(),
  7706.                 'dateEnd' => $item->getDateEnd(),
  7707.                 'servicePrice' => $item->getServicePrice(),
  7708.                 'subtotalProduct' => $subtotalProduct,
  7709.                 'iva' => $item->getIva(),
  7710.                 'pax' => $pax,
  7711.                 'qty' => $qty,
  7712.                 'type' => $item->getType(),
  7713.                 'subtotal' => $subtotal,
  7714.             );
  7715.             $i++;
  7716.         }
  7717.         $data_supplier['productSubTotal'] = array(
  7718.             'neto' => $product['neto'],
  7719.             'sumSubT' => $product['sumSubT'],
  7720.         );
  7721.         $payment = array(
  7722.             'sumSubT' => 0,
  7723.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7724.         $i 0;
  7725.         foreach ($payments as $item) {
  7726.             $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  7727.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7728.             $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  7729.             $data_supplier['payment'][$i] = array(
  7730.                 'id' => $item->getId(),
  7731.                 'amount' => $item->getAmount(),
  7732.                 'amountTotal' => $item->getAmountTotal(),
  7733.                 'vat' => $item->getVat(),
  7734.                 'datePayAt' => $item->getDatePayAt(),
  7735.                 'wayToPay' => $item->getWayToPay(),
  7736.             );
  7737.             $arrayItems[] = array(
  7738.                 'type' => 'Payment',
  7739.                 'name' => $item->getWayToPay(),
  7740.                 'amount' => $item->getAmount(),
  7741.                 'total' => $item->getAmountTotal(),
  7742.                 'iva' => $item->getVat(),
  7743.             );
  7744.             $i++;
  7745.         }
  7746.         if (!empty($payments)) {
  7747.             $data_supplier['paymentSubTotal'] = array(
  7748.                 'sumSubT' => $payment['sumSubT'],
  7749.             );
  7750.         }
  7751.         foreach ($services as $item) {
  7752.             if (is_null($item->getPrice()) or empty($item->getPrice())) {
  7753.                 $subtotal 0;
  7754.                 $neto 0;
  7755.                 $subtotalService 0;
  7756.             } else {
  7757.                 $subtotalService $item->getPrice();
  7758.                 $subneto $item->getPrice();
  7759.                 // Commission
  7760.                 if ($item->getOpCommission() == '1') {
  7761.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  7762.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  7763.                 } else {
  7764.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  7765.                     $subneto $subneto * (- ($item->getCommission() / 100));
  7766.                 }
  7767.                 // Over
  7768.                 if ($item->getOpOver() == '1') {
  7769.                     $subtotalService $subtotalService $item->getOver();
  7770.                     $subneto $subneto $item->getOver();
  7771.                 } else {
  7772.                     $subtotalService $subtotalService $item->getOver();
  7773.                     $subneto $subneto $item->getOver();
  7774.                 }
  7775.                 // IVA
  7776.                 if ($item->getOpIva() == '1') {
  7777.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  7778.                 } else {
  7779.                     $subtotalService $item->getPrice();
  7780.                     $subneto = ($subneto 100) / (100 $item->getIva());
  7781.                 }
  7782.                 switch ($item->getServiceCatId()) {
  7783.                     case 1// Alojamiento
  7784.                         // el numero de noches $numNoches; precio unitario $subneto
  7785.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  7786.                         // La personas no afectan este calculo
  7787.                         $subtotal $subtotalService $numNoches $item->getUnits();
  7788.                         $subnetoUnit $subneto;
  7789.                         $subneto $subneto $numNoches $item->getUnits();
  7790.                         $data_supplier['service'][$i] = array(
  7791.                             'id' => $item->getId(),
  7792.                             'serviceCatId' => $item->getServiceCatId(),
  7793.                             'serviceName' => $item->getName(),
  7794.                             'serviceType' => 'Hotel',
  7795.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  7796.                             'qty' => $item->getUnits(),
  7797.                             'iva' => $item->getIva(),
  7798.                             'pax' => '-',
  7799.                             'precioUnit' => $subnetoUnit,
  7800.                             'subneto' => $subneto,
  7801.                             'subtotal' => $subtotal,
  7802.                         );
  7803.                         break;
  7804.                     case 2//Actividades
  7805.                         // El nĂºmero de personas es considerado en el calculo
  7806.                         $pax $item->getPax();
  7807.                         if (empty($pax) or $pax == "0") {
  7808.                             $pax 1;
  7809.                         }
  7810.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7811.                         if ($days 1) {
  7812.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7813.                         } else {
  7814.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7815.                         }
  7816.                         $subtotal $subtotalService $days $item->getUnits();
  7817.                         $subnetoUnit $subneto;
  7818.                         $subneto $subneto $days $item->getUnits();
  7819.                         $data_supplier['service'][$i] = array(
  7820.                             'id' => $item->getId(),
  7821.                             'serviceCatId' => $item->getServiceCatId(),
  7822.                             'serviceName' => $item->getName(),
  7823.                             'serviceType' => 'Actividad',
  7824.                             'date' => $dateServ,
  7825.                             'qty' => $item->getUnits(),
  7826.                             'iva' => $item->getIva(),
  7827.                             'pax' => $item->getPax(),
  7828.                             'precioUnit' => $subnetoUnit,
  7829.                             'subneto' => $subneto,
  7830.                             'subtotal' => $subtotal,
  7831.                         );
  7832.                         break;
  7833.                     case 3// AV
  7834.                         $pax $item->getPax();
  7835.                         if (empty($pax) or $pax == "0") {
  7836.                             $pax 1;
  7837.                         }
  7838.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7839.                         if ($days 1) {
  7840.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7841.                         } else {
  7842.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7843.                         }
  7844.                         $unitsServ $item->getUnits();
  7845.                         if (empty($unitsServ) or $unitsServ == "0") {
  7846.                             $unitsServ 1;
  7847.                         }
  7848.                         $subtotal $subtotalService $days $unitsServ $pax;
  7849.                         $subnetoUnit $subneto;
  7850.                         $subneto $subneto $days $unitsServ $pax;
  7851.                         $data_supplier['service'][$i] = array(
  7852.                             'id' => $item->getId(),
  7853.                             'serviceCatId' => $item->getServiceCatId(),
  7854.                             'serviceName' => $item->getName(),
  7855.                             'serviceType' => 'AV',
  7856.                             'date' => $dateServ,
  7857.                             'qty' => $unitsServ,
  7858.                             'iva' => $item->getIva(),
  7859.                             'pax' => $item->getPax(),
  7860.                             'precioUnit' => $subnetoUnit,
  7861.                             'subneto' => $subneto,
  7862.                             'subtotal' => $subtotal,
  7863.                         );
  7864.                         break;
  7865.                     case 4//Creative
  7866.                         $pax $item->getPax();
  7867.                         if (empty($pax) or $pax == "0") {
  7868.                             $pax 1;
  7869.                         }
  7870.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7871.                         if ($days 1) {
  7872.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7873.                         } else {
  7874.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7875.                         }
  7876.                         $unitsServ $item->getUnits();
  7877.                         if (empty($unitsServ) or $unitsServ == "0") {
  7878.                             $unitsServ 1;
  7879.                         }
  7880.                         $subtotal $subtotalService $days $unitsServ $pax;
  7881.                         $subnetoUnit $subneto;
  7882.                         $subneto $subneto $days $unitsServ $pax;
  7883.                         $data_supplier['service'][$i] = array(
  7884.                             'id' => $item->getId(),
  7885.                             'serviceCatId' => $item->getServiceCatId(),
  7886.                             'serviceName' => $item->getName(),
  7887.                             'serviceType' => 'Creativo',
  7888.                             'date' => $dateServ,
  7889.                             'qty' => $unitsServ,
  7890.                             'iva' => $item->getIva(),
  7891.                             'pax' => $item->getPax(),
  7892.                             'precioUnit' => $subnetoUnit,
  7893.                             'subneto' => $subneto,
  7894.                             'subtotal' => $subtotal,
  7895.                         );
  7896.                         break;
  7897.                     case 5//Cruise
  7898.                         $pax $item->getPax();
  7899.                         if (empty($pax) or $pax == "0") {
  7900.                             $pax 1;
  7901.                         }
  7902.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  7903.                         if ($days 1) {
  7904.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7905.                         } else {
  7906.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7907.                         }
  7908.                         $unitsServ $item->getUnits();
  7909.                         if (empty($unitsServ) or $unitsServ == "0") {
  7910.                             $unitsServ 1;
  7911.                         }
  7912.                         $subtotal $subtotalService $days $unitsServ $pax;
  7913.                         $subnetoUnit $subneto;
  7914.                         $subneto $subneto $days $unitsServ $pax;
  7915.                         $data_supplier['service'][$i] = array(
  7916.                             'id' => $item->getId(),
  7917.                             'serviceCatId' => $item->getServiceCatId(),
  7918.                             'serviceName' => $item->getName(),
  7919.                             'serviceType' => 'Crucero',
  7920.                             'date' => $dateServ,
  7921.                             'qty' => $unitsServ,
  7922.                             'iva' => $item->getIva(),
  7923.                             'pax' => $item->getPax(),
  7924.                             'precioUnit' => $subnetoUnit,
  7925.                             'subneto' => $subneto,
  7926.                             'subtotal' => $subtotal,
  7927.                         );
  7928.                         break;
  7929.                     case 6//Entertaiment
  7930.                         $pax $item->getPax();
  7931.                         if (empty($pax) or $pax == "0") {
  7932.                             $pax 1;
  7933.                         }
  7934.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7935.                         if ($days 1) {
  7936.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7937.                         } else {
  7938.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7939.                         }
  7940.                         $unitsServ $item->getUnits();
  7941.                         if (empty($unitsServ) or $unitsServ == "0") {
  7942.                             $unitsServ 1;
  7943.                         }
  7944.                         $subtotal $subtotalService $days $unitsServ $pax;
  7945.                         $subnetoUnit $subneto;
  7946.                         $subneto $subneto $days $unitsServ $pax;
  7947.                         $data_supplier['service'][$i] = array(
  7948.                             'id' => $item->getId(),
  7949.                             'serviceCatId' => $item->getServiceCatId(),
  7950.                             'serviceName' => $item->getName(),
  7951.                             'serviceType' => 'Entretenimiento',
  7952.                             'date' => $dateServ,
  7953.                             'qty' => $unitsServ,
  7954.                             'iva' => $item->getIva(),
  7955.                             'pax' => $item->getPax(),
  7956.                             'precioUnit' => $subnetoUnit,
  7957.                             'subneto' => $subneto,
  7958.                             'subtotal' => $subtotal,
  7959.                         );
  7960.                         break;
  7961.                     case 7// Gifts
  7962.                         $pax $item->getPax();
  7963.                         if (empty($pax) or $pax == "0") {
  7964.                             $pax 1;
  7965.                         }
  7966.                         $days 1;
  7967.                         if ($days 1) {
  7968.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7969.                         } else {
  7970.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7971.                         }
  7972.                         $unitsServ $item->getUnits();
  7973.                         if (empty($unitsServ) or $unitsServ == "0") {
  7974.                             $unitsServ 1;
  7975.                         }
  7976.                         $subtotal $subtotalService $days $unitsServ $pax;
  7977.                         $subnetoUnit $subneto;
  7978.                         $subneto $subneto $days $unitsServ $pax;
  7979.                         $data_supplier['service'][$i] = array(
  7980.                             'id' => $item->getId(),
  7981.                             'serviceCatId' => $item->getServiceCatId(),
  7982.                             'serviceName' => $item->getName(),
  7983.                             'serviceType' => 'Regalos',
  7984.                             'date' => $dateServ,
  7985.                             'qty' => $unitsServ,
  7986.                             'iva' => $item->getIva(),
  7987.                             'pax' => $item->getPax(),
  7988.                             'precioUnit' => $subnetoUnit,
  7989.                             'subneto' => $subneto,
  7990.                             'subtotal' => $subtotal,
  7991.                         );
  7992.                         break;
  7993.                     case 8//Guide
  7994.                         $pax $item->getPax();
  7995.                         if (empty($pax) or $pax == "0") {
  7996.                             $pax 1;
  7997.                         }
  7998.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7999.                         if ($days 1) {
  8000.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8001.                         } else {
  8002.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8003.                         }
  8004.                         $unitsServ $item->getUnits();
  8005.                         if (empty($unitsServ) or $unitsServ == "0") {
  8006.                             $unitsServ 1;
  8007.                         }
  8008.                         $subtotal $subtotalService $days $unitsServ $pax;
  8009.                         $subnetoUnit $subneto;
  8010.                         $subneto $subneto $days $unitsServ $pax;
  8011.                         $data_supplier['service'][$i] = array(
  8012.                             'id' => $item->getId(),
  8013.                             'serviceCatId' => $item->getServiceCatId(),
  8014.                             'serviceName' => $item->getName(),
  8015.                             'serviceType' => 'Regalos',
  8016.                             'date' => $dateServ,
  8017.                             'qty' => $unitsServ,
  8018.                             'iva' => $item->getIva(),
  8019.                             'pax' => $item->getPax(),
  8020.                             'precioUnit' => $subnetoUnit,
  8021.                             'subneto' => $subneto,
  8022.                             'subtotal' => $subtotal,
  8023.                         );
  8024.                         break;
  8025.                     case 9//Itineraries
  8026.                         $pax $item->getPax();
  8027.                         if (empty($pax) or $pax == "0") {
  8028.                             $pax 1;
  8029.                         }
  8030.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8031.                         if ($days 1) {
  8032.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8033.                         } else {
  8034.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8035.                         }
  8036.                         $unitsServ $item->getUnits();
  8037.                         if (empty($unitsServ) or $unitsServ == "0") {
  8038.                             $unitsServ 1;
  8039.                         }
  8040.                         $subtotal $subtotalService $days $unitsServ $pax;
  8041.                         $subnetoUnit $subneto;
  8042.                         $subneto $subneto $days $unitsServ $pax;
  8043.                         $data_supplier['service'][$i] = array(
  8044.                             'id' => $item->getId(),
  8045.                             'serviceCatId' => $item->getServiceCatId(),
  8046.                             'serviceName' => $item->getName(),
  8047.                             'serviceType' => 'Itinerarios',
  8048.                             'date' => $dateServ,
  8049.                             'qty' => $unitsServ,
  8050.                             'iva' => $item->getIva(),
  8051.                             'pax' => $item->getPax(),
  8052.                             'precioUnit' => $subnetoUnit,
  8053.                             'subneto' => $subneto,
  8054.                             'subtotal' => $subtotal,
  8055.                         );
  8056.                         break;
  8057.                     case 10//Lounge  -- No Aplica
  8058.                         //                        $pax = $item->getPax();
  8059.                         //                        if (empty($pax) or $pax == "0") {
  8060.                         //                            $pax = 1;
  8061.                         //                        }
  8062.                         //
  8063.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  8064.                         //                        if ($days > 1){
  8065.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  8066.                         //                        } else {
  8067.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8068.                         //                        }
  8069.                         //
  8070.                         //                        $unitsServ = $item->getUnits();
  8071.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  8072.                         //                            $unitsServ = 1;
  8073.                         //                        }
  8074.                         //
  8075.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  8076.                         //                        $subnetoUnit = $subneto;
  8077.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  8078.                         //
  8079.                         //                        $data_supplier['service'][$i] = array (
  8080.                         //                            'id' => $item->getId(),
  8081.                         //                            'serviceCatId' => $item->getServiceCatId(),
  8082.                         //                            'serviceName' => $item->getName(),
  8083.                         //                            'serviceType' => 'Itinerarios',
  8084.                         //                            'date' => $dateServ,
  8085.                         //                            'qty' => $unitsServ,
  8086.                         //                            'iva' => $item->getIva(),
  8087.                         //                            'pax' => $item->getPax(),
  8088.                         //                            'precioUnit' => $subnetoUnit,
  8089.                         //                            'subneto' => $subneto,
  8090.                         //                            'subtotal' => $subtotal,
  8091.                         //                        );
  8092.                         break;
  8093.                     case 11//Menu
  8094.                         $pax $item->getPax();
  8095.                         if (empty($pax) or $pax == "0") {
  8096.                             $pax 1;
  8097.                         }
  8098.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8099.                         if ($days 1) {
  8100.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8101.                         } else {
  8102.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8103.                         }
  8104.                         $unitsServ $item->getUnits();
  8105.                         if (empty($unitsServ) or $unitsServ == "0") {
  8106.                             $unitsServ 1;
  8107.                         }
  8108.                         $subtotal $subtotalService $days $unitsServ $pax;
  8109.                         $subnetoUnit $subneto;
  8110.                         $subneto $subneto $days $unitsServ $pax;
  8111.                         $data_supplier['service'][$i] = array(
  8112.                             'id' => $item->getId(),
  8113.                             'serviceCatId' => $item->getServiceCatId(),
  8114.                             'serviceName' => $item->getName(),
  8115.                             'serviceType' => 'MenĂº',
  8116.                             'date' => $dateServ,
  8117.                             'qty' => $unitsServ,
  8118.                             'iva' => $item->getIva(),
  8119.                             'pax' => $item->getPax(),
  8120.                             'precioUnit' => $subnetoUnit,
  8121.                             'subneto' => $subneto,
  8122.                             'subtotal' => $subtotal,
  8123.                         );
  8124.                         break;
  8125.                     case 12//Others
  8126.                         $pax $item->getPax();
  8127.                         if (empty($pax) or $pax == "0") {
  8128.                             $pax 1;
  8129.                         }
  8130.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8131.                         if ($days 1) {
  8132.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8133.                         } else {
  8134.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8135.                         }
  8136.                         $unitsServ $item->getUnits();
  8137.                         if (empty($unitsServ) or $unitsServ == "0") {
  8138.                             $unitsServ 1;
  8139.                         }
  8140.                         $subtotal $subtotalService $days $unitsServ $pax;
  8141.                         $subnetoUnit $subneto;
  8142.                         $subneto $subneto $days $unitsServ $pax;
  8143.                         $data_supplier['service'][$i] = array(
  8144.                             'id' => $item->getId(),
  8145.                             'serviceCatId' => $item->getServiceCatId(),
  8146.                             'serviceName' => $item->getName(),
  8147.                             'serviceType' => 'Otros',
  8148.                             'date' => $dateServ,
  8149.                             'qty' => $unitsServ,
  8150.                             'iva' => $item->getIva(),
  8151.                             'pax' => $item->getPax(),
  8152.                             'precioUnit' => $subnetoUnit,
  8153.                             'subneto' => $subneto,
  8154.                             'subtotal' => $subtotal,
  8155.                         );
  8156.                         break;
  8157.                     case 13//Transport
  8158.                         $pax $item->getPax();
  8159.                         if (empty($pax) or $pax == "0") {
  8160.                             $pax 1;
  8161.                         }
  8162.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8163.                         if ($days 1) {
  8164.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8165.                         } else {
  8166.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8167.                         }
  8168.                         $unitsServ $item->getUnits();
  8169.                         if (empty($unitsServ) or $unitsServ == "0") {
  8170.                             $unitsServ 1;
  8171.                         }
  8172.                         $subtotal $subtotalService $days $unitsServ $pax;
  8173.                         $subnetoUnit $subneto;
  8174.                         $subneto $subneto $days $unitsServ $pax;
  8175.                         $data_supplier['service'][$i] = array(
  8176.                             'id' => $item->getId(),
  8177.                             'serviceCatId' => $item->getServiceCatId(),
  8178.                             'serviceName' => $item->getName(),
  8179.                             'serviceType' => 'Transporte',
  8180.                             'date' => $dateServ,
  8181.                             'qty' => $unitsServ,
  8182.                             'iva' => $item->getIva(),
  8183.                             'pax' => $item->getPax(),
  8184.                             'precioUnit' => $subnetoUnit,
  8185.                             'subneto' => $subneto,
  8186.                             'subtotal' => $subtotal,
  8187.                         );
  8188.                         break;
  8189.                     case 14//Technology
  8190.                         $pax $item->getPax();
  8191.                         if (empty($pax) or $pax == "0") {
  8192.                             $pax 1;
  8193.                         }
  8194.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  8195.                         $days 1;
  8196.                         //                        if ($days > 1){
  8197.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  8198.                         //                        } else {
  8199.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8200.                         //                        }
  8201.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8202.                         $unitsServ $item->getUnits();
  8203.                         if (empty($unitsServ) or $unitsServ == "0") {
  8204.                             $unitsServ 1;
  8205.                         }
  8206.                         $subtotal $subtotalService $days $unitsServ $pax;
  8207.                         $subnetoUnit $subneto;
  8208.                         $subneto $subneto $days $unitsServ $pax;
  8209.                         $data_supplier['service'][$i] = array(
  8210.                             'id' => $item->getId(),
  8211.                             'serviceCatId' => $item->getServiceCatId(),
  8212.                             'serviceName' => $item->getName(),
  8213.                             'serviceType' => 'TecnologĂ­a',
  8214.                             'date' => $dateServ,
  8215.                             'qty' => $unitsServ,
  8216.                             'iva' => $item->getIva(),
  8217.                             'pax' => $item->getPax(),
  8218.                             'precioUnit' => $subnetoUnit,
  8219.                             'subneto' => $subneto,
  8220.                             'subtotal' => $subtotal,
  8221.                         );
  8222.                         break;
  8223.                     case 15//Assisstant
  8224.                         $pax $item->getPax();
  8225.                         if (empty($pax) or $pax == "0") {
  8226.                             $pax 1;
  8227.                         }
  8228.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8229.                         if ($days 1) {
  8230.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8231.                         } else {
  8232.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8233.                         }
  8234.                         $unitsServ $item->getUnits();
  8235.                         if (empty($unitsServ) or $unitsServ == "0") {
  8236.                             $unitsServ 1;
  8237.                         }
  8238.                         $subtotal $subtotalService $days $unitsServ $pax;
  8239.                         $subnetoUnit $subneto;
  8240.                         $subneto $subneto $days $unitsServ $pax;
  8241.                         $data_supplier['service'][$i] = array(
  8242.                             'id' => $item->getId(),
  8243.                             'serviceCatId' => $item->getServiceCatId(),
  8244.                             'serviceName' => $item->getName(),
  8245.                             'serviceType' => 'Asistente',
  8246.                             'date' => $dateServ,
  8247.                             'qty' => $unitsServ,
  8248.                             'iva' => $item->getIva(),
  8249.                             'pax' => $item->getPax(),
  8250.                             'precioUnit' => $subnetoUnit,
  8251.                             'subneto' => $subneto,
  8252.                             'subtotal' => $subtotal,
  8253.                         );
  8254.                         break;
  8255.                     case 16//DDR
  8256.                         $pax $item->getPax();
  8257.                         if (empty($pax) or $pax == "0") {
  8258.                             $pax 1;
  8259.                         }
  8260.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8261.                         if ($days 1) {
  8262.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8263.                         } else {
  8264.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8265.                         }
  8266.                         $unitsServ $item->getUnits();
  8267.                         if (empty($unitsServ) or $unitsServ == "0") {
  8268.                             $unitsServ 1;
  8269.                         }
  8270.                         $subtotal $subtotalService $days $unitsServ $pax;
  8271.                         $subnetoUnit $subneto;
  8272.                         $subneto $subneto $days $unitsServ $pax;
  8273.                         $data_supplier['service'][$i] = array(
  8274.                             'id' => $item->getId(),
  8275.                             'serviceCatId' => $item->getServiceCatId(),
  8276.                             'serviceName' => $item->getName(),
  8277.                             'serviceType' => 'DDR',
  8278.                             'date' => $dateServ,
  8279.                             'qty' => $unitsServ,
  8280.                             'iva' => $item->getIva(),
  8281.                             'pax' => $item->getPax(),
  8282.                             'precioUnit' => $subnetoUnit,
  8283.                             'subneto' => $subneto,
  8284.                             'subtotal' => $subtotal,
  8285.                         );
  8286.                         break;
  8287.                     default:
  8288.                         break;
  8289.                 }
  8290.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8291.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8292.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  8293.                 $arrayItems[] = array(
  8294.                     'type' => 'Service',
  8295.                     'name' => $item->getName(),
  8296.                     'amount' => $neto,
  8297.                     'iva' => $item->getIva(),
  8298.                     'total' => $subtotal,
  8299.                 );
  8300.             }
  8301.             switch ($item->getIva()) {
  8302.                     // Acumula IVA
  8303.                 case 21:
  8304.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  8305.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  8306.                     break;
  8307.                 case 10:
  8308.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  8309.                     $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  8310.                     break;
  8311.                 case 0:
  8312.                     $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto * ($item->getIva() / 100));
  8313.                     break;
  8314.                 default:
  8315.                     $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  8316.                     $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  8317.                     break;
  8318.             }
  8319.             $totales_neto_all $totales_neto_all $neto;
  8320.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8321.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  8322.             // Acumula netos totales e IVA
  8323.             $service['neto'] = $service['neto'] + $neto;
  8324.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  8325.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8326.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  8327.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  8328.             $i++;
  8329.         }
  8330.         $data_supplier['serviceSubTotal'] = array(
  8331.             'neto' => $service['neto'],
  8332.             'sumSubT' => $service['sumSubT'],
  8333.         );
  8334.         $currency '€';
  8335.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  8336.         if (!empty($payments)) {
  8337.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  8338.         } else {
  8339.             $amount_pay 0;
  8340.         }
  8341.         $totales_all $totales_total $amount_pay;
  8342.         if ($type == 'Invoice') {
  8343.             $em->clear();   // sin este clear se producia error al guardar
  8344.             $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($numberInvoiceOrProforma);
  8345.             $newInvoice->setBalance($totales_all);
  8346.             $em->persist($newInvoice);
  8347.             $em->flush();
  8348.         }
  8349.         $data = array(
  8350.             'id' => $id,
  8351.             'type' => $type,
  8352.             'number' => $number,
  8353.             'prefix' => $number,
  8354.             'date' => new DateTime('now'),
  8355.             'file' => $file,
  8356.             'company' => $company,
  8357.             'clients' => $clientNew,
  8358.             'arrayItems' => $arrayItems,
  8359.             'datasupplier' => $data_supplier,
  8360.             'currency' => $currency,
  8361.             'totales_neto' => $totales_neto_all,
  8362.             'bases_imponibles' => $data_iva,
  8363.             'totales' => $totales_total,
  8364.             'balance' => $totales_all,
  8365.             'paymentInvoice' => $amount_pay,
  8366.         );
  8367.         return $data;
  8368.     }
  8369.     private function baseInvoiceDoneDocument($fileId$invoiceId$typeBase)
  8370.     {
  8371.         $em $this->getDoctrine()->getManager();
  8372.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  8373.         $dateDocument null;                                                                           //Fecha final del documento
  8374.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  8375.             if ($typeBase == 'I') {
  8376.                 // Es una factura
  8377.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  8378.                 // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  8379.                 $allProductFile $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
  8380.                 $arrayLocation = array();
  8381.                 $arrayLocationWithNull false;
  8382.                 foreach ($allProductFile as $item) {
  8383.                     if (!empty($item->getLocation())) {
  8384.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  8385.                     } else {
  8386.                         $arrayLocationWithNull true;
  8387.                     }
  8388.                 }
  8389.                 if ($arrayLocationWithNull) {
  8390.                     $arrayLocation['null'] = 'null';
  8391.                 }
  8392.                 $arrayItemsSorted = array();
  8393.                 $productsInFile = array();
  8394.                 foreach ($arrayLocation as $item) {
  8395.                     // VIDEO
  8396.                     $parameters = array(
  8397.                         'fileId' => $fileId,
  8398.                         'proformaId' => $invoiceId,
  8399.                         'type' => 'VĂ­deo',
  8400.                         'location' => $item,
  8401.                     );
  8402.                     $dql 'SELECT i
  8403.                             FROM AvexpressBundle:AveProductFile i
  8404.                             INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8405.                             WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8406.                             ORDER BY i.rankAv ASC';
  8407.                     $query $em->createQuery($dql)->setParameters($parameters);
  8408.                     $productsInFileVid $query->getResult();
  8409.                     // SONIDO
  8410.                     $parameters = array(
  8411.                         'fileId' => $fileId,
  8412.                         'proformaId' => $invoiceId,
  8413.                         'type' => 'Sonido',
  8414.                         'location' => $item,
  8415.                     );
  8416.                     $dql 'SELECT i
  8417.                     FROM AvexpressBundle:AveProductFile i
  8418.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8419.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8420.                     ORDER BY i.rankAv ASC';
  8421.                     $query $em->createQuery($dql)->setParameters($parameters);
  8422.                     $productsInFileSound $query->getResult();
  8423.                     // ILUMINACION
  8424.                     $parameters = array(
  8425.                         'fileId' => $fileId,
  8426.                         'proformaId' => $invoiceId,
  8427.                         'type' => 'IluminaciĂ³n',
  8428.                         'location' => $item,
  8429.                     );
  8430.                     $dql 'SELECT i
  8431.                     FROM AvexpressBundle:AveProductFile i                    
  8432.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id                  
  8433.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8434.                     ORDER BY i.rankAv ASC';
  8435.                     $query $em->createQuery($dql)->setParameters($parameters);
  8436.                     $productsInFileLights $query->getResult();
  8437.                     // OTROS
  8438.                     $parameters = array(
  8439.                         'fileId' => $fileId,
  8440.                         'proformaId' => $invoiceId,
  8441.                         'typeV' => 'VĂ­deo',
  8442.                         'typeS' => 'Sonido',
  8443.                         'typeI' => 'IluminaciĂ³n',
  8444.                         'location' => $item,
  8445.                     );
  8446.                     $dql 'SELECT i
  8447.                     FROM AvexpressBundle:AveProductFile i                    
  8448.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8449.                     WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
  8450.                     ORDER BY i.rankAv ASC';
  8451.                     $query $em->createQuery($dql)->setParameters($parameters);
  8452.                     $productsInFileOther $query->getResult();
  8453.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  8454.                     $parameters = array(
  8455.                         'fileId' => $fileId,
  8456.                         'proformaId' => $invoiceId,
  8457.                         'location' => $item,
  8458.                     );
  8459.                     $dql 'SELECT i
  8460.                     FROM AvexpressBundle:AveProductFile i                    
  8461.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8462.                     WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
  8463.                     ORDER BY i.rankAv ASC';
  8464.                     $query $em->createQuery($dql)->setParameters($parameters);
  8465.                     $productsInFileNull $query->getResult();
  8466.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  8467.                     if ($item == 'null') {
  8468.                         // VIDEO
  8469.                         $parameters = array(
  8470.                             'fileId' => $fileId,
  8471.                             'proformaId' => $invoiceId,
  8472.                             'type' => 'VĂ­deo',
  8473.                             'location' => '',
  8474.                         );
  8475.                         $dql 'SELECT i
  8476.                         FROM AvexpressBundle:AveProductFile i                        
  8477.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8478.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8479.                         ORDER BY i.rankAv ASC';
  8480.                         $query $em->createQuery($dql)->setParameters($parameters);
  8481.                         $productsInFileVid $query->getResult();
  8482.                         // SONIDO
  8483.                         $parameters = array(
  8484.                             'fileId' => $fileId,
  8485.                             'proformaId' => $invoiceId,
  8486.                             'type' => 'Sonido',
  8487.                             'location' => '',
  8488.                         );
  8489.                         $dql 'SELECT i
  8490.                         FROM AvexpressBundle:AveProductFile i
  8491.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8492.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8493.                         ORDER BY i.rankAv ASC';
  8494.                         $query $em->createQuery($dql)->setParameters($parameters);
  8495.                         $productsInFileSound $query->getResult();
  8496.                         // ILUMINACION
  8497.                         $parameters = array(
  8498.                             'fileId' => $fileId,
  8499.                             'proformaId' => $invoiceId,
  8500.                             'type' => 'IluminaciĂ³n',
  8501.                             'location' => '',
  8502.                         );
  8503.                         $dql 'SELECT i
  8504.                         FROM AvexpressBundle:AveProductFile i
  8505.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8506.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8507.                         ORDER BY i.rankAv ASC';
  8508.                         $query $em->createQuery($dql)->setParameters($parameters);
  8509.                         $productsInFileLights $query->getResult();
  8510.                         // OTROS
  8511.                         $parameters = array(
  8512.                             'fileId' => $fileId,
  8513.                             'proformaId' => $invoiceId,
  8514.                             'typeV' => 'VĂ­deo',
  8515.                             'typeS' => 'Sonido',
  8516.                             'typeI' => 'IluminaciĂ³n',
  8517.                             'location' => '',
  8518.                         );
  8519.                         $dql 'SELECT i
  8520.                         FROM AvexpressBundle:AveProductFile i                        
  8521.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8522.                         WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8523.                         ORDER BY i.rankAv ASC';
  8524.                         $query $em->createQuery($dql)->setParameters($parameters);
  8525.                         $productsInFileOther $query->getResult();
  8526.                         // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  8527.                         $parameters = array(
  8528.                             'fileId' => $fileId,
  8529.                             'proformaId' => $invoiceId,
  8530.                             'location' => '',
  8531.                         );
  8532.                         $dql 'SELECT i
  8533.                         FROM AvexpressBundle:AveProductFile i                        
  8534.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8535.                         WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8536.                         ORDER BY i.rankAv ASC';
  8537.                         $query $em->createQuery($dql)->setParameters($parameters);
  8538.                         $productsInFileNull $query->getResult();
  8539.                     }
  8540.                     $arrayItemsSorted array_merge($arrayItemsSorted$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  8541.                 }
  8542.                 $items = array();
  8543.                 foreach ($arrayItemsSorted as $elem) {
  8544.                     $items[] = $em->getRepository(AveDocInvoiceItems::class)->findOneBy(array('fileId' => $fileId'invoiceId' => $invoiceId'prdControlId' => $elem->getId()));
  8545.                 }
  8546.             } else {
  8547.                 // Es una proforma
  8548.                 //                $items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
  8549.                 // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  8550.                 $allProductFile $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
  8551.                 $arrayLocation = array();
  8552.                 $arrayLocationWithNull false;
  8553.                 foreach ($allProductFile as $item) {
  8554.                     if (!empty($item->getLocation())) {
  8555.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  8556.                     } else {
  8557.                         $arrayLocationWithNull true;
  8558.                     }
  8559.                 }
  8560.                 if ($arrayLocationWithNull) {
  8561.                     $arrayLocation['null'] = 'null';
  8562.                 }
  8563.                 $arrayItemsSorted = array();
  8564.                 $productsInFile = array();
  8565.                 foreach ($arrayLocation as $item) {
  8566.                     // VIDEO
  8567.                     $parameters = array(
  8568.                         'fileId' => $fileId,
  8569.                         'proformaId' => $invoiceId,
  8570.                         'type' => 'VĂ­deo',
  8571.                         'location' => $item,
  8572.                     );
  8573.                     $dql 'SELECT i
  8574.                     FROM AvexpressBundle:AveProductFile i
  8575.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  8576.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8577.                     ORDER BY i.rankAv ASC';
  8578.                     $query $em->createQuery($dql)->setParameters($parameters);
  8579.                     $productsInFileVid $query->getResult();
  8580.                     // SONIDO
  8581.                     $parameters = array(
  8582.                         'fileId' => $fileId,
  8583.                         'proformaId' => $invoiceId,
  8584.                         'type' => 'Sonido',
  8585.                         'location' => $item,
  8586.                     );
  8587.                     $dql 'SELECT i
  8588.                     FROM AvexpressBundle:AveProductFile i
  8589.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  8590.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8591.                     ORDER BY i.rankAv ASC';
  8592.                     $query $em->createQuery($dql)->setParameters($parameters);
  8593.                     $productsInFileSound $query->getResult();
  8594.                     // ILUMINACION
  8595.                     $parameters = array(
  8596.                         'fileId' => $fileId,
  8597.                         'proformaId' => $invoiceId,
  8598.                         'type' => 'IluminaciĂ³n',
  8599.                         'location' => $item,
  8600.                     );
  8601.                     $dql 'SELECT i
  8602.                     FROM AvexpressBundle:AveProductFile i                    
  8603.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                  
  8604.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8605.                     ORDER BY i.rankAv ASC';
  8606.                     $query $em->createQuery($dql)->setParameters($parameters);
  8607.                     $productsInFileLights $query->getResult();
  8608.                     // OTROS
  8609.                     $parameters = array(
  8610.                         'fileId' => $fileId,
  8611.                         'proformaId' => $invoiceId,
  8612.                         'typeV' => 'VĂ­deo',
  8613.                         'typeS' => 'Sonido',
  8614.                         'typeI' => 'IluminaciĂ³n',
  8615.                         'location' => $item,
  8616.                     );
  8617.                     $dql 'SELECT i
  8618.                     FROM AvexpressBundle:AveProductFile i                    
  8619.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                                        
  8620.                     WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
  8621.                     ORDER BY i.rankAv ASC';
  8622.                     $query $em->createQuery($dql)->setParameters($parameters);
  8623.                     $productsInFileOther $query->getResult();
  8624.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  8625.                     $parameters = array(
  8626.                         'fileId' => $fileId,
  8627.                         'proformaId' => $invoiceId,
  8628.                         'location' => $item,
  8629.                     );
  8630.                     $dql 'SELECT i
  8631.                     FROM AvexpressBundle:AveProductFile i                    
  8632.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                    
  8633.                     WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
  8634.                     ORDER BY i.rankAv ASC';
  8635.                     $query $em->createQuery($dql)->setParameters($parameters);
  8636.                     $productsInFileNull $query->getResult();
  8637.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  8638.                     if ($item == 'null') {
  8639.                         // VIDEO
  8640.                         $parameters = array(
  8641.                             'fileId' => $fileId,
  8642.                             'proformaId' => $invoiceId,
  8643.                             'type' => 'VĂ­deo',
  8644.                             'location' => '',
  8645.                         );
  8646.                         $dql 'SELECT i
  8647.                         FROM AvexpressBundle:AveProductFile i                        
  8648.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                  
  8649.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8650.                         ORDER BY i.rankAv ASC';
  8651.                         $query $em->createQuery($dql)->setParameters($parameters);
  8652.                         $productsInFileVid $query->getResult();
  8653.                         // SONIDO
  8654.                         $parameters = array(
  8655.                             'fileId' => $fileId,
  8656.                             'proformaId' => $invoiceId,
  8657.                             'type' => 'Sonido',
  8658.                             'location' => '',
  8659.                         );
  8660.                         $dql 'SELECT i
  8661.                         FROM AvexpressBundle:AveProductFile i
  8662.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8663.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8664.                         ORDER BY i.rankAv ASC';
  8665.                         $query $em->createQuery($dql)->setParameters($parameters);
  8666.                         $productsInFileSound $query->getResult();
  8667.                         // ILUMINACION
  8668.                         $parameters = array(
  8669.                             'fileId' => $fileId,
  8670.                             'proformaId' => $invoiceId,
  8671.                             'type' => 'IluminaciĂ³n',
  8672.                             'location' => '',
  8673.                         );
  8674.                         $dql 'SELECT i
  8675.                         FROM AvexpressBundle:AveProductFile i
  8676.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8677.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8678.                         ORDER BY i.rankAv ASC';
  8679.                         $query $em->createQuery($dql)->setParameters($parameters);
  8680.                         $productsInFileLights $query->getResult();
  8681.                         // OTROS
  8682.                         $parameters = array(
  8683.                             'fileId' => $fileId,
  8684.                             'proformaId' => $invoiceId,
  8685.                             'typeV' => 'VĂ­deo',
  8686.                             'typeS' => 'Sonido',
  8687.                             'typeI' => 'IluminaciĂ³n',
  8688.                             'location' => '',
  8689.                         );
  8690.                         $dql 'SELECT i
  8691.                         FROM AvexpressBundle:AveProductFile i                        
  8692.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8693.                         WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8694.                         ORDER BY i.rankAv ASC';
  8695.                         $query $em->createQuery($dql)->setParameters($parameters);
  8696.                         $productsInFileOther $query->getResult();
  8697.                         // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  8698.                         $parameters = array(
  8699.                             'fileId' => $fileId,
  8700.                             'proformaId' => $invoiceId,
  8701.                             'location' => '',
  8702.                         );
  8703.                         $dql 'SELECT i
  8704.                         FROM AvexpressBundle:AveProductFile i                        
  8705.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8706.                         WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8707.                         ORDER BY i.rankAv ASC';
  8708.                         $query $em->createQuery($dql)->setParameters($parameters);
  8709.                         $productsInFileNull $query->getResult();
  8710.                     }
  8711.                     $arrayItemsSorted array_merge($arrayItemsSorted$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  8712.                 }
  8713.                 $items = array();
  8714.                 foreach ($arrayItemsSorted as $elem) {
  8715.                     $items[] = $em->getRepository(AveDocProformaItems::class)->findOneBy(array('fileId' => $fileId'proformaId' => $invoiceId'controlId' => $elem->getId()));
  8716.                 }
  8717.             }
  8718.         } else {
  8719.             // No es factura ni proforma, es una rectificativa
  8720.             $items $em->getRepository(ReservationInvoiceRecItems::class)->findBy(array('reservationId' => $fileId'invoiceRecId' => $invoiceId));
  8721.         }
  8722.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  8723.         $client $em->getRepository(Client::class)->findById($file->getClient());
  8724.         if (empty($client)) {
  8725.             $client[0] = new Client();
  8726.             $client[0]->setName('');
  8727.             $client[0]->setTitle('');
  8728.             $client[0]->setIdDocument('');
  8729.             $client[0]->setPopulation('');
  8730.             $client[0]->setRegion('');
  8731.             $client[0]->setCountry('');
  8732.         } else {
  8733.             if (is_numeric($client[0]->getPopulation())) {
  8734.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8735. //                $client[0]->setPopulation($city->getCity());
  8736.             }
  8737.             if (is_numeric($client[0]->getRegion())) {
  8738.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8739. //                $client[0]->setRegion($region->getRegion());
  8740.             }
  8741.             if (is_numeric($client[0]->getCountry())) {
  8742.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8743. //                $client[0]->setCountry($country->getCountry());
  8744.             }
  8745.         }
  8746.         if (empty($client)) {
  8747.             $client[0] = new Client();
  8748.             $client[0]->setName('');
  8749.             $client[0]->setTitle('');
  8750.             $client[0]->setIdDocument('');
  8751.             $client[0]->setPopulation('');
  8752.             $client[0]->setRegion('');
  8753.             $client[0]->setCountry('');
  8754.             $clientNew = array(
  8755.                 'name' => '',
  8756.                 'title' => '',
  8757.                 'idDocument' => '',
  8758.                 'population' => '',
  8759.                 'region' => '',
  8760.                 'country' => '',
  8761.                 'address' => '',
  8762.                 'addressNumber' => '',
  8763.                 'zipCode' => '',
  8764.                 'typeDocument' => '',
  8765.             );
  8766.         } else {
  8767.             $clientNew = array(
  8768.                 'name' => $client[0]->getName(),
  8769.                 'title' => $client[0]->getTitle(),
  8770.                 'idDocument' => $client[0]->getIdDocument(),
  8771.                 'population' => '',
  8772.                 'region' => '',
  8773.                 'country' => '',
  8774.                 'address' => $client[0]->getAddress(),
  8775.                 'addressNumber' => $client[0]->getAddressNumber(),
  8776.                 'zipCode' => $client[0]->getZipCode(),
  8777.                 'typeDocument' => $client[0]->getTypeDocument(),
  8778.             );
  8779.             if (is_numeric($client[0]->getPopulation())) {
  8780.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8781.                 $clientNew['population'] = $city->getCity();
  8782.             }
  8783.             if (is_numeric($client[0]->getRegion())) {
  8784.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8785.                 $clientNew['region'] = $region->getRegion();
  8786.             }
  8787.             if (is_numeric($client[0]->getCountry())) {
  8788.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8789.                 $clientNew['country'] = $country->getCountry();
  8790.             }
  8791.         }
  8792.         // Acumuladores de los calculos
  8793.         $totales_neto_all 0;
  8794.         $data_iva = array(
  8795.             'iva' => 21,
  8796.             'ivaMontoVeintiUno' => 0,
  8797.             'ivaMontoDiez' => 0,
  8798.             'ivaMontoCero' => null,
  8799.         );
  8800.         //INICIO: Determinamos el numero de factura o proforma
  8801.         if ($typeBase == 'I') {
  8802.             // Es una Factura
  8803.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  8804.             $dateDocument $number->getDateAt();
  8805.             $number $number->getNumber();
  8806.             $type 'Invoice';
  8807.         } else {
  8808.             if ($typeBase == 'R') {
  8809.                 // Es una factura rectificativa
  8810.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  8811.                 $dateDocument $number->getDateAt();
  8812.                 $type 'Invoice Rec';
  8813.             } else {
  8814.                 // Es una Proforma
  8815.                 //                $number = $em->getRepository('DevelupBundle:ReservationProforma')->findOneById($invoiceId);
  8816.                 //                $number = $number->getNumber();
  8817.                 $number $invoiceId;
  8818.                 //                $number = $number->getPrefix().$number->getReservationId();
  8819.                 $type 'Proforma';
  8820.             }
  8821.         }
  8822.         //FIN: Determinamos el numero de factura o proforma
  8823.         // Buscamos las salas reservadas, pagos y servicios para el evento
  8824.         $arrayItems = array();
  8825.         $fileProducts = array();
  8826.         $payments = array();
  8827.         $services = array();
  8828.         if (!empty($items)) {
  8829.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  8830.                 foreach ($items as $item) {
  8831.                     switch ($item->getItemType()) {
  8832.                         case 'PRODUCT'// Salon
  8833.                             $fileProducts[] = $item;
  8834.                             break;
  8835.                         case 'PAYMENT'// Pago
  8836.                             $payments[] = $item;
  8837.                             break;
  8838.                         case 'SERVICE'// Servicio
  8839.                             $services[] = $item;
  8840.                             break;
  8841.                         default:
  8842.                             break;
  8843.                     }
  8844.                 }
  8845.             } else {
  8846.                 // Es una proforma
  8847.                 foreach ($items as $item) {
  8848.                     switch ($item->getType()) {
  8849.                         case 'PRODUCT'// Producto
  8850.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  8851.                             if (!empty($productPro)) {
  8852.                                 $fileProducts[] = $productPro;
  8853.                             }
  8854.                             break;
  8855.                         case 'PAYMENT'// Pago
  8856.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  8857.                             if (!empty($paymentPro)) {
  8858.                                 $payments[] = $paymentPro;
  8859.                             }
  8860.                             break;
  8861.                         case 'SERVICE'// Servicio
  8862.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  8863.                             if (!empty($servicePro)) {
  8864.                                 $services[] = $servicePro;
  8865.                             }
  8866.                             break;
  8867.                         default:
  8868.                             break;
  8869.                     }
  8870.                 }
  8871.             }
  8872.         }
  8873.         $data_supplier = array();
  8874.         $i 0;
  8875.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  8876.         $pax '1';
  8877.         $qty '1';
  8878.         $product = array(
  8879.             'neto' => 0,
  8880.             'sumSubT' => 0,
  8881.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  8882.         $service = array(
  8883.             'neto' => 0,
  8884.             'sumSubT' => 0,
  8885.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  8886.         foreach ($fileProducts as $item) {
  8887.             //            $days = '1';
  8888.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  8889.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  8890.                 if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
  8891.                     $subtotal 0;
  8892.                     $neto 0;
  8893.                     $subnetoMounting 0;
  8894.                     $subtotalLounge 0;
  8895.                     $subnetoRemoval 0;
  8896.                 } else {
  8897.                     if ($item->getIva() == '21') {
  8898.                         $subtotalLounge $item->getSubTotalPrice() * 1.21;
  8899.                     }
  8900.                     if ($item->getIva() == '10') {
  8901.                         $subtotalLounge $item->getSubTotalPrice() * 1.1;
  8902.                     }
  8903.                     if ($item->getIva() == '0') {
  8904.                         $subtotalLounge $item->getSubTotalPrice() * 1;
  8905.                     }
  8906.                     $subneto $item->getSubTotalPrice();
  8907.                     $subtotal =  $subtotalLounge;
  8908.                     $neto =  $subneto;
  8909.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8910.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8911.                     $neto round($neto2PHP_ROUND_HALF_UP);
  8912.                     $arrayItems[] = array(
  8913.                         'type' => 'Product',
  8914.                         'name' => $item->getLngLoungeName(),
  8915.                         'amount' => $item->getServicePrice(),
  8916.                         'iva' => $item->getIva(),
  8917.                         'amountSubTotal' => $neto,
  8918.                         //                        'iva' => '21',
  8919.                         'total' => $subtotal,
  8920.                     );
  8921.                 }
  8922.             } else {
  8923.                 // Es proforma
  8924.                 if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
  8925.                     $subtotal 0;
  8926.                     $neto 0;
  8927.                     $subtotalProduct 0;
  8928.                 } else {
  8929.                     if ($item->getIva() == '21') {
  8930.                         $subtotalProduct $item->getSubTotalPrice() * 1.21;
  8931.                     }
  8932.                     if ($item->getIva() == '10') {
  8933.                         $subtotalProduct $item->getSubTotalPrice() * 1.1;
  8934.                     }
  8935.                     if ($item->getIva() == '0') {
  8936.                         $subtotalProduct $item->getSubTotalPrice() * 1;
  8937.                     }
  8938.                     $subneto $item->getSubTotalPrice();
  8939.                     $subtotal =  $subtotalProduct;
  8940.                     $neto =  $subneto;
  8941.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8942.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8943.                     $neto round($neto2PHP_ROUND_HALF_UP);
  8944.                     $arrayItems[] = array(
  8945.                         'type' => 'Product',
  8946.                         'name' => $item->getProductName(),
  8947.                         'amount' => $item->getServicePrice(),
  8948.                         'amountSubTotal' => $neto,
  8949.                         //                        'iva' => '21',
  8950.                         'iva' => $item->getIva(),
  8951.                         'total' => $subtotal,
  8952.                     );
  8953.                 }
  8954.             }
  8955.             // Acumula netos totales e IVA
  8956.             $totales_neto_all $totales_neto_all $neto;
  8957.             if ($item->getIva() == '21') {
  8958.                 $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  8959.             }
  8960.             if ($item->getIva() == '10') {
  8961.                 $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  8962.             }
  8963.             if ($item->getIva() == '0') {
  8964.                 $data_iva['ivaMontoCero'] = $neto 0;
  8965.             }
  8966.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8967.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  8968.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  8969.             // Acumula netos totales e IVA
  8970.             $product['neto'] = $product['neto'] + $neto;
  8971.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  8972.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8973.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  8974.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  8975.             $pax $item->getPax();
  8976.             $qty $item->getUnits();
  8977.             if (!empty($item->getDays())) {
  8978.                 $days $item->getDays();
  8979.             }
  8980.             // Calculo del precio unitario despues de aplicar Over y Comision
  8981.             $multiplo = (float)$qty * (float)$days;
  8982.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  8983.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  8984.                 $data_supplier['product'][$i] = array(
  8985.                     'id' => $item->getId(),
  8986.                     'loungeName' => $item->getLngLoungeName(),
  8987.                     'idLounge' => $item->getLngIdLounge(),
  8988.                     'dateStart' => $item->getLngDateStart(),
  8989.                     'dateEnd' => $item->getLngDateEnd(),
  8990.                     //                    'servicePrice' => $item->getLngServicePrice(),
  8991.                     'servicePrice' => $item->getServicePrice(),
  8992.                     'serviceSubTotalPrice' => $item->getSubTotalPrice(),
  8993.                     'subtotalLounge' => $subtotalLounge,
  8994.                     // 'iva' => $iva,
  8995.                     'iva' => $item->getIva(),
  8996.                     'pax' => $pax,
  8997.                     'qty' => $qty,
  8998.                     'days' => $days,
  8999.                     'type' => $item->getLngType(),
  9000.                     'subtotal' => $subtotal,
  9001.                 );
  9002.             } else {
  9003.                 // Es proforma
  9004.                 $data_supplier['product'][$i] = array(
  9005.                     'id' => $item->getId(),
  9006.                     'productName' => $item->getProductName(),
  9007.                     'productId' => $item->getProductId(),
  9008.                     'dateStart' => $item->getDateStart(),
  9009.                     'dateEnd' => $item->getDateEnd(),
  9010.                     'location' => $item->getLocation(),
  9011.                     //                    'servicePrice' => $item->getServicePrice(),
  9012.                     'servicePrice' => $item->getServicePrice(),
  9013.                     'serviceSubTotalPrice' => $item->getSubTotalPrice(),
  9014.                     'subtotalProduct' => $subtotalProduct,
  9015.                     // 'iva' => $iva,
  9016.                     'iva' => $item->getIva(),
  9017.                     'pax' => $pax,
  9018.                     'qty' => $qty,
  9019.                     'days' => $days,
  9020.                     'type' => $item->getType(),
  9021.                     'subtotal' => $subtotal,
  9022.                 );
  9023.             }
  9024.             $i++;
  9025.         }
  9026.         $data_supplier['productSubTotal'] = array(
  9027.             'neto' => $product['neto'],
  9028.             'sumSubT' => $product['sumSubT'],
  9029.         );
  9030.         $payment = array(
  9031.             'sumSubT' => 0,
  9032.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  9033.         $i 0;
  9034.         foreach ($payments as $item) {
  9035.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9036.                 //                $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmount();
  9037.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  9038.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9039.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  9040.                 $data_supplier['payment'][$i] = array(
  9041.                     'id' => $item->getId(),
  9042.                     'amount' => $item->getPayAmount(),
  9043.                     'amountTotal' => $item->getPayAmountTotal(),
  9044.                     'vat' => $item->getPayVat(),
  9045.                     'datePayAt' => $item->getPayDatePayAt(),
  9046.                     'wayToPay' => $item->getPayWayToPay(),
  9047.                 );
  9048.                 $arrayItems[] = array(
  9049.                     'type' => 'Payment',
  9050.                     'name' => $item->getPayWayToPay(),
  9051.                     'amount' => $item->getPayAmount(),
  9052.                     'total' => $item->getPayAmountTotal(),
  9053.                     'iva' => $item->getPayVat(),
  9054.                     //                    'iva' => '',
  9055.                     //                    'total' => $item->getPayAmount(),
  9056.                 );
  9057.             } else {
  9058.                 // Es una proforma
  9059.                 //                $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmount();
  9060.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  9061.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9062.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  9063.                 $data_supplier['payment'][$i] = array(
  9064.                     'id' => $item->getId(),
  9065.                     'amount' => $item->getAmount(),
  9066.                     'amountTotal' => $item->getAmountTotal(),
  9067.                     'vat' => $item->getVat(),
  9068.                     'datePayAt' => $item->getDatePayAt(),
  9069.                     'wayToPay' => $item->getWayToPay(),
  9070.                 );
  9071.                 $arrayItems[] = array(
  9072.                     'type' => 'Payment',
  9073.                     'name' => $item->getWayToPay(),
  9074.                     'amount' => $item->getAmount(),
  9075.                     'total' => $item->getAmountTotal(),
  9076.                     'iva' => $item->getVat(),
  9077.                     //                    'iva' => '',
  9078.                     //                    'total' => $item->getAmount(),
  9079.                 );
  9080.             }
  9081.             $i++;
  9082.         }
  9083.         if (!empty($payments)) {
  9084.             $data_supplier['paymentSubTotal'] = array(
  9085.                 'sumSubT' => $payment['sumSubT'],
  9086.             );
  9087.         }
  9088.         foreach ($services as $item) {
  9089.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9090.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  9091.                     $subtotal 0;
  9092.                     $neto 0;
  9093.                     $subtotalService 0;
  9094.                 } else {
  9095.                     $subtotalService $item->getSrvPrice();
  9096.                     $subneto $item->getSrvPrice();
  9097.                     // Commission
  9098.                     if ($item->getSrvOpCommission() == '1') {
  9099.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  9100.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  9101.                     } else {
  9102.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  9103.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  9104.                     }
  9105.                     // Over
  9106.                     if ($item->getSrvOpOver() == '1') {
  9107.                         $subtotalService $subtotalService $item->getSrvOver();
  9108.                         $subneto $subneto $item->getSrvOver();
  9109.                     } else {
  9110.                         $subtotalService $subtotalService $item->getSrvOver();
  9111.                         $subneto $subneto $item->getSrvOver();
  9112.                     }
  9113.                     // IVA
  9114.                     if ($item->getSrvOpIva() == '1') {
  9115.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  9116.                     } else {
  9117.                         $subtotalService $item->getSrvPrice();
  9118.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  9119.                     }
  9120.                     switch ($item->getSrvServiceCatId()) {
  9121.                         case 1// Alojamiento
  9122.                             // el numero de noches $numNoches; precio unitario $subneto
  9123.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  9124.                             // La personas no afectan este calculo
  9125.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  9126.                             $subnetoUnit $subneto;
  9127.                             $subneto $subneto $numNoches $item->getSrvUnits();
  9128.                             $data_supplier['service'][$i] = array(
  9129.                                 'id' => $item->getId(),
  9130.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9131.                                 'serviceName' => $item->getSrvName(),
  9132.                                 'serviceType' => 'Hotel',
  9133.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  9134.                                 'qty' => $item->getSrvUnits(),
  9135.                                 'iva' => $item->getSrvIva(),
  9136.                                 'pax' => '-',
  9137.                                 'precioUnit' => $subnetoUnit,
  9138.                                 'subneto' => $subneto,
  9139.                                 'subtotal' => $subtotal,
  9140.                             );
  9141.                             break;
  9142.                         case 2//Actividades
  9143.                             // El nĂºmero de personas es considerado en el calculo
  9144.                             $pax $item->getSrvPax();
  9145.                             if (empty($pax) or $pax == "0") {
  9146.                                 $pax 1;
  9147.                             }
  9148.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9149.                             if ($days 1) {
  9150.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9151.                             } else {
  9152.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9153.                             }
  9154.                             $subtotal $subtotalService $days $item->getSrvUnits();
  9155.                             $subnetoUnit $subneto;
  9156.                             $subneto $subneto $days $item->getSrvUnits();
  9157.                             $data_supplier['service'][$i] = array(
  9158.                                 'id' => $item->getId(),
  9159.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9160.                                 'serviceName' => $item->getSrvName(),
  9161.                                 'serviceType' => 'Actividad',
  9162.                                 'date' => $dateServ,
  9163.                                 'qty' => $item->getSrvUnits(),
  9164.                                 'iva' => $item->getSrvIva(),
  9165.                                 'pax' => $item->getSrvPax(),
  9166.                                 'precioUnit' => $subnetoUnit,
  9167.                                 'subneto' => $subneto,
  9168.                                 'subtotal' => $subtotal,
  9169.                             );
  9170.                             break;
  9171.                         case 3// AV
  9172.                             $pax $item->getSrvPax();
  9173.                             if (empty($pax) or $pax == "0") {
  9174.                                 $pax 1;
  9175.                             }
  9176.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9177.                             if ($days 1) {
  9178.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9179.                             } else {
  9180.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9181.                             }
  9182.                             $unitsServ $item->getSrvUnits();
  9183.                             if (empty($unitsServ) or $unitsServ == "0") {
  9184.                                 $unitsServ 1;
  9185.                             }
  9186.                             $subtotal $subtotalService $days $unitsServ $pax;
  9187.                             $subnetoUnit $subneto;
  9188.                             $subneto $subneto $days $unitsServ $pax;
  9189.                             $data_supplier['service'][$i] = array(
  9190.                                 'id' => $item->getId(),
  9191.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9192.                                 'serviceName' => $item->getSrvName(),
  9193.                                 'serviceType' => 'AV',
  9194.                                 'date' => $dateServ,
  9195.                                 'qty' => $unitsServ,
  9196.                                 'iva' => $item->getSrvIva(),
  9197.                                 'pax' => $item->getSrvPax(),
  9198.                                 'precioUnit' => $subnetoUnit,
  9199.                                 'subneto' => $subneto,
  9200.                                 'subtotal' => $subtotal,
  9201.                             );
  9202.                             break;
  9203.                         case 4//Creative
  9204.                             $pax $item->getSrvPax();
  9205.                             if (empty($pax) or $pax == "0") {
  9206.                                 $pax 1;
  9207.                             }
  9208.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9209.                             if ($days 1) {
  9210.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9211.                             } else {
  9212.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9213.                             }
  9214.                             $unitsServ $item->getSrvUnits();
  9215.                             if (empty($unitsServ) or $unitsServ == "0") {
  9216.                                 $unitsServ 1;
  9217.                             }
  9218.                             $subtotal $subtotalService $days $unitsServ $pax;
  9219.                             $subnetoUnit $subneto;
  9220.                             $subneto $subneto $days $unitsServ $pax;
  9221.                             $data_supplier['service'][$i] = array(
  9222.                                 'id' => $item->getId(),
  9223.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9224.                                 'serviceName' => $item->getSrvName(),
  9225.                                 'serviceType' => 'Creativo',
  9226.                                 'date' => $dateServ,
  9227.                                 'qty' => $unitsServ,
  9228.                                 'iva' => $item->getSrvIva(),
  9229.                                 'pax' => $item->getSrvPax(),
  9230.                                 'precioUnit' => $subnetoUnit,
  9231.                                 'subneto' => $subneto,
  9232.                                 'subtotal' => $subtotal,
  9233.                             );
  9234.                             break;
  9235.                         case 5//Cruise
  9236.                             $pax $item->getSrvPax();
  9237.                             if (empty($pax) or $pax == "0") {
  9238.                                 $pax 1;
  9239.                             }
  9240.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  9241.                             if ($days 1) {
  9242.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9243.                             } else {
  9244.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9245.                             }
  9246.                             $unitsServ $item->getSrvUnits();
  9247.                             if (empty($unitsServ) or $unitsServ == "0") {
  9248.                                 $unitsServ 1;
  9249.                             }
  9250.                             $subtotal $subtotalService $days $unitsServ $pax;
  9251.                             $subnetoUnit $subneto;
  9252.                             $subneto $subneto $days $unitsServ $pax;
  9253.                             $data_supplier['service'][$i] = array(
  9254.                                 'id' => $item->getId(),
  9255.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9256.                                 'serviceName' => $item->getSrvName(),
  9257.                                 'serviceType' => 'Crucero',
  9258.                                 'date' => $dateServ,
  9259.                                 'qty' => $unitsServ,
  9260.                                 'iva' => $item->getSrvIva(),
  9261.                                 'pax' => $item->getSrvPax(),
  9262.                                 'precioUnit' => $subnetoUnit,
  9263.                                 'subneto' => $subneto,
  9264.                                 'subtotal' => $subtotal,
  9265.                             );
  9266.                             break;
  9267.                         case 6//Entertaiment
  9268.                             $pax $item->getSrvPax();
  9269.                             if (empty($pax) or $pax == "0") {
  9270.                                 $pax 1;
  9271.                             }
  9272.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9273.                             if ($days 1) {
  9274.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9275.                             } else {
  9276.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9277.                             }
  9278.                             $unitsServ $item->getSrvUnits();
  9279.                             if (empty($unitsServ) or $unitsServ == "0") {
  9280.                                 $unitsServ 1;
  9281.                             }
  9282.                             $subtotal $subtotalService $days $unitsServ $pax;
  9283.                             $subnetoUnit $subneto;
  9284.                             $subneto $subneto $days $unitsServ $pax;
  9285.                             $data_supplier['service'][$i] = array(
  9286.                                 'id' => $item->getId(),
  9287.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9288.                                 'serviceName' => $item->getSrvName(),
  9289.                                 'serviceType' => 'Entretenimiento',
  9290.                                 'date' => $dateServ,
  9291.                                 'qty' => $unitsServ,
  9292.                                 'iva' => $item->getSrvIva(),
  9293.                                 'pax' => $item->getSrvPax(),
  9294.                                 'precioUnit' => $subnetoUnit,
  9295.                                 'subneto' => $subneto,
  9296.                                 'subtotal' => $subtotal,
  9297.                             );
  9298.                             break;
  9299.                         case 7// Gifts
  9300.                             $pax $item->getSrvPax();
  9301.                             if (empty($pax) or $pax == "0") {
  9302.                                 $pax 1;
  9303.                             }
  9304.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9305.                             $days 1;
  9306.                             if ($days 1) {
  9307.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9308.                             } else {
  9309.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9310.                             }
  9311.                             $unitsServ $item->getSrvUnits();
  9312.                             if (empty($unitsServ) or $unitsServ == "0") {
  9313.                                 $unitsServ 1;
  9314.                             }
  9315.                             $subtotal $subtotalService $days $unitsServ $pax;
  9316.                             $subnetoUnit $subneto;
  9317.                             $subneto $subneto $days $unitsServ $pax;
  9318.                             $data_supplier['service'][$i] = array(
  9319.                                 'id' => $item->getId(),
  9320.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9321.                                 'serviceName' => $item->getSrvName(),
  9322.                                 'serviceType' => 'Regalos',
  9323.                                 'date' => $dateServ,
  9324.                                 'qty' => $unitsServ,
  9325.                                 'iva' => $item->getSrvIva(),
  9326.                                 'pax' => $item->getSrvPax(),
  9327.                                 'precioUnit' => $subnetoUnit,
  9328.                                 'subneto' => $subneto,
  9329.                                 'subtotal' => $subtotal,
  9330.                             );
  9331.                             break;
  9332.                         case 8//Guide
  9333.                             $pax $item->getSrvPax();
  9334.                             if (empty($pax) or $pax == "0") {
  9335.                                 $pax 1;
  9336.                             }
  9337.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9338.                             if ($days 1) {
  9339.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9340.                             } else {
  9341.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9342.                             }
  9343.                             $unitsServ $item->getSrvUnits();
  9344.                             if (empty($unitsServ) or $unitsServ == "0") {
  9345.                                 $unitsServ 1;
  9346.                             }
  9347.                             $subtotal $subtotalService $days $unitsServ $pax;
  9348.                             $subnetoUnit $subneto;
  9349.                             $subneto $subneto $days $unitsServ $pax;
  9350.                             $data_supplier['service'][$i] = array(
  9351.                                 'id' => $item->getId(),
  9352.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9353.                                 'serviceName' => $item->getSrvName(),
  9354.                                 'serviceType' => 'Regalos',
  9355.                                 'date' => $dateServ,
  9356.                                 'qty' => $unitsServ,
  9357.                                 'iva' => $item->getSrvIva(),
  9358.                                 'pax' => $item->getSrvPax(),
  9359.                                 'precioUnit' => $subnetoUnit,
  9360.                                 'subneto' => $subneto,
  9361.                                 'subtotal' => $subtotal,
  9362.                             );
  9363.                             break;
  9364.                         case 9//Itineraries
  9365.                             $pax $item->getSrvPax();
  9366.                             if (empty($pax) or $pax == "0") {
  9367.                                 $pax 1;
  9368.                             }
  9369.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9370.                             if ($days 1) {
  9371.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9372.                             } else {
  9373.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9374.                             }
  9375.                             $unitsServ $item->getSrvUnits();
  9376.                             if (empty($unitsServ) or $unitsServ == "0") {
  9377.                                 $unitsServ 1;
  9378.                             }
  9379.                             $subtotal $subtotalService $days $unitsServ $pax;
  9380.                             $subnetoUnit $subneto;
  9381.                             $subneto $subneto $days $unitsServ $pax;
  9382.                             $data_supplier['service'][$i] = array(
  9383.                                 'id' => $item->getId(),
  9384.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9385.                                 'serviceName' => $item->getSrvName(),
  9386.                                 'serviceType' => 'Itinerarios',
  9387.                                 'date' => $dateServ,
  9388.                                 'qty' => $unitsServ,
  9389.                                 'iva' => $item->getSrvIva(),
  9390.                                 'pax' => $item->getSrvPax(),
  9391.                                 'precioUnit' => $subnetoUnit,
  9392.                                 'subneto' => $subneto,
  9393.                                 'subtotal' => $subtotal,
  9394.                             );
  9395.                             break;
  9396.                         case 10//Lounge  -- No Aplica
  9397.                             //                        $pax = $item->getPax();
  9398.                             //                        if (empty($pax) or $pax == "0") {
  9399.                             //                            $pax = 1;
  9400.                             //                        }
  9401.                             //
  9402.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9403.                             //                        if ($days > 1){
  9404.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9405.                             //                        } else {
  9406.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9407.                             //                        }
  9408.                             //
  9409.                             //                        $unitsServ = $item->getUnits();
  9410.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  9411.                             //                            $unitsServ = 1;
  9412.                             //                        }
  9413.                             //
  9414.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  9415.                             //                        $subnetoUnit = $subneto;
  9416.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  9417.                             //
  9418.                             //                        $data_supplier['service'][$i] = array (
  9419.                             //                            'id' => $item->getId(),
  9420.                             //                            'serviceCatId' => $item->getServiceCatId(),
  9421.                             //                            'serviceName' => $item->getName(),
  9422.                             //                            'serviceType' => 'Itinerarios',
  9423.                             //                            'date' => $dateServ,
  9424.                             //                            'qty' => $unitsServ,
  9425.                             //                            'iva' => $item->getIva(),
  9426.                             //                            'pax' => $item->getPax(),
  9427.                             //                            'precioUnit' => $subnetoUnit,
  9428.                             //                            'subneto' => $subneto,
  9429.                             //                            'subtotal' => $subtotal,
  9430.                             //                        );
  9431.                             break;
  9432.                         case 11//Menu
  9433.                             $pax $item->getSrvPax();
  9434.                             if (empty($pax) or $pax == "0") {
  9435.                                 $pax 1;
  9436.                             }
  9437.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9438.                             if ($days 1) {
  9439.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9440.                             } else {
  9441.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9442.                             }
  9443.                             $unitsServ $item->getSrvUnits();
  9444.                             if (empty($unitsServ) or $unitsServ == "0") {
  9445.                                 $unitsServ 1;
  9446.                             }
  9447.                             $subtotal $subtotalService $days $unitsServ $pax;
  9448.                             $subnetoUnit $subneto;
  9449.                             $subneto $subneto $days $unitsServ $pax;
  9450.                             $data_supplier['service'][$i] = array(
  9451.                                 'id' => $item->getId(),
  9452.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9453.                                 'serviceName' => $item->getSrvName(),
  9454.                                 'serviceType' => 'MenĂº',
  9455.                                 'date' => $dateServ,
  9456.                                 'qty' => $unitsServ,
  9457.                                 'iva' => $item->getSrvIva(),
  9458.                                 'pax' => $item->getSrvPax(),
  9459.                                 'precioUnit' => $subnetoUnit,
  9460.                                 'subneto' => $subneto,
  9461.                                 'subtotal' => $subtotal,
  9462.                             );
  9463.                             break;
  9464.                         case 12//Others
  9465.                             $pax $item->getSrvPax();
  9466.                             if (empty($pax) or $pax == "0") {
  9467.                                 $pax 1;
  9468.                             }
  9469.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9470.                             if ($days 1) {
  9471.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9472.                             } else {
  9473.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9474.                             }
  9475.                             $unitsServ $item->getSrvUnits();
  9476.                             if (empty($unitsServ) or $unitsServ == "0") {
  9477.                                 $unitsServ 1;
  9478.                             }
  9479.                             $subtotal $subtotalService $days $unitsServ $pax;
  9480.                             $subnetoUnit $subneto;
  9481.                             $subneto $subneto $days $unitsServ $pax;
  9482.                             $data_supplier['service'][$i] = array(
  9483.                                 'id' => $item->getId(),
  9484.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9485.                                 'serviceName' => $item->getSrvName(),
  9486.                                 'serviceType' => 'Otros',
  9487.                                 'date' => $dateServ,
  9488.                                 'qty' => $unitsServ,
  9489.                                 'iva' => $item->getSrvIva(),
  9490.                                 'pax' => $item->getSrvPax(),
  9491.                                 'precioUnit' => $subnetoUnit,
  9492.                                 'subneto' => $subneto,
  9493.                                 'subtotal' => $subtotal,
  9494.                             );
  9495.                             break;
  9496.                         case 13//Transport
  9497.                             $pax $item->getSrvPax();
  9498.                             if (empty($pax) or $pax == "0") {
  9499.                                 $pax 1;
  9500.                             }
  9501.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9502.                             if ($days 1) {
  9503.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9504.                             } else {
  9505.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9506.                             }
  9507.                             $unitsServ $item->getSrvUnits();
  9508.                             if (empty($unitsServ) or $unitsServ == "0") {
  9509.                                 $unitsServ 1;
  9510.                             }
  9511.                             $subtotal $subtotalService $days $unitsServ $pax;
  9512.                             $subnetoUnit $subneto;
  9513.                             $subneto $subneto $days $unitsServ $pax;
  9514.                             $data_supplier['service'][$i] = array(
  9515.                                 'id' => $item->getId(),
  9516.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9517.                                 'serviceName' => $item->getSrvName(),
  9518.                                 'serviceType' => 'Transporte',
  9519.                                 'date' => $dateServ,
  9520.                                 'qty' => $unitsServ,
  9521.                                 'iva' => $item->getSrvIva(),
  9522.                                 'pax' => $item->getSrvPax(),
  9523.                                 'precioUnit' => $subnetoUnit,
  9524.                                 'subneto' => $subneto,
  9525.                                 'subtotal' => $subtotal,
  9526.                             );
  9527.                             break;
  9528.                         case 14//Technology
  9529.                             $pax $item->getSrvPax();
  9530.                             if (empty($pax) or $pax == "0") {
  9531.                                 $pax 1;
  9532.                             }
  9533.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9534.                             $days 1;
  9535.                             //                        if ($days > 1){
  9536.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9537.                             //                        } else {
  9538.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9539.                             //                        }
  9540.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9541.                             $unitsServ $item->getSrvUnits();
  9542.                             if (empty($unitsServ) or $unitsServ == "0") {
  9543.                                 $unitsServ 1;
  9544.                             }
  9545.                             $subtotal $subtotalService $days $unitsServ $pax;
  9546.                             $subnetoUnit $subneto;
  9547.                             $subneto $subneto $days $unitsServ $pax;
  9548.                             $data_supplier['service'][$i] = array(
  9549.                                 'id' => $item->getId(),
  9550.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9551.                                 'serviceName' => $item->getSrvName(),
  9552.                                 'serviceType' => 'TecnologĂ­a',
  9553.                                 'date' => $dateServ,
  9554.                                 'qty' => $unitsServ,
  9555.                                 'iva' => $item->getSrvIva(),
  9556.                                 'pax' => $item->getSrvPax(),
  9557.                                 'precioUnit' => $subnetoUnit,
  9558.                                 'subneto' => $subneto,
  9559.                                 'subtotal' => $subtotal,
  9560.                             );
  9561.                             break;
  9562.                         case 15//Assisstant
  9563.                             $pax $item->getSrvPax();
  9564.                             if (empty($pax) or $pax == "0") {
  9565.                                 $pax 1;
  9566.                             }
  9567.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9568.                             if ($days 1) {
  9569.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9570.                             } else {
  9571.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9572.                             }
  9573.                             $unitsServ $item->getSrvUnits();
  9574.                             if (empty($unitsServ) or $unitsServ == "0") {
  9575.                                 $unitsServ 1;
  9576.                             }
  9577.                             $subtotal $subtotalService $days $unitsServ $pax;
  9578.                             $subnetoUnit $subneto;
  9579.                             $subneto $subneto $days $unitsServ $pax;
  9580.                             $data_supplier['service'][$i] = array(
  9581.                                 'id' => $item->getId(),
  9582.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9583.                                 'serviceName' => $item->getSrvName(),
  9584.                                 'serviceType' => 'Asistente',
  9585.                                 'date' => $dateServ,
  9586.                                 'qty' => $unitsServ,
  9587.                                 'iva' => $item->getSrvIva(),
  9588.                                 'pax' => $item->getSrvPax(),
  9589.                                 'precioUnit' => $subnetoUnit,
  9590.                                 'subneto' => $subneto,
  9591.                                 'subtotal' => $subtotal,
  9592.                             );
  9593.                             break;
  9594.                         case 16//DDR
  9595.                             $pax $item->getSrvPax();
  9596.                             if (empty($pax) or $pax == "0") {
  9597.                                 $pax 1;
  9598.                             }
  9599.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9600.                             if ($days 1) {
  9601.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9602.                             } else {
  9603.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9604.                             }
  9605.                             $unitsServ $item->getSrvUnits();
  9606.                             if (empty($unitsServ) or $unitsServ == "0") {
  9607.                                 $unitsServ 1;
  9608.                             }
  9609.                             $subtotal $subtotalService $days $unitsServ $pax;
  9610.                             $subnetoUnit $subneto;
  9611.                             $subneto $subneto $days $unitsServ $pax;
  9612.                             $data_supplier['service'][$i] = array(
  9613.                                 'id' => $item->getId(),
  9614.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9615.                                 'serviceName' => $item->getSrvName(),
  9616.                                 'serviceType' => 'DDR',
  9617.                                 'date' => $dateServ,
  9618.                                 'qty' => $unitsServ,
  9619.                                 'iva' => $item->getSrvIva(),
  9620.                                 'pax' => $item->getSrvPax(),
  9621.                                 'precioUnit' => $subnetoUnit,
  9622.                                 'subneto' => $subneto,
  9623.                                 'subtotal' => $subtotal,
  9624.                             );
  9625.                             break;
  9626.                         default:
  9627.                             break;
  9628.                     }
  9629.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  9630.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  9631.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  9632.                     $arrayItems[] = array(
  9633.                         'type' => 'Service',
  9634.                         'name' => $item->getSrvName(),
  9635.                         'amount' => $neto,
  9636.                         'iva' => $item->getSrvIva(),
  9637.                         'total' => $subtotal,
  9638.                     );
  9639.                 }
  9640.                 switch ($item->getSrvIva()) {
  9641.                         // Acumula IVA
  9642.                     case 21:
  9643.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  9644.                         break;
  9645.                     case 10:
  9646.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  9647.                         break;
  9648.                     case 0:
  9649.                         break;
  9650.                     default:
  9651.                         break;
  9652.                 }
  9653.             } else {
  9654.                 // Es una proforma
  9655.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  9656.                     $subtotal 0;
  9657.                     $neto 0;
  9658.                     $subtotalService 0;
  9659.                 } else {
  9660.                     $subtotalService $item->getPrice();
  9661.                     $subneto $item->getPrice();
  9662.                     // Commission
  9663.                     if ($item->getOpCommission() == '1') {
  9664.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  9665.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  9666.                     } else {
  9667.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  9668.                         $subneto $subneto * (- ($item->getCommission() / 100));
  9669.                     }
  9670.                     // Over
  9671.                     if ($item->getOpOver() == '1') {
  9672.                         $subtotalService $subtotalService $item->getOver();
  9673.                         $subneto $subneto $item->getOver();
  9674.                     } else {
  9675.                         $subtotalService $subtotalService $item->getOver();
  9676.                         $subneto $subneto $item->getOver();
  9677.                     }
  9678.                     // IVA
  9679.                     if ($item->getOpIva() == '1') {
  9680.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  9681.                     } else {
  9682.                         $subtotalService $item->getPrice();
  9683.                         $subneto = ($subneto 100) / (100 $item->getIva());
  9684.                     }
  9685.                     switch ($item->getServiceCatId()) {
  9686.                         case 1// Alojamiento
  9687.                             // el numero de noches $numNoches; precio unitario $subneto
  9688.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  9689.                             // La personas no afectan este calculo
  9690.                             $subtotal $subtotalService $numNoches $item->getUnits();
  9691.                             $subnetoUnit $subneto;
  9692.                             $subneto $subneto $numNoches $item->getUnits();
  9693.                             $data_supplier['service'][$i] = array(
  9694.                                 'id' => $item->getId(),
  9695.                                 'serviceCatId' => $item->getServiceCatId(),
  9696.                                 'serviceName' => $item->getName(),
  9697.                                 'serviceType' => 'Hotel',
  9698.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  9699.                                 'qty' => $item->getUnits(),
  9700.                                 'iva' => $item->getIva(),
  9701.                                 'pax' => '-',
  9702.                                 'precioUnit' => $subnetoUnit,
  9703.                                 'subneto' => $subneto,
  9704.                                 'subtotal' => $subtotal,
  9705.                             );
  9706.                             break;
  9707.                         case 2//Actividades
  9708.                             // El nĂºmero de personas es considerado en el calculo
  9709.                             $pax $item->getPax();
  9710.                             if (empty($pax) or $pax == "0") {
  9711.                                 $pax 1;
  9712.                             }
  9713.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9714.                             if ($days 1) {
  9715.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9716.                             } else {
  9717.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9718.                             }
  9719.                             $subtotal $subtotalService $days $item->getUnits();
  9720.                             $subnetoUnit $subneto;
  9721.                             $subneto $subneto $days $item->getUnits();
  9722.                             $data_supplier['service'][$i] = array(
  9723.                                 'id' => $item->getId(),
  9724.                                 'serviceCatId' => $item->getServiceCatId(),
  9725.                                 'serviceName' => $item->getName(),
  9726.                                 'serviceType' => 'Actividad',
  9727.                                 'date' => $dateServ,
  9728.                                 'qty' => $item->getUnits(),
  9729.                                 'iva' => $item->getIva(),
  9730.                                 'pax' => $item->getPax(),
  9731.                                 'precioUnit' => $subnetoUnit,
  9732.                                 'subneto' => $subneto,
  9733.                                 'subtotal' => $subtotal,
  9734.                             );
  9735.                             break;
  9736.                         case 3// AV
  9737.                             $pax $item->getPax();
  9738.                             if (empty($pax) or $pax == "0") {
  9739.                                 $pax 1;
  9740.                             }
  9741.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9742.                             if ($days 1) {
  9743.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9744.                             } else {
  9745.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9746.                             }
  9747.                             $unitsServ $item->getUnits();
  9748.                             if (empty($unitsServ) or $unitsServ == "0") {
  9749.                                 $unitsServ 1;
  9750.                             }
  9751.                             $subtotal $subtotalService $days $unitsServ $pax;
  9752.                             $subnetoUnit $subneto;
  9753.                             $subneto $subneto $days $unitsServ $pax;
  9754.                             $data_supplier['service'][$i] = array(
  9755.                                 'id' => $item->getId(),
  9756.                                 'serviceCatId' => $item->getServiceCatId(),
  9757.                                 'serviceName' => $item->getName(),
  9758.                                 'serviceType' => 'AV',
  9759.                                 'date' => $dateServ,
  9760.                                 'qty' => $unitsServ,
  9761.                                 'iva' => $item->getIva(),
  9762.                                 'pax' => $item->getPax(),
  9763.                                 'precioUnit' => $subnetoUnit,
  9764.                                 'subneto' => $subneto,
  9765.                                 'subtotal' => $subtotal,
  9766.                             );
  9767.                             break;
  9768.                         case 4//Creative
  9769.                             $pax $item->getPax();
  9770.                             if (empty($pax) or $pax == "0") {
  9771.                                 $pax 1;
  9772.                             }
  9773.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9774.                             if ($days 1) {
  9775.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9776.                             } else {
  9777.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9778.                             }
  9779.                             $unitsServ $item->getUnits();
  9780.                             if (empty($unitsServ) or $unitsServ == "0") {
  9781.                                 $unitsServ 1;
  9782.                             }
  9783.                             $subtotal $subtotalService $days $unitsServ $pax;
  9784.                             $subnetoUnit $subneto;
  9785.                             $subneto $subneto $days $unitsServ $pax;
  9786.                             $data_supplier['service'][$i] = array(
  9787.                                 'id' => $item->getId(),
  9788.                                 'serviceCatId' => $item->getServiceCatId(),
  9789.                                 'serviceName' => $item->getName(),
  9790.                                 'serviceType' => 'Creativo',
  9791.                                 'date' => $dateServ,
  9792.                                 'qty' => $unitsServ,
  9793.                                 'iva' => $item->getIva(),
  9794.                                 'pax' => $item->getPax(),
  9795.                                 'precioUnit' => $subnetoUnit,
  9796.                                 'subneto' => $subneto,
  9797.                                 'subtotal' => $subtotal,
  9798.                             );
  9799.                             break;
  9800.                         case 5//Cruise
  9801.                             $pax $item->getPax();
  9802.                             if (empty($pax) or $pax == "0") {
  9803.                                 $pax 1;
  9804.                             }
  9805.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  9806.                             if ($days 1) {
  9807.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9808.                             } else {
  9809.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9810.                             }
  9811.                             $unitsServ $item->getUnits();
  9812.                             if (empty($unitsServ) or $unitsServ == "0") {
  9813.                                 $unitsServ 1;
  9814.                             }
  9815.                             $subtotal $subtotalService $days $unitsServ $pax;
  9816.                             $subnetoUnit $subneto;
  9817.                             $subneto $subneto $days $unitsServ $pax;
  9818.                             $data_supplier['service'][$i] = array(
  9819.                                 'id' => $item->getId(),
  9820.                                 'serviceCatId' => $item->getServiceCatId(),
  9821.                                 'serviceName' => $item->getName(),
  9822.                                 'serviceType' => 'Crucero',
  9823.                                 'date' => $dateServ,
  9824.                                 'qty' => $unitsServ,
  9825.                                 'iva' => $item->getIva(),
  9826.                                 'pax' => $item->getPax(),
  9827.                                 'precioUnit' => $subnetoUnit,
  9828.                                 'subneto' => $subneto,
  9829.                                 'subtotal' => $subtotal,
  9830.                             );
  9831.                             break;
  9832.                         case 6//Entertaiment
  9833.                             $pax $item->getPax();
  9834.                             if (empty($pax) or $pax == "0") {
  9835.                                 $pax 1;
  9836.                             }
  9837.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9838.                             if ($days 1) {
  9839.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9840.                             } else {
  9841.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9842.                             }
  9843.                             $unitsServ $item->getUnits();
  9844.                             if (empty($unitsServ) or $unitsServ == "0") {
  9845.                                 $unitsServ 1;
  9846.                             }
  9847.                             $subtotal $subtotalService $days $unitsServ $pax;
  9848.                             $subnetoUnit $subneto;
  9849.                             $subneto $subneto $days $unitsServ $pax;
  9850.                             $data_supplier['service'][$i] = array(
  9851.                                 'id' => $item->getId(),
  9852.                                 'serviceCatId' => $item->getServiceCatId(),
  9853.                                 'serviceName' => $item->getName(),
  9854.                                 'serviceType' => 'Entretenimiento',
  9855.                                 'date' => $dateServ,
  9856.                                 'qty' => $unitsServ,
  9857.                                 'iva' => $item->getIva(),
  9858.                                 'pax' => $item->getPax(),
  9859.                                 'precioUnit' => $subnetoUnit,
  9860.                                 'subneto' => $subneto,
  9861.                                 'subtotal' => $subtotal,
  9862.                             );
  9863.                             break;
  9864.                         case 7// Gifts
  9865.                             $pax $item->getPax();
  9866.                             if (empty($pax) or $pax == "0") {
  9867.                                 $pax 1;
  9868.                             }
  9869.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9870.                             $days 1;
  9871.                             if ($days 1) {
  9872.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9873.                             } else {
  9874.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9875.                             }
  9876.                             $unitsServ $item->getUnits();
  9877.                             if (empty($unitsServ) or $unitsServ == "0") {
  9878.                                 $unitsServ 1;
  9879.                             }
  9880.                             $subtotal $subtotalService $days $unitsServ $pax;
  9881.                             $subnetoUnit $subneto;
  9882.                             $subneto $subneto $days $unitsServ $pax;
  9883.                             $data_supplier['service'][$i] = array(
  9884.                                 'id' => $item->getId(),
  9885.                                 'serviceCatId' => $item->getServiceCatId(),
  9886.                                 'serviceName' => $item->getName(),
  9887.                                 'serviceType' => 'Regalos',
  9888.                                 'date' => $dateServ,
  9889.                                 'qty' => $unitsServ,
  9890.                                 'iva' => $item->getIva(),
  9891.                                 'pax' => $item->getPax(),
  9892.                                 'precioUnit' => $subnetoUnit,
  9893.                                 'subneto' => $subneto,
  9894.                                 'subtotal' => $subtotal,
  9895.                             );
  9896.                             break;
  9897.                         case 8//Guide
  9898.                             $pax $item->getPax();
  9899.                             if (empty($pax) or $pax == "0") {
  9900.                                 $pax 1;
  9901.                             }
  9902.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9903.                             if ($days 1) {
  9904.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9905.                             } else {
  9906.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9907.                             }
  9908.                             $unitsServ $item->getUnits();
  9909.                             if (empty($unitsServ) or $unitsServ == "0") {
  9910.                                 $unitsServ 1;
  9911.                             }
  9912.                             $subtotal $subtotalService $days $unitsServ $pax;
  9913.                             $subnetoUnit $subneto;
  9914.                             $subneto $subneto $days $unitsServ $pax;
  9915.                             $data_supplier['service'][$i] = array(
  9916.                                 'id' => $item->getId(),
  9917.                                 'serviceCatId' => $item->getServiceCatId(),
  9918.                                 'serviceName' => $item->getName(),
  9919.                                 'serviceType' => 'Regalos',
  9920.                                 'date' => $dateServ,
  9921.                                 'qty' => $unitsServ,
  9922.                                 'iva' => $item->getIva(),
  9923.                                 'pax' => $item->getPax(),
  9924.                                 'precioUnit' => $subnetoUnit,
  9925.                                 'subneto' => $subneto,
  9926.                                 'subtotal' => $subtotal,
  9927.                             );
  9928.                             break;
  9929.                         case 9//Itineraries
  9930.                             $pax $item->getPax();
  9931.                             if (empty($pax) or $pax == "0") {
  9932.                                 $pax 1;
  9933.                             }
  9934.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9935.                             if ($days 1) {
  9936.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9937.                             } else {
  9938.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9939.                             }
  9940.                             $unitsServ $item->getUnits();
  9941.                             if (empty($unitsServ) or $unitsServ == "0") {
  9942.                                 $unitsServ 1;
  9943.                             }
  9944.                             $subtotal $subtotalService $days $unitsServ $pax;
  9945.                             $subnetoUnit $subneto;
  9946.                             $subneto $subneto $days $unitsServ $pax;
  9947.                             $data_supplier['service'][$i] = array(
  9948.                                 'id' => $item->getId(),
  9949.                                 'serviceCatId' => $item->getServiceCatId(),
  9950.                                 'serviceName' => $item->getName(),
  9951.                                 'serviceType' => 'Itinerarios',
  9952.                                 'date' => $dateServ,
  9953.                                 'qty' => $unitsServ,
  9954.                                 'iva' => $item->getIva(),
  9955.                                 'pax' => $item->getPax(),
  9956.                                 'precioUnit' => $subnetoUnit,
  9957.                                 'subneto' => $subneto,
  9958.                                 'subtotal' => $subtotal,
  9959.                             );
  9960.                             break;
  9961.                         case 10//Lounge  -- No Aplica
  9962.                             //                        $pax = $item->getPax();
  9963.                             //                        if (empty($pax) or $pax == "0") {
  9964.                             //                            $pax = 1;
  9965.                             //                        }
  9966.                             //
  9967.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9968.                             //                        if ($days > 1){
  9969.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9970.                             //                        } else {
  9971.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9972.                             //                        }
  9973.                             //
  9974.                             //                        $unitsServ = $item->getUnits();
  9975.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  9976.                             //                            $unitsServ = 1;
  9977.                             //                        }
  9978.                             //
  9979.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  9980.                             //                        $subnetoUnit = $subneto;
  9981.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  9982.                             //
  9983.                             //                        $data_supplier['service'][$i] = array (
  9984.                             //                            'id' => $item->getId(),
  9985.                             //                            'serviceCatId' => $item->getServiceCatId(),
  9986.                             //                            'serviceName' => $item->getName(),
  9987.                             //                            'serviceType' => 'Itinerarios',
  9988.                             //                            'date' => $dateServ,
  9989.                             //                            'qty' => $unitsServ,
  9990.                             //                            'iva' => $item->getIva(),
  9991.                             //                            'pax' => $item->getPax(),
  9992.                             //                            'precioUnit' => $subnetoUnit,
  9993.                             //                            'subneto' => $subneto,
  9994.                             //                            'subtotal' => $subtotal,
  9995.                             //                        );
  9996.                             break;
  9997.                         case 11//Menu
  9998.                             $pax $item->getPax();
  9999.                             if (empty($pax) or $pax == "0") {
  10000.                                 $pax 1;
  10001.                             }
  10002.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10003.                             if ($days 1) {
  10004.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10005.                             } else {
  10006.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10007.                             }
  10008.                             $unitsServ $item->getUnits();
  10009.                             if (empty($unitsServ) or $unitsServ == "0") {
  10010.                                 $unitsServ 1;
  10011.                             }
  10012.                             $subtotal $subtotalService $days $unitsServ $pax;
  10013.                             $subnetoUnit $subneto;
  10014.                             $subneto $subneto $days $unitsServ $pax;
  10015.                             $data_supplier['service'][$i] = array(
  10016.                                 'id' => $item->getId(),
  10017.                                 'serviceCatId' => $item->getServiceCatId(),
  10018.                                 'serviceName' => $item->getName(),
  10019.                                 'serviceType' => 'MenĂº',
  10020.                                 'date' => $dateServ,
  10021.                                 'qty' => $unitsServ,
  10022.                                 'iva' => $item->getIva(),
  10023.                                 'pax' => $item->getPax(),
  10024.                                 'precioUnit' => $subnetoUnit,
  10025.                                 'subneto' => $subneto,
  10026.                                 'subtotal' => $subtotal,
  10027.                             );
  10028.                             break;
  10029.                         case 12//Others
  10030.                             $pax $item->getPax();
  10031.                             if (empty($pax) or $pax == "0") {
  10032.                                 $pax 1;
  10033.                             }
  10034.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10035.                             if ($days 1) {
  10036.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10037.                             } else {
  10038.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10039.                             }
  10040.                             $unitsServ $item->getUnits();
  10041.                             if (empty($unitsServ) or $unitsServ == "0") {
  10042.                                 $unitsServ 1;
  10043.                             }
  10044.                             $subtotal $subtotalService $days $unitsServ $pax;
  10045.                             $subnetoUnit $subneto;
  10046.                             $subneto $subneto $days $unitsServ $pax;
  10047.                             $data_supplier['service'][$i] = array(
  10048.                                 'id' => $item->getId(),
  10049.                                 'serviceCatId' => $item->getServiceCatId(),
  10050.                                 'serviceName' => $item->getName(),
  10051.                                 'serviceType' => 'Otros',
  10052.                                 'date' => $dateServ,
  10053.                                 'qty' => $unitsServ,
  10054.                                 'iva' => $item->getIva(),
  10055.                                 'pax' => $item->getPax(),
  10056.                                 'precioUnit' => $subnetoUnit,
  10057.                                 'subneto' => $subneto,
  10058.                                 'subtotal' => $subtotal,
  10059.                             );
  10060.                             break;
  10061.                         case 13//Transport
  10062.                             $pax $item->getPax();
  10063.                             if (empty($pax) or $pax == "0") {
  10064.                                 $pax 1;
  10065.                             }
  10066.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10067.                             if ($days 1) {
  10068.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10069.                             } else {
  10070.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10071.                             }
  10072.                             $unitsServ $item->getUnits();
  10073.                             if (empty($unitsServ) or $unitsServ == "0") {
  10074.                                 $unitsServ 1;
  10075.                             }
  10076.                             $subtotal $subtotalService $days $unitsServ $pax;
  10077.                             $subnetoUnit $subneto;
  10078.                             $subneto $subneto $days $unitsServ $pax;
  10079.                             $data_supplier['service'][$i] = array(
  10080.                                 'id' => $item->getId(),
  10081.                                 'serviceCatId' => $item->getServiceCatId(),
  10082.                                 'serviceName' => $item->getName(),
  10083.                                 'serviceType' => 'Transporte',
  10084.                                 'date' => $dateServ,
  10085.                                 'qty' => $unitsServ,
  10086.                                 'iva' => $item->getIva(),
  10087.                                 'pax' => $item->getPax(),
  10088.                                 'precioUnit' => $subnetoUnit,
  10089.                                 'subneto' => $subneto,
  10090.                                 'subtotal' => $subtotal,
  10091.                             );
  10092.                             break;
  10093.                         case 14//Technology
  10094.                             $pax $item->getPax();
  10095.                             if (empty($pax) or $pax == "0") {
  10096.                                 $pax 1;
  10097.                             }
  10098.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  10099.                             $days 1;
  10100.                             //                        if ($days > 1){
  10101.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  10102.                             //                        } else {
  10103.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10104.                             //                        }
  10105.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10106.                             $unitsServ $item->getUnits();
  10107.                             if (empty($unitsServ) or $unitsServ == "0") {
  10108.                                 $unitsServ 1;
  10109.                             }
  10110.                             $subtotal $subtotalService $days $unitsServ $pax;
  10111.                             $subnetoUnit $subneto;
  10112.                             $subneto $subneto $days $unitsServ $pax;
  10113.                             $data_supplier['service'][$i] = array(
  10114.                                 'id' => $item->getId(),
  10115.                                 'serviceCatId' => $item->getServiceCatId(),
  10116.                                 'serviceName' => $item->getName(),
  10117.                                 'serviceType' => 'TecnologĂ­a',
  10118.                                 'date' => $dateServ,
  10119.                                 'qty' => $unitsServ,
  10120.                                 'iva' => $item->getIva(),
  10121.                                 'pax' => $item->getPax(),
  10122.                                 'precioUnit' => $subnetoUnit,
  10123.                                 'subneto' => $subneto,
  10124.                                 'subtotal' => $subtotal,
  10125.                             );
  10126.                             break;
  10127.                         case 15//Assisstant
  10128.                             $pax $item->getPax();
  10129.                             if (empty($pax) or $pax == "0") {
  10130.                                 $pax 1;
  10131.                             }
  10132.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10133.                             if ($days 1) {
  10134.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10135.                             } else {
  10136.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10137.                             }
  10138.                             $unitsServ $item->getUnits();
  10139.                             if (empty($unitsServ) or $unitsServ == "0") {
  10140.                                 $unitsServ 1;
  10141.                             }
  10142.                             $subtotal $subtotalService $days $unitsServ $pax;
  10143.                             $subnetoUnit $subneto;
  10144.                             $subneto $subneto $days $unitsServ $pax;
  10145.                             $data_supplier['service'][$i] = array(
  10146.                                 'id' => $item->getId(),
  10147.                                 'serviceCatId' => $item->getServiceCatId(),
  10148.                                 'serviceName' => $item->getName(),
  10149.                                 'serviceType' => 'Asistente',
  10150.                                 'date' => $dateServ,
  10151.                                 'qty' => $unitsServ,
  10152.                                 'iva' => $item->getIva(),
  10153.                                 'pax' => $item->getPax(),
  10154.                                 'precioUnit' => $subnetoUnit,
  10155.                                 'subneto' => $subneto,
  10156.                                 'subtotal' => $subtotal,
  10157.                             );
  10158.                             break;
  10159.                         case 16//DDR
  10160.                             $pax $item->getPax();
  10161.                             if (empty($pax) or $pax == "0") {
  10162.                                 $pax 1;
  10163.                             }
  10164.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10165.                             if ($days 1) {
  10166.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10167.                             } else {
  10168.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10169.                             }
  10170.                             $unitsServ $item->getUnits();
  10171.                             if (empty($unitsServ) or $unitsServ == "0") {
  10172.                                 $unitsServ 1;
  10173.                             }
  10174.                             $subtotal $subtotalService $days $unitsServ $pax;
  10175.                             $subnetoUnit $subneto;
  10176.                             $subneto $subneto $days $unitsServ $pax;
  10177.                             $data_supplier['service'][$i] = array(
  10178.                                 'id' => $item->getId(),
  10179.                                 'serviceCatId' => $item->getServiceCatId(),
  10180.                                 'serviceName' => $item->getName(),
  10181.                                 'serviceType' => 'DDR',
  10182.                                 'date' => $dateServ,
  10183.                                 'qty' => $unitsServ,
  10184.                                 'iva' => $item->getIva(),
  10185.                                 'pax' => $item->getPax(),
  10186.                                 'precioUnit' => $subnetoUnit,
  10187.                                 'subneto' => $subneto,
  10188.                                 'subtotal' => $subtotal,
  10189.                             );
  10190.                             break;
  10191.                         default:
  10192.                             break;
  10193.                     }
  10194.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10195.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10196.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  10197.                     $arrayItems[] = array(
  10198.                         'type' => 'Service',
  10199.                         'name' => $item->getName(),
  10200.                         'amount' => $neto,
  10201.                         'iva' => $item->getIva(),
  10202.                         'total' => $subtotal,
  10203.                     );
  10204.                 }
  10205.                 switch ($item->getIva()) {
  10206.                         // Acumula IVA
  10207.                     case 21:
  10208.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  10209.                         break;
  10210.                     case 10:
  10211.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  10212.                         break;
  10213.                     case 0:
  10214.                         break;
  10215.                     default:
  10216.                         break;
  10217.                 }
  10218.             }
  10219.             $totales_neto_all $totales_neto_all $neto;
  10220.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10221.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  10222.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10223.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10224.             // Acumula netos totales e IVA
  10225.             $service['neto'] = $service['neto'] + $neto;
  10226.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  10227.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10228.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  10229.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  10230.             $i++;
  10231.         }
  10232.         $data_supplier['serviceSubTotal'] = array(
  10233.             'neto' => $service['neto'],
  10234.             'sumSubT' => $service['sumSubT'],
  10235.         );
  10236.         $currency '€';
  10237.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  10238.         if (!empty($payments)) {
  10239.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  10240.         } else {
  10241.             $amount_pay 0;
  10242.         }
  10243.         $totales_all $totales_total $amount_pay;
  10244.         if (empty($dateDocument)) {
  10245.             $dateDocument = new DateTime('now');
  10246.         }
  10247.         $data = array(
  10248.             'id' => $fileId,
  10249.             'type' => $type,
  10250.             'number' => $number,
  10251.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $fileId,
  10252.             'date' => $dateDocument,
  10253.             'file' => $file,
  10254.             'company' => $company,
  10255.             'clients' => $clientNew,
  10256.             'arrayItems' => $arrayItems,
  10257.             'datasupplier' => $data_supplier,
  10258.             'currency' => $currency,
  10259.             'totales_neto' => $totales_neto_all,
  10260.             'bases_imponibles' => $data_iva,
  10261.             'totales' => $totales_total,
  10262.             'balance' => $totales_all,
  10263.             'paymentInvoice' => $amount_pay,
  10264.         );
  10265.         return $data;
  10266.     }
  10267.     private function baseInvoiceDoneFile($fileId$invoiceId$typeBase)
  10268.     {
  10269.         $em $this->getDoctrine()->getManager();
  10270.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  10271.         $dateDocument null;                                                                           //Fecha final del documento
  10272.         $subneto 0;
  10273.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  10274.             if ($typeBase == 'I') {
  10275.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  10276.                 $arrayLocation = array();
  10277.                 $arrayLocationWithNull false;
  10278.                 foreach ($items as $item) {
  10279.                     if (!empty($item->getLocation())) {
  10280.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  10281.                     } else {
  10282.                         $arrayLocationWithNull true;
  10283.                     }
  10284.                 }
  10285.                 if ($arrayLocationWithNull) {
  10286.                     $arrayLocation['null'] = 'null';
  10287.                 }
  10288.                 $productsInFile = array();
  10289.                 foreach ($arrayLocation as $item) {
  10290.                     // VIDEO
  10291.                     $parameters = array(
  10292.                         'fileId' => $fileId,
  10293.                         'type' => 'VĂ­deo',
  10294.                         'location' => $item,
  10295.                         'invoiceId' => $invoiceId,
  10296.                     );
  10297.                     $dql 'SELECT i
  10298.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10299.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10300.                             ORDER BY i.rankAv ASC';
  10301.                     $query $em->createQuery($dql)->setParameters($parameters);
  10302.                     $productsInFileVid $query->getResult();
  10303.                     // SONIDO
  10304.                     $parameters = array(
  10305.                         'fileId' => $fileId,
  10306.                         'type' => 'Sonido',
  10307.                         'location' => $item,
  10308.                         'invoiceId' => $invoiceId,
  10309.                     );
  10310.                     $dql 'SELECT i
  10311.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10312.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10313.                             ORDER BY i.rankAv ASC';
  10314.                     $query $em->createQuery($dql)->setParameters($parameters);
  10315.                     $productsInFileSound $query->getResult();
  10316.                     // ILUMINACION
  10317.                     $parameters = array(
  10318.                         'fileId' => $fileId,
  10319.                         'type' => 'IluminaciĂ³n',
  10320.                         'location' => $item,
  10321.                         'invoiceId' => $invoiceId,
  10322.                     );
  10323.                     $dql 'SELECT i
  10324.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10325.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10326.                             ORDER BY i.rankAv ASC';
  10327.                     $query $em->createQuery($dql)->setParameters($parameters);
  10328.                     $productsInFileLights $query->getResult();
  10329.                     // OTROS
  10330.                     $parameters = array(
  10331.                         'fileId' => $fileId,
  10332.                         'typeV' => 'VĂ­deo',
  10333.                         'typeS' => 'Sonido',
  10334.                         'typeI' => 'IluminaciĂ³n',
  10335.                         'location' => $item,
  10336.                         'invoiceId' => $invoiceId,
  10337.                     );
  10338.                     $dql 'SELECT i
  10339.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10340.                             WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceId = :invoiceId)
  10341.                             ORDER BY i.rankAv ASC';
  10342.                     $query $em->createQuery($dql)->setParameters($parameters);
  10343.                     $productsInFileOther $query->getResult();
  10344.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10345.                     $parameters = array(
  10346.                         'fileId' => $fileId,
  10347.                         'location' => $item,
  10348.                         'invoiceId' => $invoiceId,
  10349.                     );
  10350.                     $dql 'SELECT i
  10351.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10352.                             WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceId = :invoiceId)
  10353.                             ORDER BY i.rankAv ASC';
  10354.                     $query $em->createQuery($dql)->setParameters($parameters);
  10355.                     $productsInFileNull $query->getResult();
  10356.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  10357.                     if ($item == 'null') {
  10358.                         // VIDEO
  10359.                         $parameters = array(
  10360.                             'fileId' => $fileId,
  10361.                             'type' => 'VĂ­deo',
  10362.                             'invoiceId' => $invoiceId,
  10363.                         );
  10364.                         $dql 'SELECT i
  10365.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10366.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10367.                                 ORDER BY i.rankAv ASC';
  10368.                         $query $em->createQuery($dql)->setParameters($parameters);
  10369.                         $productsInFileVid $query->getResult();
  10370.                         // SONIDO
  10371.                         $parameters = array(
  10372.                             'fileId' => $fileId,
  10373.                             'type' => 'Sonido',
  10374.                             'invoiceId' => $invoiceId,
  10375.                         );
  10376.                         $dql 'SELECT i
  10377.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10378.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10379.                                 ORDER BY i.rankAv ASC';
  10380.                         $query $em->createQuery($dql)->setParameters($parameters);
  10381.                         $productsInFileSound $query->getResult();
  10382.                         // ILUMINACION
  10383.                         $parameters = array(
  10384.                             'fileId' => $fileId,
  10385.                             'type' => 'IluminaciĂ³n',
  10386.                             'invoiceId' => $invoiceId,
  10387.                         );
  10388.                         $dql 'SELECT i
  10389.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10390.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10391.                                 ORDER BY i.rankAv ASC';
  10392.                         $query $em->createQuery($dql)->setParameters($parameters);
  10393.                         $productsInFileLights $query->getResult();
  10394.                         // OTROS
  10395.                         $parameters = array(
  10396.                             'fileId' => $fileId,
  10397.                             'typeV' => 'VĂ­deo',
  10398.                             'typeS' => 'Sonido',
  10399.                             'typeI' => 'IluminaciĂ³n',
  10400.                             'invoiceId' => $invoiceId,
  10401.                         );
  10402.                         $dql 'SELECT i
  10403.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10404.                                 WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location IS NULL AND i.invoiceId = :invoiceId)
  10405.                                 ORDER BY i.rankAv ASC';
  10406.                         $query $em->createQuery($dql)->setParameters($parameters);
  10407.                         $productsInFileOther $query->getResult();
  10408.                         // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10409.                         $parameters = array(
  10410.                             'fileId' => $fileId,
  10411.                             'invoiceId' => $invoiceId,
  10412.                         );
  10413.                         $dql 'SELECT i
  10414.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10415.                                 WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceId = :invoiceId)
  10416.                                 ORDER BY i.rankAv ASC';
  10417.                         $query $em->createQuery($dql)->setParameters($parameters);
  10418.                         $productsInFileNull $query->getResult();
  10419.                     }
  10420.                     $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  10421.                 }
  10422.                 $items $productsInFile;       // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
  10423.             } else {
  10424.                 // Es factura ni proforma
  10425.                 $items $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId'proformaId' => $invoiceId));
  10426.             }
  10427.         } else {
  10428.             // No es factura ni proforma, es una rectificativa
  10429.             $items $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  10430.             $arrayLocation = array();
  10431.             $arrayLocationWithNull false;
  10432.             foreach ($items as $item) {
  10433.                 if (!empty($item->getLocation())) {
  10434.                     $arrayLocation[$item->getLocation()] = $item->getLocation();
  10435.                 } else {
  10436.                     $arrayLocationWithNull true;
  10437.                 }
  10438.             }
  10439.             if ($arrayLocationWithNull) {
  10440.                 $arrayLocation['null'] = 'null';
  10441.             }
  10442.             $productsInFile = array();
  10443.             foreach ($arrayLocation as $item) {
  10444.                 // VIDEO
  10445.                 $parameters = array(
  10446.                     'fileId' => $fileId,
  10447.                     'type' => 'VĂ­deo',
  10448.                     'location' => $item,
  10449.                     'invoiceId' => $invoiceId,
  10450.                 );
  10451.                 $dql 'SELECT i
  10452.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10453.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10454.                         ORDER BY i.rankAv ASC';
  10455.                 $query $em->createQuery($dql)->setParameters($parameters);
  10456.                 $productsInFileVid $query->getResult();
  10457.                 // SONIDO
  10458.                 $parameters = array(
  10459.                     'fileId' => $fileId,
  10460.                     'type' => 'Sonido',
  10461.                     'location' => $item,
  10462.                     'invoiceId' => $invoiceId,
  10463.                 );
  10464.                 $dql 'SELECT i
  10465.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10466.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10467.                         ORDER BY i.rankAv ASC';
  10468.                 $query $em->createQuery($dql)->setParameters($parameters);
  10469.                 $productsInFileSound $query->getResult();
  10470.                 // ILUMINACION
  10471.                 $parameters = array(
  10472.                     'fileId' => $fileId,
  10473.                     'type' => 'IluminaciĂ³n',
  10474.                     'location' => $item,
  10475.                     'invoiceId' => $invoiceId,
  10476.                 );
  10477.                 $dql 'SELECT i
  10478.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10479.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10480.                         ORDER BY i.rankAv ASC';
  10481.                 $query $em->createQuery($dql)->setParameters($parameters);
  10482.                 $productsInFileLights $query->getResult();
  10483.                 // OTROS
  10484.                 $parameters = array(
  10485.                     'fileId' => $fileId,
  10486.                     'typeV' => 'VĂ­deo',
  10487.                     'typeS' => 'Sonido',
  10488.                     'typeI' => 'IluminaciĂ³n',
  10489.                     'location' => $item,
  10490.                     'invoiceId' => $invoiceId,
  10491.                 );
  10492.                 $dql 'SELECT i
  10493.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10494.                         WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceRecId = :invoiceId)
  10495.                         ORDER BY i.rankAv ASC';
  10496.                 $query $em->createQuery($dql)->setParameters($parameters);
  10497.                 $productsInFileOther $query->getResult();
  10498.                 // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10499.                 $parameters = array(
  10500.                     'fileId' => $fileId,
  10501.                     'location' => $item,
  10502.                     'invoiceId' => $invoiceId,
  10503.                 );
  10504.                 $dql 'SELECT i
  10505.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10506.                         WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceRecId = :invoiceId)
  10507.                         ORDER BY i.rankAv ASC';
  10508.                 $query $em->createQuery($dql)->setParameters($parameters);
  10509.                 $productsInFileNull $query->getResult();
  10510.                 // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  10511.                 if ($item == 'null') {
  10512.                     // VIDEO
  10513.                     $parameters = array(
  10514.                         'fileId' => $fileId,
  10515.                         'type' => 'VĂ­deo',
  10516.                         'invoiceId' => $invoiceId,
  10517.                     );
  10518.                     $dql 'SELECT i
  10519.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10520.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10521.                             ORDER BY i.rankAv ASC';
  10522.                     $query $em->createQuery($dql)->setParameters($parameters);
  10523.                     $productsInFileVid $query->getResult();
  10524.                     // SONIDO
  10525.                     $parameters = array(
  10526.                         'fileId' => $fileId,
  10527.                         'type' => 'Sonido',
  10528.                         'invoiceId' => $invoiceId,
  10529.                     );
  10530.                     $dql 'SELECT i
  10531.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10532.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10533.                             ORDER BY i.rankAv ASC';
  10534.                     $query $em->createQuery($dql)->setParameters($parameters);
  10535.                     $productsInFileSound $query->getResult();
  10536.                     // ILUMINACION
  10537.                     $parameters = array(
  10538.                         'fileId' => $fileId,
  10539.                         'type' => 'IluminaciĂ³n',
  10540.                         'invoiceId' => $invoiceId,
  10541.                     );
  10542.                     $dql 'SELECT i
  10543.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10544.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10545.                             ORDER BY i.rankAv ASC';
  10546.                     $query $em->createQuery($dql)->setParameters($parameters);
  10547.                     $productsInFileLights $query->getResult();
  10548.                     // OTROS
  10549.                     $parameters = array(
  10550.                         'fileId' => $fileId,
  10551.                         'typeV' => 'VĂ­deo',
  10552.                         'typeS' => 'Sonido',
  10553.                         'typeI' => 'IluminaciĂ³n',
  10554.                         'invoiceId' => $invoiceId,
  10555.                     );
  10556.                     $dql 'SELECT i
  10557.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10558.                             WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location IS NULL AND i.invoiceRecId = :invoiceId)
  10559.                             ORDER BY i.rankAv ASC';
  10560.                     $query $em->createQuery($dql)->setParameters($parameters);
  10561.                     $productsInFileOther $query->getResult();
  10562.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10563.                     $parameters = array(
  10564.                         'fileId' => $fileId,
  10565.                         'invoiceId' => $invoiceId,
  10566.                     );
  10567.                     $dql 'SELECT i
  10568.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10569.                             WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceRecId = :invoiceId)
  10570.                             ORDER BY i.rankAv ASC';
  10571.                     $query $em->createQuery($dql)->setParameters($parameters);
  10572.                     $productsInFileNull $query->getResult();
  10573.                 }
  10574.                 $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  10575.             }
  10576.             $items $productsInFile;       // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
  10577.         }
  10578.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority(4);
  10579.         $client $em->getRepository(Client::class)->findById($file->getClient());
  10580.         if (empty($client)) {
  10581.             $client[0] = new Client();
  10582.             $client[0]->setName('');
  10583.             $client[0]->setTitle('');
  10584.             $client[0]->setIdDocument('');
  10585.             $client[0]->setPopulation('');
  10586.             $client[0]->setRegion('');
  10587.             $client[0]->setCountry('');
  10588.         } else {
  10589.             if (is_numeric($client[0]->getPopulation())) {
  10590.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  10591. //                $client[0]->setPopulation($city->getCity());
  10592.             }
  10593.             if (is_numeric($client[0]->getRegion())) {
  10594.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  10595. //                $client[0]->setRegion($region->getRegion());
  10596.             }
  10597.             if (is_numeric($client[0]->getCountry())) {
  10598.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  10599. //                $client[0]->setCountry($country->getCountry());
  10600.             }
  10601.         }
  10602.         if (empty($client)) {
  10603.             $client[0] = new Client();
  10604.             $client[0]->setName('');
  10605.             $client[0]->setTitle('');
  10606.             $client[0]->setIdDocument('');
  10607.             $client[0]->setPopulation('');
  10608.             $client[0]->setRegion('');
  10609.             $client[0]->setCountry('');
  10610.             $clientNew = array(
  10611.                 'name' => '',
  10612.                 'title' => '',
  10613.                 'idDocument' => '',
  10614.                 'population' => '',
  10615.                 'region' => '',
  10616.                 'country' => '',
  10617.                 'address' => '',
  10618.                 'addressNumber' => '',
  10619.                 'zipCode' => '',
  10620.                 'typeDocument' => '',
  10621.             );
  10622.         } else {
  10623.             $clientNew = array(
  10624.                 'name' => $client[0]->getName(),
  10625.                 'title' => $client[0]->getTitle(),
  10626.                 'idDocument' => $client[0]->getIdDocument(),
  10627.                 'population' => '',
  10628.                 'region' => '',
  10629.                 'country' => '',
  10630.                 'address' => $client[0]->getAddress(),
  10631.                 'addressNumber' => $client[0]->getAddressNumber(),
  10632.                 'zipCode' => $client[0]->getZipCode(),
  10633.                 'typeDocument' => $client[0]->getTypeDocument(),
  10634.             );
  10635.             if (is_numeric($client[0]->getPopulation())) {
  10636.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  10637.                 $clientNew['population'] = $city->getCity();
  10638.             }
  10639.             if (is_numeric($client[0]->getRegion())) {
  10640.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  10641.                 $clientNew['region'] = $region->getRegion();
  10642.             }
  10643.             if (is_numeric($client[0]->getCountry())) {
  10644.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  10645.                 $clientNew['country'] = $country->getCountry();
  10646.             }
  10647.         }
  10648.         // Acumuladores de los calculos
  10649.         $totales_neto_all 0;
  10650.         $data_iva = array(
  10651.             'iva' => 21,
  10652.             'ivaMontoVeintiUno' => 0,
  10653.             'ivaMontoDiez' => 0,
  10654.             'ivaMontoCero' => null,
  10655.         );
  10656.         //INICIO: Determinamos el numero de factura o proforma
  10657.         if ($typeBase == 'I') {
  10658.             // Es una Factura
  10659.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  10660.             $dateDocument $number->getDateAt();
  10661.             $number $number->getNumber();
  10662.             $type 'Invoice';
  10663.         } else {
  10664.             if ($typeBase == 'R') {
  10665.                 // Es una factura rectificativa
  10666.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  10667.                 $dateDocument $number->getDateAt();
  10668.                 $type 'Invoice Rec';
  10669.             } else {
  10670.                 // Es una Proforma
  10671.                 $number $invoiceId;
  10672.                 $type 'Proforma';
  10673.             }
  10674.         }
  10675.         //FIN: Determinamos el numero de factura o proforma
  10676.         // Buscamos los productos, pagos y servicios
  10677.         $arrayItems = array();
  10678.         $fileProducts = array();
  10679.         $payments = array();
  10680.         $services = array();
  10681.         if (!empty($items)) {
  10682.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10683.                 foreach ($items as $item) {
  10684.                     switch ($item->getItemType()) {
  10685.                         case 'PRODUCT'// Producto
  10686.                             $fileProducts[] = $item;
  10687.                             break;
  10688.                         case 'PAYMENT'// Pago
  10689.                             $payments[] = $item;
  10690.                             break;
  10691.                         case 'SERVICE'// Servicio
  10692.                             $services[] = $item;
  10693.                             break;
  10694.                         default:
  10695.                             break;
  10696.                     }
  10697.                 }
  10698.             } else {
  10699.                 // Es una proforma
  10700.                 foreach ($items as $item) {
  10701.                     switch ($item->getType()) {
  10702.                         case 'PRODUCT'// Producto
  10703.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  10704.                             if (!empty($productPro)) {
  10705.                                 $fileProducts[] = $productPro;
  10706.                             }
  10707.                             break;
  10708.                         case 'PAYMENT'// Pago
  10709.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  10710.                             if (!empty($paymentPro)) {
  10711.                                 $payments[] = $paymentPro;
  10712.                             }
  10713.                             break;
  10714.                         case 'SERVICE'// Servicio
  10715.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  10716.                             if (!empty($servicePro)) {
  10717.                                 $services[] = $servicePro;
  10718.                             }
  10719.                             break;
  10720.                         default:
  10721.                             break;
  10722.                     }
  10723.                 }
  10724.             }
  10725.         }
  10726.         $data_supplier = array();
  10727.         $i 0;
  10728.         $pax '1';
  10729.         $qty '1';
  10730.         $product = array(
  10731.             'neto' => 0,
  10732.             'sumSubT' => 0,
  10733.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10734.         $service = array(
  10735.             'neto' => 0,
  10736.             'sumSubT' => 0,
  10737.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10738.         foreach ($fileProducts as $item) {
  10739.             $days = ((($item->getPrdDateEnd())->diff($item->getPrdDateStart()))->days 1);
  10740.             if (!is_null($item->getPrdDays()) or !empty($item->getPrdDays())) {
  10741.                 $days $item->getPrdDays();
  10742.             }
  10743.             if (!is_null($item->getPrdQty()) or !empty($item->getPrdQty())) {
  10744.                 $qty $item->getPrdQty();
  10745.             }
  10746.             if (!empty($item->getPrdDays())) {
  10747.                 $days $item->getPrdDays();
  10748.             }
  10749.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10750.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
  10751.                     $subtotal 0;
  10752.                     $neto 0;
  10753.                     $subtotalProduct 0;
  10754.                 } else {
  10755.                     //Buscamos el iva
  10756.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10757.                     if (empty($zProductFile)) {
  10758.                         $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId());
  10759.                     }
  10760.                     if (empty($zProductFile)) {
  10761.                         $zProductFile = new AveProductFile;
  10762.                         $zProductFile->setIva(21);
  10763.                     }             // No se consigue el iva, se obliga a 21%
  10764.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  10765.                     
  10766.                     if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)) {
  10767.                         $ivaFactor = ($item->getPrdIva()) / 100;
  10768.                     }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  10769.                     $subtotalProduct $item->getPrdSubTotalPrice() * ($ivaFactor);
  10770.                     $subneto $item->getPrdSubTotalPrice();
  10771.                     $subtotal =  $subtotalProduct;
  10772.                     $neto =  $subneto;
  10773.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10774.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10775.                     $neto round($neto2PHP_ROUND_HALF_UP);
  10776.                     $arrayItems[] = array(
  10777.                         'type' => 'Product',
  10778.                         'name' => $item->getPrdName(),
  10779.                         'amount' => $neto,
  10780.                         'iva' => $zProductFile->getIva(),
  10781.                         'total' => $subtotal,
  10782.                     );
  10783.                     $ivaFactor = ($ivaFactor 100);
  10784.                     switch ($ivaFactor){
  10785.                         case 21:
  10786.                             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  10787.                             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10788.                             break;
  10789.                         case 10:
  10790.                             $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  10791.                             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10792.                             break;
  10793.                         case 0:
  10794.                             $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  10795.                             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  10796.                             break;
  10797.                         default:
  10798.                             $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  10799.                             $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  10800.                             break;
  10801.                     }
  10802.                 }
  10803.             } else {
  10804.                 // Es proforma
  10805.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  10806.                     $subtotal 0;
  10807.                     $neto 0;
  10808.                     $subtotalProduct 0;
  10809.                 } else {
  10810.                     //Buscamos el iva
  10811.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10812.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  10813.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  10814.                     $subtotalProduct $item->getSubTotalPrice() * ($ivaFactor);
  10815.                     $subneto $item->getSubTotalPrice();
  10816.                     $subtotal =  $subtotalProduct;
  10817.                     $neto =  $subneto;
  10818.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10819.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10820.                     $neto round($neto2PHP_ROUND_HALF_UP);
  10821.                     $arrayItems[] = array(
  10822.                         'type' => 'Product',
  10823.                         'name' => $item->getProductName(),
  10824.                         'amount' => $neto,
  10825.                         'iva' => $zProductFile->getIva(),
  10826.                         'total' => $subtotal,
  10827.                     );
  10828.                     switch ($zProductFile->getIva()) {
  10829.                         case 21:
  10830.                             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  10831.                             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10832.                             break;
  10833.                         case 10:
  10834.                             $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  10835.                             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10836.                             break;
  10837.                         case 0:
  10838.                             $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  10839.                             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  10840.                             break;
  10841.                         default:
  10842.                             $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  10843.                             $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  10844.                             break;
  10845.                     }
  10846.                 }
  10847.             }
  10848.             // Acumula netos totales e IVA
  10849.             $totales_neto_all $totales_neto_all $neto;
  10850.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10851.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  10852.             // Acumula netos totales e IVA
  10853.             $product['neto'] = $product['neto'] + $neto;
  10854.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  10855.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10856.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  10857.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  10858.             // Calculo del precio unitario despues de aplicar Over y Comision
  10859.             $multiplo $qty * (float)$days;
  10860.             $item->setPrdServicePrice($subneto $multiplo);
  10861.             //Buscamos el iva
  10862.             $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10863.             if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  10864.             $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  10865.             if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)){ $ivaFactor $item->getPrdIva(); }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  10866.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10867.                 $data_supplier['product'][$i] = array(
  10868.                     'id' => $item->getId(),
  10869.                     'productName' => $item->getPrdName(),
  10870.                     'productId' => $item->getPrdProductId(),
  10871.                     'dateStart' => $item->getPrdDateStart(),
  10872.                     'dateEnd' => $item->getPrdDateEnd(),
  10873.                     'location' => $item->getLocation(),
  10874.                     'servicePrice' => $item->getPrdServicePrice(),
  10875.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  10876.                     'subtotalProduct' => $subtotalProduct,
  10877.                     'iva' => $ivaFactor,
  10878.                     'pax' => $pax,
  10879.                     'qty' => $qty,
  10880.                     'days' => $days,
  10881.                     'type' => $item->getPrdType(),
  10882.                     'subtotal' => $subtotal,
  10883.                 );
  10884.             } else {
  10885.                 // Es proforma
  10886.                 $data_supplier['product'][$i] = array(
  10887.                     'id' => $item->getId(),
  10888.                     'productName' => $item->getProductName(),
  10889.                     'productId' => $item->getProductId(),
  10890.                     'dateStart' => $item->getDateStart(),
  10891.                     'dateEnd' => $item->getDateEnd(),
  10892.                     'servicePrice' => $item->getServicePrice(),
  10893.                     'subtotalProduct' => $subtotalProduct,
  10894.                     'iva' => $ivaFactor,
  10895.                     'pax' => $pax,
  10896.                     'qty' => $qty,
  10897.                     'days' => $days,
  10898.                     'type' => $item->getType(),
  10899.                     'subtotal' => $subtotal,
  10900.                 );
  10901.             }
  10902.             $i++;
  10903.         }
  10904.         $data_supplier['productSubTotal'] = array(
  10905.             'neto' => $product['neto'],
  10906.             'sumSubT' => $product['sumSubT'],
  10907.         );
  10908.         $payment = array(
  10909.             'sumSubT' => 0,
  10910.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10911.         $i 0;
  10912.         foreach ($payments as $item) {
  10913.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10914.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  10915.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10916.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  10917.                 $data_supplier['payment'][$i] = array(
  10918.                     'id' => $item->getId(),
  10919.                     'amount' => $item->getPayAmount(),
  10920.                     'amountTotal' => $item->getPayAmountTotal(),
  10921.                     'vat' => $item->getPayVat(),
  10922.                     'datePayAt' => $item->getPayDatePayAt(),
  10923.                     'wayToPay' => $item->getPayWayToPay(),
  10924.                 );
  10925.                 $arrayItems[] = array(
  10926.                     'type' => 'Payment',
  10927.                     'name' => $item->getPayWayToPay(),
  10928.                     'amount' => $item->getPayAmount(),
  10929.                     'total' => $item->getPayAmountTotal(),
  10930.                     'iva' => $item->getPayVat(),
  10931.                 );
  10932.             } else {
  10933.                 // Es una proforma
  10934.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  10935.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10936.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  10937.                 $data_supplier['payment'][$i] = array(
  10938.                     'id' => $item->getId(),
  10939.                     'amount' => $item->getAmount(),
  10940.                     'amountTotal' => $item->getAmountTotal(),
  10941.                     'vat' => $item->getVat(),
  10942.                     'datePayAt' => $item->getDatePayAt(),
  10943.                     'wayToPay' => $item->getWayToPay(),
  10944.                 );
  10945.                 $arrayItems[] = array(
  10946.                     'type' => 'Payment',
  10947.                     'name' => $item->getWayToPay(),
  10948.                     'amount' => $item->getAmount(),
  10949.                     'total' => $item->getAmountTotal(),
  10950.                     'iva' => $item->getVat(),
  10951.                 );
  10952.             }
  10953.             $i++;
  10954.         }
  10955.         if (!empty($payments)) {
  10956.             $data_supplier['paymentSubTotal'] = array(
  10957.                 'sumSubT' => $payment['sumSubT'],
  10958.             );
  10959.         }
  10960.         foreach ($services as $item) {
  10961.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10962.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  10963.                     $subtotal 0;
  10964.                     $neto 0;
  10965.                     $subtotalService 0;
  10966.                 } else {
  10967.                     $subtotalService $item->getSrvPrice();
  10968.                     $subneto $item->getSrvPrice();
  10969.                     // Commission
  10970.                     if ($item->getSrvOpCommission() == '1') {
  10971.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  10972.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  10973.                     } else {
  10974.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  10975.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  10976.                     }
  10977.                     // Over
  10978.                     if ($item->getSrvOpOver() == '1') {
  10979.                         $subtotalService $subtotalService $item->getSrvOver();
  10980.                         $subneto $subneto $item->getSrvOver();
  10981.                     } else {
  10982.                         $subtotalService $subtotalService $item->getSrvOver();
  10983.                         $subneto $subneto $item->getSrvOver();
  10984.                     }
  10985.                     // IVA
  10986.                     if ($item->getSrvOpIva() == '1') {
  10987.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  10988.                     } else {
  10989.                         $subtotalService $item->getSrvPrice();
  10990.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  10991.                     }
  10992.                     switch ($item->getSrvServiceCatId()) {
  10993.                         case 1// Alojamiento
  10994.                             // el numero de noches $numNoches; precio unitario $subneto
  10995.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  10996.                             // La personas no afectan este calculo
  10997.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  10998.                             $subnetoUnit $subneto;
  10999.                             $subneto $subneto $numNoches $item->getSrvUnits();
  11000.                             $data_supplier['service'][$i] = array(
  11001.                                 'id' => $item->getId(),
  11002.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11003.                                 'serviceName' => $item->getSrvName(),
  11004.                                 'serviceType' => 'Hotel',
  11005.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  11006.                                 'qty' => $item->getSrvUnits(),
  11007.                                 'iva' => $item->getSrvIva(),
  11008.                                 'pax' => '-',
  11009.                                 'precioUnit' => $subnetoUnit,
  11010.                                 'subneto' => $subneto,
  11011.                                 'subtotal' => $subtotal,
  11012.                             );
  11013.                             break;
  11014.                         case 2//Actividades
  11015.                             // El nĂºmero de personas es considerado en el calculo
  11016.                             $pax $item->getSrvPax();
  11017.                             if (empty($pax) or $pax == "0") {
  11018.                                 $pax 1;
  11019.                             }
  11020.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11021.                             if ($days 1) {
  11022.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11023.                             } else {
  11024.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11025.                             }
  11026.                             $subtotal $subtotalService $days $item->getSrvUnits();
  11027.                             $subnetoUnit $subneto;
  11028.                             $subneto $subneto $days $item->getSrvUnits();
  11029.                             $data_supplier['service'][$i] = array(
  11030.                                 'id' => $item->getId(),
  11031.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11032.                                 'serviceName' => $item->getSrvName(),
  11033.                                 'serviceType' => 'Actividad',
  11034.                                 'date' => $dateServ,
  11035.                                 'qty' => $item->getSrvUnits(),
  11036.                                 'iva' => $item->getSrvIva(),
  11037.                                 'pax' => $item->getSrvPax(),
  11038.                                 'precioUnit' => $subnetoUnit,
  11039.                                 'subneto' => $subneto,
  11040.                                 'subtotal' => $subtotal,
  11041.                             );
  11042.                             break;
  11043.                         case 3// AV
  11044.                             $pax $item->getSrvPax();
  11045.                             if (empty($pax) or $pax == "0") {
  11046.                                 $pax 1;
  11047.                             }
  11048.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11049.                             if ($days 1) {
  11050.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11051.                             } else {
  11052.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11053.                             }
  11054.                             $unitsServ $item->getSrvUnits();
  11055.                             if (empty($unitsServ) or $unitsServ == "0") {
  11056.                                 $unitsServ 1;
  11057.                             }
  11058.                             $subtotal $subtotalService $days $unitsServ $pax;
  11059.                             $subnetoUnit $subneto;
  11060.                             $subneto $subneto $days $unitsServ $pax;
  11061.                             $data_supplier['service'][$i] = array(
  11062.                                 'id' => $item->getId(),
  11063.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11064.                                 'serviceName' => $item->getSrvName(),
  11065.                                 'serviceType' => 'AV',
  11066.                                 'date' => $dateServ,
  11067.                                 'qty' => $unitsServ,
  11068.                                 'iva' => $item->getSrvIva(),
  11069.                                 'pax' => $item->getSrvPax(),
  11070.                                 'precioUnit' => $subnetoUnit,
  11071.                                 'subneto' => $subneto,
  11072.                                 'subtotal' => $subtotal,
  11073.                             );
  11074.                             break;
  11075.                         case 4//Creative
  11076.                             $pax $item->getSrvPax();
  11077.                             if (empty($pax) or $pax == "0") {
  11078.                                 $pax 1;
  11079.                             }
  11080.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11081.                             if ($days 1) {
  11082.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11083.                             } else {
  11084.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11085.                             }
  11086.                             $unitsServ $item->getSrvUnits();
  11087.                             if (empty($unitsServ) or $unitsServ == "0") {
  11088.                                 $unitsServ 1;
  11089.                             }
  11090.                             $subtotal $subtotalService $days $unitsServ $pax;
  11091.                             $subnetoUnit $subneto;
  11092.                             $subneto $subneto $days $unitsServ $pax;
  11093.                             $data_supplier['service'][$i] = array(
  11094.                                 'id' => $item->getId(),
  11095.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11096.                                 'serviceName' => $item->getSrvName(),
  11097.                                 'serviceType' => 'Creativo',
  11098.                                 'date' => $dateServ,
  11099.                                 'qty' => $unitsServ,
  11100.                                 'iva' => $item->getSrvIva(),
  11101.                                 'pax' => $item->getSrvPax(),
  11102.                                 'precioUnit' => $subnetoUnit,
  11103.                                 'subneto' => $subneto,
  11104.                                 'subtotal' => $subtotal,
  11105.                             );
  11106.                             break;
  11107.                         case 5//Cruise
  11108.                             $pax $item->getSrvPax();
  11109.                             if (empty($pax) or $pax == "0") {
  11110.                                 $pax 1;
  11111.                             }
  11112.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  11113.                             if ($days 1) {
  11114.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11115.                             } else {
  11116.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11117.                             }
  11118.                             $unitsServ $item->getSrvUnits();
  11119.                             if (empty($unitsServ) or $unitsServ == "0") {
  11120.                                 $unitsServ 1;
  11121.                             }
  11122.                             $subtotal $subtotalService $days $unitsServ $pax;
  11123.                             $subnetoUnit $subneto;
  11124.                             $subneto $subneto $days $unitsServ $pax;
  11125.                             $data_supplier['service'][$i] = array(
  11126.                                 'id' => $item->getId(),
  11127.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11128.                                 'serviceName' => $item->getSrvName(),
  11129.                                 'serviceType' => 'Crucero',
  11130.                                 'date' => $dateServ,
  11131.                                 'qty' => $unitsServ,
  11132.                                 'iva' => $item->getSrvIva(),
  11133.                                 'pax' => $item->getSrvPax(),
  11134.                                 'precioUnit' => $subnetoUnit,
  11135.                                 'subneto' => $subneto,
  11136.                                 'subtotal' => $subtotal,
  11137.                             );
  11138.                             break;
  11139.                         case 6//Entertaiment
  11140.                             $pax $item->getSrvPax();
  11141.                             if (empty($pax) or $pax == "0") {
  11142.                                 $pax 1;
  11143.                             }
  11144.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11145.                             if ($days 1) {
  11146.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11147.                             } else {
  11148.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11149.                             }
  11150.                             $unitsServ $item->getSrvUnits();
  11151.                             if (empty($unitsServ) or $unitsServ == "0") {
  11152.                                 $unitsServ 1;
  11153.                             }
  11154.                             $subtotal $subtotalService $days $unitsServ $pax;
  11155.                             $subnetoUnit $subneto;
  11156.                             $subneto $subneto $days $unitsServ $pax;
  11157.                             $data_supplier['service'][$i] = array(
  11158.                                 'id' => $item->getId(),
  11159.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11160.                                 'serviceName' => $item->getSrvName(),
  11161.                                 'serviceType' => 'Entretenimiento',
  11162.                                 'date' => $dateServ,
  11163.                                 'qty' => $unitsServ,
  11164.                                 'iva' => $item->getSrvIva(),
  11165.                                 'pax' => $item->getSrvPax(),
  11166.                                 'precioUnit' => $subnetoUnit,
  11167.                                 'subneto' => $subneto,
  11168.                                 'subtotal' => $subtotal,
  11169.                             );
  11170.                             break;
  11171.                         case 7// Gifts
  11172.                             $pax $item->getSrvPax();
  11173.                             if (empty($pax) or $pax == "0") {
  11174.                                 $pax 1;
  11175.                             }
  11176.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11177.                             $days 1;
  11178.                             if ($days 1) {
  11179.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11180.                             } else {
  11181.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11182.                             }
  11183.                             $unitsServ $item->getSrvUnits();
  11184.                             if (empty($unitsServ) or $unitsServ == "0") {
  11185.                                 $unitsServ 1;
  11186.                             }
  11187.                             $subtotal $subtotalService $days $unitsServ $pax;
  11188.                             $subnetoUnit $subneto;
  11189.                             $subneto $subneto $days $unitsServ $pax;
  11190.                             $data_supplier['service'][$i] = array(
  11191.                                 'id' => $item->getId(),
  11192.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11193.                                 'serviceName' => $item->getSrvName(),
  11194.                                 'serviceType' => 'Regalos',
  11195.                                 'date' => $dateServ,
  11196.                                 'qty' => $unitsServ,
  11197.                                 'iva' => $item->getSrvIva(),
  11198.                                 'pax' => $item->getSrvPax(),
  11199.                                 'precioUnit' => $subnetoUnit,
  11200.                                 'subneto' => $subneto,
  11201.                                 'subtotal' => $subtotal,
  11202.                             );
  11203.                             break;
  11204.                         case 8//Guide
  11205.                             $pax $item->getSrvPax();
  11206.                             if (empty($pax) or $pax == "0") {
  11207.                                 $pax 1;
  11208.                             }
  11209.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11210.                             if ($days 1) {
  11211.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11212.                             } else {
  11213.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11214.                             }
  11215.                             $unitsServ $item->getSrvUnits();
  11216.                             if (empty($unitsServ) or $unitsServ == "0") {
  11217.                                 $unitsServ 1;
  11218.                             }
  11219.                             $subtotal $subtotalService $days $unitsServ $pax;
  11220.                             $subnetoUnit $subneto;
  11221.                             $subneto $subneto $days $unitsServ $pax;
  11222.                             $data_supplier['service'][$i] = array(
  11223.                                 'id' => $item->getId(),
  11224.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11225.                                 'serviceName' => $item->getSrvName(),
  11226.                                 'serviceType' => 'Regalos',
  11227.                                 'date' => $dateServ,
  11228.                                 'qty' => $unitsServ,
  11229.                                 'iva' => $item->getSrvIva(),
  11230.                                 'pax' => $item->getSrvPax(),
  11231.                                 'precioUnit' => $subnetoUnit,
  11232.                                 'subneto' => $subneto,
  11233.                                 'subtotal' => $subtotal,
  11234.                             );
  11235.                             break;
  11236.                         case 9//Itineraries
  11237.                             $pax $item->getSrvPax();
  11238.                             if (empty($pax) or $pax == "0") {
  11239.                                 $pax 1;
  11240.                             }
  11241.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11242.                             if ($days 1) {
  11243.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11244.                             } else {
  11245.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11246.                             }
  11247.                             $unitsServ $item->getSrvUnits();
  11248.                             if (empty($unitsServ) or $unitsServ == "0") {
  11249.                                 $unitsServ 1;
  11250.                             }
  11251.                             $subtotal $subtotalService $days $unitsServ $pax;
  11252.                             $subnetoUnit $subneto;
  11253.                             $subneto $subneto $days $unitsServ $pax;
  11254.                             $data_supplier['service'][$i] = array(
  11255.                                 'id' => $item->getId(),
  11256.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11257.                                 'serviceName' => $item->getSrvName(),
  11258.                                 'serviceType' => 'Itinerarios',
  11259.                                 'date' => $dateServ,
  11260.                                 'qty' => $unitsServ,
  11261.                                 'iva' => $item->getSrvIva(),
  11262.                                 'pax' => $item->getSrvPax(),
  11263.                                 'precioUnit' => $subnetoUnit,
  11264.                                 'subneto' => $subneto,
  11265.                                 'subtotal' => $subtotal,
  11266.                             );
  11267.                             break;
  11268.                         case 10//Lounge  -- No Aplica
  11269.                             break;
  11270.                         case 11//Menu
  11271.                             $pax $item->getSrvPax();
  11272.                             if (empty($pax) or $pax == "0") {
  11273.                                 $pax 1;
  11274.                             }
  11275.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11276.                             if ($days 1) {
  11277.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11278.                             } else {
  11279.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11280.                             }
  11281.                             $unitsServ $item->getSrvUnits();
  11282.                             if (empty($unitsServ) or $unitsServ == "0") {
  11283.                                 $unitsServ 1;
  11284.                             }
  11285.                             $subtotal $subtotalService $days $unitsServ $pax;
  11286.                             $subnetoUnit $subneto;
  11287.                             $subneto $subneto $days $unitsServ $pax;
  11288.                             $data_supplier['service'][$i] = array(
  11289.                                 'id' => $item->getId(),
  11290.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11291.                                 'serviceName' => $item->getSrvName(),
  11292.                                 'serviceType' => 'MenĂº',
  11293.                                 'date' => $dateServ,
  11294.                                 'qty' => $unitsServ,
  11295.                                 'iva' => $item->getSrvIva(),
  11296.                                 'pax' => $item->getSrvPax(),
  11297.                                 'precioUnit' => $subnetoUnit,
  11298.                                 'subneto' => $subneto,
  11299.                                 'subtotal' => $subtotal,
  11300.                             );
  11301.                             break;
  11302.                         case 12//Others
  11303.                             $pax $item->getSrvPax();
  11304.                             if (empty($pax) or $pax == "0") {
  11305.                                 $pax 1;
  11306.                             }
  11307.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11308.                             if ($days 1) {
  11309.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11310.                             } else {
  11311.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11312.                             }
  11313.                             $unitsServ $item->getSrvUnits();
  11314.                             if (empty($unitsServ) or $unitsServ == "0") {
  11315.                                 $unitsServ 1;
  11316.                             }
  11317.                             $subtotal $subtotalService $days $unitsServ $pax;
  11318.                             $subnetoUnit $subneto;
  11319.                             $subneto $subneto $days $unitsServ $pax;
  11320.                             $data_supplier['service'][$i] = array(
  11321.                                 'id' => $item->getId(),
  11322.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11323.                                 'serviceName' => $item->getSrvName(),
  11324.                                 'serviceType' => 'Otros',
  11325.                                 'date' => $dateServ,
  11326.                                 'qty' => $unitsServ,
  11327.                                 'iva' => $item->getSrvIva(),
  11328.                                 'pax' => $item->getSrvPax(),
  11329.                                 'precioUnit' => $subnetoUnit,
  11330.                                 'subneto' => $subneto,
  11331.                                 'subtotal' => $subtotal,
  11332.                             );
  11333.                             break;
  11334.                         case 13//Transport
  11335.                             $pax $item->getSrvPax();
  11336.                             if (empty($pax) or $pax == "0") {
  11337.                                 $pax 1;
  11338.                             }
  11339.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11340.                             if ($days 1) {
  11341.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11342.                             } else {
  11343.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11344.                             }
  11345.                             $unitsServ $item->getSrvUnits();
  11346.                             if (empty($unitsServ) or $unitsServ == "0") {
  11347.                                 $unitsServ 1;
  11348.                             }
  11349.                             $subtotal $subtotalService $days $unitsServ $pax;
  11350.                             $subnetoUnit $subneto;
  11351.                             $subneto $subneto $days $unitsServ $pax;
  11352.                             $data_supplier['service'][$i] = array(
  11353.                                 'id' => $item->getId(),
  11354.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11355.                                 'serviceName' => $item->getSrvName(),
  11356.                                 'serviceType' => 'Transporte',
  11357.                                 'date' => $dateServ,
  11358.                                 'qty' => $unitsServ,
  11359.                                 'iva' => $item->getSrvIva(),
  11360.                                 'pax' => $item->getSrvPax(),
  11361.                                 'precioUnit' => $subnetoUnit,
  11362.                                 'subneto' => $subneto,
  11363.                                 'subtotal' => $subtotal,
  11364.                             );
  11365.                             break;
  11366.                         case 14//Technology
  11367.                             $pax $item->getSrvPax();
  11368.                             if (empty($pax) or $pax == "0") {
  11369.                                 $pax 1;
  11370.                             }
  11371.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11372.                             $days 1;
  11373.                             //                        if ($days > 1){
  11374.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  11375.                             //                        } else {
  11376.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11377.                             //                        }
  11378.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11379.                             $unitsServ $item->getSrvUnits();
  11380.                             if (empty($unitsServ) or $unitsServ == "0") {
  11381.                                 $unitsServ 1;
  11382.                             }
  11383.                             $subtotal $subtotalService $days $unitsServ $pax;
  11384.                             $subnetoUnit $subneto;
  11385.                             $subneto $subneto $days $unitsServ $pax;
  11386.                             $data_supplier['service'][$i] = array(
  11387.                                 'id' => $item->getId(),
  11388.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11389.                                 'serviceName' => $item->getSrvName(),
  11390.                                 'serviceType' => 'TecnologĂ­a',
  11391.                                 'date' => $dateServ,
  11392.                                 'qty' => $unitsServ,
  11393.                                 'iva' => $item->getSrvIva(),
  11394.                                 'pax' => $item->getSrvPax(),
  11395.                                 'precioUnit' => $subnetoUnit,
  11396.                                 'subneto' => $subneto,
  11397.                                 'subtotal' => $subtotal,
  11398.                             );
  11399.                             break;
  11400.                         case 15//Assisstant
  11401.                             $pax $item->getSrvPax();
  11402.                             if (empty($pax) or $pax == "0") {
  11403.                                 $pax 1;
  11404.                             }
  11405.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11406.                             if ($days 1) {
  11407.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11408.                             } else {
  11409.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11410.                             }
  11411.                             $unitsServ $item->getSrvUnits();
  11412.                             if (empty($unitsServ) or $unitsServ == "0") {
  11413.                                 $unitsServ 1;
  11414.                             }
  11415.                             $subtotal $subtotalService $days $unitsServ $pax;
  11416.                             $subnetoUnit $subneto;
  11417.                             $subneto $subneto $days $unitsServ $pax;
  11418.                             $data_supplier['service'][$i] = array(
  11419.                                 'id' => $item->getId(),
  11420.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11421.                                 'serviceName' => $item->getSrvName(),
  11422.                                 'serviceType' => 'Asistente',
  11423.                                 'date' => $dateServ,
  11424.                                 'qty' => $unitsServ,
  11425.                                 'iva' => $item->getSrvIva(),
  11426.                                 'pax' => $item->getSrvPax(),
  11427.                                 'precioUnit' => $subnetoUnit,
  11428.                                 'subneto' => $subneto,
  11429.                                 'subtotal' => $subtotal,
  11430.                             );
  11431.                             break;
  11432.                         case 16//DDR
  11433.                             $pax $item->getSrvPax();
  11434.                             if (empty($pax) or $pax == "0") {
  11435.                                 $pax 1;
  11436.                             }
  11437.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11438.                             if ($days 1) {
  11439.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11440.                             } else {
  11441.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11442.                             }
  11443.                             $unitsServ $item->getSrvUnits();
  11444.                             if (empty($unitsServ) or $unitsServ == "0") {
  11445.                                 $unitsServ 1;
  11446.                             }
  11447.                             $subtotal $subtotalService $days $unitsServ $pax;
  11448.                             $subnetoUnit $subneto;
  11449.                             $subneto $subneto $days $unitsServ $pax;
  11450.                             $data_supplier['service'][$i] = array(
  11451.                                 'id' => $item->getId(),
  11452.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11453.                                 'serviceName' => $item->getSrvName(),
  11454.                                 'serviceType' => 'DDR',
  11455.                                 'date' => $dateServ,
  11456.                                 'qty' => $unitsServ,
  11457.                                 'iva' => $item->getSrvIva(),
  11458.                                 'pax' => $item->getSrvPax(),
  11459.                                 'precioUnit' => $subnetoUnit,
  11460.                                 'subneto' => $subneto,
  11461.                                 'subtotal' => $subtotal,
  11462.                             );
  11463.                             break;
  11464.                         default:
  11465.                             break;
  11466.                     }
  11467.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  11468.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  11469.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  11470.                     $arrayItems[] = array(
  11471.                         'type' => 'Service',
  11472.                         'name' => $item->getSrvName(),
  11473.                         'amount' => $neto,
  11474.                         'iva' => $item->getSrvIva(),
  11475.                         'total' => $subtotal,
  11476.                     );
  11477.                 }
  11478.                 switch ($item->getSrvIva()) {
  11479.                         // Acumula IVA
  11480.                     case 21:
  11481.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  11482.                         break;
  11483.                     case 10:
  11484.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  11485.                         break;
  11486.                     case 0:
  11487.                         $data_iva['ivaMontoCero'] = 0;
  11488.                         break;
  11489.                     default:
  11490.                         break;
  11491.                 }
  11492.             } else {
  11493.                 // Es una proforma
  11494.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  11495.                     $subtotal 0;
  11496.                     $neto 0;
  11497.                     $subtotalService 0;
  11498.                 } else {
  11499.                     $subtotalService $item->getPrice();
  11500.                     $subneto $item->getPrice();
  11501.                     // Commission
  11502.                     if ($item->getOpCommission() == '1') {
  11503.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  11504.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  11505.                     } else {
  11506.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  11507.                         $subneto $subneto * (- ($item->getCommission() / 100));
  11508.                     }
  11509.                     // Over
  11510.                     if ($item->getOpOver() == '1') {
  11511.                         $subtotalService $subtotalService $item->getOver();
  11512.                         $subneto $subneto $item->getOver();
  11513.                     } else {
  11514.                         $subtotalService $subtotalService $item->getOver();
  11515.                         $subneto $subneto $item->getOver();
  11516.                     }
  11517.                     // IVA
  11518.                     if ($item->getOpIva() == '1') {
  11519.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  11520.                     } else {
  11521.                         $subtotalService $item->getPrice();
  11522.                         $subneto = ($subneto 100) / (100 $item->getIva());
  11523.                     }
  11524.                     switch ($item->getServiceCatId()) {
  11525.                         case 1// Alojamiento
  11526.                             // el numero de noches $numNoches; precio unitario $subneto
  11527.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  11528.                             // La personas no afectan este calculo
  11529.                             $subtotal $subtotalService $numNoches $item->getUnits();
  11530.                             $subnetoUnit $subneto;
  11531.                             $subneto $subneto $numNoches $item->getUnits();
  11532.                             $data_supplier['service'][$i] = array(
  11533.                                 'id' => $item->getId(),
  11534.                                 'serviceCatId' => $item->getServiceCatId(),
  11535.                                 'serviceName' => $item->getName(),
  11536.                                 'serviceType' => 'Hotel',
  11537.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  11538.                                 'qty' => $item->getUnits(),
  11539.                                 'iva' => $item->getIva(),
  11540.                                 'pax' => '-',
  11541.                                 'precioUnit' => $subnetoUnit,
  11542.                                 'subneto' => $subneto,
  11543.                                 'subtotal' => $subtotal,
  11544.                             );
  11545.                             break;
  11546.                         case 2//Actividades
  11547.                             // El nĂºmero de personas es considerado en el calculo
  11548.                             $pax $item->getPax();
  11549.                             if (empty($pax) or $pax == "0") {
  11550.                                 $pax 1;
  11551.                             }
  11552.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11553.                             if ($days 1) {
  11554.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11555.                             } else {
  11556.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11557.                             }
  11558.                             $subtotal $subtotalService $days $item->getUnits();
  11559.                             $subnetoUnit $subneto;
  11560.                             $subneto $subneto $days $item->getUnits();
  11561.                             $data_supplier['service'][$i] = array(
  11562.                                 'id' => $item->getId(),
  11563.                                 'serviceCatId' => $item->getServiceCatId(),
  11564.                                 'serviceName' => $item->getName(),
  11565.                                 'serviceType' => 'Actividad',
  11566.                                 'date' => $dateServ,
  11567.                                 'qty' => $item->getUnits(),
  11568.                                 'iva' => $item->getIva(),
  11569.                                 'pax' => $item->getPax(),
  11570.                                 'precioUnit' => $subnetoUnit,
  11571.                                 'subneto' => $subneto,
  11572.                                 'subtotal' => $subtotal,
  11573.                             );
  11574.                             break;
  11575.                         case 3// AV
  11576.                             $pax $item->getPax();
  11577.                             if (empty($pax) or $pax == "0") {
  11578.                                 $pax 1;
  11579.                             }
  11580.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11581.                             if ($days 1) {
  11582.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11583.                             } else {
  11584.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11585.                             }
  11586.                             $unitsServ $item->getUnits();
  11587.                             if (empty($unitsServ) or $unitsServ == "0") {
  11588.                                 $unitsServ 1;
  11589.                             }
  11590.                             $subtotal $subtotalService $days $unitsServ $pax;
  11591.                             $subnetoUnit $subneto;
  11592.                             $subneto $subneto $days $unitsServ $pax;
  11593.                             $data_supplier['service'][$i] = array(
  11594.                                 'id' => $item->getId(),
  11595.                                 'serviceCatId' => $item->getServiceCatId(),
  11596.                                 'serviceName' => $item->getName(),
  11597.                                 'serviceType' => 'AV',
  11598.                                 'date' => $dateServ,
  11599.                                 'qty' => $unitsServ,
  11600.                                 'iva' => $item->getIva(),
  11601.                                 'pax' => $item->getPax(),
  11602.                                 'precioUnit' => $subnetoUnit,
  11603.                                 'subneto' => $subneto,
  11604.                                 'subtotal' => $subtotal,
  11605.                             );
  11606.                             break;
  11607.                         case 4//Creative
  11608.                             $pax $item->getPax();
  11609.                             if (empty($pax) or $pax == "0") {
  11610.                                 $pax 1;
  11611.                             }
  11612.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11613.                             if ($days 1) {
  11614.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11615.                             } else {
  11616.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11617.                             }
  11618.                             $unitsServ $item->getUnits();
  11619.                             if (empty($unitsServ) or $unitsServ == "0") {
  11620.                                 $unitsServ 1;
  11621.                             }
  11622.                             $subtotal $subtotalService $days $unitsServ $pax;
  11623.                             $subnetoUnit $subneto;
  11624.                             $subneto $subneto $days $unitsServ $pax;
  11625.                             $data_supplier['service'][$i] = array(
  11626.                                 'id' => $item->getId(),
  11627.                                 'serviceCatId' => $item->getServiceCatId(),
  11628.                                 'serviceName' => $item->getName(),
  11629.                                 'serviceType' => 'Creativo',
  11630.                                 'date' => $dateServ,
  11631.                                 'qty' => $unitsServ,
  11632.                                 'iva' => $item->getIva(),
  11633.                                 'pax' => $item->getPax(),
  11634.                                 'precioUnit' => $subnetoUnit,
  11635.                                 'subneto' => $subneto,
  11636.                                 'subtotal' => $subtotal,
  11637.                             );
  11638.                             break;
  11639.                         case 5//Cruise
  11640.                             $pax $item->getPax();
  11641.                             if (empty($pax) or $pax == "0") {
  11642.                                 $pax 1;
  11643.                             }
  11644.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  11645.                             if ($days 1) {
  11646.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11647.                             } else {
  11648.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11649.                             }
  11650.                             $unitsServ $item->getUnits();
  11651.                             if (empty($unitsServ) or $unitsServ == "0") {
  11652.                                 $unitsServ 1;
  11653.                             }
  11654.                             $subtotal $subtotalService $days $unitsServ $pax;
  11655.                             $subnetoUnit $subneto;
  11656.                             $subneto $subneto $days $unitsServ $pax;
  11657.                             $data_supplier['service'][$i] = array(
  11658.                                 'id' => $item->getId(),
  11659.                                 'serviceCatId' => $item->getServiceCatId(),
  11660.                                 'serviceName' => $item->getName(),
  11661.                                 'serviceType' => 'Crucero',
  11662.                                 'date' => $dateServ,
  11663.                                 'qty' => $unitsServ,
  11664.                                 'iva' => $item->getIva(),
  11665.                                 'pax' => $item->getPax(),
  11666.                                 'precioUnit' => $subnetoUnit,
  11667.                                 'subneto' => $subneto,
  11668.                                 'subtotal' => $subtotal,
  11669.                             );
  11670.                             break;
  11671.                         case 6//Entertaiment
  11672.                             $pax $item->getPax();
  11673.                             if (empty($pax) or $pax == "0") {
  11674.                                 $pax 1;
  11675.                             }
  11676.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11677.                             if ($days 1) {
  11678.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11679.                             } else {
  11680.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11681.                             }
  11682.                             $unitsServ $item->getUnits();
  11683.                             if (empty($unitsServ) or $unitsServ == "0") {
  11684.                                 $unitsServ 1;
  11685.                             }
  11686.                             $subtotal $subtotalService $days $unitsServ $pax;
  11687.                             $subnetoUnit $subneto;
  11688.                             $subneto $subneto $days $unitsServ $pax;
  11689.                             $data_supplier['service'][$i] = array(
  11690.                                 'id' => $item->getId(),
  11691.                                 'serviceCatId' => $item->getServiceCatId(),
  11692.                                 'serviceName' => $item->getName(),
  11693.                                 'serviceType' => 'Entretenimiento',
  11694.                                 'date' => $dateServ,
  11695.                                 'qty' => $unitsServ,
  11696.                                 'iva' => $item->getIva(),
  11697.                                 'pax' => $item->getPax(),
  11698.                                 'precioUnit' => $subnetoUnit,
  11699.                                 'subneto' => $subneto,
  11700.                                 'subtotal' => $subtotal,
  11701.                             );
  11702.                             break;
  11703.                         case 7// Gifts
  11704.                             $pax $item->getPax();
  11705.                             if (empty($pax) or $pax == "0") {
  11706.                                 $pax 1;
  11707.                             }
  11708.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11709.                             $days 1;
  11710.                             if ($days 1) {
  11711.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11712.                             } else {
  11713.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11714.                             }
  11715.                             $unitsServ $item->getUnits();
  11716.                             if (empty($unitsServ) or $unitsServ == "0") {
  11717.                                 $unitsServ 1;
  11718.                             }
  11719.                             $subtotal $subtotalService $days $unitsServ $pax;
  11720.                             $subnetoUnit $subneto;
  11721.                             $subneto $subneto $days $unitsServ $pax;
  11722.                             $data_supplier['service'][$i] = array(
  11723.                                 'id' => $item->getId(),
  11724.                                 'serviceCatId' => $item->getServiceCatId(),
  11725.                                 'serviceName' => $item->getName(),
  11726.                                 'serviceType' => 'Regalos',
  11727.                                 'date' => $dateServ,
  11728.                                 'qty' => $unitsServ,
  11729.                                 'iva' => $item->getIva(),
  11730.                                 'pax' => $item->getPax(),
  11731.                                 'precioUnit' => $subnetoUnit,
  11732.                                 'subneto' => $subneto,
  11733.                                 'subtotal' => $subtotal,
  11734.                             );
  11735.                             break;
  11736.                         case 8//Guide
  11737.                             $pax $item->getPax();
  11738.                             if (empty($pax) or $pax == "0") {
  11739.                                 $pax 1;
  11740.                             }
  11741.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11742.                             if ($days 1) {
  11743.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11744.                             } else {
  11745.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11746.                             }
  11747.                             $unitsServ $item->getUnits();
  11748.                             if (empty($unitsServ) or $unitsServ == "0") {
  11749.                                 $unitsServ 1;
  11750.                             }
  11751.                             $subtotal $subtotalService $days $unitsServ $pax;
  11752.                             $subnetoUnit $subneto;
  11753.                             $subneto $subneto $days $unitsServ $pax;
  11754.                             $data_supplier['service'][$i] = array(
  11755.                                 'id' => $item->getId(),
  11756.                                 'serviceCatId' => $item->getServiceCatId(),
  11757.                                 'serviceName' => $item->getName(),
  11758.                                 'serviceType' => 'Regalos',
  11759.                                 'date' => $dateServ,
  11760.                                 'qty' => $unitsServ,
  11761.                                 'iva' => $item->getIva(),
  11762.                                 'pax' => $item->getPax(),
  11763.                                 'precioUnit' => $subnetoUnit,
  11764.                                 'subneto' => $subneto,
  11765.                                 'subtotal' => $subtotal,
  11766.                             );
  11767.                             break;
  11768.                         case 9//Itineraries
  11769.                             $pax $item->getPax();
  11770.                             if (empty($pax) or $pax == "0") {
  11771.                                 $pax 1;
  11772.                             }
  11773.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11774.                             if ($days 1) {
  11775.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11776.                             } else {
  11777.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11778.                             }
  11779.                             $unitsServ $item->getUnits();
  11780.                             if (empty($unitsServ) or $unitsServ == "0") {
  11781.                                 $unitsServ 1;
  11782.                             }
  11783.                             $subtotal $subtotalService $days $unitsServ $pax;
  11784.                             $subnetoUnit $subneto;
  11785.                             $subneto $subneto $days $unitsServ $pax;
  11786.                             $data_supplier['service'][$i] = array(
  11787.                                 'id' => $item->getId(),
  11788.                                 'serviceCatId' => $item->getServiceCatId(),
  11789.                                 'serviceName' => $item->getName(),
  11790.                                 'serviceType' => 'Itinerarios',
  11791.                                 'date' => $dateServ,
  11792.                                 'qty' => $unitsServ,
  11793.                                 'iva' => $item->getIva(),
  11794.                                 'pax' => $item->getPax(),
  11795.                                 'precioUnit' => $subnetoUnit,
  11796.                                 'subneto' => $subneto,
  11797.                                 'subtotal' => $subtotal,
  11798.                             );
  11799.                             break;
  11800.                         case 10//Lounge  -- No Aplica
  11801.                             break;
  11802.                         case 11//Menu
  11803.                             $pax $item->getPax();
  11804.                             if (empty($pax) or $pax == "0") {
  11805.                                 $pax 1;
  11806.                             }
  11807.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11808.                             if ($days 1) {
  11809.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11810.                             } else {
  11811.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11812.                             }
  11813.                             $unitsServ $item->getUnits();
  11814.                             if (empty($unitsServ) or $unitsServ == "0") {
  11815.                                 $unitsServ 1;
  11816.                             }
  11817.                             $subtotal $subtotalService $days $unitsServ $pax;
  11818.                             $subnetoUnit $subneto;
  11819.                             $subneto $subneto $days $unitsServ $pax;
  11820.                             $data_supplier['service'][$i] = array(
  11821.                                 'id' => $item->getId(),
  11822.                                 'serviceCatId' => $item->getServiceCatId(),
  11823.                                 'serviceName' => $item->getName(),
  11824.                                 'serviceType' => 'MenĂº',
  11825.                                 'date' => $dateServ,
  11826.                                 'qty' => $unitsServ,
  11827.                                 'iva' => $item->getIva(),
  11828.                                 'pax' => $item->getPax(),
  11829.                                 'precioUnit' => $subnetoUnit,
  11830.                                 'subneto' => $subneto,
  11831.                                 'subtotal' => $subtotal,
  11832.                             );
  11833.                             break;
  11834.                         case 12//Others
  11835.                             $pax $item->getPax();
  11836.                             if (empty($pax) or $pax == "0") {
  11837.                                 $pax 1;
  11838.                             }
  11839.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11840.                             if ($days 1) {
  11841.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11842.                             } else {
  11843.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11844.                             }
  11845.                             $unitsServ $item->getUnits();
  11846.                             if (empty($unitsServ) or $unitsServ == "0") {
  11847.                                 $unitsServ 1;
  11848.                             }
  11849.                             $subtotal $subtotalService $days $unitsServ $pax;
  11850.                             $subnetoUnit $subneto;
  11851.                             $subneto $subneto $days $unitsServ $pax;
  11852.                             $data_supplier['service'][$i] = array(
  11853.                                 'id' => $item->getId(),
  11854.                                 'serviceCatId' => $item->getServiceCatId(),
  11855.                                 'serviceName' => $item->getName(),
  11856.                                 'serviceType' => 'Otros',
  11857.                                 'date' => $dateServ,
  11858.                                 'qty' => $unitsServ,
  11859.                                 'iva' => $item->getIva(),
  11860.                                 'pax' => $item->getPax(),
  11861.                                 'precioUnit' => $subnetoUnit,
  11862.                                 'subneto' => $subneto,
  11863.                                 'subtotal' => $subtotal,
  11864.                             );
  11865.                             break;
  11866.                         case 13//Transport
  11867.                             $pax $item->getPax();
  11868.                             if (empty($pax) or $pax == "0") {
  11869.                                 $pax 1;
  11870.                             }
  11871.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11872.                             if ($days 1) {
  11873.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11874.                             } else {
  11875.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11876.                             }
  11877.                             $unitsServ $item->getUnits();
  11878.                             if (empty($unitsServ) or $unitsServ == "0") {
  11879.                                 $unitsServ 1;
  11880.                             }
  11881.                             $subtotal $subtotalService $days $unitsServ $pax;
  11882.                             $subnetoUnit $subneto;
  11883.                             $subneto $subneto $days $unitsServ $pax;
  11884.                             $data_supplier['service'][$i] = array(
  11885.                                 'id' => $item->getId(),
  11886.                                 'serviceCatId' => $item->getServiceCatId(),
  11887.                                 'serviceName' => $item->getName(),
  11888.                                 'serviceType' => 'Transporte',
  11889.                                 'date' => $dateServ,
  11890.                                 'qty' => $unitsServ,
  11891.                                 'iva' => $item->getIva(),
  11892.                                 'pax' => $item->getPax(),
  11893.                                 'precioUnit' => $subnetoUnit,
  11894.                                 'subneto' => $subneto,
  11895.                                 'subtotal' => $subtotal,
  11896.                             );
  11897.                             break;
  11898.                         case 14//Technology
  11899.                             $pax $item->getPax();
  11900.                             if (empty($pax) or $pax == "0") {
  11901.                                 $pax 1;
  11902.                             }
  11903.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11904.                             $days 1;
  11905.                             //                        if ($days > 1){
  11906.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  11907.                             //                        } else {
  11908.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11909.                             //                        }
  11910.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11911.                             $unitsServ $item->getUnits();
  11912.                             if (empty($unitsServ) or $unitsServ == "0") {
  11913.                                 $unitsServ 1;
  11914.                             }
  11915.                             $subtotal $subtotalService $days $unitsServ $pax;
  11916.                             $subnetoUnit $subneto;
  11917.                             $subneto $subneto $days $unitsServ $pax;
  11918.                             $data_supplier['service'][$i] = array(
  11919.                                 'id' => $item->getId(),
  11920.                                 'serviceCatId' => $item->getServiceCatId(),
  11921.                                 'serviceName' => $item->getName(),
  11922.                                 'serviceType' => 'TecnologĂ­a',
  11923.                                 'date' => $dateServ,
  11924.                                 'qty' => $unitsServ,
  11925.                                 'iva' => $item->getIva(),
  11926.                                 'pax' => $item->getPax(),
  11927.                                 'precioUnit' => $subnetoUnit,
  11928.                                 'subneto' => $subneto,
  11929.                                 'subtotal' => $subtotal,
  11930.                             );
  11931.                             break;
  11932.                         case 15//Assisstant
  11933.                             $pax $item->getPax();
  11934.                             if (empty($pax) or $pax == "0") {
  11935.                                 $pax 1;
  11936.                             }
  11937.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11938.                             if ($days 1) {
  11939.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11940.                             } else {
  11941.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11942.                             }
  11943.                             $unitsServ $item->getUnits();
  11944.                             if (empty($unitsServ) or $unitsServ == "0") {
  11945.                                 $unitsServ 1;
  11946.                             }
  11947.                             $subtotal $subtotalService $days $unitsServ $pax;
  11948.                             $subnetoUnit $subneto;
  11949.                             $subneto $subneto $days $unitsServ $pax;
  11950.                             $data_supplier['service'][$i] = array(
  11951.                                 'id' => $item->getId(),
  11952.                                 'serviceCatId' => $item->getServiceCatId(),
  11953.                                 'serviceName' => $item->getName(),
  11954.                                 'serviceType' => 'Asistente',
  11955.                                 'date' => $dateServ,
  11956.                                 'qty' => $unitsServ,
  11957.                                 'iva' => $item->getIva(),
  11958.                                 'pax' => $item->getPax(),
  11959.                                 'precioUnit' => $subnetoUnit,
  11960.                                 'subneto' => $subneto,
  11961.                                 'subtotal' => $subtotal,
  11962.                             );
  11963.                             break;
  11964.                         case 16//DDR
  11965.                             $pax $item->getPax();
  11966.                             if (empty($pax) or $pax == "0") {
  11967.                                 $pax 1;
  11968.                             }
  11969.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11970.                             if ($days 1) {
  11971.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11972.                             } else {
  11973.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11974.                             }
  11975.                             $unitsServ $item->getUnits();
  11976.                             if (empty($unitsServ) or $unitsServ == "0") {
  11977.                                 $unitsServ 1;
  11978.                             }
  11979.                             $subtotal $subtotalService $days $unitsServ $pax;
  11980.                             $subnetoUnit $subneto;
  11981.                             $subneto $subneto $days $unitsServ $pax;
  11982.                             $data_supplier['service'][$i] = array(
  11983.                                 'id' => $item->getId(),
  11984.                                 'serviceCatId' => $item->getServiceCatId(),
  11985.                                 'serviceName' => $item->getName(),
  11986.                                 'serviceType' => 'DDR',
  11987.                                 'date' => $dateServ,
  11988.                                 'qty' => $unitsServ,
  11989.                                 'iva' => $item->getIva(),
  11990.                                 'pax' => $item->getPax(),
  11991.                                 'precioUnit' => $subnetoUnit,
  11992.                                 'subneto' => $subneto,
  11993.                                 'subtotal' => $subtotal,
  11994.                             );
  11995.                             break;
  11996.                         default:
  11997.                             break;
  11998.                     }
  11999.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12000.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12001.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  12002.                     $arrayItems[] = array(
  12003.                         'type' => 'Service',
  12004.                         'name' => $item->getName(),
  12005.                         'amount' => $neto,
  12006.                         'iva' => $item->getIva(),
  12007.                         'total' => $subtotal,
  12008.                     );
  12009.                 }
  12010.                 switch ($item->getIva()) {
  12011.                         // Acumula IVA
  12012.                     case 21:
  12013.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  12014.                         break;
  12015.                     case 10:
  12016.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  12017.                         break;
  12018.                     case 0:
  12019.                         $data_iva['ivaMontoCero'] = 0;
  12020.                         break;
  12021.                     default:
  12022.                         break;
  12023.                 }
  12024.             }
  12025.             $totales_neto_all $totales_neto_all $neto;
  12026.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12027.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  12028.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  12029.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  12030.             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  12031.             // Acumula netos totales e IVA
  12032.             $service['neto'] = $service['neto'] + $neto;
  12033.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  12034.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12035.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  12036.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  12037.             $i++;
  12038.         }
  12039.         $data_supplier['serviceSubTotal'] = array(
  12040.             'neto' => $service['neto'],
  12041.             'sumSubT' => $service['sumSubT'],
  12042.         );
  12043.         $currency '€';
  12044.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  12045.         if (!empty($payments)) {
  12046.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  12047.         } else {
  12048.             $amount_pay 0;
  12049.         }
  12050.         $totales_all $totales_total $amount_pay;
  12051.         if (empty($dateDocument)) {
  12052.             $dateDocument = new DateTime('now');
  12053.         }
  12054.         $data = array(
  12055.             'id' => $fileId,
  12056.             'type' => $type,
  12057.             'number' => $number,
  12058.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $invoiceId,
  12059.             'date' => $dateDocument,
  12060.             'file' => $file,
  12061.             'token' => $file->getAccessKey(),
  12062.             'company' => $company,
  12063.             'clients' => $clientNew,
  12064.             'arrayItems' => $arrayItems,
  12065.             'datasupplier' => $data_supplier,
  12066.             'currency' => $currency,
  12067.             'totales_neto' => $totales_neto_all,
  12068.             'bases_imponibles' => $data_iva,
  12069.             'totales' => $totales_total,
  12070.             'balance' => $totales_all,
  12071.             'paymentInvoice' => $amount_pay,
  12072.         );
  12073.         return $data;
  12074.     }
  12075.     private function baseInvoiceDoneFileTwo($fileId$invoiceId$typeBase)
  12076.     {
  12077.         $em $this->getDoctrine()->getManager();
  12078.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  12079.         $dateDocument null;                                                                           //Fecha final del documento
  12080.         $subneto 0;
  12081.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  12082.             if ($typeBase == 'I') {
  12083.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  12084.             } else {
  12085.                 // Es factura ni proforma
  12086.                 $items $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId'proformaId' => $invoiceId));
  12087.             }
  12088.         } else {
  12089.             // No es factura ni proforma, es una rectificativa
  12090.             $items $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  12091.         }
  12092.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  12093.         $client $em->getRepository(Client::class)->findById($file->getClient());
  12094.         if (empty($client)) {
  12095.             $client[0] = new Client();
  12096.             $client[0]->setName('');
  12097.             $client[0]->setTitle('');
  12098.             $client[0]->setIdDocument('');
  12099.             $client[0]->setPopulation('');
  12100.             $client[0]->setRegion('');
  12101.             $client[0]->setCountry('');
  12102.         } else {
  12103.             if (is_numeric($client[0]->getPopulation())) {
  12104.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  12105. //                $client[0]->setPopulation($city->getCity());
  12106.             }
  12107.             if (is_numeric($client[0]->getRegion())) {
  12108.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  12109. //                $client[0]->setRegion($region->getRegion());
  12110.             }
  12111.             if (is_numeric($client[0]->getCountry())) {
  12112.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  12113. //                $client[0]->setCountry($country->getCountry());
  12114.             }
  12115.         }
  12116.         if (empty($client)) {
  12117.             $client[0] = new Client();
  12118.             $client[0]->setName('');
  12119.             $client[0]->setTitle('');
  12120.             $client[0]->setIdDocument('');
  12121.             $client[0]->setPopulation('');
  12122.             $client[0]->setRegion('');
  12123.             $client[0]->setCountry('');
  12124.             $clientNew = array(
  12125.                 'name' => '',
  12126.                 'title' => '',
  12127.                 'idDocument' => '',
  12128.                 'population' => '',
  12129.                 'region' => '',
  12130.                 'country' => '',
  12131.                 'address' => '',
  12132.                 'addressNumber' => '',
  12133.                 'zipCode' => '',
  12134.                 'typeDocument' => '',
  12135.             );
  12136.         } else {
  12137.             $clientNew = array(
  12138.                 'name' => $client[0]->getName(),
  12139.                 'title' => $client[0]->getTitle(),
  12140.                 'idDocument' => $client[0]->getIdDocument(),
  12141.                 'population' => '',
  12142.                 'region' => '',
  12143.                 'country' => '',
  12144.                 'address' => $client[0]->getAddress(),
  12145.                 'addressNumber' => $client[0]->getAddressNumber(),
  12146.                 'zipCode' => $client[0]->getZipCode(),
  12147.                 'typeDocument' => $client[0]->getTypeDocument(),
  12148.             );
  12149.             if (is_numeric($client[0]->getPopulation())) {
  12150.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  12151.                 $clientNew['population'] = $city->getCity();
  12152.             }
  12153.             if (is_numeric($client[0]->getRegion())) {
  12154.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  12155.                 $clientNew['region'] = $region->getRegion();
  12156.             }
  12157.             if (is_numeric($client[0]->getCountry())) {
  12158.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  12159.                 $clientNew['country'] = $country->getCountry();
  12160.             }
  12161.         }
  12162.         // Acumuladores de los calculos
  12163.         $totales_neto_all 0;
  12164.         $data_iva = array(
  12165.             'iva' => 21,
  12166.             'ivaMontoVeintiUno' => 0,
  12167.             'ivaMontoDiez' => 0,
  12168.             'ivaMontoCero' => 0,
  12169.         );
  12170.         //INICIO: Determinamos el numero de factura o proforma
  12171.         if ($typeBase == 'I') {
  12172.             // Es una Factura
  12173.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  12174.             $dateDocument $number->getDateAt();
  12175.             $number $number->getNumber();
  12176.             $type 'Invoice';
  12177.         } else {
  12178.             if ($typeBase == 'R') {
  12179.                 // Es una factura rectificativa
  12180.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  12181.                 $dateDocument $number->getDateAt();
  12182.                 $type 'Invoice Rec';
  12183.             } else {
  12184.                 // Es una Proforma
  12185.                 $number $invoiceId;
  12186.                 $type 'Proforma';
  12187.             }
  12188.         }
  12189.         //FIN: Determinamos el numero de factura o proforma
  12190.         // Buscamos los productos, pagos y servicios
  12191.         $arrayItems = array();
  12192.         $fileProducts = array();
  12193.         $payments = array();
  12194.         $services = array();
  12195.         if (!empty($items)) {
  12196.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12197.                 foreach ($items as $item) {
  12198.                     switch ($item->getItemType()) {
  12199.                         case 'PRODUCT'// Producto
  12200.                             $fileProducts[] = $item;
  12201.                             break;
  12202.                         case 'PAYMENT'// Pago
  12203.                             $payments[] = $item;
  12204.                             break;
  12205.                         case 'SERVICE'// Servicio
  12206.                             $services[] = $item;
  12207.                             break;
  12208.                         default:
  12209.                             break;
  12210.                     }
  12211.                 }
  12212.             } else {
  12213.                 // Es una proforma
  12214.                 foreach ($items as $item) {
  12215.                     switch ($item->getType()) {
  12216.                         case 'PRODUCT'// Producto
  12217.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  12218.                             if (!empty($productPro)) {
  12219.                                 $fileProducts[] = $productPro;
  12220.                             }
  12221.                             break;
  12222.                         case 'PAYMENT'// Pago
  12223.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  12224.                             if (!empty($paymentPro)) {
  12225.                                 $payments[] = $paymentPro;
  12226.                             }
  12227.                             break;
  12228.                         case 'SERVICE'// Servicio
  12229.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  12230.                             if (!empty($servicePro)) {
  12231.                                 $services[] = $servicePro;
  12232.                             }
  12233.                             break;
  12234.                         default:
  12235.                             break;
  12236.                     }
  12237.                 }
  12238.             }
  12239.         }
  12240.         $data_supplier = array();
  12241.         $i 0;
  12242.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  12243.         $pax '1';
  12244.         $qty '1';
  12245.         $product = array(
  12246.             'neto' => 0,
  12247.             'sumSubT' => 0,
  12248.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12249.         $service = array(
  12250.             'neto' => 0,
  12251.             'sumSubT' => 0,
  12252.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12253.         foreach ($fileProducts as $item) {
  12254.             if (!is_null($item->getUnits()) or !empty($item->getUnits())) {
  12255.                 $qty $item->getUnits();
  12256.             }
  12257.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12258.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
  12259.                     $subtotal 0;
  12260.                     $neto 0;
  12261.                     $subtotalProduct 0;
  12262.                     $ivaFactor 0;
  12263.                 } else {
  12264.                         
  12265.                     //Buscamos el iva
  12266.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  12267.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  12268. //                    $subtotalProduct = $item->getPrdServicePrice() * 1.21;
  12269.                     $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  12270.                     if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)){ $ivaFactor $item->getPrdIva(); }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  12271.                     $ivaFactor = (+ ($ivaFactor/100));
  12272.                     
  12273.                     $subtotalProduct $item->getPrdSubTotalPrice() * $ivaFactor;
  12274.                     $ivaFactor = (($ivaFactor 1) * 100);
  12275.                     $subneto $item->getPrdSubTotalPrice();
  12276.                     $subtotal =  $subtotalProduct;
  12277.                     $neto =  $subneto;
  12278.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12279.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12280.                     $neto round($neto2PHP_ROUND_HALF_UP);
  12281.                     $arrayItems[] = array(
  12282.                         'type' => 'Product',
  12283.                         'name' => $item->getPrdName(),
  12284.                         'amount' => $neto,
  12285.                         'iva' => $ivaFactor,
  12286.                         'total' => $subtotal,
  12287.                     );
  12288.                 }
  12289.             } else {
  12290.                 // Es proforma
  12291.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  12292.                     $subtotal 0;
  12293.                     $neto 0;
  12294.                     $subtotalProduct 0;
  12295.                     $ivaFactor 0;
  12296.                 } else {
  12297.                     //Buscamos el iva
  12298. //                    d($item);
  12299. //                    $zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  12300.                     $zProductFile $item;
  12301.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  12302. //                    $subtotalProduct = $item->getServicePrice() * 1.21;
  12303.                     $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  12304. //                    if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)){ $ivaFactor = $item->getPrdIva(); }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  12305.                     if (!empty($item->getIva()) or ($item->getIva() == 0)){ $ivaFactor $item->getIva(); }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  12306.                     $ivaFactor = (+ ($ivaFactor/100));
  12307.                     $subtotalProduct $item->getSubTotalPrice() * $ivaFactor;
  12308.                     $ivaFactor = (($ivaFactor 1) * 100);
  12309.                     $subneto $item->getSubTotalPrice();
  12310.                     $subtotal =  $subtotalProduct;
  12311.                     $neto =  $subneto;
  12312.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12313.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12314.                     $neto round($neto2PHP_ROUND_HALF_UP);
  12315.                     $arrayItems[] = array(
  12316.                         'type' => 'Product',
  12317.                         'name' => $item->getProductName(),
  12318.                         'amount' => $neto,
  12319.                         'iva' => '21',
  12320.                         'total' => $subtotal,
  12321.                     );
  12322.                 }
  12323.             }
  12324.             // Acumula netos totales e IVA
  12325.             $totales_neto_all $totales_neto_all $neto;
  12326.             switch ($ivaFactor) {
  12327.                 case 21$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21); break;
  12328.                 case 10$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1); break;
  12329.                 case 0$data_iva['ivaMontoCero'] = 0; break;
  12330.                 default: break;
  12331.             }
  12332.             
  12333.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12334.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  12335.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  12336.             // Acumula netos totales e IVA
  12337.             $product['neto'] = $product['neto'] + $neto;
  12338.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  12339.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12340.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  12341.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  12342.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12343.                 $data_supplier['product'][$i] = array(
  12344.                     'id' => $item->getId(),
  12345.                     'productName' => $item->getPrdName(),
  12346.                     'productId' => $item->getPrdProductId(),
  12347.                     'dateStart' => $item->getPrdDateStart(),
  12348.                     'dateEnd' => $item->getPrdDateEnd(),
  12349.                     'servicePrice' => $item->getPrdServicePrice(),
  12350.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  12351.                     'subtotalProduct' => $subtotalProduct,
  12352.                     'iva' => $iva,
  12353.                     'pax' => $pax,
  12354.                     'qty' => $qty,
  12355.                     'type' => $item->getPrdType(),
  12356.                     'subtotal' => $subtotal,
  12357.                 );
  12358.             } else {
  12359.                 // Es proforma
  12360.                 $data_supplier['product'][$i] = array(
  12361.                     'id' => $item->getId(),
  12362.                     'productName' => $item->getProductName(),
  12363.                     'productId' => $item->getProductId(),
  12364.                     'dateStart' => $item->getDateStart(),
  12365.                     'dateEnd' => $item->getDateEnd(),
  12366.                     'servicePrice' => $item->getServicePrice(),
  12367.                     'subtotalProduct' => $subtotalProduct,
  12368.                     'iva' => $iva,
  12369.                     'pax' => $pax,
  12370.                     'qty' => $qty,
  12371.                     'type' => $item->getType(),
  12372.                     'subtotal' => $subtotal,
  12373.                 );
  12374.             }
  12375.             $i++;
  12376.         }
  12377.         $data_supplier['productSubTotal'] = array(
  12378.             'neto' => $product['neto'],
  12379.             'sumSubT' => $product['sumSubT'],
  12380.         );
  12381.         $payment = array(
  12382.             'sumSubT' => 0,
  12383.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12384.         $i 0;
  12385.         foreach ($payments as $item) {
  12386.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12387.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  12388.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12389.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  12390.                 $data_supplier['payment'][$i] = array(
  12391.                     'id' => $item->getId(),
  12392.                     'amount' => $item->getPayAmount(),
  12393.                     'amountTotal' => $item->getPayAmountTotal(),
  12394.                     'vat' => $item->getPayVat(),
  12395.                     'datePayAt' => $item->getPayDatePayAt(),
  12396.                     'wayToPay' => $item->getPayWayToPay(),
  12397.                 );
  12398.                 $arrayItems[] = array(
  12399.                     'type' => 'Payment',
  12400.                     'name' => $item->getPayWayToPay(),
  12401.                     'amount' => $item->getPayAmount(),
  12402.                     'total' => $item->getPayAmountTotal(),
  12403.                     'iva' => $item->getPayVat(),
  12404.                 );
  12405.             } else {
  12406.                 // Es una proforma
  12407.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  12408.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12409.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  12410.                 $data_supplier['payment'][$i] = array(
  12411.                     'id' => $item->getId(),
  12412.                     'amount' => $item->getAmount(),
  12413.                     'amountTotal' => $item->getAmountTotal(),
  12414.                     'vat' => $item->getVat(),
  12415.                     'datePayAt' => $item->getDatePayAt(),
  12416.                     'wayToPay' => $item->getWayToPay(),
  12417.                 );
  12418.                 $arrayItems[] = array(
  12419.                     'type' => 'Payment',
  12420.                     'name' => $item->getWayToPay(),
  12421.                     'amount' => $item->getAmount(),
  12422.                     'total' => $item->getAmountTotal(),
  12423.                     'iva' => $item->getVat(),
  12424.                 );
  12425.             }
  12426.             $i++;
  12427.         }
  12428.         if (!empty($payments)) {
  12429.             $data_supplier['paymentSubTotal'] = array(
  12430.                 'sumSubT' => $payment['sumSubT'],
  12431.             );
  12432.         }
  12433.         foreach ($services as $item) {
  12434.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12435.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  12436.                     $subtotal 0;
  12437.                     $neto 0;
  12438.                     $subtotalService 0;
  12439.                 } else {
  12440.                     $subtotalService $item->getSrvPrice();
  12441.                     $subneto $item->getSrvPrice();
  12442.                     // Commission
  12443.                     if ($item->getSrvOpCommission() == '1') {
  12444.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  12445.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  12446.                     } else {
  12447.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  12448.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  12449.                     }
  12450.                     // Over
  12451.                     if ($item->getSrvOpOver() == '1') {
  12452.                         $subtotalService $subtotalService $item->getSrvOver();
  12453.                         $subneto $subneto $item->getSrvOver();
  12454.                     } else {
  12455.                         $subtotalService $subtotalService $item->getSrvOver();
  12456.                         $subneto $subneto $item->getSrvOver();
  12457.                     }
  12458.                     // IVA
  12459.                     if ($item->getSrvOpIva() == '1') {
  12460.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  12461.                     } else {
  12462.                         $subtotalService $item->getSrvPrice();
  12463.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  12464.                     }
  12465.                     switch ($item->getSrvServiceCatId()) {
  12466.                         case 1// Alojamiento
  12467.                             // el numero de noches $numNoches; precio unitario $subneto
  12468.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  12469.                             // La personas no afectan este calculo
  12470.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  12471.                             $subnetoUnit $subneto;
  12472.                             $subneto $subneto $numNoches $item->getSrvUnits();
  12473.                             $data_supplier['service'][$i] = array(
  12474.                                 'id' => $item->getId(),
  12475.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12476.                                 'serviceName' => $item->getSrvName(),
  12477.                                 'serviceType' => 'Hotel',
  12478.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  12479.                                 'qty' => $item->getSrvUnits(),
  12480.                                 'iva' => $item->getSrvIva(),
  12481.                                 'pax' => '-',
  12482.                                 'precioUnit' => $subnetoUnit,
  12483.                                 'subneto' => $subneto,
  12484.                                 'subtotal' => $subtotal,
  12485.                             );
  12486.                             break;
  12487.                         case 2//Actividades
  12488.                             // El nĂºmero de personas es considerado en el calculo
  12489.                             $pax $item->getSrvPax();
  12490.                             if (empty($pax) or $pax == "0") {
  12491.                                 $pax 1;
  12492.                             }
  12493.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12494.                             if ($days 1) {
  12495.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12496.                             } else {
  12497.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12498.                             }
  12499.                             $subtotal $subtotalService $days $item->getSrvUnits();
  12500.                             $subnetoUnit $subneto;
  12501.                             $subneto $subneto $days $item->getSrvUnits();
  12502.                             $data_supplier['service'][$i] = array(
  12503.                                 'id' => $item->getId(),
  12504.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12505.                                 'serviceName' => $item->getSrvName(),
  12506.                                 'serviceType' => 'Actividad',
  12507.                                 'date' => $dateServ,
  12508.                                 'qty' => $item->getSrvUnits(),
  12509.                                 'iva' => $item->getSrvIva(),
  12510.                                 'pax' => $item->getSrvPax(),
  12511.                                 'precioUnit' => $subnetoUnit,
  12512.                                 'subneto' => $subneto,
  12513.                                 'subtotal' => $subtotal,
  12514.                             );
  12515.                             break;
  12516.                         case 3// AV
  12517.                             $pax $item->getSrvPax();
  12518.                             if (empty($pax) or $pax == "0") {
  12519.                                 $pax 1;
  12520.                             }
  12521.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12522.                             if ($days 1) {
  12523.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12524.                             } else {
  12525.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12526.                             }
  12527.                             $unitsServ $item->getSrvUnits();
  12528.                             if (empty($unitsServ) or $unitsServ == "0") {
  12529.                                 $unitsServ 1;
  12530.                             }
  12531.                             $subtotal $subtotalService $days $unitsServ $pax;
  12532.                             $subnetoUnit $subneto;
  12533.                             $subneto $subneto $days $unitsServ $pax;
  12534.                             $data_supplier['service'][$i] = array(
  12535.                                 'id' => $item->getId(),
  12536.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12537.                                 'serviceName' => $item->getSrvName(),
  12538.                                 'serviceType' => 'AV',
  12539.                                 'date' => $dateServ,
  12540.                                 'qty' => $unitsServ,
  12541.                                 'iva' => $item->getSrvIva(),
  12542.                                 'pax' => $item->getSrvPax(),
  12543.                                 'precioUnit' => $subnetoUnit,
  12544.                                 'subneto' => $subneto,
  12545.                                 'subtotal' => $subtotal,
  12546.                             );
  12547.                             break;
  12548.                         case 4//Creative
  12549.                             $pax $item->getSrvPax();
  12550.                             if (empty($pax) or $pax == "0") {
  12551.                                 $pax 1;
  12552.                             }
  12553.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12554.                             if ($days 1) {
  12555.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12556.                             } else {
  12557.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12558.                             }
  12559.                             $unitsServ $item->getSrvUnits();
  12560.                             if (empty($unitsServ) or $unitsServ == "0") {
  12561.                                 $unitsServ 1;
  12562.                             }
  12563.                             $subtotal $subtotalService $days $unitsServ $pax;
  12564.                             $subnetoUnit $subneto;
  12565.                             $subneto $subneto $days $unitsServ $pax;
  12566.                             $data_supplier['service'][$i] = array(
  12567.                                 'id' => $item->getId(),
  12568.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12569.                                 'serviceName' => $item->getSrvName(),
  12570.                                 'serviceType' => 'Creativo',
  12571.                                 'date' => $dateServ,
  12572.                                 'qty' => $unitsServ,
  12573.                                 'iva' => $item->getSrvIva(),
  12574.                                 'pax' => $item->getSrvPax(),
  12575.                                 'precioUnit' => $subnetoUnit,
  12576.                                 'subneto' => $subneto,
  12577.                                 'subtotal' => $subtotal,
  12578.                             );
  12579.                             break;
  12580.                         case 5//Cruise
  12581.                             $pax $item->getSrvPax();
  12582.                             if (empty($pax) or $pax == "0") {
  12583.                                 $pax 1;
  12584.                             }
  12585.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  12586.                             if ($days 1) {
  12587.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12588.                             } else {
  12589.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12590.                             }
  12591.                             $unitsServ $item->getSrvUnits();
  12592.                             if (empty($unitsServ) or $unitsServ == "0") {
  12593.                                 $unitsServ 1;
  12594.                             }
  12595.                             $subtotal $subtotalService $days $unitsServ $pax;
  12596.                             $subnetoUnit $subneto;
  12597.                             $subneto $subneto $days $unitsServ $pax;
  12598.                             $data_supplier['service'][$i] = array(
  12599.                                 'id' => $item->getId(),
  12600.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12601.                                 'serviceName' => $item->getSrvName(),
  12602.                                 'serviceType' => 'Crucero',
  12603.                                 'date' => $dateServ,
  12604.                                 'qty' => $unitsServ,
  12605.                                 'iva' => $item->getSrvIva(),
  12606.                                 'pax' => $item->getSrvPax(),
  12607.                                 'precioUnit' => $subnetoUnit,
  12608.                                 'subneto' => $subneto,
  12609.                                 'subtotal' => $subtotal,
  12610.                             );
  12611.                             break;
  12612.                         case 6//Entertaiment
  12613.                             $pax $item->getSrvPax();
  12614.                             if (empty($pax) or $pax == "0") {
  12615.                                 $pax 1;
  12616.                             }
  12617.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12618.                             if ($days 1) {
  12619.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12620.                             } else {
  12621.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12622.                             }
  12623.                             $unitsServ $item->getSrvUnits();
  12624.                             if (empty($unitsServ) or $unitsServ == "0") {
  12625.                                 $unitsServ 1;
  12626.                             }
  12627.                             $subtotal $subtotalService $days $unitsServ $pax;
  12628.                             $subnetoUnit $subneto;
  12629.                             $subneto $subneto $days $unitsServ $pax;
  12630.                             $data_supplier['service'][$i] = array(
  12631.                                 'id' => $item->getId(),
  12632.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12633.                                 'serviceName' => $item->getSrvName(),
  12634.                                 'serviceType' => 'Entretenimiento',
  12635.                                 'date' => $dateServ,
  12636.                                 'qty' => $unitsServ,
  12637.                                 'iva' => $item->getSrvIva(),
  12638.                                 'pax' => $item->getSrvPax(),
  12639.                                 'precioUnit' => $subnetoUnit,
  12640.                                 'subneto' => $subneto,
  12641.                                 'subtotal' => $subtotal,
  12642.                             );
  12643.                             break;
  12644.                         case 7// Gifts
  12645.                             $pax $item->getSrvPax();
  12646.                             if (empty($pax) or $pax == "0") {
  12647.                                 $pax 1;
  12648.                             }
  12649.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12650.                             $days 1;
  12651.                             if ($days 1) {
  12652.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12653.                             } else {
  12654.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12655.                             }
  12656.                             $unitsServ $item->getSrvUnits();
  12657.                             if (empty($unitsServ) or $unitsServ == "0") {
  12658.                                 $unitsServ 1;
  12659.                             }
  12660.                             $subtotal $subtotalService $days $unitsServ $pax;
  12661.                             $subnetoUnit $subneto;
  12662.                             $subneto $subneto $days $unitsServ $pax;
  12663.                             $data_supplier['service'][$i] = array(
  12664.                                 'id' => $item->getId(),
  12665.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12666.                                 'serviceName' => $item->getSrvName(),
  12667.                                 'serviceType' => 'Regalos',
  12668.                                 'date' => $dateServ,
  12669.                                 'qty' => $unitsServ,
  12670.                                 'iva' => $item->getSrvIva(),
  12671.                                 'pax' => $item->getSrvPax(),
  12672.                                 'precioUnit' => $subnetoUnit,
  12673.                                 'subneto' => $subneto,
  12674.                                 'subtotal' => $subtotal,
  12675.                             );
  12676.                             break;
  12677.                         case 8//Guide
  12678.                             $pax $item->getSrvPax();
  12679.                             if (empty($pax) or $pax == "0") {
  12680.                                 $pax 1;
  12681.                             }
  12682.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12683.                             if ($days 1) {
  12684.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12685.                             } else {
  12686.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12687.                             }
  12688.                             $unitsServ $item->getSrvUnits();
  12689.                             if (empty($unitsServ) or $unitsServ == "0") {
  12690.                                 $unitsServ 1;
  12691.                             }
  12692.                             $subtotal $subtotalService $days $unitsServ $pax;
  12693.                             $subnetoUnit $subneto;
  12694.                             $subneto $subneto $days $unitsServ $pax;
  12695.                             $data_supplier['service'][$i] = array(
  12696.                                 'id' => $item->getId(),
  12697.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12698.                                 'serviceName' => $item->getSrvName(),
  12699.                                 'serviceType' => 'Regalos',
  12700.                                 'date' => $dateServ,
  12701.                                 'qty' => $unitsServ,
  12702.                                 'iva' => $item->getSrvIva(),
  12703.                                 'pax' => $item->getSrvPax(),
  12704.                                 'precioUnit' => $subnetoUnit,
  12705.                                 'subneto' => $subneto,
  12706.                                 'subtotal' => $subtotal,
  12707.                             );
  12708.                             break;
  12709.                         case 9//Itineraries
  12710.                             $pax $item->getSrvPax();
  12711.                             if (empty($pax) or $pax == "0") {
  12712.                                 $pax 1;
  12713.                             }
  12714.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12715.                             if ($days 1) {
  12716.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12717.                             } else {
  12718.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12719.                             }
  12720.                             $unitsServ $item->getSrvUnits();
  12721.                             if (empty($unitsServ) or $unitsServ == "0") {
  12722.                                 $unitsServ 1;
  12723.                             }
  12724.                             $subtotal $subtotalService $days $unitsServ $pax;
  12725.                             $subnetoUnit $subneto;
  12726.                             $subneto $subneto $days $unitsServ $pax;
  12727.                             $data_supplier['service'][$i] = array(
  12728.                                 'id' => $item->getId(),
  12729.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12730.                                 'serviceName' => $item->getSrvName(),
  12731.                                 'serviceType' => 'Itinerarios',
  12732.                                 'date' => $dateServ,
  12733.                                 'qty' => $unitsServ,
  12734.                                 'iva' => $item->getSrvIva(),
  12735.                                 'pax' => $item->getSrvPax(),
  12736.                                 'precioUnit' => $subnetoUnit,
  12737.                                 'subneto' => $subneto,
  12738.                                 'subtotal' => $subtotal,
  12739.                             );
  12740.                             break;
  12741.                         case 10//Lounge  -- No Aplica
  12742.                             //                        $pax = $item->getPax();
  12743.                             //                        if (empty($pax) or $pax == "0") {
  12744.                             //                            $pax = 1;
  12745.                             //                        }
  12746.                             //
  12747.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12748.                             //                        if ($days > 1){
  12749.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  12750.                             //                        } else {
  12751.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12752.                             //                        }
  12753.                             //
  12754.                             //                        $unitsServ = $item->getUnits();
  12755.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  12756.                             //                            $unitsServ = 1;
  12757.                             //                        }
  12758.                             //
  12759.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  12760.                             //                        $subnetoUnit = $subneto;
  12761.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  12762.                             //
  12763.                             //                        $data_supplier['service'][$i] = array (
  12764.                             //                            'id' => $item->getId(),
  12765.                             //                            'serviceCatId' => $item->getServiceCatId(),
  12766.                             //                            'serviceName' => $item->getName(),
  12767.                             //                            'serviceType' => 'Itinerarios',
  12768.                             //                            'date' => $dateServ,
  12769.                             //                            'qty' => $unitsServ,
  12770.                             //                            'iva' => $item->getIva(),
  12771.                             //                            'pax' => $item->getPax(),
  12772.                             //                            'precioUnit' => $subnetoUnit,
  12773.                             //                            'subneto' => $subneto,
  12774.                             //                            'subtotal' => $subtotal,
  12775.                             //                        );
  12776.                             break;
  12777.                         case 11//Menu
  12778.                             $pax $item->getSrvPax();
  12779.                             if (empty($pax) or $pax == "0") {
  12780.                                 $pax 1;
  12781.                             }
  12782.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12783.                             if ($days 1) {
  12784.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12785.                             } else {
  12786.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12787.                             }
  12788.                             $unitsServ $item->getSrvUnits();
  12789.                             if (empty($unitsServ) or $unitsServ == "0") {
  12790.                                 $unitsServ 1;
  12791.                             }
  12792.                             $subtotal $subtotalService $days $unitsServ $pax;
  12793.                             $subnetoUnit $subneto;
  12794.                             $subneto $subneto $days $unitsServ $pax;
  12795.                             $data_supplier['service'][$i] = array(
  12796.                                 'id' => $item->getId(),
  12797.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12798.                                 'serviceName' => $item->getSrvName(),
  12799.                                 'serviceType' => 'MenĂº',
  12800.                                 'date' => $dateServ,
  12801.                                 'qty' => $unitsServ,
  12802.                                 'iva' => $item->getSrvIva(),
  12803.                                 'pax' => $item->getSrvPax(),
  12804.                                 'precioUnit' => $subnetoUnit,
  12805.                                 'subneto' => $subneto,
  12806.                                 'subtotal' => $subtotal,
  12807.                             );
  12808.                             break;
  12809.                         case 12//Others
  12810.                             $pax $item->getSrvPax();
  12811.                             if (empty($pax) or $pax == "0") {
  12812.                                 $pax 1;
  12813.                             }
  12814.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12815.                             if ($days 1) {
  12816.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12817.                             } else {
  12818.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12819.                             }
  12820.                             $unitsServ $item->getSrvUnits();
  12821.                             if (empty($unitsServ) or $unitsServ == "0") {
  12822.                                 $unitsServ 1;
  12823.                             }
  12824.                             $subtotal $subtotalService $days $unitsServ $pax;
  12825.                             $subnetoUnit $subneto;
  12826.                             $subneto $subneto $days $unitsServ $pax;
  12827.                             $data_supplier['service'][$i] = array(
  12828.                                 'id' => $item->getId(),
  12829.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12830.                                 'serviceName' => $item->getSrvName(),
  12831.                                 'serviceType' => 'Otros',
  12832.                                 'date' => $dateServ,
  12833.                                 'qty' => $unitsServ,
  12834.                                 'iva' => $item->getSrvIva(),
  12835.                                 'pax' => $item->getSrvPax(),
  12836.                                 'precioUnit' => $subnetoUnit,
  12837.                                 'subneto' => $subneto,
  12838.                                 'subtotal' => $subtotal,
  12839.                             );
  12840.                             break;
  12841.                         case 13//Transport
  12842.                             $pax $item->getSrvPax();
  12843.                             if (empty($pax) or $pax == "0") {
  12844.                                 $pax 1;
  12845.                             }
  12846.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12847.                             if ($days 1) {
  12848.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12849.                             } else {
  12850.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12851.                             }
  12852.                             $unitsServ $item->getSrvUnits();
  12853.                             if (empty($unitsServ) or $unitsServ == "0") {
  12854.                                 $unitsServ 1;
  12855.                             }
  12856.                             $subtotal $subtotalService $days $unitsServ $pax;
  12857.                             $subnetoUnit $subneto;
  12858.                             $subneto $subneto $days $unitsServ $pax;
  12859.                             $data_supplier['service'][$i] = array(
  12860.                                 'id' => $item->getId(),
  12861.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12862.                                 'serviceName' => $item->getSrvName(),
  12863.                                 'serviceType' => 'Transporte',
  12864.                                 'date' => $dateServ,
  12865.                                 'qty' => $unitsServ,
  12866.                                 'iva' => $item->getSrvIva(),
  12867.                                 'pax' => $item->getSrvPax(),
  12868.                                 'precioUnit' => $subnetoUnit,
  12869.                                 'subneto' => $subneto,
  12870.                                 'subtotal' => $subtotal,
  12871.                             );
  12872.                             break;
  12873.                         case 14//Technology
  12874.                             $pax $item->getSrvPax();
  12875.                             if (empty($pax) or $pax == "0") {
  12876.                                 $pax 1;
  12877.                             }
  12878.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12879.                             $days 1;
  12880.                             //                        if ($days > 1){
  12881.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  12882.                             //                        } else {
  12883.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12884.                             //                        }
  12885.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12886.                             $unitsServ $item->getSrvUnits();
  12887.                             if (empty($unitsServ) or $unitsServ == "0") {
  12888.                                 $unitsServ 1;
  12889.                             }
  12890.                             $subtotal $subtotalService $days $unitsServ $pax;
  12891.                             $subnetoUnit $subneto;
  12892.                             $subneto $subneto $days $unitsServ $pax;
  12893.                             $data_supplier['service'][$i] = array(
  12894.                                 'id' => $item->getId(),
  12895.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12896.                                 'serviceName' => $item->getSrvName(),
  12897.                                 'serviceType' => 'TecnologĂ­a',
  12898.                                 'date' => $dateServ,
  12899.                                 'qty' => $unitsServ,
  12900.                                 'iva' => $item->getSrvIva(),
  12901.                                 'pax' => $item->getSrvPax(),
  12902.                                 'precioUnit' => $subnetoUnit,
  12903.                                 'subneto' => $subneto,
  12904.                                 'subtotal' => $subtotal,
  12905.                             );
  12906.                             break;
  12907.                         case 15//Assisstant
  12908.                             $pax $item->getSrvPax();
  12909.                             if (empty($pax) or $pax == "0") {
  12910.                                 $pax 1;
  12911.                             }
  12912.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12913.                             if ($days 1) {
  12914.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12915.                             } else {
  12916.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12917.                             }
  12918.                             $unitsServ $item->getSrvUnits();
  12919.                             if (empty($unitsServ) or $unitsServ == "0") {
  12920.                                 $unitsServ 1;
  12921.                             }
  12922.                             $subtotal $subtotalService $days $unitsServ $pax;
  12923.                             $subnetoUnit $subneto;
  12924.                             $subneto $subneto $days $unitsServ $pax;
  12925.                             $data_supplier['service'][$i] = array(
  12926.                                 'id' => $item->getId(),
  12927.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12928.                                 'serviceName' => $item->getSrvName(),
  12929.                                 'serviceType' => 'Asistente',
  12930.                                 'date' => $dateServ,
  12931.                                 'qty' => $unitsServ,
  12932.                                 'iva' => $item->getSrvIva(),
  12933.                                 'pax' => $item->getSrvPax(),
  12934.                                 'precioUnit' => $subnetoUnit,
  12935.                                 'subneto' => $subneto,
  12936.                                 'subtotal' => $subtotal,
  12937.                             );
  12938.                             break;
  12939.                         case 16//DDR
  12940.                             $pax $item->getSrvPax();
  12941.                             if (empty($pax) or $pax == "0") {
  12942.                                 $pax 1;
  12943.                             }
  12944.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12945.                             if ($days 1) {
  12946.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12947.                             } else {
  12948.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12949.                             }
  12950.                             $unitsServ $item->getSrvUnits();
  12951.                             if (empty($unitsServ) or $unitsServ == "0") {
  12952.                                 $unitsServ 1;
  12953.                             }
  12954.                             $subtotal $subtotalService $days $unitsServ $pax;
  12955.                             $subnetoUnit $subneto;
  12956.                             $subneto $subneto $days $unitsServ $pax;
  12957.                             $data_supplier['service'][$i] = array(
  12958.                                 'id' => $item->getId(),
  12959.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12960.                                 'serviceName' => $item->getSrvName(),
  12961.                                 'serviceType' => 'DDR',
  12962.                                 'date' => $dateServ,
  12963.                                 'qty' => $unitsServ,
  12964.                                 'iva' => $item->getSrvIva(),
  12965.                                 'pax' => $item->getSrvPax(),
  12966.                                 'precioUnit' => $subnetoUnit,
  12967.                                 'subneto' => $subneto,
  12968.                                 'subtotal' => $subtotal,
  12969.                             );
  12970.                             break;
  12971.                         default:
  12972.                             break;
  12973.                     }
  12974.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12975.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12976.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  12977.                     $arrayItems[] = array(
  12978.                         'type' => 'Service',
  12979.                         'name' => $item->getSrvName(),
  12980.                         'amount' => $neto,
  12981.                         'iva' => $item->getSrvIva(),
  12982.                         'total' => $subtotal,
  12983.                     );
  12984.                 }
  12985.                 switch ($item->getSrvIva()) {
  12986.                         // Acumula IVA
  12987.                     case 21:
  12988.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  12989.                         break;
  12990.                     case 10:
  12991.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  12992.                         break;
  12993.                     case 0:
  12994.                         break;
  12995.                     default:
  12996.                         break;
  12997.                 }
  12998.             } else {
  12999.                 // Es una proforma
  13000.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  13001.                     $subtotal 0;
  13002.                     $neto 0;
  13003.                     $subtotalService 0;
  13004.                 } else {
  13005.                     $subtotalService $item->getPrice();
  13006.                     $subneto $item->getPrice();
  13007.                     // Commission
  13008.                     if ($item->getOpCommission() == '1') {
  13009.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  13010.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  13011.                     } else {
  13012.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  13013.                         $subneto $subneto * (- ($item->getCommission() / 100));
  13014.                     }
  13015.                     // Over
  13016.                     if ($item->getOpOver() == '1') {
  13017.                         $subtotalService $subtotalService $item->getOver();
  13018.                         $subneto $subneto $item->getOver();
  13019.                     } else {
  13020.                         $subtotalService $subtotalService $item->getOver();
  13021.                         $subneto $subneto $item->getOver();
  13022.                     }
  13023.                     // IVA
  13024.                     if ($item->getOpIva() == '1') {
  13025.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  13026.                     } else {
  13027.                         $subtotalService $item->getPrice();
  13028.                         $subneto = ($subneto 100) / (100 $item->getIva());
  13029.                     }
  13030.                     switch ($item->getServiceCatId()) {
  13031.                         case 1// Alojamiento
  13032.                             // el numero de noches $numNoches; precio unitario $subneto
  13033.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  13034.                             // La personas no afectan este calculo
  13035.                             $subtotal $subtotalService $numNoches $item->getUnits();
  13036.                             $subnetoUnit $subneto;
  13037.                             $subneto $subneto $numNoches $item->getUnits();
  13038.                             $data_supplier['service'][$i] = array(
  13039.                                 'id' => $item->getId(),
  13040.                                 'serviceCatId' => $item->getServiceCatId(),
  13041.                                 'serviceName' => $item->getName(),
  13042.                                 'serviceType' => 'Hotel',
  13043.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  13044.                                 'qty' => $item->getUnits(),
  13045.                                 'iva' => $item->getIva(),
  13046.                                 'pax' => '-',
  13047.                                 'precioUnit' => $subnetoUnit,
  13048.                                 'subneto' => $subneto,
  13049.                                 'subtotal' => $subtotal,
  13050.                             );
  13051.                             break;
  13052.                         case 2//Actividades
  13053.                             // El nĂºmero de personas es considerado en el calculo
  13054.                             $pax $item->getPax();
  13055.                             if (empty($pax) or $pax == "0") {
  13056.                                 $pax 1;
  13057.                             }
  13058.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13059.                             if ($days 1) {
  13060.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13061.                             } else {
  13062.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13063.                             }
  13064.                             $subtotal $subtotalService $days $item->getUnits();
  13065.                             $subnetoUnit $subneto;
  13066.                             $subneto $subneto $days $item->getUnits();
  13067.                             $data_supplier['service'][$i] = array(
  13068.                                 'id' => $item->getId(),
  13069.                                 'serviceCatId' => $item->getServiceCatId(),
  13070.                                 'serviceName' => $item->getName(),
  13071.                                 'serviceType' => 'Actividad',
  13072.                                 'date' => $dateServ,
  13073.                                 'qty' => $item->getUnits(),
  13074.                                 'iva' => $item->getIva(),
  13075.                                 'pax' => $item->getPax(),
  13076.                                 'precioUnit' => $subnetoUnit,
  13077.                                 'subneto' => $subneto,
  13078.                                 'subtotal' => $subtotal,
  13079.                             );
  13080.                             break;
  13081.                         case 3// AV
  13082.                             $pax $item->getPax();
  13083.                             if (empty($pax) or $pax == "0") {
  13084.                                 $pax 1;
  13085.                             }
  13086.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13087.                             if ($days 1) {
  13088.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13089.                             } else {
  13090.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13091.                             }
  13092.                             $unitsServ $item->getUnits();
  13093.                             if (empty($unitsServ) or $unitsServ == "0") {
  13094.                                 $unitsServ 1;
  13095.                             }
  13096.                             $subtotal $subtotalService $days $unitsServ $pax;
  13097.                             $subnetoUnit $subneto;
  13098.                             $subneto $subneto $days $unitsServ $pax;
  13099.                             $data_supplier['service'][$i] = array(
  13100.                                 'id' => $item->getId(),
  13101.                                 'serviceCatId' => $item->getServiceCatId(),
  13102.                                 'serviceName' => $item->getName(),
  13103.                                 'serviceType' => 'AV',
  13104.                                 'date' => $dateServ,
  13105.                                 'qty' => $unitsServ,
  13106.                                 'iva' => $item->getIva(),
  13107.                                 'pax' => $item->getPax(),
  13108.                                 'precioUnit' => $subnetoUnit,
  13109.                                 'subneto' => $subneto,
  13110.                                 'subtotal' => $subtotal,
  13111.                             );
  13112.                             break;
  13113.                         case 4//Creative
  13114.                             $pax $item->getPax();
  13115.                             if (empty($pax) or $pax == "0") {
  13116.                                 $pax 1;
  13117.                             }
  13118.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13119.                             if ($days 1) {
  13120.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13121.                             } else {
  13122.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13123.                             }
  13124.                             $unitsServ $item->getUnits();
  13125.                             if (empty($unitsServ) or $unitsServ == "0") {
  13126.                                 $unitsServ 1;
  13127.                             }
  13128.                             $subtotal $subtotalService $days $unitsServ $pax;
  13129.                             $subnetoUnit $subneto;
  13130.                             $subneto $subneto $days $unitsServ $pax;
  13131.                             $data_supplier['service'][$i] = array(
  13132.                                 'id' => $item->getId(),
  13133.                                 'serviceCatId' => $item->getServiceCatId(),
  13134.                                 'serviceName' => $item->getName(),
  13135.                                 'serviceType' => 'Creativo',
  13136.                                 'date' => $dateServ,
  13137.                                 'qty' => $unitsServ,
  13138.                                 'iva' => $item->getIva(),
  13139.                                 'pax' => $item->getPax(),
  13140.                                 'precioUnit' => $subnetoUnit,
  13141.                                 'subneto' => $subneto,
  13142.                                 'subtotal' => $subtotal,
  13143.                             );
  13144.                             break;
  13145.                         case 5//Cruise
  13146.                             $pax $item->getPax();
  13147.                             if (empty($pax) or $pax == "0") {
  13148.                                 $pax 1;
  13149.                             }
  13150.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  13151.                             if ($days 1) {
  13152.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13153.                             } else {
  13154.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13155.                             }
  13156.                             $unitsServ $item->getUnits();
  13157.                             if (empty($unitsServ) or $unitsServ == "0") {
  13158.                                 $unitsServ 1;
  13159.                             }
  13160.                             $subtotal $subtotalService $days $unitsServ $pax;
  13161.                             $subnetoUnit $subneto;
  13162.                             $subneto $subneto $days $unitsServ $pax;
  13163.                             $data_supplier['service'][$i] = array(
  13164.                                 'id' => $item->getId(),
  13165.                                 'serviceCatId' => $item->getServiceCatId(),
  13166.                                 'serviceName' => $item->getName(),
  13167.                                 'serviceType' => 'Crucero',
  13168.                                 'date' => $dateServ,
  13169.                                 'qty' => $unitsServ,
  13170.                                 'iva' => $item->getIva(),
  13171.                                 'pax' => $item->getPax(),
  13172.                                 'precioUnit' => $subnetoUnit,
  13173.                                 'subneto' => $subneto,
  13174.                                 'subtotal' => $subtotal,
  13175.                             );
  13176.                             break;
  13177.                         case 6//Entertaiment
  13178.                             $pax $item->getPax();
  13179.                             if (empty($pax) or $pax == "0") {
  13180.                                 $pax 1;
  13181.                             }
  13182.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13183.                             if ($days 1) {
  13184.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13185.                             } else {
  13186.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13187.                             }
  13188.                             $unitsServ $item->getUnits();
  13189.                             if (empty($unitsServ) or $unitsServ == "0") {
  13190.                                 $unitsServ 1;
  13191.                             }
  13192.                             $subtotal $subtotalService $days $unitsServ $pax;
  13193.                             $subnetoUnit $subneto;
  13194.                             $subneto $subneto $days $unitsServ $pax;
  13195.                             $data_supplier['service'][$i] = array(
  13196.                                 'id' => $item->getId(),
  13197.                                 'serviceCatId' => $item->getServiceCatId(),
  13198.                                 'serviceName' => $item->getName(),
  13199.                                 'serviceType' => 'Entretenimiento',
  13200.                                 'date' => $dateServ,
  13201.                                 'qty' => $unitsServ,
  13202.                                 'iva' => $item->getIva(),
  13203.                                 'pax' => $item->getPax(),
  13204.                                 'precioUnit' => $subnetoUnit,
  13205.                                 'subneto' => $subneto,
  13206.                                 'subtotal' => $subtotal,
  13207.                             );
  13208.                             break;
  13209.                         case 7// Gifts
  13210.                             $pax $item->getPax();
  13211.                             if (empty($pax) or $pax == "0") {
  13212.                                 $pax 1;
  13213.                             }
  13214.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13215.                             $days 1;
  13216.                             if ($days 1) {
  13217.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13218.                             } else {
  13219.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13220.                             }
  13221.                             $unitsServ $item->getUnits();
  13222.                             if (empty($unitsServ) or $unitsServ == "0") {
  13223.                                 $unitsServ 1;
  13224.                             }
  13225.                             $subtotal $subtotalService $days $unitsServ $pax;
  13226.                             $subnetoUnit $subneto;
  13227.                             $subneto $subneto $days $unitsServ $pax;
  13228.                             $data_supplier['service'][$i] = array(
  13229.                                 'id' => $item->getId(),
  13230.                                 'serviceCatId' => $item->getServiceCatId(),
  13231.                                 'serviceName' => $item->getName(),
  13232.                                 'serviceType' => 'Regalos',
  13233.                                 'date' => $dateServ,
  13234.                                 'qty' => $unitsServ,
  13235.                                 'iva' => $item->getIva(),
  13236.                                 'pax' => $item->getPax(),
  13237.                                 'precioUnit' => $subnetoUnit,
  13238.                                 'subneto' => $subneto,
  13239.                                 'subtotal' => $subtotal,
  13240.                             );
  13241.                             break;
  13242.                         case 8//Guide
  13243.                             $pax $item->getPax();
  13244.                             if (empty($pax) or $pax == "0") {
  13245.                                 $pax 1;
  13246.                             }
  13247.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13248.                             if ($days 1) {
  13249.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13250.                             } else {
  13251.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13252.                             }
  13253.                             $unitsServ $item->getUnits();
  13254.                             if (empty($unitsServ) or $unitsServ == "0") {
  13255.                                 $unitsServ 1;
  13256.                             }
  13257.                             $subtotal $subtotalService $days $unitsServ $pax;
  13258.                             $subnetoUnit $subneto;
  13259.                             $subneto $subneto $days $unitsServ $pax;
  13260.                             $data_supplier['service'][$i] = array(
  13261.                                 'id' => $item->getId(),
  13262.                                 'serviceCatId' => $item->getServiceCatId(),
  13263.                                 'serviceName' => $item->getName(),
  13264.                                 'serviceType' => 'Regalos',
  13265.                                 'date' => $dateServ,
  13266.                                 'qty' => $unitsServ,
  13267.                                 'iva' => $item->getIva(),
  13268.                                 'pax' => $item->getPax(),
  13269.                                 'precioUnit' => $subnetoUnit,
  13270.                                 'subneto' => $subneto,
  13271.                                 'subtotal' => $subtotal,
  13272.                             );
  13273.                             break;
  13274.                         case 9//Itineraries
  13275.                             $pax $item->getPax();
  13276.                             if (empty($pax) or $pax == "0") {
  13277.                                 $pax 1;
  13278.                             }
  13279.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13280.                             if ($days 1) {
  13281.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13282.                             } else {
  13283.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13284.                             }
  13285.                             $unitsServ $item->getUnits();
  13286.                             if (empty($unitsServ) or $unitsServ == "0") {
  13287.                                 $unitsServ 1;
  13288.                             }
  13289.                             $subtotal $subtotalService $days $unitsServ $pax;
  13290.                             $subnetoUnit $subneto;
  13291.                             $subneto $subneto $days $unitsServ $pax;
  13292.                             $data_supplier['service'][$i] = array(
  13293.                                 'id' => $item->getId(),
  13294.                                 'serviceCatId' => $item->getServiceCatId(),
  13295.                                 'serviceName' => $item->getName(),
  13296.                                 'serviceType' => 'Itinerarios',
  13297.                                 'date' => $dateServ,
  13298.                                 'qty' => $unitsServ,
  13299.                                 'iva' => $item->getIva(),
  13300.                                 'pax' => $item->getPax(),
  13301.                                 'precioUnit' => $subnetoUnit,
  13302.                                 'subneto' => $subneto,
  13303.                                 'subtotal' => $subtotal,
  13304.                             );
  13305.                             break;
  13306.                         case 10//Lounge  -- No Aplica
  13307.                             //                        $pax = $item->getPax();
  13308.                             //                        if (empty($pax) or $pax == "0") {
  13309.                             //                            $pax = 1;
  13310.                             //                        }
  13311.                             //
  13312.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13313.                             //                        if ($days > 1){
  13314.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  13315.                             //                        } else {
  13316.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13317.                             //                        }
  13318.                             //
  13319.                             //                        $unitsServ = $item->getUnits();
  13320.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  13321.                             //                            $unitsServ = 1;
  13322.                             //                        }
  13323.                             //
  13324.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  13325.                             //                        $subnetoUnit = $subneto;
  13326.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  13327.                             //
  13328.                             //                        $data_supplier['service'][$i] = array (
  13329.                             //                            'id' => $item->getId(),
  13330.                             //                            'serviceCatId' => $item->getServiceCatId(),
  13331.                             //                            'serviceName' => $item->getName(),
  13332.                             //                            'serviceType' => 'Itinerarios',
  13333.                             //                            'date' => $dateServ,
  13334.                             //                            'qty' => $unitsServ,
  13335.                             //                            'iva' => $item->getIva(),
  13336.                             //                            'pax' => $item->getPax(),
  13337.                             //                            'precioUnit' => $subnetoUnit,
  13338.                             //                            'subneto' => $subneto,
  13339.                             //                            'subtotal' => $subtotal,
  13340.                             //                        );
  13341.                             break;
  13342.                         case 11//Menu
  13343.                             $pax $item->getPax();
  13344.                             if (empty($pax) or $pax == "0") {
  13345.                                 $pax 1;
  13346.                             }
  13347.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13348.                             if ($days 1) {
  13349.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13350.                             } else {
  13351.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13352.                             }
  13353.                             $unitsServ $item->getUnits();
  13354.                             if (empty($unitsServ) or $unitsServ == "0") {
  13355.                                 $unitsServ 1;
  13356.                             }
  13357.                             $subtotal $subtotalService $days $unitsServ $pax;
  13358.                             $subnetoUnit $subneto;
  13359.                             $subneto $subneto $days $unitsServ $pax;
  13360.                             $data_supplier['service'][$i] = array(
  13361.                                 'id' => $item->getId(),
  13362.                                 'serviceCatId' => $item->getServiceCatId(),
  13363.                                 'serviceName' => $item->getName(),
  13364.                                 'serviceType' => 'MenĂº',
  13365.                                 'date' => $dateServ,
  13366.                                 'qty' => $unitsServ,
  13367.                                 'iva' => $item->getIva(),
  13368.                                 'pax' => $item->getPax(),
  13369.                                 'precioUnit' => $subnetoUnit,
  13370.                                 'subneto' => $subneto,
  13371.                                 'subtotal' => $subtotal,
  13372.                             );
  13373.                             break;
  13374.                         case 12//Others
  13375.                             $pax $item->getPax();
  13376.                             if (empty($pax) or $pax == "0") {
  13377.                                 $pax 1;
  13378.                             }
  13379.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13380.                             if ($days 1) {
  13381.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13382.                             } else {
  13383.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13384.                             }
  13385.                             $unitsServ $item->getUnits();
  13386.                             if (empty($unitsServ) or $unitsServ == "0") {
  13387.                                 $unitsServ 1;
  13388.                             }
  13389.                             $subtotal $subtotalService $days $unitsServ $pax;
  13390.                             $subnetoUnit $subneto;
  13391.                             $subneto $subneto $days $unitsServ $pax;
  13392.                             $data_supplier['service'][$i] = array(
  13393.                                 'id' => $item->getId(),
  13394.                                 'serviceCatId' => $item->getServiceCatId(),
  13395.                                 'serviceName' => $item->getName(),
  13396.                                 'serviceType' => 'Otros',
  13397.                                 'date' => $dateServ,
  13398.                                 'qty' => $unitsServ,
  13399.                                 'iva' => $item->getIva(),
  13400.                                 'pax' => $item->getPax(),
  13401.                                 'precioUnit' => $subnetoUnit,
  13402.                                 'subneto' => $subneto,
  13403.                                 'subtotal' => $subtotal,
  13404.                             );
  13405.                             break;
  13406.                         case 13//Transport
  13407.                             $pax $item->getPax();
  13408.                             if (empty($pax) or $pax == "0") {
  13409.                                 $pax 1;
  13410.                             }
  13411.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13412.                             if ($days 1) {
  13413.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13414.                             } else {
  13415.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13416.                             }
  13417.                             $unitsServ $item->getUnits();
  13418.                             if (empty($unitsServ) or $unitsServ == "0") {
  13419.                                 $unitsServ 1;
  13420.                             }
  13421.                             $subtotal $subtotalService $days $unitsServ $pax;
  13422.                             $subnetoUnit $subneto;
  13423.                             $subneto $subneto $days $unitsServ $pax;
  13424.                             $data_supplier['service'][$i] = array(
  13425.                                 'id' => $item->getId(),
  13426.                                 'serviceCatId' => $item->getServiceCatId(),
  13427.                                 'serviceName' => $item->getName(),
  13428.                                 'serviceType' => 'Transporte',
  13429.                                 'date' => $dateServ,
  13430.                                 'qty' => $unitsServ,
  13431.                                 'iva' => $item->getIva(),
  13432.                                 'pax' => $item->getPax(),
  13433.                                 'precioUnit' => $subnetoUnit,
  13434.                                 'subneto' => $subneto,
  13435.                                 'subtotal' => $subtotal,
  13436.                             );
  13437.                             break;
  13438.                         case 14//Technology
  13439.                             $pax $item->getPax();
  13440.                             if (empty($pax) or $pax == "0") {
  13441.                                 $pax 1;
  13442.                             }
  13443.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13444.                             $days 1;
  13445.                             //                        if ($days > 1){
  13446.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  13447.                             //                        } else {
  13448.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13449.                             //                        }
  13450.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13451.                             $unitsServ $item->getUnits();
  13452.                             if (empty($unitsServ) or $unitsServ == "0") {
  13453.                                 $unitsServ 1;
  13454.                             }
  13455.                             $subtotal $subtotalService $days $unitsServ $pax;
  13456.                             $subnetoUnit $subneto;
  13457.                             $subneto $subneto $days $unitsServ $pax;
  13458.                             $data_supplier['service'][$i] = array(
  13459.                                 'id' => $item->getId(),
  13460.                                 'serviceCatId' => $item->getServiceCatId(),
  13461.                                 'serviceName' => $item->getName(),
  13462.                                 'serviceType' => 'TecnologĂ­a',
  13463.                                 'date' => $dateServ,
  13464.                                 'qty' => $unitsServ,
  13465.                                 'iva' => $item->getIva(),
  13466.                                 'pax' => $item->getPax(),
  13467.                                 'precioUnit' => $subnetoUnit,
  13468.                                 'subneto' => $subneto,
  13469.                                 'subtotal' => $subtotal,
  13470.                             );
  13471.                             break;
  13472.                         case 15//Assisstant
  13473.                             $pax $item->getPax();
  13474.                             if (empty($pax) or $pax == "0") {
  13475.                                 $pax 1;
  13476.                             }
  13477.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13478.                             if ($days 1) {
  13479.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13480.                             } else {
  13481.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13482.                             }
  13483.                             $unitsServ $item->getUnits();
  13484.                             if (empty($unitsServ) or $unitsServ == "0") {
  13485.                                 $unitsServ 1;
  13486.                             }
  13487.                             $subtotal $subtotalService $days $unitsServ $pax;
  13488.                             $subnetoUnit $subneto;
  13489.                             $subneto $subneto $days $unitsServ $pax;
  13490.                             $data_supplier['service'][$i] = array(
  13491.                                 'id' => $item->getId(),
  13492.                                 'serviceCatId' => $item->getServiceCatId(),
  13493.                                 'serviceName' => $item->getName(),
  13494.                                 'serviceType' => 'Asistente',
  13495.                                 'date' => $dateServ,
  13496.                                 'qty' => $unitsServ,
  13497.                                 'iva' => $item->getIva(),
  13498.                                 'pax' => $item->getPax(),
  13499.                                 'precioUnit' => $subnetoUnit,
  13500.                                 'subneto' => $subneto,
  13501.                                 'subtotal' => $subtotal,
  13502.                             );
  13503.                             break;
  13504.                         case 16//DDR
  13505.                             $pax $item->getPax();
  13506.                             if (empty($pax) or $pax == "0") {
  13507.                                 $pax 1;
  13508.                             }
  13509.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13510.                             if ($days 1) {
  13511.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13512.                             } else {
  13513.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13514.                             }
  13515.                             $unitsServ $item->getUnits();
  13516.                             if (empty($unitsServ) or $unitsServ == "0") {
  13517.                                 $unitsServ 1;
  13518.                             }
  13519.                             $subtotal $subtotalService $days $unitsServ $pax;
  13520.                             $subnetoUnit $subneto;
  13521.                             $subneto $subneto $days $unitsServ $pax;
  13522.                             $data_supplier['service'][$i] = array(
  13523.                                 'id' => $item->getId(),
  13524.                                 'serviceCatId' => $item->getServiceCatId(),
  13525.                                 'serviceName' => $item->getName(),
  13526.                                 'serviceType' => 'DDR',
  13527.                                 'date' => $dateServ,
  13528.                                 'qty' => $unitsServ,
  13529.                                 'iva' => $item->getIva(),
  13530.                                 'pax' => $item->getPax(),
  13531.                                 'precioUnit' => $subnetoUnit,
  13532.                                 'subneto' => $subneto,
  13533.                                 'subtotal' => $subtotal,
  13534.                             );
  13535.                             break;
  13536.                         default:
  13537.                             break;
  13538.                     }
  13539.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  13540.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  13541.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  13542.                     $arrayItems[] = array(
  13543.                         'type' => 'Service',
  13544.                         'name' => $item->getName(),
  13545.                         'amount' => $neto,
  13546.                         'iva' => $item->getIva(),
  13547.                         'total' => $subtotal,
  13548.                     );
  13549.                 }
  13550.                 switch ($item->getIva()) {
  13551.                         // Acumula IVA
  13552.                     case 21:
  13553.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  13554.                         break;
  13555.                     case 10:
  13556.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  13557.                         break;
  13558.                     case 0:
  13559.                         break;
  13560.                     default:
  13561.                         break;
  13562.                 }
  13563.             }
  13564.             $totales_neto_all $totales_neto_all $neto;
  13565.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13566.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  13567.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  13568.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  13569.             // Acumula netos totales e IVA
  13570.             $service['neto'] = $service['neto'] + $neto;
  13571.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  13572.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13573.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  13574.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  13575.             $i++;
  13576.         }
  13577.         $data_supplier['serviceSubTotal'] = array(
  13578.             'neto' => $service['neto'],
  13579.             'sumSubT' => $service['sumSubT'],
  13580.         );
  13581.         $currency '€';
  13582.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  13583.         if (!empty($payments)) {
  13584.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  13585.         } else {
  13586.             $amount_pay 0;
  13587.         }
  13588.         $totales_all $totales_total $amount_pay;
  13589.         if (empty($dateDocument)) {
  13590.             $dateDocument = new DateTime('now');
  13591.         }
  13592.         $data = array(
  13593.             'id' => $fileId,
  13594.             'type' => $type,
  13595.             'number' => $number,
  13596.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $invoiceId,
  13597.             'date' => $dateDocument,
  13598.             'file' => $file,
  13599.             'token' => $file->getAccessKey(),
  13600.             'company' => $company,
  13601.             'clients' => $clientNew,
  13602.             'arrayItems' => $arrayItems,
  13603.             'datasupplier' => $data_supplier,
  13604.             'currency' => $currency,
  13605.             'totales_neto' => $totales_neto_all,
  13606.             'bases_imponibles' => $data_iva,
  13607.             'totales' => $totales_total,
  13608.             'balance' => $totales_all,
  13609.             'paymentInvoice' => $amount_pay,
  13610.         );
  13611.         return $data;
  13612.     }
  13613.     private function sendTelegram($id$text)
  13614.     {
  13615.         $em $this->getDoctrine()->getManager();
  13616.         $telegUser $em->getRepository(MdvTelegramUser::class)->findOneByUserId($id);
  13617.         if (empty($telegUser)) {
  13618.             return true;
  13619.         }
  13620.         $parameters = array(
  13621.             'chat_id' => $telegUser->getChatId(),
  13622.             'text' => $text,
  13623.         );
  13624.         $bot_token $telegUser->getBotToken();
  13625.         $url "https://api.telegram.org/bot$bot_token/sendMessage";
  13626.         if (!$curl curl_init()) {
  13627.             exit();
  13628.         }
  13629.         curl_setopt($curlCURLOPT_POSTtrue);
  13630.         curl_setopt($curlCURLOPT_POSTFIELDS$parameters);
  13631.         curl_setopt($curlCURLOPT_URL$url);
  13632.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  13633.         $output curl_exec($curl);
  13634.         curl_close($curl);
  13635.         return true;
  13636.     }
  13637.     private function baseProformaSelect($id$type$number$prefix$date$proformaId)
  13638.     {
  13639.         $em $this->getDoctrine()->getManager();
  13640.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  13641.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  13642.         $client $em->getRepository(Client::class)->findById($file->getClient());
  13643.         if (empty($client)) {
  13644.             $client[0] = new Client();
  13645.             $client[0]->setName('');
  13646.             $client[0]->setTitle('');
  13647.             $client[0]->setIdDocument('');
  13648.             $client[0]->setPopulation('');
  13649.             $client[0]->setRegion('');
  13650.             $client[0]->setCountry('');
  13651.         } else {
  13652.             if (is_numeric($client[0]->getPopulation())) {
  13653.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  13654. //                $client[0]->setPopulation($city->getCity());
  13655.             }
  13656.             if (is_numeric($client[0]->getRegion())) {
  13657.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  13658. //                $client[0]->setRegion($region->getRegion());
  13659.             }
  13660.             if (is_numeric($client[0]->getCountry())) {
  13661.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  13662. //                $client[0]->setCountry($country->getCountry());
  13663.             }
  13664.         }
  13665.         if (empty($client)) {
  13666.             $client[0] = new Client();
  13667.             $client[0]->setName('');
  13668.             $client[0]->setTitle('');
  13669.             $client[0]->setIdDocument('');
  13670.             $client[0]->setPopulation('');
  13671.             $client[0]->setRegion('');
  13672.             $client[0]->setCountry('');
  13673.             $clientNew = array(
  13674.                 'name' => '',
  13675.                 'title' => '',
  13676.                 'idDocument' => '',
  13677.                 'population' => '',
  13678.                 'region' => '',
  13679.                 'country' => '',
  13680.                 'address' => '',
  13681.                 'addressNumber' => '',
  13682.                 'zipCode' => '',
  13683.                 'typeDocument' => '',
  13684.             );
  13685.         } else {
  13686.             $clientNew = array(
  13687.                 'name' => $client[0]->getName(),
  13688.                 'title' => $client[0]->getTitle(),
  13689.                 'idDocument' => $client[0]->getIdDocument(),
  13690.                 'population' => '',
  13691.                 'region' => '',
  13692.                 'country' => '',
  13693.                 'address' => $client[0]->getAddress(),
  13694.                 'addressNumber' => $client[0]->getAddressNumber(),
  13695.                 'zipCode' => $client[0]->getZipCode(),
  13696.                 'typeDocument' => $client[0]->getTypeDocument(),
  13697.             );
  13698.             if (is_numeric($client[0]->getPopulation())) {
  13699.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  13700.                 $clientNew['population'] = $city->getCity();
  13701.             }
  13702.             if (is_numeric($client[0]->getRegion())) {
  13703.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  13704.                 $clientNew['region'] = $region->getRegion();
  13705.             }
  13706.             if (is_numeric($client[0]->getCountry())) {
  13707.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  13708.                 $clientNew['country'] = $country->getCountry();
  13709.             }
  13710.         }
  13711.         // Acumuladores de los calculos
  13712.         $totales_neto_all 0;
  13713.         $data_iva = array(
  13714.             'iva' => 21,
  13715.             'ivaMontoVeintiUno' => 0,
  13716.             'ivaMontoDiez' => 0,
  13717.             'ivaMontoCero' => null,
  13718.         );
  13719.         // Buscamos las salas reservadas, pagos y servicios para el evento
  13720.         // Buscamos los productos de la proforma
  13721.         $productsInProforma $em->getRepository(AveDocProformaItems::class)->findByProformaId($proformaId);
  13722.         $productsInFile = array();
  13723.         foreach ($productsInProforma as $item) {
  13724.             $producto $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  13725.             if (!empty($producto)) {
  13726.                 $productsInFile[] = $producto;
  13727.             }
  13728.         }
  13729.         //        $productsInFile = $em->getRepository(AveProductFile::class)->findByFileId($id);
  13730.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  13731.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  13732.         $data_supplier = array();
  13733.         $i 0;
  13734.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  13735.         $pax '1';
  13736.         $qty '1';
  13737.         $product = array(
  13738.             'neto' => 0,
  13739.             'sumSubT' => 0,
  13740.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13741.         $service = array(
  13742.             'neto' => 0,
  13743.             'sumSubT' => 0,
  13744.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13745.         foreach ($productsInFile as $item) {
  13746.             //            $days = '1';
  13747.             //            $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13748.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  13749.             // Verificamos que el producto no se encuentre ya en una factura
  13750.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
  13751.             $pax $item->getPax();
  13752.             $qty $item->getUnits();
  13753.             if (!empty($item->getDays())) {
  13754.                 $days $item->getDays();
  13755.             }
  13756.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
  13757.                 $subtotal 0;
  13758.                 $neto 0;
  13759.                 $subtotalProduct 0;
  13760.             } else {
  13761.                 //                $subtotalProduct = $item->getServicePrice() * 1.21;
  13762.                 $subtotalProduct $item->getSubTotalPrice() * 1.21;
  13763.                 //                $subneto = $item->getServicePrice();
  13764.                 $subneto $item->getSubTotalPrice();
  13765.                 $subtotal =  $subtotalProduct;
  13766.                 $neto =  $subneto;
  13767.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  13768.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  13769.                 $neto round($neto2PHP_ROUND_HALF_UP);
  13770.             }
  13771.             // Acumula netos totales e IVA
  13772.             $totales_neto_all $totales_neto_all $neto;
  13773.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  13774.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13775.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  13776.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  13777.             // Acumula netos totales e IVA
  13778.             $product['neto'] = $product['neto'] + $neto;
  13779.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  13780.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13781.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  13782.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  13783.             $data_supplier['product'][$i] = array(
  13784.                 'id' => $item->getId(),
  13785.                 'productName' => $item->getProductName(),
  13786.                 'productId' => $item->getProductId(),
  13787.                 'dateStart' => $item->getDateStart(),
  13788.                 'dateEnd' => $item->getDateEnd(),
  13789.                 'servicePrice' => $item->getServicePrice(),
  13790.                 'subTotalPrice' => $item->getSubTotalPrice(),
  13791.                 'subtotalProduct' => $subtotalProduct,
  13792.                 'iva' => $iva,
  13793.                 'pax' => $pax,
  13794.                 'qty' => $qty,
  13795.                 'days' => $days,
  13796.                 'type' => $item->getType(),
  13797.                 'subtotal' => $subtotal,
  13798.             );
  13799.             $i++;
  13800.         }
  13801.         $data_supplier['productSubTotal'] = array(
  13802.             'neto' => $product['neto'],
  13803.             'sumSubT' => $product['sumSubT'],
  13804.         );
  13805.         $payment = array(
  13806.             'sumSubT' => 0,
  13807.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13808.         $i 0;
  13809.         foreach ($payments as $item) {
  13810.             // Verificamos que el pago no se encuentre ya en una factura
  13811.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
  13812.             if (!empty($existe)) {
  13813.                 $payment['sumSubT'] = $payment['sumSubT'] + 0;
  13814.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13815.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  13816.             } else {
  13817.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  13818.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13819.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  13820.             }
  13821.             $data_supplier['payment'][$i] = array(
  13822.                 'id' => $item->getId(),
  13823.                 'amount' => $item->getAmount(),
  13824.                 'datePayAt' => $item->getDatePayAt(),
  13825.                 'wayToPay' => $item->getWayToPay(),
  13826.                 'amountTotal' => $item->getAmountTotal(),
  13827.                 'vat' => $item->getVat(),
  13828.             );
  13829.             $i++;
  13830.         }
  13831.         if (!empty($payments)) {
  13832.             $data_supplier['paymentSubTotal'] = array(
  13833.                 'sumSubT' => $payment['sumSubT'],
  13834.             );
  13835.         }
  13836.         foreach ($services as $item) {
  13837.             // Verificamos que el servicio no se encuentre ya en una factura
  13838.             $existe $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
  13839.             if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
  13840.                 $subtotal 0;
  13841.                 $neto 0;
  13842.                 $subtotalService 0;
  13843.                 $subneto 0;
  13844.                 switch ($item->getServiceCatId()) {
  13845.                     case 1// Alojamiento
  13846.                         // el numero de noches $numNoches; precio unitario $subneto
  13847.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  13848.                         // La personas no afectan este calculo
  13849.                         $subtotal $subtotalService $numNoches $item->getUnits();
  13850.                         $subnetoUnit $subneto;
  13851.                         $subneto $subneto $numNoches $item->getUnits();
  13852.                         $data_supplier['service'][$i] = array(
  13853.                             'id' => $item->getId(),
  13854.                             'serviceCatId' => $item->getServiceCatId(),
  13855.                             'serviceName' => $item->getName(),
  13856.                             'serviceType' => 'Hotel',
  13857.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  13858.                             'qty' => $item->getUnits(),
  13859.                             'iva' => $item->getIva(),
  13860.                             'pax' => '-',
  13861.                             'precioUnit' => $subnetoUnit,
  13862.                             'subneto' => $subneto,
  13863.                             'subtotal' => $subtotal,
  13864.                         );
  13865.                         break;
  13866.                     case 2//Actividades
  13867.                         // El nĂºmero de personas es considerado en el calculo
  13868.                         $pax $item->getPax();
  13869.                         if (empty($pax) or $pax == "0") {
  13870.                             $pax 1;
  13871.                         }
  13872.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13873.                         if ($days 1) {
  13874.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13875.                         } else {
  13876.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13877.                         }
  13878.                         $subtotal $subtotalService $days $item->getUnits();
  13879.                         $subnetoUnit $subneto;
  13880.                         $subneto $subneto $days $item->getUnits();
  13881.                         $data_supplier['service'][$i] = array(
  13882.                             'id' => $item->getId(),
  13883.                             'serviceCatId' => $item->getServiceCatId(),
  13884.                             'serviceName' => $item->getName(),
  13885.                             'serviceType' => 'Actividad',
  13886.                             'date' => $dateServ,
  13887.                             'qty' => $item->getUnits(),
  13888.                             'iva' => $item->getIva(),
  13889.                             'pax' => $item->getPax(),
  13890.                             'precioUnit' => $subnetoUnit,
  13891.                             'subneto' => $subneto,
  13892.                             'subtotal' => $subtotal,
  13893.                         );
  13894.                         break;
  13895.                     case 3// AV
  13896.                         $pax $item->getPax();
  13897.                         if (empty($pax) or $pax == "0") {
  13898.                             $pax 1;
  13899.                         }
  13900.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13901.                         if ($days 1) {
  13902.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13903.                         } else {
  13904.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13905.                         }
  13906.                         $unitsServ $item->getUnits();
  13907.                         if (empty($unitsServ) or $unitsServ == "0") {
  13908.                             $unitsServ 1;
  13909.                         }
  13910.                         $subtotal $subtotalService $days $unitsServ $pax;
  13911.                         $subnetoUnit $subneto;
  13912.                         $subneto $subneto $days $unitsServ $pax;
  13913.                         $data_supplier['service'][$i] = array(
  13914.                             'id' => $item->getId(),
  13915.                             'serviceCatId' => $item->getServiceCatId(),
  13916.                             'serviceName' => $item->getName(),
  13917.                             'serviceType' => 'AV',
  13918.                             'date' => $dateServ,
  13919.                             'qty' => $unitsServ,
  13920.                             'iva' => $item->getIva(),
  13921.                             'pax' => $item->getPax(),
  13922.                             'precioUnit' => $subnetoUnit,
  13923.                             'subneto' => $subneto,
  13924.                             'subtotal' => $subtotal,
  13925.                         );
  13926.                         break;
  13927.                     case 4//Creative
  13928.                         $pax $item->getPax();
  13929.                         if (empty($pax) or $pax == "0") {
  13930.                             $pax 1;
  13931.                         }
  13932.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13933.                         if ($days 1) {
  13934.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13935.                         } else {
  13936.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13937.                         }
  13938.                         $unitsServ $item->getUnits();
  13939.                         if (empty($unitsServ) or $unitsServ == "0") {
  13940.                             $unitsServ 1;
  13941.                         }
  13942.                         $subtotal $subtotalService $days $unitsServ $pax;
  13943.                         $subnetoUnit $subneto;
  13944.                         $subneto $subneto $days $unitsServ $pax;
  13945.                         $data_supplier['service'][$i] = array(
  13946.                             'id' => $item->getId(),
  13947.                             'serviceCatId' => $item->getServiceCatId(),
  13948.                             'serviceName' => $item->getName(),
  13949.                             'serviceType' => 'Creativo',
  13950.                             'date' => $dateServ,
  13951.                             'qty' => $unitsServ,
  13952.                             'iva' => $item->getIva(),
  13953.                             'pax' => $item->getPax(),
  13954.                             'precioUnit' => $subnetoUnit,
  13955.                             'subneto' => $subneto,
  13956.                             'subtotal' => $subtotal,
  13957.                         );
  13958.                         break;
  13959.                     case 5//Cruise
  13960.                         $pax $item->getPax();
  13961.                         if (empty($pax) or $pax == "0") {
  13962.                             $pax 1;
  13963.                         }
  13964.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  13965.                         if ($days 1) {
  13966.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13967.                         } else {
  13968.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13969.                         }
  13970.                         $unitsServ $item->getUnits();
  13971.                         if (empty($unitsServ) or $unitsServ == "0") {
  13972.                             $unitsServ 1;
  13973.                         }
  13974.                         $subtotal $subtotalService $days $unitsServ $pax;
  13975.                         $subnetoUnit $subneto;
  13976.                         $subneto $subneto $days $unitsServ $pax;
  13977.                         $data_supplier['service'][$i] = array(
  13978.                             'id' => $item->getId(),
  13979.                             'serviceCatId' => $item->getServiceCatId(),
  13980.                             'serviceName' => $item->getName(),
  13981.                             'serviceType' => 'Crucero',
  13982.                             'date' => $dateServ,
  13983.                             'qty' => $unitsServ,
  13984.                             'iva' => $item->getIva(),
  13985.                             'pax' => $item->getPax(),
  13986.                             'precioUnit' => $subnetoUnit,
  13987.                             'subneto' => $subneto,
  13988.                             'subtotal' => $subtotal,
  13989.                         );
  13990.                         break;
  13991.                     case 6//Entertaiment
  13992.                         $pax $item->getPax();
  13993.                         if (empty($pax) or $pax == "0") {
  13994.                             $pax 1;
  13995.                         }
  13996.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13997.                         if ($days 1) {
  13998.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13999.                         } else {
  14000.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14001.                         }
  14002.                         $unitsServ $item->getUnits();
  14003.                         if (empty($unitsServ) or $unitsServ == "0") {
  14004.                             $unitsServ 1;
  14005.                         }
  14006.                         $subtotal $subtotalService $days $unitsServ $pax;
  14007.                         $subnetoUnit $subneto;
  14008.                         $subneto $subneto $days $unitsServ $pax;
  14009.                         $data_supplier['service'][$i] = array(
  14010.                             'id' => $item->getId(),
  14011.                             'serviceCatId' => $item->getServiceCatId(),
  14012.                             'serviceName' => $item->getName(),
  14013.                             'serviceType' => 'Entretenimiento',
  14014.                             'date' => $dateServ,
  14015.                             'qty' => $unitsServ,
  14016.                             'iva' => $item->getIva(),
  14017.                             'pax' => $item->getPax(),
  14018.                             'precioUnit' => $subnetoUnit,
  14019.                             'subneto' => $subneto,
  14020.                             'subtotal' => $subtotal,
  14021.                         );
  14022.                         break;
  14023.                     case 7// Gifts
  14024.                         $pax $item->getPax();
  14025.                         if (empty($pax) or $pax == "0") {
  14026.                             $pax 1;
  14027.                         }
  14028.                         $days 1;
  14029.                         if ($days 1) {
  14030.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14031.                         } else {
  14032.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14033.                         }
  14034.                         $unitsServ $item->getUnits();
  14035.                         if (empty($unitsServ) or $unitsServ == "0") {
  14036.                             $unitsServ 1;
  14037.                         }
  14038.                         $subtotal $subtotalService $days $unitsServ $pax;
  14039.                         $subnetoUnit $subneto;
  14040.                         $subneto $subneto $days $unitsServ $pax;
  14041.                         $data_supplier['service'][$i] = array(
  14042.                             'id' => $item->getId(),
  14043.                             'serviceCatId' => $item->getServiceCatId(),
  14044.                             'serviceName' => $item->getName(),
  14045.                             'serviceType' => 'Regalos',
  14046.                             'date' => $dateServ,
  14047.                             'qty' => $unitsServ,
  14048.                             'iva' => $item->getIva(),
  14049.                             'pax' => $item->getPax(),
  14050.                             'precioUnit' => $subnetoUnit,
  14051.                             'subneto' => $subneto,
  14052.                             'subtotal' => $subtotal,
  14053.                         );
  14054.                         break;
  14055.                     case 8//Guide
  14056.                         $pax $item->getPax();
  14057.                         if (empty($pax) or $pax == "0") {
  14058.                             $pax 1;
  14059.                         }
  14060.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14061.                         if ($days 1) {
  14062.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14063.                         } else {
  14064.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14065.                         }
  14066.                         $unitsServ $item->getUnits();
  14067.                         if (empty($unitsServ) or $unitsServ == "0") {
  14068.                             $unitsServ 1;
  14069.                         }
  14070.                         $subtotal $subtotalService $days $unitsServ $pax;
  14071.                         $subnetoUnit $subneto;
  14072.                         $subneto $subneto $days $unitsServ $pax;
  14073.                         $data_supplier['service'][$i] = array(
  14074.                             'id' => $item->getId(),
  14075.                             'serviceCatId' => $item->getServiceCatId(),
  14076.                             'serviceName' => $item->getName(),
  14077.                             'serviceType' => 'Regalos',
  14078.                             'date' => $dateServ,
  14079.                             'qty' => $unitsServ,
  14080.                             'iva' => $item->getIva(),
  14081.                             'pax' => $item->getPax(),
  14082.                             'precioUnit' => $subnetoUnit,
  14083.                             'subneto' => $subneto,
  14084.                             'subtotal' => $subtotal,
  14085.                         );
  14086.                         break;
  14087.                     case 9//Itineraries
  14088.                         $pax $item->getPax();
  14089.                         if (empty($pax) or $pax == "0") {
  14090.                             $pax 1;
  14091.                         }
  14092.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14093.                         if ($days 1) {
  14094.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14095.                         } else {
  14096.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14097.                         }
  14098.                         $unitsServ $item->getUnits();
  14099.                         if (empty($unitsServ) or $unitsServ == "0") {
  14100.                             $unitsServ 1;
  14101.                         }
  14102.                         $subtotal $subtotalService $days $unitsServ $pax;
  14103.                         $subnetoUnit $subneto;
  14104.                         $subneto $subneto $days $unitsServ $pax;
  14105.                         $data_supplier['service'][$i] = array(
  14106.                             'id' => $item->getId(),
  14107.                             'serviceCatId' => $item->getServiceCatId(),
  14108.                             'serviceName' => $item->getName(),
  14109.                             'serviceType' => 'Itinerarios',
  14110.                             'date' => $dateServ,
  14111.                             'qty' => $unitsServ,
  14112.                             'iva' => $item->getIva(),
  14113.                             'pax' => $item->getPax(),
  14114.                             'precioUnit' => $subnetoUnit,
  14115.                             'subneto' => $subneto,
  14116.                             'subtotal' => $subtotal,
  14117.                         );
  14118.                         break;
  14119.                     case 10//Lounge  -- No Aplica
  14120.                         //                        $pax = $item->getPax();
  14121.                         //                        if (empty($pax) or $pax == "0") {
  14122.                         //                            $pax = 1;
  14123.                         //                        }
  14124.                         //
  14125.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  14126.                         //                        if ($days > 1){
  14127.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  14128.                         //                        } else {
  14129.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14130.                         //                        }
  14131.                         //
  14132.                         //                        $unitsServ = $item->getUnits();
  14133.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  14134.                         //                            $unitsServ = 1;
  14135.                         //                        }
  14136.                         //
  14137.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  14138.                         //                        $subnetoUnit = $subneto;
  14139.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  14140.                         //
  14141.                         //                        $data_supplier['service'][$i] = array (
  14142.                         //                            'id' => $item->getId(),
  14143.                         //                            'serviceCatId' => $item->getServiceCatId(),
  14144.                         //                            'serviceName' => $item->getName(),
  14145.                         //                            'serviceType' => 'Itinerarios',
  14146.                         //                            'date' => $dateServ,
  14147.                         //                            'qty' => $unitsServ,
  14148.                         //                            'iva' => $item->getIva(),
  14149.                         //                            'pax' => $item->getPax(),
  14150.                         //                            'precioUnit' => $subnetoUnit,
  14151.                         //                            'subneto' => $subneto,
  14152.                         //                            'subtotal' => $subtotal,
  14153.                         //                        );
  14154.                         break;
  14155.                     case 11//Menu
  14156.                         $pax $item->getPax();
  14157.                         if (empty($pax) or $pax == "0") {
  14158.                             $pax 1;
  14159.                         }
  14160.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14161.                         if ($days 1) {
  14162.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14163.                         } else {
  14164.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14165.                         }
  14166.                         $unitsServ $item->getUnits();
  14167.                         if (empty($unitsServ) or $unitsServ == "0") {
  14168.                             $unitsServ 1;
  14169.                         }
  14170.                         $subtotal $subtotalService $days $unitsServ $pax;
  14171.                         $subnetoUnit $subneto;
  14172.                         $subneto $subneto $days $unitsServ $pax;
  14173.                         $data_supplier['service'][$i] = array(
  14174.                             'id' => $item->getId(),
  14175.                             'serviceCatId' => $item->getServiceCatId(),
  14176.                             'serviceName' => $item->getName(),
  14177.                             'serviceType' => 'MenĂº',
  14178.                             'date' => $dateServ,
  14179.                             'qty' => $unitsServ,
  14180.                             'iva' => $item->getIva(),
  14181.                             'pax' => $item->getPax(),
  14182.                             'precioUnit' => $subnetoUnit,
  14183.                             'subneto' => $subneto,
  14184.                             'subtotal' => $subtotal,
  14185.                         );
  14186.                         break;
  14187.                     case 12//Others
  14188.                         $pax $item->getPax();
  14189.                         if (empty($pax) or $pax == "0") {
  14190.                             $pax 1;
  14191.                         }
  14192.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14193.                         if ($days 1) {
  14194.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14195.                         } else {
  14196.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14197.                         }
  14198.                         $unitsServ $item->getUnits();
  14199.                         if (empty($unitsServ) or $unitsServ == "0") {
  14200.                             $unitsServ 1;
  14201.                         }
  14202.                         $subtotal $subtotalService $days $unitsServ $pax;
  14203.                         $subnetoUnit $subneto;
  14204.                         $subneto $subneto $days $unitsServ $pax;
  14205.                         $data_supplier['service'][$i] = array(
  14206.                             'id' => $item->getId(),
  14207.                             'serviceCatId' => $item->getServiceCatId(),
  14208.                             'serviceName' => $item->getName(),
  14209.                             'serviceType' => 'Otros',
  14210.                             'date' => $dateServ,
  14211.                             'qty' => $unitsServ,
  14212.                             'iva' => $item->getIva(),
  14213.                             'pax' => $item->getPax(),
  14214.                             'precioUnit' => $subnetoUnit,
  14215.                             'subneto' => $subneto,
  14216.                             'subtotal' => $subtotal,
  14217.                         );
  14218.                         break;
  14219.                     case 13//Transport
  14220.                         $pax $item->getPax();
  14221.                         if (empty($pax) or $pax == "0") {
  14222.                             $pax 1;
  14223.                         }
  14224.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14225.                         if ($days 1) {
  14226.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14227.                         } else {
  14228.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14229.                         }
  14230.                         $unitsServ $item->getUnits();
  14231.                         if (empty($unitsServ) or $unitsServ == "0") {
  14232.                             $unitsServ 1;
  14233.                         }
  14234.                         $subtotal $subtotalService $days $unitsServ $pax;
  14235.                         $subnetoUnit $subneto;
  14236.                         $subneto $subneto $days $unitsServ $pax;
  14237.                         $data_supplier['service'][$i] = array(
  14238.                             'id' => $item->getId(),
  14239.                             'serviceCatId' => $item->getServiceCatId(),
  14240.                             'serviceName' => $item->getName(),
  14241.                             'serviceType' => 'Transporte',
  14242.                             'date' => $dateServ,
  14243.                             'qty' => $unitsServ,
  14244.                             'iva' => $item->getIva(),
  14245.                             'pax' => $item->getPax(),
  14246.                             'precioUnit' => $subnetoUnit,
  14247.                             'subneto' => $subneto,
  14248.                             'subtotal' => $subtotal,
  14249.                         );
  14250.                         break;
  14251.                     case 14//Technology
  14252.                         $pax $item->getPax();
  14253.                         if (empty($pax) or $pax == "0") {
  14254.                             $pax 1;
  14255.                         }
  14256.                         $days 1;
  14257.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14258.                         $unitsServ $item->getUnits();
  14259.                         if (empty($unitsServ) or $unitsServ == "0") {
  14260.                             $unitsServ 1;
  14261.                         }
  14262.                         $subtotal $subtotalService $days $unitsServ $pax;
  14263.                         $subnetoUnit $subneto;
  14264.                         $subneto $subneto $days $unitsServ $pax;
  14265.                         $data_supplier['service'][$i] = array(
  14266.                             'id' => $item->getId(),
  14267.                             'serviceCatId' => $item->getServiceCatId(),
  14268.                             'serviceName' => $item->getName(),
  14269.                             'serviceType' => 'TecnologĂ­a',
  14270.                             'date' => $dateServ,
  14271.                             'qty' => $unitsServ,
  14272.                             'iva' => $item->getIva(),
  14273.                             'pax' => $item->getPax(),
  14274.                             'precioUnit' => $subnetoUnit,
  14275.                             'subneto' => $subneto,
  14276.                             'subtotal' => $subtotal,
  14277.                         );
  14278.                         break;
  14279.                     case 15//Assisstant
  14280.                         $pax $item->getPax();
  14281.                         if (empty($pax) or $pax == "0") {
  14282.                             $pax 1;
  14283.                         }
  14284.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14285.                         if ($days 1) {
  14286.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14287.                         } else {
  14288.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14289.                         }
  14290.                         $unitsServ $item->getUnits();
  14291.                         if (empty($unitsServ) or $unitsServ == "0") {
  14292.                             $unitsServ 1;
  14293.                         }
  14294.                         $subtotal $subtotalService $days $unitsServ $pax;
  14295.                         $subnetoUnit $subneto;
  14296.                         $subneto $subneto $days $unitsServ $pax;
  14297.                         $data_supplier['service'][$i] = array(
  14298.                             'id' => $item->getId(),
  14299.                             'serviceCatId' => $item->getServiceCatId(),
  14300.                             'serviceName' => $item->getName(),
  14301.                             'serviceType' => 'Asistente',
  14302.                             'date' => $dateServ,
  14303.                             'qty' => $unitsServ,
  14304.                             'iva' => $item->getIva(),
  14305.                             'pax' => $item->getPax(),
  14306.                             'precioUnit' => $subnetoUnit,
  14307.                             'subneto' => $subneto,
  14308.                             'subtotal' => $subtotal,
  14309.                         );
  14310.                         break;
  14311.                     case 16//DDR
  14312.                         $pax $item->getPax();
  14313.                         if (empty($pax) or $pax == "0") {
  14314.                             $pax 1;
  14315.                         }
  14316.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14317.                         if ($days 1) {
  14318.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14319.                         } else {
  14320.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14321.                         }
  14322.                         $unitsServ $item->getUnits();
  14323.                         if (empty($unitsServ) or $unitsServ == "0") {
  14324.                             $unitsServ 1;
  14325.                         }
  14326.                         $subtotal $subtotalService $days $unitsServ $pax;
  14327.                         $subnetoUnit $subneto;
  14328.                         $subneto $subneto $days $unitsServ $pax;
  14329.                         $data_supplier['service'][$i] = array(
  14330.                             'id' => $item->getId(),
  14331.                             'serviceCatId' => $item->getServiceCatId(),
  14332.                             'serviceName' => $item->getName(),
  14333.                             'serviceType' => 'DDR',
  14334.                             'date' => $dateServ,
  14335.                             'qty' => $unitsServ,
  14336.                             'iva' => $item->getIva(),
  14337.                             'pax' => $item->getPax(),
  14338.                             'precioUnit' => $subnetoUnit,
  14339.                             'subneto' => $subneto,
  14340.                             'subtotal' => $subtotal,
  14341.                         );
  14342.                         break;
  14343.                     default:
  14344.                         break;
  14345.                 }
  14346.             } else {
  14347.                 $subtotalService $item->getPrice();
  14348.                 $subneto $item->getPrice();
  14349.                 // Commission
  14350.                 if ($item->getOpCommission() == '1') {
  14351.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  14352.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  14353.                 } else {
  14354.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  14355.                     $subneto $subneto * (- ($item->getCommission() / 100));
  14356.                 }
  14357.                 // Over
  14358.                 if ($item->getOpOver() == '1') {
  14359.                     $subtotalService $subtotalService $item->getOver();
  14360.                     $subneto $subneto $item->getOver();
  14361.                 } else {
  14362.                     $subtotalService $subtotalService $item->getOver();
  14363.                     $subneto $subneto $item->getOver();
  14364.                 }
  14365.                 // IVA
  14366.                 if ($item->getOpIva() == '1') {
  14367.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  14368.                 } else {
  14369.                     $subtotalService $item->getPrice();
  14370.                     $subneto = ($subneto 100) / (100 $item->getIva());
  14371.                 }
  14372.                 switch ($item->getServiceCatId()) {
  14373.                     case 1// Alojamiento
  14374.                         // el numero de noches $numNoches; precio unitario $subneto
  14375.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  14376.                         // La personas no afectan este calculo
  14377.                         $subtotal $subtotalService $numNoches $item->getUnits();
  14378.                         $subnetoUnit $subneto;
  14379.                         $subneto $subneto $numNoches $item->getUnits();
  14380.                         $data_supplier['service'][$i] = array(
  14381.                             'id' => $item->getId(),
  14382.                             'serviceCatId' => $item->getServiceCatId(),
  14383.                             'serviceName' => $item->getName(),
  14384.                             'serviceType' => 'Hotel',
  14385.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  14386.                             'qty' => $item->getUnits(),
  14387.                             'iva' => $item->getIva(),
  14388.                             'pax' => '-',
  14389.                             'precioUnit' => $subnetoUnit,
  14390.                             'subneto' => $subneto,
  14391.                             'subtotal' => $subtotal,
  14392.                         );
  14393.                         break;
  14394.                     case 2//Actividades
  14395.                         // El nĂºmero de personas es considerado en el calculo
  14396.                         $pax $item->getPax();
  14397.                         if (empty($pax) or $pax == "0") {
  14398.                             $pax 1;
  14399.                         }
  14400.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14401.                         if ($days 1) {
  14402.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14403.                         } else {
  14404.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14405.                         }
  14406.                         $subtotal $subtotalService $days $item->getUnits();
  14407.                         $subnetoUnit $subneto;
  14408.                         $subneto $subneto $days $item->getUnits();
  14409.                         $data_supplier['service'][$i] = array(
  14410.                             'id' => $item->getId(),
  14411.                             'serviceCatId' => $item->getServiceCatId(),
  14412.                             'serviceName' => $item->getName(),
  14413.                             'serviceType' => 'Actividad',
  14414.                             'date' => $dateServ,
  14415.                             'qty' => $item->getUnits(),
  14416.                             'iva' => $item->getIva(),
  14417.                             'pax' => $item->getPax(),
  14418.                             'precioUnit' => $subnetoUnit,
  14419.                             'subneto' => $subneto,
  14420.                             'subtotal' => $subtotal,
  14421.                         );
  14422.                         break;
  14423.                     case 3// AV
  14424.                         $pax $item->getPax();
  14425.                         if (empty($pax) or $pax == "0") {
  14426.                             $pax 1;
  14427.                         }
  14428.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14429.                         if ($days 1) {
  14430.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14431.                         } else {
  14432.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14433.                         }
  14434.                         $unitsServ $item->getUnits();
  14435.                         if (empty($unitsServ) or $unitsServ == "0") {
  14436.                             $unitsServ 1;
  14437.                         }
  14438.                         $subtotal $subtotalService $days $unitsServ $pax;
  14439.                         $subnetoUnit $subneto;
  14440.                         $subneto $subneto $days $unitsServ $pax;
  14441.                         $data_supplier['service'][$i] = array(
  14442.                             'id' => $item->getId(),
  14443.                             'serviceCatId' => $item->getServiceCatId(),
  14444.                             'serviceName' => $item->getName(),
  14445.                             'serviceType' => 'AV',
  14446.                             'date' => $dateServ,
  14447.                             'qty' => $unitsServ,
  14448.                             'iva' => $item->getIva(),
  14449.                             'pax' => $item->getPax(),
  14450.                             'precioUnit' => $subnetoUnit,
  14451.                             'subneto' => $subneto,
  14452.                             'subtotal' => $subtotal,
  14453.                         );
  14454.                         break;
  14455.                     case 4//Creative
  14456.                         $pax $item->getPax();
  14457.                         if (empty($pax) or $pax == "0") {
  14458.                             $pax 1;
  14459.                         }
  14460.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14461.                         if ($days 1) {
  14462.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14463.                         } else {
  14464.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14465.                         }
  14466.                         $unitsServ $item->getUnits();
  14467.                         if (empty($unitsServ) or $unitsServ == "0") {
  14468.                             $unitsServ 1;
  14469.                         }
  14470.                         $subtotal $subtotalService $days $unitsServ $pax;
  14471.                         $subnetoUnit $subneto;
  14472.                         $subneto $subneto $days $unitsServ $pax;
  14473.                         $data_supplier['service'][$i] = array(
  14474.                             'id' => $item->getId(),
  14475.                             'serviceCatId' => $item->getServiceCatId(),
  14476.                             'serviceName' => $item->getName(),
  14477.                             'serviceType' => 'Creativo',
  14478.                             'date' => $dateServ,
  14479.                             'qty' => $unitsServ,
  14480.                             'iva' => $item->getIva(),
  14481.                             'pax' => $item->getPax(),
  14482.                             'precioUnit' => $subnetoUnit,
  14483.                             'subneto' => $subneto,
  14484.                             'subtotal' => $subtotal,
  14485.                         );
  14486.                         break;
  14487.                     case 5//Cruise
  14488.                         $pax $item->getPax();
  14489.                         if (empty($pax) or $pax == "0") {
  14490.                             $pax 1;
  14491.                         }
  14492.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  14493.                         if ($days 1) {
  14494.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14495.                         } else {
  14496.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14497.                         }
  14498.                         $unitsServ $item->getUnits();
  14499.                         if (empty($unitsServ) or $unitsServ == "0") {
  14500.                             $unitsServ 1;
  14501.                         }
  14502.                         $subtotal $subtotalService $days $unitsServ $pax;
  14503.                         $subnetoUnit $subneto;
  14504.                         $subneto $subneto $days $unitsServ $pax;
  14505.                         $data_supplier['service'][$i] = array(
  14506.                             'id' => $item->getId(),
  14507.                             'serviceCatId' => $item->getServiceCatId(),
  14508.                             'serviceName' => $item->getName(),
  14509.                             'serviceType' => 'Crucero',
  14510.                             'date' => $dateServ,
  14511.                             'qty' => $unitsServ,
  14512.                             'iva' => $item->getIva(),
  14513.                             'pax' => $item->getPax(),
  14514.                             'precioUnit' => $subnetoUnit,
  14515.                             'subneto' => $subneto,
  14516.                             'subtotal' => $subtotal,
  14517.                         );
  14518.                         break;
  14519.                     case 6//Entertaiment
  14520.                         $pax $item->getPax();
  14521.                         if (empty($pax) or $pax == "0") {
  14522.                             $pax 1;
  14523.                         }
  14524.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14525.                         if ($days 1) {
  14526.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14527.                         } else {
  14528.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14529.                         }
  14530.                         $unitsServ $item->getUnits();
  14531.                         if (empty($unitsServ) or $unitsServ == "0") {
  14532.                             $unitsServ 1;
  14533.                         }
  14534.                         $subtotal $subtotalService $days $unitsServ $pax;
  14535.                         $subnetoUnit $subneto;
  14536.                         $subneto $subneto $days $unitsServ $pax;
  14537.                         $data_supplier['service'][$i] = array(
  14538.                             'id' => $item->getId(),
  14539.                             'serviceCatId' => $item->getServiceCatId(),
  14540.                             'serviceName' => $item->getName(),
  14541.                             'serviceType' => 'Entretenimiento',
  14542.                             'date' => $dateServ,
  14543.                             'qty' => $unitsServ,
  14544.                             'iva' => $item->getIva(),
  14545.                             'pax' => $item->getPax(),
  14546.                             'precioUnit' => $subnetoUnit,
  14547.                             'subneto' => $subneto,
  14548.                             'subtotal' => $subtotal,
  14549.                         );
  14550.                         break;
  14551.                     case 7// Gifts
  14552.                         $pax $item->getPax();
  14553.                         if (empty($pax) or $pax == "0") {
  14554.                             $pax 1;
  14555.                         }
  14556.                         $days 1;
  14557.                         if ($days 1) {
  14558.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14559.                         } else {
  14560.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14561.                         }
  14562.                         $unitsServ $item->getUnits();
  14563.                         if (empty($unitsServ) or $unitsServ == "0") {
  14564.                             $unitsServ 1;
  14565.                         }
  14566.                         $subtotal $subtotalService $days $unitsServ $pax;
  14567.                         $subnetoUnit $subneto;
  14568.                         $subneto $subneto $days $unitsServ $pax;
  14569.                         $data_supplier['service'][$i] = array(
  14570.                             'id' => $item->getId(),
  14571.                             'serviceCatId' => $item->getServiceCatId(),
  14572.                             'serviceName' => $item->getName(),
  14573.                             'serviceType' => 'Regalos',
  14574.                             'date' => $dateServ,
  14575.                             'qty' => $unitsServ,
  14576.                             'iva' => $item->getIva(),
  14577.                             'pax' => $item->getPax(),
  14578.                             'precioUnit' => $subnetoUnit,
  14579.                             'subneto' => $subneto,
  14580.                             'subtotal' => $subtotal,
  14581.                         );
  14582.                         break;
  14583.                     case 8//Guide
  14584.                         $pax $item->getPax();
  14585.                         if (empty($pax) or $pax == "0") {
  14586.                             $pax 1;
  14587.                         }
  14588.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14589.                         if ($days 1) {
  14590.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14591.                         } else {
  14592.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14593.                         }
  14594.                         $unitsServ $item->getUnits();
  14595.                         if (empty($unitsServ) or $unitsServ == "0") {
  14596.                             $unitsServ 1;
  14597.                         }
  14598.                         $subtotal $subtotalService $days $unitsServ $pax;
  14599.                         $subnetoUnit $subneto;
  14600.                         $subneto $subneto $days $unitsServ $pax;
  14601.                         $data_supplier['service'][$i] = array(
  14602.                             'id' => $item->getId(),
  14603.                             'serviceCatId' => $item->getServiceCatId(),
  14604.                             'serviceName' => $item->getName(),
  14605.                             'serviceType' => 'Regalos',
  14606.                             'date' => $dateServ,
  14607.                             'qty' => $unitsServ,
  14608.                             'iva' => $item->getIva(),
  14609.                             'pax' => $item->getPax(),
  14610.                             'precioUnit' => $subnetoUnit,
  14611.                             'subneto' => $subneto,
  14612.                             'subtotal' => $subtotal,
  14613.                         );
  14614.                         break;
  14615.                     case 9//Itineraries
  14616.                         $pax $item->getPax();
  14617.                         if (empty($pax) or $pax == "0") {
  14618.                             $pax 1;
  14619.                         }
  14620.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14621.                         if ($days 1) {
  14622.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14623.                         } else {
  14624.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14625.                         }
  14626.                         $unitsServ $item->getUnits();
  14627.                         if (empty($unitsServ) or $unitsServ == "0") {
  14628.                             $unitsServ 1;
  14629.                         }
  14630.                         $subtotal $subtotalService $days $unitsServ $pax;
  14631.                         $subnetoUnit $subneto;
  14632.                         $subneto $subneto $days $unitsServ $pax;
  14633.                         $data_supplier['service'][$i] = array(
  14634.                             'id' => $item->getId(),
  14635.                             'serviceCatId' => $item->getServiceCatId(),
  14636.                             'serviceName' => $item->getName(),
  14637.                             'serviceType' => 'Itinerarios',
  14638.                             'date' => $dateServ,
  14639.                             'qty' => $unitsServ,
  14640.                             'iva' => $item->getIva(),
  14641.                             'pax' => $item->getPax(),
  14642.                             'precioUnit' => $subnetoUnit,
  14643.                             'subneto' => $subneto,
  14644.                             'subtotal' => $subtotal,
  14645.                         );
  14646.                         break;
  14647.                     case 10//Lounge  -- No Aplica
  14648.                         //                        $pax = $item->getPax();
  14649.                         //                        if (empty($pax) or $pax == "0") {
  14650.                         //                            $pax = 1;
  14651.                         //                        }
  14652.                         //
  14653.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  14654.                         //                        if ($days > 1){
  14655.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  14656.                         //                        } else {
  14657.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14658.                         //                        }
  14659.                         //
  14660.                         //                        $unitsServ = $item->getUnits();
  14661.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  14662.                         //                            $unitsServ = 1;
  14663.                         //                        }
  14664.                         //
  14665.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  14666.                         //                        $subnetoUnit = $subneto;
  14667.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  14668.                         //
  14669.                         //                        $data_supplier['service'][$i] = array (
  14670.                         //                            'id' => $item->getId(),
  14671.                         //                            'serviceCatId' => $item->getServiceCatId(),
  14672.                         //                            'serviceName' => $item->getName(),
  14673.                         //                            'serviceType' => 'Itinerarios',
  14674.                         //                            'date' => $dateServ,
  14675.                         //                            'qty' => $unitsServ,
  14676.                         //                            'iva' => $item->getIva(),
  14677.                         //                            'pax' => $item->getPax(),
  14678.                         //                            'precioUnit' => $subnetoUnit,
  14679.                         //                            'subneto' => $subneto,
  14680.                         //                            'subtotal' => $subtotal,
  14681.                         //                        );
  14682.                         break;
  14683.                     case 11//Menu
  14684.                         $pax $item->getPax();
  14685.                         if (empty($pax) or $pax == "0") {
  14686.                             $pax 1;
  14687.                         }
  14688.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14689.                         if ($days 1) {
  14690.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14691.                         } else {
  14692.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14693.                         }
  14694.                         $unitsServ $item->getUnits();
  14695.                         if (empty($unitsServ) or $unitsServ == "0") {
  14696.                             $unitsServ 1;
  14697.                         }
  14698.                         $subtotal $subtotalService $days $unitsServ $pax;
  14699.                         $subnetoUnit $subneto;
  14700.                         $subneto $subneto $days $unitsServ $pax;
  14701.                         $data_supplier['service'][$i] = array(
  14702.                             'id' => $item->getId(),
  14703.                             'serviceCatId' => $item->getServiceCatId(),
  14704.                             'serviceName' => $item->getName(),
  14705.                             'serviceType' => 'MenĂº',
  14706.                             'date' => $dateServ,
  14707.                             'qty' => $unitsServ,
  14708.                             'iva' => $item->getIva(),
  14709.                             'pax' => $item->getPax(),
  14710.                             'precioUnit' => $subnetoUnit,
  14711.                             'subneto' => $subneto,
  14712.                             'subtotal' => $subtotal,
  14713.                         );
  14714.                         break;
  14715.                     case 12//Others
  14716.                         $pax $item->getPax();
  14717.                         if (empty($pax) or $pax == "0") {
  14718.                             $pax 1;
  14719.                         }
  14720.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14721.                         if ($days 1) {
  14722.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14723.                         } else {
  14724.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14725.                         }
  14726.                         $unitsServ $item->getUnits();
  14727.                         if (empty($unitsServ) or $unitsServ == "0") {
  14728.                             $unitsServ 1;
  14729.                         }
  14730.                         $subtotal $subtotalService $days $unitsServ $pax;
  14731.                         $subnetoUnit $subneto;
  14732.                         $subneto $subneto $days $unitsServ $pax;
  14733.                         $data_supplier['service'][$i] = array(
  14734.                             'id' => $item->getId(),
  14735.                             'serviceCatId' => $item->getServiceCatId(),
  14736.                             'serviceName' => $item->getName(),
  14737.                             'serviceType' => 'Otros',
  14738.                             'date' => $dateServ,
  14739.                             'qty' => $unitsServ,
  14740.                             'iva' => $item->getIva(),
  14741.                             'pax' => $item->getPax(),
  14742.                             'precioUnit' => $subnetoUnit,
  14743.                             'subneto' => $subneto,
  14744.                             'subtotal' => $subtotal,
  14745.                         );
  14746.                         break;
  14747.                     case 13//Transport
  14748.                         $pax $item->getPax();
  14749.                         if (empty($pax) or $pax == "0") {
  14750.                             $pax 1;
  14751.                         }
  14752.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14753.                         if ($days 1) {
  14754.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14755.                         } else {
  14756.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14757.                         }
  14758.                         $unitsServ $item->getUnits();
  14759.                         if (empty($unitsServ) or $unitsServ == "0") {
  14760.                             $unitsServ 1;
  14761.                         }
  14762.                         $subtotal $subtotalService $days $unitsServ $pax;
  14763.                         $subnetoUnit $subneto;
  14764.                         $subneto $subneto $days $unitsServ $pax;
  14765.                         $data_supplier['service'][$i] = array(
  14766.                             'id' => $item->getId(),
  14767.                             'serviceCatId' => $item->getServiceCatId(),
  14768.                             'serviceName' => $item->getName(),
  14769.                             'serviceType' => 'Transporte',
  14770.                             'date' => $dateServ,
  14771.                             'qty' => $unitsServ,
  14772.                             'iva' => $item->getIva(),
  14773.                             'pax' => $item->getPax(),
  14774.                             'precioUnit' => $subnetoUnit,
  14775.                             'subneto' => $subneto,
  14776.                             'subtotal' => $subtotal,
  14777.                         );
  14778.                         break;
  14779.                     case 14//Technology
  14780.                         $pax $item->getPax();
  14781.                         if (empty($pax) or $pax == "0") {
  14782.                             $pax 1;
  14783.                         }
  14784.                         $days 1;
  14785.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14786.                         $unitsServ $item->getUnits();
  14787.                         if (empty($unitsServ) or $unitsServ == "0") {
  14788.                             $unitsServ 1;
  14789.                         }
  14790.                         $subtotal $subtotalService $days $unitsServ $pax;
  14791.                         $subnetoUnit $subneto;
  14792.                         $subneto $subneto $days $unitsServ $pax;
  14793.                         $data_supplier['service'][$i] = array(
  14794.                             'id' => $item->getId(),
  14795.                             'serviceCatId' => $item->getServiceCatId(),
  14796.                             'serviceName' => $item->getName(),
  14797.                             'serviceType' => 'TecnologĂ­a',
  14798.                             'date' => $dateServ,
  14799.                             'qty' => $unitsServ,
  14800.                             'iva' => $item->getIva(),
  14801.                             'pax' => $item->getPax(),
  14802.                             'precioUnit' => $subnetoUnit,
  14803.                             'subneto' => $subneto,
  14804.                             'subtotal' => $subtotal,
  14805.                         );
  14806.                         break;
  14807.                     case 15//Assisstant
  14808.                         $pax $item->getPax();
  14809.                         if (empty($pax) or $pax == "0") {
  14810.                             $pax 1;
  14811.                         }
  14812.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14813.                         if ($days 1) {
  14814.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14815.                         } else {
  14816.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14817.                         }
  14818.                         $unitsServ $item->getUnits();
  14819.                         if (empty($unitsServ) or $unitsServ == "0") {
  14820.                             $unitsServ 1;
  14821.                         }
  14822.                         $subtotal $subtotalService $days $unitsServ $pax;
  14823.                         $subnetoUnit $subneto;
  14824.                         $subneto $subneto $days $unitsServ $pax;
  14825.                         $data_supplier['service'][$i] = array(
  14826.                             'id' => $item->getId(),
  14827.                             'serviceCatId' => $item->getServiceCatId(),
  14828.                             'serviceName' => $item->getName(),
  14829.                             'serviceType' => 'Asistente',
  14830.                             'date' => $dateServ,
  14831.                             'qty' => $unitsServ,
  14832.                             'iva' => $item->getIva(),
  14833.                             'pax' => $item->getPax(),
  14834.                             'precioUnit' => $subnetoUnit,
  14835.                             'subneto' => $subneto,
  14836.                             'subtotal' => $subtotal,
  14837.                         );
  14838.                         break;
  14839.                     case 16//DDR
  14840.                         $pax $item->getPax();
  14841.                         if (empty($pax) or $pax == "0") {
  14842.                             $pax 1;
  14843.                         }
  14844.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14845.                         if ($days 1) {
  14846.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14847.                         } else {
  14848.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14849.                         }
  14850.                         $unitsServ $item->getUnits();
  14851.                         if (empty($unitsServ) or $unitsServ == "0") {
  14852.                             $unitsServ 1;
  14853.                         }
  14854.                         $subtotal $subtotalService $days $unitsServ $pax;
  14855.                         $subnetoUnit $subneto;
  14856.                         $subneto $subneto $days $unitsServ $pax;
  14857.                         $data_supplier['service'][$i] = array(
  14858.                             'id' => $item->getId(),
  14859.                             'serviceCatId' => $item->getServiceCatId(),
  14860.                             'serviceName' => $item->getName(),
  14861.                             'serviceType' => 'DDR',
  14862.                             'date' => $dateServ,
  14863.                             'qty' => $unitsServ,
  14864.                             'iva' => $item->getIva(),
  14865.                             'pax' => $item->getPax(),
  14866.                             'precioUnit' => $subnetoUnit,
  14867.                             'subneto' => $subneto,
  14868.                             'subtotal' => $subtotal,
  14869.                         );
  14870.                         break;
  14871.                     default:
  14872.                         break;
  14873.                 }
  14874.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  14875.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  14876.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  14877.             }
  14878.             switch ($item->getIva()) {
  14879.                     // Acumula IVA
  14880.                 case 21:
  14881.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  14882.                     break;
  14883.                 case 10:
  14884.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  14885.                     break;
  14886.                 case 0:
  14887.                     break;
  14888.                 default:
  14889.                     break;
  14890.             }
  14891.             $totales_neto_all $totales_neto_all $neto;
  14892.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  14893.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  14894.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  14895.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  14896.             // Acumula netos totales e IVA
  14897.             $service['neto'] = $service['neto'] + $neto;
  14898.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  14899.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  14900.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  14901.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  14902.             $i++;
  14903.         }
  14904.         $data_supplier['serviceSubTotal'] = array(
  14905.             'neto' => $service['neto'],
  14906.             'sumSubT' => $service['sumSubT'],
  14907.         );
  14908.         $currency '€';
  14909.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  14910.         if (!empty($payments)) {
  14911.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  14912.         } else {
  14913.             $amount_pay 0;
  14914.         }
  14915.         $totales_all $totales_total $amount_pay;
  14916.         $data = array(
  14917.             'id' => $id,
  14918.             'type' => $type,
  14919.             'number' => $number,
  14920.             'prefix' => $prefix,
  14921.             'date' => $date,
  14922.             'file' => $file,
  14923.             'token' => ''// $file->getAccessKey(),
  14924.             'company' => $company,
  14925.             'clients' => $clientNew,
  14926.             'datasupplier' => $data_supplier,
  14927.             'currency' => $currency,
  14928.             'totales_neto' => $totales_neto_all,
  14929.             'bases_imponibles' => $data_iva,
  14930.             'totales' => $totales_total,
  14931.             'balance' => $totales_all,
  14932.             'paymentInvoice' => $amount_pay,
  14933.         );
  14934.         return $data;
  14935.     }
  14936.     private function sendMailLot($mailAddressFrom$mailArrayTo$mailSubject$mailBody)
  14937.     {
  14938.         $em $this->getDoctrine()->getManager();
  14939.         $agent $em->getRepository(User::class)->findOneByEmail($mailAddressFrom);
  14940.         //        $client = $em->getRepository(User::class)->findOneByEmail($mailAddressTo);
  14941.         $replyTo = array();
  14942.         foreach ($mailArrayTo as $item) {
  14943.             // Verificamos que los correos sean validos
  14944.             if (filter_var($itemFILTER_VALIDATE_EMAIL)) {
  14945.                 $replyTo[$item] = $item;
  14946.             }
  14947.         }
  14948.         $agentMail $mailAddressFrom;
  14949.         $mailAgent $agentMail;
  14950.         //Se prepara el correo con los agentes a notificar
  14951.         $firmGmail $agent->getFirmGmail();
  14952.         $data = array(
  14953.             'body' => $mailBody,
  14954.             'firm' => $firmGmail,
  14955.         );
  14956.         // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  14957.         $transporter = new Swift_SmtpTransport();
  14958.         $transporter->setHost('smtp.gmail.com')
  14959.             ->setEncryption('ssl'//ssl / tls
  14960.             ->setPort(465// 465 / 587
  14961.             ->setUsername('desarrollo@develup.solutions')
  14962.             ->setPassword('utvh hzoi wfdo ztjs');
  14963.         $mailer = new Swift_Mailer($transporter);
  14964.         $message = new Swift_Message();
  14965.         $message->setSubject($mailSubject)
  14966.             ->setSender($agentMail)
  14967.             ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  14968.             ->setReplyTo($agentMail)
  14969.             ->setTo($replyTo)
  14970.             ->setBody(
  14971.                 $this->renderView(
  14972.                     'mail/structure-mail.html.twig',
  14973.                     array('data' => $data)
  14974.                 ),
  14975.                 'text/html'
  14976.             );
  14977.         $mailer->send($message);
  14978.         return true;
  14979.     }
  14980.     private function calculoBeneficiosDocumento($id$typeDoc)
  14981.     {
  14982.         // Funcion para registrar los beneficios al crear facturas o facturas rectificativas
  14983.         $em $this->getDoctrine()->getManager();
  14984.         if ($typeDoc == 'Invoice') {
  14985.             // Es factura
  14986.             $invoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  14987.             $invoiceItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  14988.             // ComisiĂ³n de AV a GreenPatio
  14989.             $aveFile $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  14990.             $reserva $em->getRepository(Reservation::class)->findOneById($aveFile->getReservation());
  14991.             if (!empty($reserva)){
  14992.                 if (!is_null($reserva->getComAvGp())) {
  14993.                     $supplierNet $invoice->getTotalNet() * ($reserva->getComAvGp()/100);
  14994.                 } else {
  14995.                     // Valor por defecto de la Comision de Av 10%
  14996.                     $supplierNet $invoice->getTotalNet() * (10/100);
  14997.                 }
  14998.                 $description $id.' - ComisiĂ³n MANTE de Green Patio (Generado automaticamente)';
  14999.                 $supplier $em->getRepository(Supplier::class)->findOneById(2028);     // Green Patio como proveedor
  15000.                 $benSup = new AveBenefitsSupplier();
  15001.                 $benSup->setFileId($aveFile->getId());
  15002.                 $benSup->setDocId(0);
  15003.                 $benSup->setDocType('.');
  15004.                 $benSup->setSupplierId(2028);
  15005.                 $benSup->setSupplierName($supplier->getCompany() . ' | ' $supplier->getName());
  15006.                 $benSup->setDescription($description);
  15007.                 $benSup->setBenefitSupplier($supplierNet);
  15008.                 $em->persist($benSup);
  15009.                 $em->flush();
  15010.             }
  15011.         } else {
  15012.             // Es factura rectificativa
  15013.             // Se busca la entrada de los beneficios de la factura y se genera su contraparte. Tambien se necesita el ID de la factura rectificativa
  15014.             $invoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  15015.             if (empty($invoiceRec)) { return true; }
  15016.             $ben $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByDocId($invoiceRec->getInvoiceToRec());
  15017.             $benefits = new AveBenefitsInvoiceInvoiceRec();
  15018.             $benefits->setDocId($invoiceRec->getId());
  15019.             $benefits->setFileId($ben->getFileId());
  15020.             $benefits->setDocType('Invoice Rec');
  15021.             $benefits->setDateAt($invoiceRec->getDateAt());
  15022.             $benefits->setFileName($ben->getFileName());
  15023.             $benefits->setClientId($ben->getClientId());
  15024.             $benefits->setClientName($ben->getClientName());
  15025.             $benefits->setBenefitEuro($ben->getBenefitEuro() * (-1));
  15026.             $benefits->setBenefitPerc($ben->getBenefitPerc());
  15027.             $benefits->setNetSale($ben->getNetSale() * (-1));
  15028.             $benefits->setTotalSale($ben->getTotalSale() * (-1));
  15029.             $em->persist($benefits);
  15030.             $em->flush();
  15031.             return true;
  15032.         }
  15033.         $productsItems = array();
  15034.         // Buscamos los productos de la factura para determinar el proveedor
  15035.         foreach ($invoiceItems as $item) {
  15036.             $prdItem $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  15037.             $sup = (empty($prdItem) or empty($prdItem->getSupplierExt())) ? 'AV EXPRESS S.L.' $prdItem->getSupplierExt();
  15038.             $iva = (empty($prdItem) or empty($prdItem->getIva())) ? '21' $prdItem->getSupplierExt();
  15039.             switch ($iva) {
  15040.                 case '21':
  15041.                     if (empty($prdItem)) {
  15042.                         $ivaxPlus 1.21;
  15043.                     } else {
  15044.                         $ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.83 1.21;  // 100/121 = 0.826
  15045.                     }
  15046.                     break;
  15047.                 case '10':
  15048.                     if (empty($prdItem)) {
  15049.                         $ivaxPlus 1.10;
  15050.                     } else {
  15051.                         $ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.91 1.10;  // 100/110 = 0.909
  15052.                     }
  15053.                     break;
  15054.                 case '0':
  15055.                     $ivaxPlus 1;
  15056.                     break;
  15057.                 default:
  15058.                     $ivaxPlus 1.21;
  15059.                     break;
  15060.             }
  15061.             $productsItems[] = array(
  15062.                 'invoiceItemOrInvoiceRecItem' => $item,
  15063.                 'productFile' => $prdItem,
  15064.                 'supplier' => $sup,
  15065.                 'iva' => $ivaxPlus,
  15066.                 'typeDoc' => $typeDoc
  15067.             );
  15068.         }
  15069.         $data = array();
  15070.         foreach ($productsItems as $elem) {
  15071.             if (empty($data[$invoice->getFileId()])) {
  15072.                 $data[$invoice->getFileId()] = array(
  15073.                     'id' => $invoice->getFileId(),
  15074.                     'benefitEuro' => 0,
  15075.                     'benefitPerc' => 0,
  15076.                     'netSale' => 0,
  15077.                     'totalSale' => 0,
  15078.                 );
  15079.             }
  15080.             $benefitEuro $data[$invoice->getFileId()]['benefitEuro'];
  15081.             $benefitPerc $data[$invoice->getFileId()]['benefitPerc'];
  15082.             $netSale $data[$invoice->getFileId()]['netSale'];
  15083.             $totalSale $data[$invoice->getFileId()]['totalSale'];
  15084.             // Con los factores se sumarĂ¡ o restarĂ¡ el beneficio
  15085.             // Se verifica si es una factura o factura rectificativa
  15086.             if ($typeDoc == 'Invoice') {
  15087.                 $indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? $elem['productFile']->getOpOver();
  15088.                 $indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? $elem['productFile']->getOpCommission();
  15089.                 $indicePax $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
  15090.                 $indiceQty $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
  15091.                 $indiceDays $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
  15092.                 $indicePriceProduct $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
  15093.                 $indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? $elem['productFile']->getOver();
  15094.                 $indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? $elem['productFile']->getCommission();
  15095.             } else {
  15096.                 $indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? $elem['productFile']->getOpOver();
  15097.                 $indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? $elem['productFile']->getOpCommission();
  15098.                 $indicePax $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
  15099.                 $indiceQty $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
  15100.                 $indiceDays $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
  15101.                 $indicePriceProduct $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
  15102.                 $indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? $elem['productFile']->getOver();
  15103.                 $indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? $elem['productFile']->getCommission();
  15104.             }
  15105.             // Se verifica el proveedor
  15106.             if ($elem['supplier'] == 'AV EXPRESS S.L.') { $factorSupp 0; } else { $factorSupp 1; }
  15107.             // Se verifica si es ganancia o perdida segun OVER (- o +)
  15108.             if ($indiceOpOver == 0) { $factorOver = -1; } else { $factorOver 1; }
  15109.             // Se verifica si es ganancia o perdida segun COMISION (- o +)
  15110.             if ($indiceOpComission == 0) { $factorCommission = -1; } else { $factorCommission 1; }
  15111.             // Pax
  15112.             if ($indicePax == or empty($indicePax)) { $pax 1; } else { $pax $indicePax; }
  15113.             // Qty
  15114.             if ($indiceQty == or empty($indiceQty)) { $qty 1; } else { $qty $indiceQty; }
  15115.             // Days
  15116.             if ($indiceDays == or empty($indiceDays)) { $days 1; } else { $days $indiceDays; }
  15117.             // Precio base
  15118.             $priceBase $indicePriceProduct $pax $qty $days;
  15119.             // Agregamos el over (se consideran over + o -)
  15120.             $price $priceBase + ($factorOver $indiceOver);
  15121.             // Agregamos la comision (se consideran comision + o -)
  15122.             $price $price + ((($factorCommission $indiceCommission) * $price) / 100);
  15123.             // Agregamos el factor proveedor
  15124.             $benefitEuroItem $price - ($priceBase $factorSupp);
  15125.             // Agregamos al porcentaje el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
  15126.             //                $benefitEuroItem = $benefitEuroItem * $factorTypeDoc;
  15127.             // Agregamos al precio el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
  15128.             //                $price = $price * $factorTypeDoc;
  15129.             // Agregamos el precio a la venta neta
  15130.             $netSale $netSale $price;
  15131.             // Agregamos al precio el IVA para la venta total
  15132.             $totalSale $totalSale + ($price $elem['iva']);
  15133.             $benefitPercItem = (empty($invoice) or ($invoice->getTotalNet() == 0)) ? round((($benefitEuroItem 100) / $invoice->getTotalNet()), 2PHP_ROUND_HALF_UP);
  15134.             $data[$invoice->getFileId()] = array(
  15135.                 'id' => $invoice->getFileId(),
  15136.                 'benefitEuro' => $benefitEuro $benefitEuroItem,
  15137.                 'benefitPerc' => $benefitPerc $benefitPercItem,
  15138.                 'netSale' => $netSale,
  15139.                 'totalSale' => $totalSale,
  15140.             );
  15141.         }
  15142.         foreach ($data as $key => $elem) {
  15143.             // Verificamos beneficios simplificados de proveedores
  15144.             $simplyBen $em->getRepository(AveBenefitsSupplier::class)->findByFileId($elem['id']);
  15145.             $benefitEuro $elem['benefitEuro'];
  15146.             foreach ($simplyBen as $item) { $benefitEuro $benefitEuro $item->getBenefitSupplier(); }
  15147.             $data[$key]['benefitEuro'] = $benefitEuro;
  15148.             $newBenefitPerc = (($benefitEuro 100) / $elem['netSale']);
  15149.             $newBenefitPerc round($newBenefitPerc2PHP_ROUND_HALF_UP);
  15150.             $data[$key]['benefitPerc'] = $newBenefitPerc;
  15151.         }
  15152.         // Los $benefitPercItem de 99.97 o 100.01 lo llevamos a 100
  15153. //        if ($data[$invoice->getFileId()]['benefitEuro'] == $data[$invoice->getFileId()]['netSale']) { $data[$invoice->getFileId()]['benefitPerc'] = 100; }
  15154.         $fileId $invoice->getFileId();
  15155.         if (isset($data[$fileId]) && $data[$fileId]['benefitEuro'] == $data[$fileId]['netSale']) {
  15156.             $data[$fileId]['benefitPerc'] = 100;
  15157.         }
  15158.         // Buscamos los datos del cliente
  15159.         if (!empty($invoice)) {
  15160.             $file $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  15161.             $clientId = empty($file) ? null $file->getClient();
  15162.             $clientName = empty($clientId) ? null $em->getRepository(Client::class)->findOneById($clientId);
  15163.             $clientName = empty($clientName) ? null $clientName->getName();
  15164.         } else {
  15165.             $clientId null;
  15166.             $clientName null;
  15167.         }
  15168.         if (!empty($data)) {
  15169.             $benefits = new AveBenefitsInvoiceInvoiceRec();
  15170.             $benefits->setDocId($invoice->getId());
  15171.             $benefits->setFileId($invoice->getFileId());
  15172.             $benefits->setDocType($typeDoc);
  15173.             $benefits->setDateAt($invoice->getDateAt());
  15174.             $benefits->setFileName($file->getTitle());
  15175.             $benefits->setClientId($clientId);
  15176.             $benefits->setClientName($clientName);
  15177.             $benefits->setBenefitEuro($data[$invoice->getFileId()]['benefitEuro']);
  15178.             $benefits->setBenefitPerc($data[$invoice->getFileId()]['benefitPerc']);
  15179.             $benefits->setNetSale($data[$invoice->getFileId()]['netSale']);
  15180.             $benefits->setTotalSale($data[$invoice->getFileId()]['totalSale']);
  15181.             $em->persist($benefits);
  15182.             $em->flush();
  15183.         }
  15184.         //Llamamos al servicio del gestor de comisiones internas entre empresas
  15185.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  15186.         $user_id $user_logueado->getId();
  15187.         $dataService $this->commisionEnterpriseService->commissionAvExpressGreenPatio($invoice->getId(), $user_id);
  15188.         return true;
  15189.     }
  15190. };