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.                     'typeP' => 'Paquete',
  6261.                     'location' => '',
  6262.                 );
  6263.                 $dql 'SELECT i
  6264.                         FROM AvexpressBundle:AveProductFile i
  6265.                         WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.type != :typeP AND (i.location IS NULL OR i.location = :location))
  6266.                         ORDER BY i.rankAv ASC';
  6267.                 $query $em->createQuery($dql)->setParameters($parameters);
  6268.                 $productsInFileOther $query->getResult();
  6269.                 // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  6270.                 $parameters = array(
  6271.                     'fileId' => $id,
  6272.                     'location' => '',
  6273.                 );
  6274.                 $dql 'SELECT i
  6275.                         FROM AvexpressBundle:AveProductFile i
  6276.                         WHERE (i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location))
  6277.                         ORDER BY i.rankAv ASC';
  6278.                 $query $em->createQuery($dql)->setParameters($parameters);
  6279.                 $productsInFileNull $query->getResult();
  6280.             }
  6281.             $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFilePackage$productsInFileOther$productsInFileNull);
  6282.         }
  6283.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  6284.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  6285.         $data_supplier = [];
  6286.         $i 0;
  6287.         $product = array(
  6288.             'neto' => 0,
  6289.             'sumSubT' => 0,
  6290.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6291.         $service = array(
  6292.             'neto' => 0,
  6293.             'sumSubT' => 0,
  6294.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6295.         foreach ($productsInFile as $item) {
  6296.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  6297.             // Verificamos que el producto no se encuentre ya en una factura
  6298.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
  6299.             $pax $item->getPax();
  6300.             $qty $item->getUnits();
  6301.             if (!empty($item->getDays())) { $days $item->getDays(); }
  6302.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
  6303.                 $subtotal $neto $subtotalProduct 0;
  6304.             } else {
  6305.                 $subtotalProduct 0;
  6306.                 if ($item->getIva() == '21') {
  6307.                     $subtotalProduct $item->getSubTotalPrice() * 1.21;
  6308.                 } // Iva a 21%
  6309.                 if ($item->getIva() == '10') {
  6310.                     $subtotalProduct $item->getSubTotalPrice() * 1.1;
  6311.                 } // Iva a 10%
  6312.                 if ($item->getIva() == '0') {
  6313.                     $subtotalProduct $item->getSubTotalPrice() * 1;
  6314.                 } // Iva a 0%
  6315.                 $subneto $item->getSubTotalPrice();
  6316.                 $subtotal =  $subtotalProduct;
  6317.                 $neto =  $subneto;
  6318.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  6319.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  6320.                 $neto round($neto2PHP_ROUND_HALF_UP);
  6321.             }
  6322.             // Acumula netos totales e IVA
  6323.             $totales_neto_all $totales_neto_all $neto;
  6324.             if ($item->getIva() == '21') {
  6325.                 $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  6326.             } // Iva a 21%
  6327.             if ($item->getIva() == '10') {
  6328.                 $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  6329.             } // Iva a 10%
  6330.             if ($item->getIva() == '0') {
  6331.                 $data_iva['ivaMontoCero'] = $neto 0;
  6332.             } // Iva a 0%, estaba inicializado en null para que aparezca en la factura solo si estĂ¡ a cero
  6333.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6334.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  6335.             if ($item->getIva() == '21') {
  6336.                 $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  6337.             } // Iva a 21%
  6338.             if ($item->getIva() == '10') {
  6339.                 $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  6340.             } // Iva a 10%
  6341.             if ($item->getIva() == '0') {
  6342.                 $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  6343.             } // Iva a 0%
  6344.             // Acumula netos totales e IVA
  6345.             $product['neto'] = $product['neto'] + $neto;
  6346.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  6347.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6348.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  6349.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  6350.             // Calculo del precio unitario despues de aplicar Over y Comision
  6351.             $multiplo = (float)$qty * (float)$days;
  6352.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  6353.             $data_supplier['product'][$i] = array(
  6354.                 'id' => $item->getId(),
  6355.                 'productName' => $item->getProductName(),
  6356.                 'productId' => $item->getProductId(),
  6357.                 'dateStart' => $item->getDateStart(),
  6358.                 'dateEnd' => $item->getDateEnd(),
  6359.                 'location' => $item->getLocation(),
  6360.                 'servicePrice' => $item->getServicePrice(),
  6361.                 'subTotalPrice' => $item->getSubTotalPrice(),
  6362.                 'subtotalProduct' => $subtotalProduct,
  6363.                 'iva' => $item->getIva(),
  6364.                 'pax' => $pax,
  6365.                 'qty' => $qty,
  6366.                 'days' => $days,
  6367.                 'type' => $item->getType(),
  6368.                 'subtotal' => $subtotal,
  6369.             );
  6370.             $i++;
  6371.         }
  6372.         $data_supplier['productSubTotal'] = array(
  6373.             'neto' => $product['neto'],
  6374.             'sumSubT' => $product['sumSubT'],
  6375.         );
  6376.         $payment = array(
  6377.             'sumSubT' => 0,
  6378.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  6379.         $i 0;
  6380.         foreach ($payments as $item) {
  6381.             // Verificamos que el pago no se encuentre ya en una factura
  6382.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
  6383.             if (!empty($existe)) {
  6384.                 $payment['sumSubT'] = $payment['sumSubT'] + 0;
  6385.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6386.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  6387.             } else {
  6388.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  6389.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  6390.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  6391.             }
  6392.             $data_supplier['payment'][$i] = array(
  6393.                 'id' => $item->getId(),
  6394.                 'amount' => $item->getAmount(),
  6395.                 'datePayAt' => $item->getDatePayAt(),
  6396.                 'wayToPay' => $item->getWayToPay(),
  6397.                 'amountTotal' => $item->getAmountTotal(),
  6398.                 'vat' => $item->getVat(),
  6399.             );
  6400.             $i++;
  6401.         }
  6402.         if (!empty($payments)) {
  6403.             $data_supplier['paymentSubTotal'] = array(
  6404.                 'sumSubT' => $payment['sumSubT'],
  6405.             );
  6406.         }
  6407.         foreach ($services as $item) {
  6408.             // Verificamos que el servicio no se encuentre ya en una factura
  6409.             $existe $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
  6410.             if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
  6411.                 $subtotal 0;
  6412.                 $neto 0;
  6413.                 $subtotalService 0;
  6414.                 $subneto 0;
  6415.                 switch ($item->getServiceCatId()) {
  6416.                     case 1// Alojamiento
  6417.                         // el numero de noches $numNoches; precio unitario $subneto
  6418.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  6419.                         // La personas no afectan este calculo
  6420.                         $subtotal $subtotalService $numNoches $item->getUnits();
  6421.                         $subnetoUnit $subneto;
  6422.                         $subneto $subneto $numNoches $item->getUnits();
  6423.                         $data_supplier['service'][$i] = array(
  6424.                             'id' => $item->getId(),
  6425.                             'serviceCatId' => $item->getServiceCatId(),
  6426.                             'serviceName' => $item->getName(),
  6427.                             'serviceType' => 'Hotel',
  6428.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  6429.                             'qty' => $item->getUnits(),
  6430.                             'iva' => $item->getIva(),
  6431.                             'pax' => '-',
  6432.                             'precioUnit' => $subnetoUnit,
  6433.                             'subneto' => $subneto,
  6434.                             'subtotal' => $subtotal,
  6435.                         );
  6436.                         break;
  6437.                     case 2//Actividades
  6438.                         // El nĂºmero de personas es considerado en el calculo
  6439.                         $pax $item->getPax();
  6440.                         if (empty($pax) or $pax == "0") {
  6441.                             $pax 1;
  6442.                         }
  6443.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6444.                         if ($days 1) {
  6445.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6446.                         } else {
  6447.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6448.                         }
  6449.                         $subtotal $subtotalService $days $item->getUnits();
  6450.                         $subnetoUnit $subneto;
  6451.                         $subneto $subneto $days $item->getUnits();
  6452.                         $data_supplier['service'][$i] = array(
  6453.                             'id' => $item->getId(),
  6454.                             'serviceCatId' => $item->getServiceCatId(),
  6455.                             'serviceName' => $item->getName(),
  6456.                             'serviceType' => 'Actividad',
  6457.                             'date' => $dateServ,
  6458.                             'qty' => $item->getUnits(),
  6459.                             'iva' => $item->getIva(),
  6460.                             'pax' => $item->getPax(),
  6461.                             'precioUnit' => $subnetoUnit,
  6462.                             'subneto' => $subneto,
  6463.                             'subtotal' => $subtotal,
  6464.                         );
  6465.                         break;
  6466.                     case 3// AV
  6467.                         $pax $item->getPax();
  6468.                         if (empty($pax) or $pax == "0") {
  6469.                             $pax 1;
  6470.                         }
  6471.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6472.                         if ($days 1) {
  6473.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6474.                         } else {
  6475.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6476.                         }
  6477.                         $unitsServ $item->getUnits();
  6478.                         if (empty($unitsServ) or $unitsServ == "0") {
  6479.                             $unitsServ 1;
  6480.                         }
  6481.                         $subtotal $subtotalService $days $unitsServ $pax;
  6482.                         $subnetoUnit $subneto;
  6483.                         $subneto $subneto $days $unitsServ $pax;
  6484.                         $data_supplier['service'][$i] = array(
  6485.                             'id' => $item->getId(),
  6486.                             'serviceCatId' => $item->getServiceCatId(),
  6487.                             'serviceName' => $item->getName(),
  6488.                             'serviceType' => 'AV',
  6489.                             'date' => $dateServ,
  6490.                             'qty' => $unitsServ,
  6491.                             'iva' => $item->getIva(),
  6492.                             'pax' => $item->getPax(),
  6493.                             'precioUnit' => $subnetoUnit,
  6494.                             'subneto' => $subneto,
  6495.                             'subtotal' => $subtotal,
  6496.                         );
  6497.                         break;
  6498.                     case 4//Creative
  6499.                         $pax $item->getPax();
  6500.                         if (empty($pax) or $pax == "0") {
  6501.                             $pax 1;
  6502.                         }
  6503.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6504.                         if ($days 1) {
  6505.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6506.                         } else {
  6507.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6508.                         }
  6509.                         $unitsServ $item->getUnits();
  6510.                         if (empty($unitsServ) or $unitsServ == "0") {
  6511.                             $unitsServ 1;
  6512.                         }
  6513.                         $subtotal $subtotalService $days $unitsServ $pax;
  6514.                         $subnetoUnit $subneto;
  6515.                         $subneto $subneto $days $unitsServ $pax;
  6516.                         $data_supplier['service'][$i] = array(
  6517.                             'id' => $item->getId(),
  6518.                             'serviceCatId' => $item->getServiceCatId(),
  6519.                             'serviceName' => $item->getName(),
  6520.                             'serviceType' => 'Creativo',
  6521.                             'date' => $dateServ,
  6522.                             'qty' => $unitsServ,
  6523.                             'iva' => $item->getIva(),
  6524.                             'pax' => $item->getPax(),
  6525.                             'precioUnit' => $subnetoUnit,
  6526.                             'subneto' => $subneto,
  6527.                             'subtotal' => $subtotal,
  6528.                         );
  6529.                         break;
  6530.                     case 5//Cruise
  6531.                         $pax $item->getPax();
  6532.                         if (empty($pax) or $pax == "0") {
  6533.                             $pax 1;
  6534.                         }
  6535.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  6536.                         if ($days 1) {
  6537.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6538.                         } else {
  6539.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6540.                         }
  6541.                         $unitsServ $item->getUnits();
  6542.                         if (empty($unitsServ) or $unitsServ == "0") {
  6543.                             $unitsServ 1;
  6544.                         }
  6545.                         $subtotal $subtotalService $days $unitsServ $pax;
  6546.                         $subnetoUnit $subneto;
  6547.                         $subneto $subneto $days $unitsServ $pax;
  6548.                         $data_supplier['service'][$i] = array(
  6549.                             'id' => $item->getId(),
  6550.                             'serviceCatId' => $item->getServiceCatId(),
  6551.                             'serviceName' => $item->getName(),
  6552.                             'serviceType' => 'Crucero',
  6553.                             'date' => $dateServ,
  6554.                             'qty' => $unitsServ,
  6555.                             'iva' => $item->getIva(),
  6556.                             'pax' => $item->getPax(),
  6557.                             'precioUnit' => $subnetoUnit,
  6558.                             'subneto' => $subneto,
  6559.                             'subtotal' => $subtotal,
  6560.                         );
  6561.                         break;
  6562.                     case 6//Entertaiment
  6563.                         $pax $item->getPax();
  6564.                         if (empty($pax) or $pax == "0") {
  6565.                             $pax 1;
  6566.                         }
  6567.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6568.                         if ($days 1) {
  6569.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6570.                         } else {
  6571.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6572.                         }
  6573.                         $unitsServ $item->getUnits();
  6574.                         if (empty($unitsServ) or $unitsServ == "0") {
  6575.                             $unitsServ 1;
  6576.                         }
  6577.                         $subtotal $subtotalService $days $unitsServ $pax;
  6578.                         $subnetoUnit $subneto;
  6579.                         $subneto $subneto $days $unitsServ $pax;
  6580.                         $data_supplier['service'][$i] = array(
  6581.                             'id' => $item->getId(),
  6582.                             'serviceCatId' => $item->getServiceCatId(),
  6583.                             'serviceName' => $item->getName(),
  6584.                             'serviceType' => 'Entretenimiento',
  6585.                             'date' => $dateServ,
  6586.                             'qty' => $unitsServ,
  6587.                             'iva' => $item->getIva(),
  6588.                             'pax' => $item->getPax(),
  6589.                             'precioUnit' => $subnetoUnit,
  6590.                             'subneto' => $subneto,
  6591.                             'subtotal' => $subtotal,
  6592.                         );
  6593.                         break;
  6594.                     case 7// Gifts
  6595.                         $pax $item->getPax();
  6596.                         if (empty($pax) or $pax == "0") {
  6597.                             $pax 1;
  6598.                         }
  6599.                         $days 1;
  6600.                         if ($days 1) {
  6601.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6602.                         } else {
  6603.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6604.                         }
  6605.                         $unitsServ $item->getUnits();
  6606.                         if (empty($unitsServ) or $unitsServ == "0") {
  6607.                             $unitsServ 1;
  6608.                         }
  6609.                         $subtotal $subtotalService $days $unitsServ $pax;
  6610.                         $subnetoUnit $subneto;
  6611.                         $subneto $subneto $days $unitsServ $pax;
  6612.                         $data_supplier['service'][$i] = array(
  6613.                             'id' => $item->getId(),
  6614.                             'serviceCatId' => $item->getServiceCatId(),
  6615.                             'serviceName' => $item->getName(),
  6616.                             'serviceType' => 'Regalos',
  6617.                             'date' => $dateServ,
  6618.                             'qty' => $unitsServ,
  6619.                             'iva' => $item->getIva(),
  6620.                             'pax' => $item->getPax(),
  6621.                             'precioUnit' => $subnetoUnit,
  6622.                             'subneto' => $subneto,
  6623.                             'subtotal' => $subtotal,
  6624.                         );
  6625.                         break;
  6626.                     case 8//Guide
  6627.                         $pax $item->getPax();
  6628.                         if (empty($pax) or $pax == "0") {
  6629.                             $pax 1;
  6630.                         }
  6631.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6632.                         if ($days 1) {
  6633.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6634.                         } else {
  6635.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6636.                         }
  6637.                         $unitsServ $item->getUnits();
  6638.                         if (empty($unitsServ) or $unitsServ == "0") {
  6639.                             $unitsServ 1;
  6640.                         }
  6641.                         $subtotal $subtotalService $days $unitsServ $pax;
  6642.                         $subnetoUnit $subneto;
  6643.                         $subneto $subneto $days $unitsServ $pax;
  6644.                         $data_supplier['service'][$i] = array(
  6645.                             'id' => $item->getId(),
  6646.                             'serviceCatId' => $item->getServiceCatId(),
  6647.                             'serviceName' => $item->getName(),
  6648.                             'serviceType' => 'Regalos',
  6649.                             'date' => $dateServ,
  6650.                             'qty' => $unitsServ,
  6651.                             'iva' => $item->getIva(),
  6652.                             'pax' => $item->getPax(),
  6653.                             'precioUnit' => $subnetoUnit,
  6654.                             'subneto' => $subneto,
  6655.                             'subtotal' => $subtotal,
  6656.                         );
  6657.                         break;
  6658.                     case 9//Itineraries
  6659.                         $pax $item->getPax();
  6660.                         if (empty($pax) or $pax == "0") {
  6661.                             $pax 1;
  6662.                         }
  6663.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6664.                         if ($days 1) {
  6665.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6666.                         } else {
  6667.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6668.                         }
  6669.                         $unitsServ $item->getUnits();
  6670.                         if (empty($unitsServ) or $unitsServ == "0") {
  6671.                             $unitsServ 1;
  6672.                         }
  6673.                         $subtotal $subtotalService $days $unitsServ $pax;
  6674.                         $subnetoUnit $subneto;
  6675.                         $subneto $subneto $days $unitsServ $pax;
  6676.                         $data_supplier['service'][$i] = array(
  6677.                             'id' => $item->getId(),
  6678.                             'serviceCatId' => $item->getServiceCatId(),
  6679.                             'serviceName' => $item->getName(),
  6680.                             'serviceType' => 'Itinerarios',
  6681.                             'date' => $dateServ,
  6682.                             'qty' => $unitsServ,
  6683.                             'iva' => $item->getIva(),
  6684.                             'pax' => $item->getPax(),
  6685.                             'precioUnit' => $subnetoUnit,
  6686.                             'subneto' => $subneto,
  6687.                             'subtotal' => $subtotal,
  6688.                         );
  6689.                         break;
  6690.                     case 10//Lounge  -- No Aplica
  6691.                         //                        $pax = $item->getPax();
  6692.                         //                        if (empty($pax) or $pax == "0") {
  6693.                         //                            $pax = 1;
  6694.                         //                        }
  6695.                         //
  6696.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  6697.                         //                        if ($days > 1){
  6698.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  6699.                         //                        } else {
  6700.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6701.                         //                        }
  6702.                         //
  6703.                         //                        $unitsServ = $item->getUnits();
  6704.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  6705.                         //                            $unitsServ = 1;
  6706.                         //                        }
  6707.                         //
  6708.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  6709.                         //                        $subnetoUnit = $subneto;
  6710.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  6711.                         //
  6712.                         //                        $data_supplier['service'][$i] = array (
  6713.                         //                            'id' => $item->getId(),
  6714.                         //                            'serviceCatId' => $item->getServiceCatId(),
  6715.                         //                            'serviceName' => $item->getName(),
  6716.                         //                            'serviceType' => 'Itinerarios',
  6717.                         //                            'date' => $dateServ,
  6718.                         //                            'qty' => $unitsServ,
  6719.                         //                            'iva' => $item->getIva(),
  6720.                         //                            'pax' => $item->getPax(),
  6721.                         //                            'precioUnit' => $subnetoUnit,
  6722.                         //                            'subneto' => $subneto,
  6723.                         //                            'subtotal' => $subtotal,
  6724.                         //                        );
  6725.                         break;
  6726.                     case 11//Menu
  6727.                         $pax $item->getPax();
  6728.                         if (empty($pax) or $pax == "0") {
  6729.                             $pax 1;
  6730.                         }
  6731.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6732.                         if ($days 1) {
  6733.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6734.                         } else {
  6735.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6736.                         }
  6737.                         $unitsServ $item->getUnits();
  6738.                         if (empty($unitsServ) or $unitsServ == "0") {
  6739.                             $unitsServ 1;
  6740.                         }
  6741.                         $subtotal $subtotalService $days $unitsServ $pax;
  6742.                         $subnetoUnit $subneto;
  6743.                         $subneto $subneto $days $unitsServ $pax;
  6744.                         $data_supplier['service'][$i] = array(
  6745.                             'id' => $item->getId(),
  6746.                             'serviceCatId' => $item->getServiceCatId(),
  6747.                             'serviceName' => $item->getName(),
  6748.                             'serviceType' => 'MenĂº',
  6749.                             'date' => $dateServ,
  6750.                             'qty' => $unitsServ,
  6751.                             'iva' => $item->getIva(),
  6752.                             'pax' => $item->getPax(),
  6753.                             'precioUnit' => $subnetoUnit,
  6754.                             'subneto' => $subneto,
  6755.                             'subtotal' => $subtotal,
  6756.                         );
  6757.                         break;
  6758.                     case 12//Others
  6759.                         $pax $item->getPax();
  6760.                         if (empty($pax) or $pax == "0") {
  6761.                             $pax 1;
  6762.                         }
  6763.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6764.                         if ($days 1) {
  6765.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6766.                         } else {
  6767.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6768.                         }
  6769.                         $unitsServ $item->getUnits();
  6770.                         if (empty($unitsServ) or $unitsServ == "0") {
  6771.                             $unitsServ 1;
  6772.                         }
  6773.                         $subtotal $subtotalService $days $unitsServ $pax;
  6774.                         $subnetoUnit $subneto;
  6775.                         $subneto $subneto $days $unitsServ $pax;
  6776.                         $data_supplier['service'][$i] = array(
  6777.                             'id' => $item->getId(),
  6778.                             'serviceCatId' => $item->getServiceCatId(),
  6779.                             'serviceName' => $item->getName(),
  6780.                             'serviceType' => 'Otros',
  6781.                             'date' => $dateServ,
  6782.                             'qty' => $unitsServ,
  6783.                             'iva' => $item->getIva(),
  6784.                             'pax' => $item->getPax(),
  6785.                             'precioUnit' => $subnetoUnit,
  6786.                             'subneto' => $subneto,
  6787.                             'subtotal' => $subtotal,
  6788.                         );
  6789.                         break;
  6790.                     case 13//Transport
  6791.                         $pax $item->getPax();
  6792.                         if (empty($pax) or $pax == "0") {
  6793.                             $pax 1;
  6794.                         }
  6795.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6796.                         if ($days 1) {
  6797.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6798.                         } else {
  6799.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6800.                         }
  6801.                         $unitsServ $item->getUnits();
  6802.                         if (empty($unitsServ) or $unitsServ == "0") {
  6803.                             $unitsServ 1;
  6804.                         }
  6805.                         $subtotal $subtotalService $days $unitsServ $pax;
  6806.                         $subnetoUnit $subneto;
  6807.                         $subneto $subneto $days $unitsServ $pax;
  6808.                         $data_supplier['service'][$i] = array(
  6809.                             'id' => $item->getId(),
  6810.                             'serviceCatId' => $item->getServiceCatId(),
  6811.                             'serviceName' => $item->getName(),
  6812.                             'serviceType' => 'Transporte',
  6813.                             'date' => $dateServ,
  6814.                             'qty' => $unitsServ,
  6815.                             'iva' => $item->getIva(),
  6816.                             'pax' => $item->getPax(),
  6817.                             'precioUnit' => $subnetoUnit,
  6818.                             'subneto' => $subneto,
  6819.                             'subtotal' => $subtotal,
  6820.                         );
  6821.                         break;
  6822.                     case 14//Technology
  6823.                         $pax $item->getPax();
  6824.                         if (empty($pax) or $pax == "0") {
  6825.                             $pax 1;
  6826.                         }
  6827.                         $days 1;
  6828.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6829.                         $unitsServ $item->getUnits();
  6830.                         if (empty($unitsServ) or $unitsServ == "0") {
  6831.                             $unitsServ 1;
  6832.                         }
  6833.                         $subtotal $subtotalService $days $unitsServ $pax;
  6834.                         $subnetoUnit $subneto;
  6835.                         $subneto $subneto $days $unitsServ $pax;
  6836.                         $data_supplier['service'][$i] = array(
  6837.                             'id' => $item->getId(),
  6838.                             'serviceCatId' => $item->getServiceCatId(),
  6839.                             'serviceName' => $item->getName(),
  6840.                             'serviceType' => 'TecnologĂ­a',
  6841.                             'date' => $dateServ,
  6842.                             'qty' => $unitsServ,
  6843.                             'iva' => $item->getIva(),
  6844.                             'pax' => $item->getPax(),
  6845.                             'precioUnit' => $subnetoUnit,
  6846.                             'subneto' => $subneto,
  6847.                             'subtotal' => $subtotal,
  6848.                         );
  6849.                         break;
  6850.                     case 15//Assisstant
  6851.                         $pax $item->getPax();
  6852.                         if (empty($pax) or $pax == "0") {
  6853.                             $pax 1;
  6854.                         }
  6855.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6856.                         if ($days 1) {
  6857.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6858.                         } else {
  6859.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6860.                         }
  6861.                         $unitsServ $item->getUnits();
  6862.                         if (empty($unitsServ) or $unitsServ == "0") {
  6863.                             $unitsServ 1;
  6864.                         }
  6865.                         $subtotal $subtotalService $days $unitsServ $pax;
  6866.                         $subnetoUnit $subneto;
  6867.                         $subneto $subneto $days $unitsServ $pax;
  6868.                         $data_supplier['service'][$i] = array(
  6869.                             'id' => $item->getId(),
  6870.                             'serviceCatId' => $item->getServiceCatId(),
  6871.                             'serviceName' => $item->getName(),
  6872.                             'serviceType' => 'Asistente',
  6873.                             'date' => $dateServ,
  6874.                             'qty' => $unitsServ,
  6875.                             'iva' => $item->getIva(),
  6876.                             'pax' => $item->getPax(),
  6877.                             'precioUnit' => $subnetoUnit,
  6878.                             'subneto' => $subneto,
  6879.                             'subtotal' => $subtotal,
  6880.                         );
  6881.                         break;
  6882.                     case 16//DDR
  6883.                         $pax $item->getPax();
  6884.                         if (empty($pax) or $pax == "0") {
  6885.                             $pax 1;
  6886.                         }
  6887.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6888.                         if ($days 1) {
  6889.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6890.                         } else {
  6891.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6892.                         }
  6893.                         $unitsServ $item->getUnits();
  6894.                         if (empty($unitsServ) or $unitsServ == "0") {
  6895.                             $unitsServ 1;
  6896.                         }
  6897.                         $subtotal $subtotalService $days $unitsServ $pax;
  6898.                         $subnetoUnit $subneto;
  6899.                         $subneto $subneto $days $unitsServ $pax;
  6900.                         $data_supplier['service'][$i] = array(
  6901.                             'id' => $item->getId(),
  6902.                             'serviceCatId' => $item->getServiceCatId(),
  6903.                             'serviceName' => $item->getName(),
  6904.                             'serviceType' => 'DDR',
  6905.                             'date' => $dateServ,
  6906.                             'qty' => $unitsServ,
  6907.                             'iva' => $item->getIva(),
  6908.                             'pax' => $item->getPax(),
  6909.                             'precioUnit' => $subnetoUnit,
  6910.                             'subneto' => $subneto,
  6911.                             'subtotal' => $subtotal,
  6912.                         );
  6913.                         break;
  6914.                     default:
  6915.                         break;
  6916.                 }
  6917.             } else {
  6918.                 $subtotalService $item->getPrice();
  6919.                 $subneto $item->getPrice();
  6920.                 // Commission
  6921.                 if ($item->getOpCommission() == '1') {
  6922.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  6923.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  6924.                 } else {
  6925.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  6926.                     $subneto $subneto * (- ($item->getCommission() / 100));
  6927.                 }
  6928.                 // Over
  6929.                 if ($item->getOpOver() == '1') {
  6930.                     $subtotalService $subtotalService $item->getOver();
  6931.                     $subneto $subneto $item->getOver();
  6932.                 } else {
  6933.                     $subtotalService $subtotalService $item->getOver();
  6934.                     $subneto $subneto $item->getOver();
  6935.                 }
  6936.                 // IVA
  6937.                 if ($item->getOpIva() == '1') {
  6938.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  6939.                 } else {
  6940.                     $subtotalService $item->getPrice();
  6941.                     $subneto = ($subneto 100) / (100 $item->getIva());
  6942.                 }
  6943.                 switch ($item->getServiceCatId()) {
  6944.                     case 1// Alojamiento
  6945.                         // el numero de noches $numNoches; precio unitario $subneto
  6946.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  6947.                         // La personas no afectan este calculo
  6948.                         $subtotal $subtotalService $numNoches $item->getUnits();
  6949.                         $subnetoUnit $subneto;
  6950.                         $subneto $subneto $numNoches $item->getUnits();
  6951.                         $data_supplier['service'][$i] = array(
  6952.                             'id' => $item->getId(),
  6953.                             'serviceCatId' => $item->getServiceCatId(),
  6954.                             'serviceName' => $item->getName(),
  6955.                             'serviceType' => 'Hotel',
  6956.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  6957.                             'qty' => $item->getUnits(),
  6958.                             'iva' => $item->getIva(),
  6959.                             'pax' => '-',
  6960.                             'precioUnit' => $subnetoUnit,
  6961.                             'subneto' => $subneto,
  6962.                             'subtotal' => $subtotal,
  6963.                         );
  6964.                         break;
  6965.                     case 2//Actividades
  6966.                         // El nĂºmero de personas es considerado en el calculo
  6967.                         $pax $item->getPax();
  6968.                         if (empty($pax) or $pax == "0") {
  6969.                             $pax 1;
  6970.                         }
  6971.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  6972.                         if ($days 1) {
  6973.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  6974.                         } else {
  6975.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  6976.                         }
  6977.                         $subtotal $subtotalService $days $item->getUnits();
  6978.                         $subnetoUnit $subneto;
  6979.                         $subneto $subneto $days $item->getUnits();
  6980.                         $data_supplier['service'][$i] = array(
  6981.                             'id' => $item->getId(),
  6982.                             'serviceCatId' => $item->getServiceCatId(),
  6983.                             'serviceName' => $item->getName(),
  6984.                             'serviceType' => 'Actividad',
  6985.                             'date' => $dateServ,
  6986.                             'qty' => $item->getUnits(),
  6987.                             'iva' => $item->getIva(),
  6988.                             'pax' => $item->getPax(),
  6989.                             'precioUnit' => $subnetoUnit,
  6990.                             'subneto' => $subneto,
  6991.                             'subtotal' => $subtotal,
  6992.                         );
  6993.                         break;
  6994.                     case 3// AV
  6995.                         $pax $item->getPax();
  6996.                         if (empty($pax) or $pax == "0") {
  6997.                             $pax 1;
  6998.                         }
  6999.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7000.                         if ($days 1) {
  7001.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7002.                         } else {
  7003.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7004.                         }
  7005.                         $unitsServ $item->getUnits();
  7006.                         if (empty($unitsServ) or $unitsServ == "0") {
  7007.                             $unitsServ 1;
  7008.                         }
  7009.                         $subtotal $subtotalService $days $unitsServ $pax;
  7010.                         $subnetoUnit $subneto;
  7011.                         $subneto $subneto $days $unitsServ $pax;
  7012.                         $data_supplier['service'][$i] = array(
  7013.                             'id' => $item->getId(),
  7014.                             'serviceCatId' => $item->getServiceCatId(),
  7015.                             'serviceName' => $item->getName(),
  7016.                             'serviceType' => 'AV',
  7017.                             'date' => $dateServ,
  7018.                             'qty' => $unitsServ,
  7019.                             'iva' => $item->getIva(),
  7020.                             'pax' => $item->getPax(),
  7021.                             'precioUnit' => $subnetoUnit,
  7022.                             'subneto' => $subneto,
  7023.                             'subtotal' => $subtotal,
  7024.                         );
  7025.                         break;
  7026.                     case 4//Creative
  7027.                         $pax $item->getPax();
  7028.                         if (empty($pax) or $pax == "0") {
  7029.                             $pax 1;
  7030.                         }
  7031.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7032.                         if ($days 1) {
  7033.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7034.                         } else {
  7035.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7036.                         }
  7037.                         $unitsServ $item->getUnits();
  7038.                         if (empty($unitsServ) or $unitsServ == "0") {
  7039.                             $unitsServ 1;
  7040.                         }
  7041.                         $subtotal $subtotalService $days $unitsServ $pax;
  7042.                         $subnetoUnit $subneto;
  7043.                         $subneto $subneto $days $unitsServ $pax;
  7044.                         $data_supplier['service'][$i] = array(
  7045.                             'id' => $item->getId(),
  7046.                             'serviceCatId' => $item->getServiceCatId(),
  7047.                             'serviceName' => $item->getName(),
  7048.                             'serviceType' => 'Creativo',
  7049.                             'date' => $dateServ,
  7050.                             'qty' => $unitsServ,
  7051.                             'iva' => $item->getIva(),
  7052.                             'pax' => $item->getPax(),
  7053.                             'precioUnit' => $subnetoUnit,
  7054.                             'subneto' => $subneto,
  7055.                             'subtotal' => $subtotal,
  7056.                         );
  7057.                         break;
  7058.                     case 5//Cruise
  7059.                         $pax $item->getPax();
  7060.                         if (empty($pax) or $pax == "0") {
  7061.                             $pax 1;
  7062.                         }
  7063.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  7064.                         if ($days 1) {
  7065.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7066.                         } else {
  7067.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7068.                         }
  7069.                         $unitsServ $item->getUnits();
  7070.                         if (empty($unitsServ) or $unitsServ == "0") {
  7071.                             $unitsServ 1;
  7072.                         }
  7073.                         $subtotal $subtotalService $days $unitsServ $pax;
  7074.                         $subnetoUnit $subneto;
  7075.                         $subneto $subneto $days $unitsServ $pax;
  7076.                         $data_supplier['service'][$i] = array(
  7077.                             'id' => $item->getId(),
  7078.                             'serviceCatId' => $item->getServiceCatId(),
  7079.                             'serviceName' => $item->getName(),
  7080.                             'serviceType' => 'Crucero',
  7081.                             'date' => $dateServ,
  7082.                             'qty' => $unitsServ,
  7083.                             'iva' => $item->getIva(),
  7084.                             'pax' => $item->getPax(),
  7085.                             'precioUnit' => $subnetoUnit,
  7086.                             'subneto' => $subneto,
  7087.                             'subtotal' => $subtotal,
  7088.                         );
  7089.                         break;
  7090.                     case 6//Entertaiment
  7091.                         $pax $item->getPax();
  7092.                         if (empty($pax) or $pax == "0") {
  7093.                             $pax 1;
  7094.                         }
  7095.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7096.                         if ($days 1) {
  7097.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7098.                         } else {
  7099.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7100.                         }
  7101.                         $unitsServ $item->getUnits();
  7102.                         if (empty($unitsServ) or $unitsServ == "0") {
  7103.                             $unitsServ 1;
  7104.                         }
  7105.                         $subtotal $subtotalService $days $unitsServ $pax;
  7106.                         $subnetoUnit $subneto;
  7107.                         $subneto $subneto $days $unitsServ $pax;
  7108.                         $data_supplier['service'][$i] = array(
  7109.                             'id' => $item->getId(),
  7110.                             'serviceCatId' => $item->getServiceCatId(),
  7111.                             'serviceName' => $item->getName(),
  7112.                             'serviceType' => 'Entretenimiento',
  7113.                             'date' => $dateServ,
  7114.                             'qty' => $unitsServ,
  7115.                             'iva' => $item->getIva(),
  7116.                             'pax' => $item->getPax(),
  7117.                             'precioUnit' => $subnetoUnit,
  7118.                             'subneto' => $subneto,
  7119.                             'subtotal' => $subtotal,
  7120.                         );
  7121.                         break;
  7122.                     case 7// Gifts
  7123.                         $pax $item->getPax();
  7124.                         if (empty($pax) or $pax == "0") {
  7125.                             $pax 1;
  7126.                         }
  7127.                         $days 1;
  7128.                         if ($days 1) {
  7129.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7130.                         } else {
  7131.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7132.                         }
  7133.                         $unitsServ $item->getUnits();
  7134.                         if (empty($unitsServ) or $unitsServ == "0") {
  7135.                             $unitsServ 1;
  7136.                         }
  7137.                         $subtotal $subtotalService $days $unitsServ $pax;
  7138.                         $subnetoUnit $subneto;
  7139.                         $subneto $subneto $days $unitsServ $pax;
  7140.                         $data_supplier['service'][$i] = array(
  7141.                             'id' => $item->getId(),
  7142.                             'serviceCatId' => $item->getServiceCatId(),
  7143.                             'serviceName' => $item->getName(),
  7144.                             'serviceType' => 'Regalos',
  7145.                             'date' => $dateServ,
  7146.                             'qty' => $unitsServ,
  7147.                             'iva' => $item->getIva(),
  7148.                             'pax' => $item->getPax(),
  7149.                             'precioUnit' => $subnetoUnit,
  7150.                             'subneto' => $subneto,
  7151.                             'subtotal' => $subtotal,
  7152.                         );
  7153.                         break;
  7154.                     case 8//Guide
  7155.                         $pax $item->getPax();
  7156.                         if (empty($pax) or $pax == "0") {
  7157.                             $pax 1;
  7158.                         }
  7159.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7160.                         if ($days 1) {
  7161.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7162.                         } else {
  7163.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7164.                         }
  7165.                         $unitsServ $item->getUnits();
  7166.                         if (empty($unitsServ) or $unitsServ == "0") {
  7167.                             $unitsServ 1;
  7168.                         }
  7169.                         $subtotal $subtotalService $days $unitsServ $pax;
  7170.                         $subnetoUnit $subneto;
  7171.                         $subneto $subneto $days $unitsServ $pax;
  7172.                         $data_supplier['service'][$i] = array(
  7173.                             'id' => $item->getId(),
  7174.                             'serviceCatId' => $item->getServiceCatId(),
  7175.                             'serviceName' => $item->getName(),
  7176.                             'serviceType' => 'Regalos',
  7177.                             'date' => $dateServ,
  7178.                             'qty' => $unitsServ,
  7179.                             'iva' => $item->getIva(),
  7180.                             'pax' => $item->getPax(),
  7181.                             'precioUnit' => $subnetoUnit,
  7182.                             'subneto' => $subneto,
  7183.                             'subtotal' => $subtotal,
  7184.                         );
  7185.                         break;
  7186.                     case 9//Itineraries
  7187.                         $pax $item->getPax();
  7188.                         if (empty($pax) or $pax == "0") {
  7189.                             $pax 1;
  7190.                         }
  7191.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7192.                         if ($days 1) {
  7193.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7194.                         } else {
  7195.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7196.                         }
  7197.                         $unitsServ $item->getUnits();
  7198.                         if (empty($unitsServ) or $unitsServ == "0") {
  7199.                             $unitsServ 1;
  7200.                         }
  7201.                         $subtotal $subtotalService $days $unitsServ $pax;
  7202.                         $subnetoUnit $subneto;
  7203.                         $subneto $subneto $days $unitsServ $pax;
  7204.                         $data_supplier['service'][$i] = array(
  7205.                             'id' => $item->getId(),
  7206.                             'serviceCatId' => $item->getServiceCatId(),
  7207.                             'serviceName' => $item->getName(),
  7208.                             'serviceType' => 'Itinerarios',
  7209.                             'date' => $dateServ,
  7210.                             'qty' => $unitsServ,
  7211.                             'iva' => $item->getIva(),
  7212.                             'pax' => $item->getPax(),
  7213.                             'precioUnit' => $subnetoUnit,
  7214.                             'subneto' => $subneto,
  7215.                             'subtotal' => $subtotal,
  7216.                         );
  7217.                         break;
  7218.                     case 10//Lounge  -- No Aplica
  7219.                         //                        $pax = $item->getPax();
  7220.                         //                        if (empty($pax) or $pax == "0") {
  7221.                         //                            $pax = 1;
  7222.                         //                        }
  7223.                         //
  7224.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  7225.                         //                        if ($days > 1){
  7226.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  7227.                         //                        } else {
  7228.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7229.                         //                        }
  7230.                         //
  7231.                         //                        $unitsServ = $item->getUnits();
  7232.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  7233.                         //                            $unitsServ = 1;
  7234.                         //                        }
  7235.                         //
  7236.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  7237.                         //                        $subnetoUnit = $subneto;
  7238.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  7239.                         //
  7240.                         //                        $data_supplier['service'][$i] = array (
  7241.                         //                            'id' => $item->getId(),
  7242.                         //                            'serviceCatId' => $item->getServiceCatId(),
  7243.                         //                            'serviceName' => $item->getName(),
  7244.                         //                            'serviceType' => 'Itinerarios',
  7245.                         //                            'date' => $dateServ,
  7246.                         //                            'qty' => $unitsServ,
  7247.                         //                            'iva' => $item->getIva(),
  7248.                         //                            'pax' => $item->getPax(),
  7249.                         //                            'precioUnit' => $subnetoUnit,
  7250.                         //                            'subneto' => $subneto,
  7251.                         //                            'subtotal' => $subtotal,
  7252.                         //                        );
  7253.                         break;
  7254.                     case 11//Menu
  7255.                         $pax $item->getPax();
  7256.                         if (empty($pax) or $pax == "0") {
  7257.                             $pax 1;
  7258.                         }
  7259.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7260.                         if ($days 1) {
  7261.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7262.                         } else {
  7263.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7264.                         }
  7265.                         $unitsServ $item->getUnits();
  7266.                         if (empty($unitsServ) or $unitsServ == "0") {
  7267.                             $unitsServ 1;
  7268.                         }
  7269.                         $subtotal $subtotalService $days $unitsServ $pax;
  7270.                         $subnetoUnit $subneto;
  7271.                         $subneto $subneto $days $unitsServ $pax;
  7272.                         $data_supplier['service'][$i] = array(
  7273.                             'id' => $item->getId(),
  7274.                             'serviceCatId' => $item->getServiceCatId(),
  7275.                             'serviceName' => $item->getName(),
  7276.                             'serviceType' => 'MenĂº',
  7277.                             'date' => $dateServ,
  7278.                             'qty' => $unitsServ,
  7279.                             'iva' => $item->getIva(),
  7280.                             'pax' => $item->getPax(),
  7281.                             'precioUnit' => $subnetoUnit,
  7282.                             'subneto' => $subneto,
  7283.                             'subtotal' => $subtotal,
  7284.                         );
  7285.                         break;
  7286.                     case 12//Others
  7287.                         $pax $item->getPax();
  7288.                         if (empty($pax) or $pax == "0") {
  7289.                             $pax 1;
  7290.                         }
  7291.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7292.                         if ($days 1) {
  7293.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7294.                         } else {
  7295.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7296.                         }
  7297.                         $unitsServ $item->getUnits();
  7298.                         if (empty($unitsServ) or $unitsServ == "0") {
  7299.                             $unitsServ 1;
  7300.                         }
  7301.                         $subtotal $subtotalService $days $unitsServ $pax;
  7302.                         $subnetoUnit $subneto;
  7303.                         $subneto $subneto $days $unitsServ $pax;
  7304.                         $data_supplier['service'][$i] = array(
  7305.                             'id' => $item->getId(),
  7306.                             'serviceCatId' => $item->getServiceCatId(),
  7307.                             'serviceName' => $item->getName(),
  7308.                             'serviceType' => 'Otros',
  7309.                             'date' => $dateServ,
  7310.                             'qty' => $unitsServ,
  7311.                             'iva' => $item->getIva(),
  7312.                             'pax' => $item->getPax(),
  7313.                             'precioUnit' => $subnetoUnit,
  7314.                             'subneto' => $subneto,
  7315.                             'subtotal' => $subtotal,
  7316.                         );
  7317.                         break;
  7318.                     case 13//Transport
  7319.                         $pax $item->getPax();
  7320.                         if (empty($pax) or $pax == "0") {
  7321.                             $pax 1;
  7322.                         }
  7323.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7324.                         if ($days 1) {
  7325.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7326.                         } else {
  7327.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7328.                         }
  7329.                         $unitsServ $item->getUnits();
  7330.                         if (empty($unitsServ) or $unitsServ == "0") {
  7331.                             $unitsServ 1;
  7332.                         }
  7333.                         $subtotal $subtotalService $days $unitsServ $pax;
  7334.                         $subnetoUnit $subneto;
  7335.                         $subneto $subneto $days $unitsServ $pax;
  7336.                         $data_supplier['service'][$i] = array(
  7337.                             'id' => $item->getId(),
  7338.                             'serviceCatId' => $item->getServiceCatId(),
  7339.                             'serviceName' => $item->getName(),
  7340.                             'serviceType' => 'Transporte',
  7341.                             'date' => $dateServ,
  7342.                             'qty' => $unitsServ,
  7343.                             'iva' => $item->getIva(),
  7344.                             'pax' => $item->getPax(),
  7345.                             'precioUnit' => $subnetoUnit,
  7346.                             'subneto' => $subneto,
  7347.                             'subtotal' => $subtotal,
  7348.                         );
  7349.                         break;
  7350.                     case 14//Technology
  7351.                         $pax $item->getPax();
  7352.                         if (empty($pax) or $pax == "0") {
  7353.                             $pax 1;
  7354.                         }
  7355.                         $days 1;
  7356.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7357.                         $unitsServ $item->getUnits();
  7358.                         if (empty($unitsServ) or $unitsServ == "0") {
  7359.                             $unitsServ 1;
  7360.                         }
  7361.                         $subtotal $subtotalService $days $unitsServ $pax;
  7362.                         $subnetoUnit $subneto;
  7363.                         $subneto $subneto $days $unitsServ $pax;
  7364.                         $data_supplier['service'][$i] = array(
  7365.                             'id' => $item->getId(),
  7366.                             'serviceCatId' => $item->getServiceCatId(),
  7367.                             'serviceName' => $item->getName(),
  7368.                             'serviceType' => 'TecnologĂ­a',
  7369.                             'date' => $dateServ,
  7370.                             'qty' => $unitsServ,
  7371.                             'iva' => $item->getIva(),
  7372.                             'pax' => $item->getPax(),
  7373.                             'precioUnit' => $subnetoUnit,
  7374.                             'subneto' => $subneto,
  7375.                             'subtotal' => $subtotal,
  7376.                         );
  7377.                         break;
  7378.                     case 15//Assisstant
  7379.                         $pax $item->getPax();
  7380.                         if (empty($pax) or $pax == "0") {
  7381.                             $pax 1;
  7382.                         }
  7383.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7384.                         if ($days 1) {
  7385.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7386.                         } else {
  7387.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7388.                         }
  7389.                         $unitsServ $item->getUnits();
  7390.                         if (empty($unitsServ) or $unitsServ == "0") {
  7391.                             $unitsServ 1;
  7392.                         }
  7393.                         $subtotal $subtotalService $days $unitsServ $pax;
  7394.                         $subnetoUnit $subneto;
  7395.                         $subneto $subneto $days $unitsServ $pax;
  7396.                         $data_supplier['service'][$i] = array(
  7397.                             'id' => $item->getId(),
  7398.                             'serviceCatId' => $item->getServiceCatId(),
  7399.                             'serviceName' => $item->getName(),
  7400.                             'serviceType' => 'Asistente',
  7401.                             'date' => $dateServ,
  7402.                             'qty' => $unitsServ,
  7403.                             'iva' => $item->getIva(),
  7404.                             'pax' => $item->getPax(),
  7405.                             'precioUnit' => $subnetoUnit,
  7406.                             'subneto' => $subneto,
  7407.                             'subtotal' => $subtotal,
  7408.                         );
  7409.                         break;
  7410.                     case 16//DDR
  7411.                         $pax $item->getPax();
  7412.                         if (empty($pax) or $pax == "0") {
  7413.                             $pax 1;
  7414.                         }
  7415.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7416.                         if ($days 1) {
  7417.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7418.                         } else {
  7419.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7420.                         }
  7421.                         $unitsServ $item->getUnits();
  7422.                         if (empty($unitsServ) or $unitsServ == "0") {
  7423.                             $unitsServ 1;
  7424.                         }
  7425.                         $subtotal $subtotalService $days $unitsServ $pax;
  7426.                         $subnetoUnit $subneto;
  7427.                         $subneto $subneto $days $unitsServ $pax;
  7428.                         $data_supplier['service'][$i] = array(
  7429.                             'id' => $item->getId(),
  7430.                             'serviceCatId' => $item->getServiceCatId(),
  7431.                             'serviceName' => $item->getName(),
  7432.                             'serviceType' => 'DDR',
  7433.                             'date' => $dateServ,
  7434.                             'qty' => $unitsServ,
  7435.                             'iva' => $item->getIva(),
  7436.                             'pax' => $item->getPax(),
  7437.                             'precioUnit' => $subnetoUnit,
  7438.                             'subneto' => $subneto,
  7439.                             'subtotal' => $subtotal,
  7440.                         );
  7441.                         break;
  7442.                     default:
  7443.                         break;
  7444.                 }
  7445.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7446.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  7447.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  7448.             }
  7449.             switch ($item->getIva()) {
  7450.                     // Acumula IVA
  7451.                 case 21:
  7452.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  7453.                     break;
  7454.                 case 10:
  7455.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  7456.                     break;
  7457.                 case 0:
  7458.                     break;
  7459.                 default:
  7460.                     break;
  7461.             }
  7462.             $totales_neto_all $totales_neto_all $neto;
  7463.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7464.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  7465.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  7466.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  7467.             // Acumula netos totales e IVA
  7468.             $service['neto'] = $service['neto'] + $neto;
  7469.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  7470.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7471.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  7472.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  7473.             $i++;
  7474.         }
  7475.         $data_supplier['serviceSubTotal'] = array(
  7476.             'neto' => $service['neto'],
  7477.             'sumSubT' => $service['sumSubT'],
  7478.         );
  7479.         $currency '€';
  7480.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  7481.         if (!empty($payments)) {
  7482.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  7483.         } else {
  7484.             $amount_pay 0;
  7485.         }
  7486.         $totales_all $totales_total $amount_pay;
  7487.         $data = array(
  7488.             'id' => $id,
  7489.             'type' => $type,
  7490.             'number' => $number,
  7491.             'prefix' => $prefix,
  7492.             'date' => $date,
  7493.             'file' => $file,
  7494.             'token' => ''// $file->getAccessKey(),
  7495.             'company' => $company,
  7496.             'clients' => $clientNew,
  7497.             'datasupplier' => $data_supplier,
  7498.             'currency' => $currency,
  7499.             'totales_neto' => $totales_neto_all,
  7500.             'bases_imponibles' => $data_iva,
  7501.             'totales' => $totales_total,
  7502.             'balance' => $totales_all,
  7503.             'paymentInvoice' => $amount_pay,
  7504.         );
  7505.         return $data;
  7506.     }
  7507.     private function baseInvoiceSelectedFile($id$arrayBools$number)
  7508.     {
  7509.         $em $this->getDoctrine()->getManager();
  7510.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  7511.         $items $em->getRepository(AveDocProformaItems::class)->findByFileId($file->getId());
  7512.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  7513.         $client $em->getRepository(Client::class)->findById($file->getClient());
  7514.         if (empty($client)) {
  7515.             $client[0] = new Client();
  7516.             $client[0]->setName('');
  7517.             $client[0]->setTitle('');
  7518.             $client[0]->setIdDocument('');
  7519.             $client[0]->setPopulation('');
  7520.             $client[0]->setRegion('');
  7521.             $client[0]->setCountry('');
  7522.         } else {
  7523.             if (is_numeric($client[0]->getPopulation())) {
  7524.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  7525. //                $client[0]->setPopulation($city->getCity());
  7526.             }
  7527.             if (is_numeric($client[0]->getRegion())) {
  7528.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  7529. //                $client[0]->setRegion($region->getRegion());
  7530.             }
  7531.             if (is_numeric($client[0]->getCountry())) {
  7532.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  7533. //                $client[0]->setCountry($country->getCountry());
  7534.             }
  7535.         }
  7536.         if (empty($client)) {
  7537.             $client[0] = new Client();
  7538.             $client[0]->setName('');
  7539.             $client[0]->setTitle('');
  7540.             $client[0]->setIdDocument('');
  7541.             $client[0]->setPopulation('');
  7542.             $client[0]->setRegion('');
  7543.             $client[0]->setCountry('');
  7544.             $clientNew = array(
  7545.                 'name' => '',
  7546.                 'title' => '',
  7547.                 'idDocument' => '',
  7548.                 'population' => '',
  7549.                 'region' => '',
  7550.                 'country' => '',
  7551.                 'address' => '',
  7552.                 'addressNumber' => '',
  7553.                 'zipCode' => '',
  7554.                 'typeDocument' => '',
  7555.             );
  7556.         } else {
  7557.             $clientNew = array(
  7558.                 'name' => $client[0]->getName(),
  7559.                 'title' => $client[0]->getTitle(),
  7560.                 'idDocument' => $client[0]->getIdDocument(),
  7561.                 'population' => '',
  7562.                 'region' => '',
  7563.                 'country' => '',
  7564.                 'address' => $client[0]->getAddress(),
  7565.                 'addressNumber' => $client[0]->getAddressNumber(),
  7566.                 'zipCode' => $client[0]->getZipCode(),
  7567.                 'typeDocument' => $client[0]->getTypeDocument(),
  7568.             );
  7569.             if (is_numeric($client[0]->getPopulation())) {
  7570.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  7571.                 $clientNew['population'] = $city->getCity();
  7572.             }
  7573.             if (is_numeric($client[0]->getRegion())) {
  7574.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  7575.                 $clientNew['region'] = $region->getRegion();
  7576.             }
  7577.             if (is_numeric($client[0]->getCountry())) {
  7578.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  7579.                 $clientNew['country'] = $country->getCountry();
  7580.             }
  7581.         }
  7582.         // Acumuladores de los calculos
  7583.         $totales_neto_all 0;
  7584.         $data_iva = array(
  7585.             'iva' => 21,
  7586.             'ivaMontoVeintiUno' => 0,
  7587.             'ivaMontoDiez' => 0,
  7588.             'ivaMontoCero' => null,                                     // Si toma el valor de cero, indica que hay un iva en 0 y se pone en la factura de resto no
  7589.         );
  7590.         //INICIO: Determinamos el numero de factura o proforma
  7591.         if (substr($number01) == 'I') {
  7592.             // Es una Factura
  7593.             $numberInvoiceOrProforma substr($number1);
  7594.             $number $numberInvoiceOrProforma;
  7595.             $number $em->getRepository(AveDocInvoice::class)->findOneById($number);
  7596.             $number $number->getNumber();
  7597.             $type 'Invoice';
  7598.         } else {
  7599.             // Es una Proforma
  7600.             $numberInvoiceOrProforma substr($number1);
  7601.             $number $numberInvoiceOrProforma;
  7602.             $number $em->getRepository(AveDocProforma::class)->findOneById($number);
  7603.             $number $number->getPrefix() . $number->getFileId();
  7604.             $type 'Proforma';
  7605.         }
  7606.         //FIN: Determinamos el numero de factura o proforma
  7607.         // Buscamos las salas reservadas, pagos y servicios para el evento
  7608.         $arrayItems = array();
  7609.         $fileProducts = array();
  7610.         if (!empty($arrayBools['product'])) {
  7611.             foreach ($arrayBools['product'] as $key => $item) {
  7612.                 if ($item == 'true') {
  7613.                     $fileProducts[] = $em->getRepository(AveProductFile::class)->findOneById($key);
  7614.                     ///***---
  7615.                 }
  7616.             }
  7617.         }
  7618.         $payments = array();
  7619.         if (!empty($arrayBools['payment'])) {
  7620.             foreach ($arrayBools['payment'] as $key => $item) {
  7621.                 if ($item == 'true') {
  7622.                     $payments[] = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
  7623.                 }
  7624.             }
  7625.         }
  7626.         $services = array();
  7627.         if (!empty($arrayBools['service'])) {
  7628.             foreach ($arrayBools['service'] as $key => $item) {
  7629.                 if ($item == 'true') {
  7630.                     $services[] = $em->getRepository(AveServices::class)->findOneById($key);
  7631.                 }
  7632.             }
  7633.         }
  7634.         $data_supplier = array();
  7635.         $i 0;
  7636.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  7637.         $pax '1';
  7638.         $qty '1';
  7639.         $product = array(
  7640.             'neto' => 0,
  7641.             'sumSubT' => 0,
  7642.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7643.         $service = array(
  7644.             'neto' => 0,
  7645.             'sumSubT' => 0,
  7646.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7647.         foreach ($fileProducts as $item) {
  7648.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  7649.                 $subtotal 0;
  7650.                 $neto 0;
  7651.                 $subtotalProduct 0;
  7652.             } else {
  7653.                 //                $subtotalProduct = $item->getServicePrice() * 1.21;
  7654.                 $subtotalProduct $item->getSubTotalPrice() * (+ ($item->getIva() / 100));
  7655.                 //                $subneto = $item->getServicePrice();
  7656.                 $subneto $item->getSubTotalPrice();
  7657.                 $subtotal =  $subtotalProduct;
  7658.                 $neto =  $subneto;
  7659.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  7660.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  7661.                 $neto round($neto2PHP_ROUND_HALF_UP);
  7662.                 $arrayItems[] = array(
  7663.                     'type' => 'Product',
  7664.                     'name' => $item->getProductName(),
  7665.                     'amount' => $neto,
  7666.                     'iva' => $item->getIva(),
  7667.                     'total' => $subtotal,
  7668.                 );
  7669.             }
  7670.             // Acumula netos totales e IVA
  7671.             $totales_neto_all $totales_neto_all $neto;
  7672.             switch ($item->getIva()) {
  7673.                 case 21:
  7674.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  7675.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  7676.                     break;
  7677.                 case 10:
  7678.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  7679.                     $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  7680.                     break;
  7681.                 case 0:
  7682.                     $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  7683.                     $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  7684.                     break;
  7685.                 default:
  7686.                     $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  7687.                     $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  7688.                     break;
  7689.             }
  7690.             //            $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
  7691.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7692.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  7693.             // Acumula netos totales e IVA
  7694.             $product['neto'] = $product['neto'] + $neto;
  7695.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  7696.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7697.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  7698.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  7699.             // Calculo del precio unitario despues de aplicar Over y Comision
  7700.             $multiplo $qty $item->getDays();
  7701.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  7702.             $data_supplier['product'][$i] = array(
  7703.                 'id' => $item->getId(),
  7704.                 'productName' => $item->getProductName(),
  7705.                 'productId' => $item->getProductId(),
  7706.                 'dateStart' => $item->getDateStart(),
  7707.                 'dateEnd' => $item->getDateEnd(),
  7708.                 'servicePrice' => $item->getServicePrice(),
  7709.                 'subtotalProduct' => $subtotalProduct,
  7710.                 'iva' => $item->getIva(),
  7711.                 'pax' => $pax,
  7712.                 'qty' => $qty,
  7713.                 'type' => $item->getType(),
  7714.                 'subtotal' => $subtotal,
  7715.             );
  7716.             $i++;
  7717.         }
  7718.         $data_supplier['productSubTotal'] = array(
  7719.             'neto' => $product['neto'],
  7720.             'sumSubT' => $product['sumSubT'],
  7721.         );
  7722.         $payment = array(
  7723.             'sumSubT' => 0,
  7724.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  7725.         $i 0;
  7726.         foreach ($payments as $item) {
  7727.             $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  7728.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  7729.             $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  7730.             $data_supplier['payment'][$i] = array(
  7731.                 'id' => $item->getId(),
  7732.                 'amount' => $item->getAmount(),
  7733.                 'amountTotal' => $item->getAmountTotal(),
  7734.                 'vat' => $item->getVat(),
  7735.                 'datePayAt' => $item->getDatePayAt(),
  7736.                 'wayToPay' => $item->getWayToPay(),
  7737.             );
  7738.             $arrayItems[] = array(
  7739.                 'type' => 'Payment',
  7740.                 'name' => $item->getWayToPay(),
  7741.                 'amount' => $item->getAmount(),
  7742.                 'total' => $item->getAmountTotal(),
  7743.                 'iva' => $item->getVat(),
  7744.             );
  7745.             $i++;
  7746.         }
  7747.         if (!empty($payments)) {
  7748.             $data_supplier['paymentSubTotal'] = array(
  7749.                 'sumSubT' => $payment['sumSubT'],
  7750.             );
  7751.         }
  7752.         foreach ($services as $item) {
  7753.             if (is_null($item->getPrice()) or empty($item->getPrice())) {
  7754.                 $subtotal 0;
  7755.                 $neto 0;
  7756.                 $subtotalService 0;
  7757.             } else {
  7758.                 $subtotalService $item->getPrice();
  7759.                 $subneto $item->getPrice();
  7760.                 // Commission
  7761.                 if ($item->getOpCommission() == '1') {
  7762.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  7763.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  7764.                 } else {
  7765.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  7766.                     $subneto $subneto * (- ($item->getCommission() / 100));
  7767.                 }
  7768.                 // Over
  7769.                 if ($item->getOpOver() == '1') {
  7770.                     $subtotalService $subtotalService $item->getOver();
  7771.                     $subneto $subneto $item->getOver();
  7772.                 } else {
  7773.                     $subtotalService $subtotalService $item->getOver();
  7774.                     $subneto $subneto $item->getOver();
  7775.                 }
  7776.                 // IVA
  7777.                 if ($item->getOpIva() == '1') {
  7778.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  7779.                 } else {
  7780.                     $subtotalService $item->getPrice();
  7781.                     $subneto = ($subneto 100) / (100 $item->getIva());
  7782.                 }
  7783.                 switch ($item->getServiceCatId()) {
  7784.                     case 1// Alojamiento
  7785.                         // el numero de noches $numNoches; precio unitario $subneto
  7786.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  7787.                         // La personas no afectan este calculo
  7788.                         $subtotal $subtotalService $numNoches $item->getUnits();
  7789.                         $subnetoUnit $subneto;
  7790.                         $subneto $subneto $numNoches $item->getUnits();
  7791.                         $data_supplier['service'][$i] = array(
  7792.                             'id' => $item->getId(),
  7793.                             'serviceCatId' => $item->getServiceCatId(),
  7794.                             'serviceName' => $item->getName(),
  7795.                             'serviceType' => 'Hotel',
  7796.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  7797.                             'qty' => $item->getUnits(),
  7798.                             'iva' => $item->getIva(),
  7799.                             'pax' => '-',
  7800.                             'precioUnit' => $subnetoUnit,
  7801.                             'subneto' => $subneto,
  7802.                             'subtotal' => $subtotal,
  7803.                         );
  7804.                         break;
  7805.                     case 2//Actividades
  7806.                         // El nĂºmero de personas es considerado en el calculo
  7807.                         $pax $item->getPax();
  7808.                         if (empty($pax) or $pax == "0") {
  7809.                             $pax 1;
  7810.                         }
  7811.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7812.                         if ($days 1) {
  7813.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7814.                         } else {
  7815.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7816.                         }
  7817.                         $subtotal $subtotalService $days $item->getUnits();
  7818.                         $subnetoUnit $subneto;
  7819.                         $subneto $subneto $days $item->getUnits();
  7820.                         $data_supplier['service'][$i] = array(
  7821.                             'id' => $item->getId(),
  7822.                             'serviceCatId' => $item->getServiceCatId(),
  7823.                             'serviceName' => $item->getName(),
  7824.                             'serviceType' => 'Actividad',
  7825.                             'date' => $dateServ,
  7826.                             'qty' => $item->getUnits(),
  7827.                             'iva' => $item->getIva(),
  7828.                             'pax' => $item->getPax(),
  7829.                             'precioUnit' => $subnetoUnit,
  7830.                             'subneto' => $subneto,
  7831.                             'subtotal' => $subtotal,
  7832.                         );
  7833.                         break;
  7834.                     case 3// AV
  7835.                         $pax $item->getPax();
  7836.                         if (empty($pax) or $pax == "0") {
  7837.                             $pax 1;
  7838.                         }
  7839.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7840.                         if ($days 1) {
  7841.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7842.                         } else {
  7843.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7844.                         }
  7845.                         $unitsServ $item->getUnits();
  7846.                         if (empty($unitsServ) or $unitsServ == "0") {
  7847.                             $unitsServ 1;
  7848.                         }
  7849.                         $subtotal $subtotalService $days $unitsServ $pax;
  7850.                         $subnetoUnit $subneto;
  7851.                         $subneto $subneto $days $unitsServ $pax;
  7852.                         $data_supplier['service'][$i] = array(
  7853.                             'id' => $item->getId(),
  7854.                             'serviceCatId' => $item->getServiceCatId(),
  7855.                             'serviceName' => $item->getName(),
  7856.                             'serviceType' => 'AV',
  7857.                             'date' => $dateServ,
  7858.                             'qty' => $unitsServ,
  7859.                             'iva' => $item->getIva(),
  7860.                             'pax' => $item->getPax(),
  7861.                             'precioUnit' => $subnetoUnit,
  7862.                             'subneto' => $subneto,
  7863.                             'subtotal' => $subtotal,
  7864.                         );
  7865.                         break;
  7866.                     case 4//Creative
  7867.                         $pax $item->getPax();
  7868.                         if (empty($pax) or $pax == "0") {
  7869.                             $pax 1;
  7870.                         }
  7871.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7872.                         if ($days 1) {
  7873.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7874.                         } else {
  7875.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7876.                         }
  7877.                         $unitsServ $item->getUnits();
  7878.                         if (empty($unitsServ) or $unitsServ == "0") {
  7879.                             $unitsServ 1;
  7880.                         }
  7881.                         $subtotal $subtotalService $days $unitsServ $pax;
  7882.                         $subnetoUnit $subneto;
  7883.                         $subneto $subneto $days $unitsServ $pax;
  7884.                         $data_supplier['service'][$i] = array(
  7885.                             'id' => $item->getId(),
  7886.                             'serviceCatId' => $item->getServiceCatId(),
  7887.                             'serviceName' => $item->getName(),
  7888.                             'serviceType' => 'Creativo',
  7889.                             'date' => $dateServ,
  7890.                             'qty' => $unitsServ,
  7891.                             'iva' => $item->getIva(),
  7892.                             'pax' => $item->getPax(),
  7893.                             'precioUnit' => $subnetoUnit,
  7894.                             'subneto' => $subneto,
  7895.                             'subtotal' => $subtotal,
  7896.                         );
  7897.                         break;
  7898.                     case 5//Cruise
  7899.                         $pax $item->getPax();
  7900.                         if (empty($pax) or $pax == "0") {
  7901.                             $pax 1;
  7902.                         }
  7903.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  7904.                         if ($days 1) {
  7905.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7906.                         } else {
  7907.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7908.                         }
  7909.                         $unitsServ $item->getUnits();
  7910.                         if (empty($unitsServ) or $unitsServ == "0") {
  7911.                             $unitsServ 1;
  7912.                         }
  7913.                         $subtotal $subtotalService $days $unitsServ $pax;
  7914.                         $subnetoUnit $subneto;
  7915.                         $subneto $subneto $days $unitsServ $pax;
  7916.                         $data_supplier['service'][$i] = array(
  7917.                             'id' => $item->getId(),
  7918.                             'serviceCatId' => $item->getServiceCatId(),
  7919.                             'serviceName' => $item->getName(),
  7920.                             'serviceType' => 'Crucero',
  7921.                             'date' => $dateServ,
  7922.                             'qty' => $unitsServ,
  7923.                             'iva' => $item->getIva(),
  7924.                             'pax' => $item->getPax(),
  7925.                             'precioUnit' => $subnetoUnit,
  7926.                             'subneto' => $subneto,
  7927.                             'subtotal' => $subtotal,
  7928.                         );
  7929.                         break;
  7930.                     case 6//Entertaiment
  7931.                         $pax $item->getPax();
  7932.                         if (empty($pax) or $pax == "0") {
  7933.                             $pax 1;
  7934.                         }
  7935.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  7936.                         if ($days 1) {
  7937.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7938.                         } else {
  7939.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7940.                         }
  7941.                         $unitsServ $item->getUnits();
  7942.                         if (empty($unitsServ) or $unitsServ == "0") {
  7943.                             $unitsServ 1;
  7944.                         }
  7945.                         $subtotal $subtotalService $days $unitsServ $pax;
  7946.                         $subnetoUnit $subneto;
  7947.                         $subneto $subneto $days $unitsServ $pax;
  7948.                         $data_supplier['service'][$i] = array(
  7949.                             'id' => $item->getId(),
  7950.                             'serviceCatId' => $item->getServiceCatId(),
  7951.                             'serviceName' => $item->getName(),
  7952.                             'serviceType' => 'Entretenimiento',
  7953.                             'date' => $dateServ,
  7954.                             'qty' => $unitsServ,
  7955.                             'iva' => $item->getIva(),
  7956.                             'pax' => $item->getPax(),
  7957.                             'precioUnit' => $subnetoUnit,
  7958.                             'subneto' => $subneto,
  7959.                             'subtotal' => $subtotal,
  7960.                         );
  7961.                         break;
  7962.                     case 7// Gifts
  7963.                         $pax $item->getPax();
  7964.                         if (empty($pax) or $pax == "0") {
  7965.                             $pax 1;
  7966.                         }
  7967.                         $days 1;
  7968.                         if ($days 1) {
  7969.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  7970.                         } else {
  7971.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  7972.                         }
  7973.                         $unitsServ $item->getUnits();
  7974.                         if (empty($unitsServ) or $unitsServ == "0") {
  7975.                             $unitsServ 1;
  7976.                         }
  7977.                         $subtotal $subtotalService $days $unitsServ $pax;
  7978.                         $subnetoUnit $subneto;
  7979.                         $subneto $subneto $days $unitsServ $pax;
  7980.                         $data_supplier['service'][$i] = array(
  7981.                             'id' => $item->getId(),
  7982.                             'serviceCatId' => $item->getServiceCatId(),
  7983.                             'serviceName' => $item->getName(),
  7984.                             'serviceType' => 'Regalos',
  7985.                             'date' => $dateServ,
  7986.                             'qty' => $unitsServ,
  7987.                             'iva' => $item->getIva(),
  7988.                             'pax' => $item->getPax(),
  7989.                             'precioUnit' => $subnetoUnit,
  7990.                             'subneto' => $subneto,
  7991.                             'subtotal' => $subtotal,
  7992.                         );
  7993.                         break;
  7994.                     case 8//Guide
  7995.                         $pax $item->getPax();
  7996.                         if (empty($pax) or $pax == "0") {
  7997.                             $pax 1;
  7998.                         }
  7999.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8000.                         if ($days 1) {
  8001.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8002.                         } else {
  8003.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8004.                         }
  8005.                         $unitsServ $item->getUnits();
  8006.                         if (empty($unitsServ) or $unitsServ == "0") {
  8007.                             $unitsServ 1;
  8008.                         }
  8009.                         $subtotal $subtotalService $days $unitsServ $pax;
  8010.                         $subnetoUnit $subneto;
  8011.                         $subneto $subneto $days $unitsServ $pax;
  8012.                         $data_supplier['service'][$i] = array(
  8013.                             'id' => $item->getId(),
  8014.                             'serviceCatId' => $item->getServiceCatId(),
  8015.                             'serviceName' => $item->getName(),
  8016.                             'serviceType' => 'Regalos',
  8017.                             'date' => $dateServ,
  8018.                             'qty' => $unitsServ,
  8019.                             'iva' => $item->getIva(),
  8020.                             'pax' => $item->getPax(),
  8021.                             'precioUnit' => $subnetoUnit,
  8022.                             'subneto' => $subneto,
  8023.                             'subtotal' => $subtotal,
  8024.                         );
  8025.                         break;
  8026.                     case 9//Itineraries
  8027.                         $pax $item->getPax();
  8028.                         if (empty($pax) or $pax == "0") {
  8029.                             $pax 1;
  8030.                         }
  8031.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8032.                         if ($days 1) {
  8033.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8034.                         } else {
  8035.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8036.                         }
  8037.                         $unitsServ $item->getUnits();
  8038.                         if (empty($unitsServ) or $unitsServ == "0") {
  8039.                             $unitsServ 1;
  8040.                         }
  8041.                         $subtotal $subtotalService $days $unitsServ $pax;
  8042.                         $subnetoUnit $subneto;
  8043.                         $subneto $subneto $days $unitsServ $pax;
  8044.                         $data_supplier['service'][$i] = array(
  8045.                             'id' => $item->getId(),
  8046.                             'serviceCatId' => $item->getServiceCatId(),
  8047.                             'serviceName' => $item->getName(),
  8048.                             'serviceType' => 'Itinerarios',
  8049.                             'date' => $dateServ,
  8050.                             'qty' => $unitsServ,
  8051.                             'iva' => $item->getIva(),
  8052.                             'pax' => $item->getPax(),
  8053.                             'precioUnit' => $subnetoUnit,
  8054.                             'subneto' => $subneto,
  8055.                             'subtotal' => $subtotal,
  8056.                         );
  8057.                         break;
  8058.                     case 10//Lounge  -- No Aplica
  8059.                         //                        $pax = $item->getPax();
  8060.                         //                        if (empty($pax) or $pax == "0") {
  8061.                         //                            $pax = 1;
  8062.                         //                        }
  8063.                         //
  8064.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  8065.                         //                        if ($days > 1){
  8066.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  8067.                         //                        } else {
  8068.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8069.                         //                        }
  8070.                         //
  8071.                         //                        $unitsServ = $item->getUnits();
  8072.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  8073.                         //                            $unitsServ = 1;
  8074.                         //                        }
  8075.                         //
  8076.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  8077.                         //                        $subnetoUnit = $subneto;
  8078.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  8079.                         //
  8080.                         //                        $data_supplier['service'][$i] = array (
  8081.                         //                            'id' => $item->getId(),
  8082.                         //                            'serviceCatId' => $item->getServiceCatId(),
  8083.                         //                            'serviceName' => $item->getName(),
  8084.                         //                            'serviceType' => 'Itinerarios',
  8085.                         //                            'date' => $dateServ,
  8086.                         //                            'qty' => $unitsServ,
  8087.                         //                            'iva' => $item->getIva(),
  8088.                         //                            'pax' => $item->getPax(),
  8089.                         //                            'precioUnit' => $subnetoUnit,
  8090.                         //                            'subneto' => $subneto,
  8091.                         //                            'subtotal' => $subtotal,
  8092.                         //                        );
  8093.                         break;
  8094.                     case 11//Menu
  8095.                         $pax $item->getPax();
  8096.                         if (empty($pax) or $pax == "0") {
  8097.                             $pax 1;
  8098.                         }
  8099.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8100.                         if ($days 1) {
  8101.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8102.                         } else {
  8103.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8104.                         }
  8105.                         $unitsServ $item->getUnits();
  8106.                         if (empty($unitsServ) or $unitsServ == "0") {
  8107.                             $unitsServ 1;
  8108.                         }
  8109.                         $subtotal $subtotalService $days $unitsServ $pax;
  8110.                         $subnetoUnit $subneto;
  8111.                         $subneto $subneto $days $unitsServ $pax;
  8112.                         $data_supplier['service'][$i] = array(
  8113.                             'id' => $item->getId(),
  8114.                             'serviceCatId' => $item->getServiceCatId(),
  8115.                             'serviceName' => $item->getName(),
  8116.                             'serviceType' => 'MenĂº',
  8117.                             'date' => $dateServ,
  8118.                             'qty' => $unitsServ,
  8119.                             'iva' => $item->getIva(),
  8120.                             'pax' => $item->getPax(),
  8121.                             'precioUnit' => $subnetoUnit,
  8122.                             'subneto' => $subneto,
  8123.                             'subtotal' => $subtotal,
  8124.                         );
  8125.                         break;
  8126.                     case 12//Others
  8127.                         $pax $item->getPax();
  8128.                         if (empty($pax) or $pax == "0") {
  8129.                             $pax 1;
  8130.                         }
  8131.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8132.                         if ($days 1) {
  8133.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8134.                         } else {
  8135.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8136.                         }
  8137.                         $unitsServ $item->getUnits();
  8138.                         if (empty($unitsServ) or $unitsServ == "0") {
  8139.                             $unitsServ 1;
  8140.                         }
  8141.                         $subtotal $subtotalService $days $unitsServ $pax;
  8142.                         $subnetoUnit $subneto;
  8143.                         $subneto $subneto $days $unitsServ $pax;
  8144.                         $data_supplier['service'][$i] = array(
  8145.                             'id' => $item->getId(),
  8146.                             'serviceCatId' => $item->getServiceCatId(),
  8147.                             'serviceName' => $item->getName(),
  8148.                             'serviceType' => 'Otros',
  8149.                             'date' => $dateServ,
  8150.                             'qty' => $unitsServ,
  8151.                             'iva' => $item->getIva(),
  8152.                             'pax' => $item->getPax(),
  8153.                             'precioUnit' => $subnetoUnit,
  8154.                             'subneto' => $subneto,
  8155.                             'subtotal' => $subtotal,
  8156.                         );
  8157.                         break;
  8158.                     case 13//Transport
  8159.                         $pax $item->getPax();
  8160.                         if (empty($pax) or $pax == "0") {
  8161.                             $pax 1;
  8162.                         }
  8163.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8164.                         if ($days 1) {
  8165.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8166.                         } else {
  8167.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8168.                         }
  8169.                         $unitsServ $item->getUnits();
  8170.                         if (empty($unitsServ) or $unitsServ == "0") {
  8171.                             $unitsServ 1;
  8172.                         }
  8173.                         $subtotal $subtotalService $days $unitsServ $pax;
  8174.                         $subnetoUnit $subneto;
  8175.                         $subneto $subneto $days $unitsServ $pax;
  8176.                         $data_supplier['service'][$i] = array(
  8177.                             'id' => $item->getId(),
  8178.                             'serviceCatId' => $item->getServiceCatId(),
  8179.                             'serviceName' => $item->getName(),
  8180.                             'serviceType' => 'Transporte',
  8181.                             'date' => $dateServ,
  8182.                             'qty' => $unitsServ,
  8183.                             'iva' => $item->getIva(),
  8184.                             'pax' => $item->getPax(),
  8185.                             'precioUnit' => $subnetoUnit,
  8186.                             'subneto' => $subneto,
  8187.                             'subtotal' => $subtotal,
  8188.                         );
  8189.                         break;
  8190.                     case 14//Technology
  8191.                         $pax $item->getPax();
  8192.                         if (empty($pax) or $pax == "0") {
  8193.                             $pax 1;
  8194.                         }
  8195.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  8196.                         $days 1;
  8197.                         //                        if ($days > 1){
  8198.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  8199.                         //                        } else {
  8200.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8201.                         //                        }
  8202.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8203.                         $unitsServ $item->getUnits();
  8204.                         if (empty($unitsServ) or $unitsServ == "0") {
  8205.                             $unitsServ 1;
  8206.                         }
  8207.                         $subtotal $subtotalService $days $unitsServ $pax;
  8208.                         $subnetoUnit $subneto;
  8209.                         $subneto $subneto $days $unitsServ $pax;
  8210.                         $data_supplier['service'][$i] = array(
  8211.                             'id' => $item->getId(),
  8212.                             'serviceCatId' => $item->getServiceCatId(),
  8213.                             'serviceName' => $item->getName(),
  8214.                             'serviceType' => 'TecnologĂ­a',
  8215.                             'date' => $dateServ,
  8216.                             'qty' => $unitsServ,
  8217.                             'iva' => $item->getIva(),
  8218.                             'pax' => $item->getPax(),
  8219.                             'precioUnit' => $subnetoUnit,
  8220.                             'subneto' => $subneto,
  8221.                             'subtotal' => $subtotal,
  8222.                         );
  8223.                         break;
  8224.                     case 15//Assisstant
  8225.                         $pax $item->getPax();
  8226.                         if (empty($pax) or $pax == "0") {
  8227.                             $pax 1;
  8228.                         }
  8229.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8230.                         if ($days 1) {
  8231.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8232.                         } else {
  8233.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8234.                         }
  8235.                         $unitsServ $item->getUnits();
  8236.                         if (empty($unitsServ) or $unitsServ == "0") {
  8237.                             $unitsServ 1;
  8238.                         }
  8239.                         $subtotal $subtotalService $days $unitsServ $pax;
  8240.                         $subnetoUnit $subneto;
  8241.                         $subneto $subneto $days $unitsServ $pax;
  8242.                         $data_supplier['service'][$i] = array(
  8243.                             'id' => $item->getId(),
  8244.                             'serviceCatId' => $item->getServiceCatId(),
  8245.                             'serviceName' => $item->getName(),
  8246.                             'serviceType' => 'Asistente',
  8247.                             'date' => $dateServ,
  8248.                             'qty' => $unitsServ,
  8249.                             'iva' => $item->getIva(),
  8250.                             'pax' => $item->getPax(),
  8251.                             'precioUnit' => $subnetoUnit,
  8252.                             'subneto' => $subneto,
  8253.                             'subtotal' => $subtotal,
  8254.                         );
  8255.                         break;
  8256.                     case 16//DDR
  8257.                         $pax $item->getPax();
  8258.                         if (empty($pax) or $pax == "0") {
  8259.                             $pax 1;
  8260.                         }
  8261.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  8262.                         if ($days 1) {
  8263.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  8264.                         } else {
  8265.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  8266.                         }
  8267.                         $unitsServ $item->getUnits();
  8268.                         if (empty($unitsServ) or $unitsServ == "0") {
  8269.                             $unitsServ 1;
  8270.                         }
  8271.                         $subtotal $subtotalService $days $unitsServ $pax;
  8272.                         $subnetoUnit $subneto;
  8273.                         $subneto $subneto $days $unitsServ $pax;
  8274.                         $data_supplier['service'][$i] = array(
  8275.                             'id' => $item->getId(),
  8276.                             'serviceCatId' => $item->getServiceCatId(),
  8277.                             'serviceName' => $item->getName(),
  8278.                             'serviceType' => 'DDR',
  8279.                             'date' => $dateServ,
  8280.                             'qty' => $unitsServ,
  8281.                             'iva' => $item->getIva(),
  8282.                             'pax' => $item->getPax(),
  8283.                             'precioUnit' => $subnetoUnit,
  8284.                             'subneto' => $subneto,
  8285.                             'subtotal' => $subtotal,
  8286.                         );
  8287.                         break;
  8288.                     default:
  8289.                         break;
  8290.                 }
  8291.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8292.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8293.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  8294.                 $arrayItems[] = array(
  8295.                     'type' => 'Service',
  8296.                     'name' => $item->getName(),
  8297.                     'amount' => $neto,
  8298.                     'iva' => $item->getIva(),
  8299.                     'total' => $subtotal,
  8300.                 );
  8301.             }
  8302.             switch ($item->getIva()) {
  8303.                     // Acumula IVA
  8304.                 case 21:
  8305.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  8306.                     $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  8307.                     break;
  8308.                 case 10:
  8309.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  8310.                     $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  8311.                     break;
  8312.                 case 0:
  8313.                     $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto * ($item->getIva() / 100));
  8314.                     break;
  8315.                 default:
  8316.                     $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  8317.                     $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  8318.                     break;
  8319.             }
  8320.             $totales_neto_all $totales_neto_all $neto;
  8321.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8322.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  8323.             // Acumula netos totales e IVA
  8324.             $service['neto'] = $service['neto'] + $neto;
  8325.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  8326.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8327.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  8328.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  8329.             $i++;
  8330.         }
  8331.         $data_supplier['serviceSubTotal'] = array(
  8332.             'neto' => $service['neto'],
  8333.             'sumSubT' => $service['sumSubT'],
  8334.         );
  8335.         $currency '€';
  8336.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  8337.         if (!empty($payments)) {
  8338.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  8339.         } else {
  8340.             $amount_pay 0;
  8341.         }
  8342.         $totales_all $totales_total $amount_pay;
  8343.         if ($type == 'Invoice') {
  8344.             $em->clear();   // sin este clear se producia error al guardar
  8345.             $newInvoice $em->getRepository(AveDocInvoice::class)->findOneById($numberInvoiceOrProforma);
  8346.             $newInvoice->setBalance($totales_all);
  8347.             $em->persist($newInvoice);
  8348.             $em->flush();
  8349.         }
  8350.         $data = array(
  8351.             'id' => $id,
  8352.             'type' => $type,
  8353.             'number' => $number,
  8354.             'prefix' => $number,
  8355.             'date' => new DateTime('now'),
  8356.             'file' => $file,
  8357.             'company' => $company,
  8358.             'clients' => $clientNew,
  8359.             'arrayItems' => $arrayItems,
  8360.             'datasupplier' => $data_supplier,
  8361.             'currency' => $currency,
  8362.             'totales_neto' => $totales_neto_all,
  8363.             'bases_imponibles' => $data_iva,
  8364.             'totales' => $totales_total,
  8365.             'balance' => $totales_all,
  8366.             'paymentInvoice' => $amount_pay,
  8367.         );
  8368.         return $data;
  8369.     }
  8370.     private function baseInvoiceDoneDocument($fileId$invoiceId$typeBase)
  8371.     {
  8372.         $em $this->getDoctrine()->getManager();
  8373.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  8374.         $dateDocument null;                                                                           //Fecha final del documento
  8375.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  8376.             if ($typeBase == 'I') {
  8377.                 // Es una factura
  8378.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  8379.                 // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  8380.                 $allProductFile $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
  8381.                 $arrayLocation = array();
  8382.                 $arrayLocationWithNull false;
  8383.                 foreach ($allProductFile as $item) {
  8384.                     if (!empty($item->getLocation())) {
  8385.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  8386.                     } else {
  8387.                         $arrayLocationWithNull true;
  8388.                     }
  8389.                 }
  8390.                 if ($arrayLocationWithNull) {
  8391.                     $arrayLocation['null'] = 'null';
  8392.                 }
  8393.                 $arrayItemsSorted = array();
  8394.                 $productsInFile = array();
  8395.                 foreach ($arrayLocation as $item) {
  8396.                     // VIDEO
  8397.                     $parameters = array(
  8398.                         'fileId' => $fileId,
  8399.                         'proformaId' => $invoiceId,
  8400.                         'type' => 'VĂ­deo',
  8401.                         'location' => $item,
  8402.                     );
  8403.                     $dql 'SELECT i
  8404.                             FROM AvexpressBundle:AveProductFile i
  8405.                             INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8406.                             WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8407.                             ORDER BY i.rankAv ASC';
  8408.                     $query $em->createQuery($dql)->setParameters($parameters);
  8409.                     $productsInFileVid $query->getResult();
  8410.                     // SONIDO
  8411.                     $parameters = array(
  8412.                         'fileId' => $fileId,
  8413.                         'proformaId' => $invoiceId,
  8414.                         'type' => 'Sonido',
  8415.                         'location' => $item,
  8416.                     );
  8417.                     $dql 'SELECT i
  8418.                     FROM AvexpressBundle:AveProductFile i
  8419.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8420.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8421.                     ORDER BY i.rankAv ASC';
  8422.                     $query $em->createQuery($dql)->setParameters($parameters);
  8423.                     $productsInFileSound $query->getResult();
  8424.                     // ILUMINACION
  8425.                     $parameters = array(
  8426.                         'fileId' => $fileId,
  8427.                         'proformaId' => $invoiceId,
  8428.                         'type' => 'IluminaciĂ³n',
  8429.                         'location' => $item,
  8430.                     );
  8431.                     $dql 'SELECT i
  8432.                     FROM AvexpressBundle:AveProductFile i                    
  8433.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id                  
  8434.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8435.                     ORDER BY i.rankAv ASC';
  8436.                     $query $em->createQuery($dql)->setParameters($parameters);
  8437.                     $productsInFileLights $query->getResult();
  8438.                     // OTROS
  8439.                     $parameters = array(
  8440.                         'fileId' => $fileId,
  8441.                         'proformaId' => $invoiceId,
  8442.                         'typeV' => 'VĂ­deo',
  8443.                         'typeS' => 'Sonido',
  8444.                         'typeI' => 'IluminaciĂ³n',
  8445.                         'location' => $item,
  8446.                     );
  8447.                     $dql 'SELECT i
  8448.                     FROM AvexpressBundle:AveProductFile i                    
  8449.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8450.                     WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
  8451.                     ORDER BY i.rankAv ASC';
  8452.                     $query $em->createQuery($dql)->setParameters($parameters);
  8453.                     $productsInFileOther $query->getResult();
  8454.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  8455.                     $parameters = array(
  8456.                         'fileId' => $fileId,
  8457.                         'proformaId' => $invoiceId,
  8458.                         'location' => $item,
  8459.                     );
  8460.                     $dql 'SELECT i
  8461.                     FROM AvexpressBundle:AveProductFile i                    
  8462.                     INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8463.                     WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
  8464.                     ORDER BY i.rankAv ASC';
  8465.                     $query $em->createQuery($dql)->setParameters($parameters);
  8466.                     $productsInFileNull $query->getResult();
  8467.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  8468.                     if ($item == 'null') {
  8469.                         // VIDEO
  8470.                         $parameters = array(
  8471.                             'fileId' => $fileId,
  8472.                             'proformaId' => $invoiceId,
  8473.                             'type' => 'VĂ­deo',
  8474.                             'location' => '',
  8475.                         );
  8476.                         $dql 'SELECT i
  8477.                         FROM AvexpressBundle:AveProductFile i                        
  8478.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8479.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8480.                         ORDER BY i.rankAv ASC';
  8481.                         $query $em->createQuery($dql)->setParameters($parameters);
  8482.                         $productsInFileVid $query->getResult();
  8483.                         // SONIDO
  8484.                         $parameters = array(
  8485.                             'fileId' => $fileId,
  8486.                             'proformaId' => $invoiceId,
  8487.                             'type' => 'Sonido',
  8488.                             'location' => '',
  8489.                         );
  8490.                         $dql 'SELECT i
  8491.                         FROM AvexpressBundle:AveProductFile i
  8492.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8493.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8494.                         ORDER BY i.rankAv ASC';
  8495.                         $query $em->createQuery($dql)->setParameters($parameters);
  8496.                         $productsInFileSound $query->getResult();
  8497.                         // ILUMINACION
  8498.                         $parameters = array(
  8499.                             'fileId' => $fileId,
  8500.                             'proformaId' => $invoiceId,
  8501.                             'type' => 'IluminaciĂ³n',
  8502.                             'location' => '',
  8503.                         );
  8504.                         $dql 'SELECT i
  8505.                         FROM AvexpressBundle:AveProductFile i
  8506.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8507.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8508.                         ORDER BY i.rankAv ASC';
  8509.                         $query $em->createQuery($dql)->setParameters($parameters);
  8510.                         $productsInFileLights $query->getResult();
  8511.                         // OTROS
  8512.                         $parameters = array(
  8513.                             'fileId' => $fileId,
  8514.                             'proformaId' => $invoiceId,
  8515.                             'typeV' => 'VĂ­deo',
  8516.                             'typeS' => 'Sonido',
  8517.                             'typeI' => 'IluminaciĂ³n',
  8518.                             'location' => '',
  8519.                         );
  8520.                         $dql 'SELECT i
  8521.                         FROM AvexpressBundle:AveProductFile i                        
  8522.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8523.                         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
  8524.                         ORDER BY i.rankAv ASC';
  8525.                         $query $em->createQuery($dql)->setParameters($parameters);
  8526.                         $productsInFileOther $query->getResult();
  8527.                         // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  8528.                         $parameters = array(
  8529.                             'fileId' => $fileId,
  8530.                             'proformaId' => $invoiceId,
  8531.                             'location' => '',
  8532.                         );
  8533.                         $dql 'SELECT i
  8534.                         FROM AvexpressBundle:AveProductFile i                        
  8535.                         INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
  8536.                         WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8537.                         ORDER BY i.rankAv ASC';
  8538.                         $query $em->createQuery($dql)->setParameters($parameters);
  8539.                         $productsInFileNull $query->getResult();
  8540.                     }
  8541.                     $arrayItemsSorted array_merge($arrayItemsSorted$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  8542.                 }
  8543.                 $items = array();
  8544.                 foreach ($arrayItemsSorted as $elem) {
  8545.                     $items[] = $em->getRepository(AveDocInvoiceItems::class)->findOneBy(array('fileId' => $fileId'invoiceId' => $invoiceId'prdControlId' => $elem->getId()));
  8546.                 }
  8547.             } else {
  8548.                 // Es una proforma
  8549.                 //                $items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
  8550.                 // Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
  8551.                 $allProductFile $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
  8552.                 $arrayLocation = array();
  8553.                 $arrayLocationWithNull false;
  8554.                 foreach ($allProductFile as $item) {
  8555.                     if (!empty($item->getLocation())) {
  8556.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  8557.                     } else {
  8558.                         $arrayLocationWithNull true;
  8559.                     }
  8560.                 }
  8561.                 if ($arrayLocationWithNull) {
  8562.                     $arrayLocation['null'] = 'null';
  8563.                 }
  8564.                 $arrayItemsSorted = array();
  8565.                 $productsInFile = array();
  8566.                 foreach ($arrayLocation as $item) {
  8567.                     // VIDEO
  8568.                     $parameters = array(
  8569.                         'fileId' => $fileId,
  8570.                         'proformaId' => $invoiceId,
  8571.                         'type' => 'VĂ­deo',
  8572.                         'location' => $item,
  8573.                     );
  8574.                     $dql 'SELECT i
  8575.                     FROM AvexpressBundle:AveProductFile i
  8576.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  8577.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8578.                     ORDER BY i.rankAv ASC';
  8579.                     $query $em->createQuery($dql)->setParameters($parameters);
  8580.                     $productsInFileVid $query->getResult();
  8581.                     // SONIDO
  8582.                     $parameters = array(
  8583.                         'fileId' => $fileId,
  8584.                         'proformaId' => $invoiceId,
  8585.                         'type' => 'Sonido',
  8586.                         'location' => $item,
  8587.                     );
  8588.                     $dql 'SELECT i
  8589.                     FROM AvexpressBundle:AveProductFile i
  8590.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
  8591.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8592.                     ORDER BY i.rankAv ASC';
  8593.                     $query $em->createQuery($dql)->setParameters($parameters);
  8594.                     $productsInFileSound $query->getResult();
  8595.                     // ILUMINACION
  8596.                     $parameters = array(
  8597.                         'fileId' => $fileId,
  8598.                         'proformaId' => $invoiceId,
  8599.                         'type' => 'IluminaciĂ³n',
  8600.                         'location' => $item,
  8601.                     );
  8602.                     $dql 'SELECT i
  8603.                     FROM AvexpressBundle:AveProductFile i                    
  8604.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                  
  8605.                     WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
  8606.                     ORDER BY i.rankAv ASC';
  8607.                     $query $em->createQuery($dql)->setParameters($parameters);
  8608.                     $productsInFileLights $query->getResult();
  8609.                     // OTROS
  8610.                     $parameters = array(
  8611.                         'fileId' => $fileId,
  8612.                         'proformaId' => $invoiceId,
  8613.                         'typeV' => 'VĂ­deo',
  8614.                         'typeS' => 'Sonido',
  8615.                         'typeI' => 'IluminaciĂ³n',
  8616.                         'location' => $item,
  8617.                     );
  8618.                     $dql 'SELECT i
  8619.                     FROM AvexpressBundle:AveProductFile i                    
  8620.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                                        
  8621.                     WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
  8622.                     ORDER BY i.rankAv ASC';
  8623.                     $query $em->createQuery($dql)->setParameters($parameters);
  8624.                     $productsInFileOther $query->getResult();
  8625.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  8626.                     $parameters = array(
  8627.                         'fileId' => $fileId,
  8628.                         'proformaId' => $invoiceId,
  8629.                         'location' => $item,
  8630.                     );
  8631.                     $dql 'SELECT i
  8632.                     FROM AvexpressBundle:AveProductFile i                    
  8633.                     INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                    
  8634.                     WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
  8635.                     ORDER BY i.rankAv ASC';
  8636.                     $query $em->createQuery($dql)->setParameters($parameters);
  8637.                     $productsInFileNull $query->getResult();
  8638.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  8639.                     if ($item == 'null') {
  8640.                         // VIDEO
  8641.                         $parameters = array(
  8642.                             'fileId' => $fileId,
  8643.                             'proformaId' => $invoiceId,
  8644.                             'type' => 'VĂ­deo',
  8645.                             'location' => '',
  8646.                         );
  8647.                         $dql 'SELECT i
  8648.                         FROM AvexpressBundle:AveProductFile i                        
  8649.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                  
  8650.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8651.                         ORDER BY i.rankAv ASC';
  8652.                         $query $em->createQuery($dql)->setParameters($parameters);
  8653.                         $productsInFileVid $query->getResult();
  8654.                         // SONIDO
  8655.                         $parameters = array(
  8656.                             'fileId' => $fileId,
  8657.                             'proformaId' => $invoiceId,
  8658.                             'type' => 'Sonido',
  8659.                             'location' => '',
  8660.                         );
  8661.                         $dql 'SELECT i
  8662.                         FROM AvexpressBundle:AveProductFile i
  8663.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8664.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8665.                         ORDER BY i.rankAv ASC';
  8666.                         $query $em->createQuery($dql)->setParameters($parameters);
  8667.                         $productsInFileSound $query->getResult();
  8668.                         // ILUMINACION
  8669.                         $parameters = array(
  8670.                             'fileId' => $fileId,
  8671.                             'proformaId' => $invoiceId,
  8672.                             'type' => 'IluminaciĂ³n',
  8673.                             'location' => '',
  8674.                         );
  8675.                         $dql 'SELECT i
  8676.                         FROM AvexpressBundle:AveProductFile i
  8677.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8678.                         WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8679.                         ORDER BY i.rankAv ASC';
  8680.                         $query $em->createQuery($dql)->setParameters($parameters);
  8681.                         $productsInFileLights $query->getResult();
  8682.                         // OTROS
  8683.                         $parameters = array(
  8684.                             'fileId' => $fileId,
  8685.                             'proformaId' => $invoiceId,
  8686.                             'typeV' => 'VĂ­deo',
  8687.                             'typeS' => 'Sonido',
  8688.                             'typeI' => 'IluminaciĂ³n',
  8689.                             'location' => '',
  8690.                         );
  8691.                         $dql 'SELECT i
  8692.                         FROM AvexpressBundle:AveProductFile i                        
  8693.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8694.                         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
  8695.                         ORDER BY i.rankAv ASC';
  8696.                         $query $em->createQuery($dql)->setParameters($parameters);
  8697.                         $productsInFileOther $query->getResult();
  8698.                         // CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
  8699.                         $parameters = array(
  8700.                             'fileId' => $fileId,
  8701.                             'proformaId' => $invoiceId,
  8702.                             'location' => '',
  8703.                         );
  8704.                         $dql 'SELECT i
  8705.                         FROM AvexpressBundle:AveProductFile i                        
  8706.                         INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id                        
  8707.                         WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
  8708.                         ORDER BY i.rankAv ASC';
  8709.                         $query $em->createQuery($dql)->setParameters($parameters);
  8710.                         $productsInFileNull $query->getResult();
  8711.                     }
  8712.                     $arrayItemsSorted array_merge($arrayItemsSorted$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  8713.                 }
  8714.                 $items = array();
  8715.                 foreach ($arrayItemsSorted as $elem) {
  8716.                     $items[] = $em->getRepository(AveDocProformaItems::class)->findOneBy(array('fileId' => $fileId'proformaId' => $invoiceId'controlId' => $elem->getId()));
  8717.                 }
  8718.             }
  8719.         } else {
  8720.             // No es factura ni proforma, es una rectificativa
  8721.             $items $em->getRepository(ReservationInvoiceRecItems::class)->findBy(array('reservationId' => $fileId'invoiceRecId' => $invoiceId));
  8722.         }
  8723.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  8724.         $client $em->getRepository(Client::class)->findById($file->getClient());
  8725.         if (empty($client)) {
  8726.             $client[0] = new Client();
  8727.             $client[0]->setName('');
  8728.             $client[0]->setTitle('');
  8729.             $client[0]->setIdDocument('');
  8730.             $client[0]->setPopulation('');
  8731.             $client[0]->setRegion('');
  8732.             $client[0]->setCountry('');
  8733.         } else {
  8734.             if (is_numeric($client[0]->getPopulation())) {
  8735.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8736. //                $client[0]->setPopulation($city->getCity());
  8737.             }
  8738.             if (is_numeric($client[0]->getRegion())) {
  8739.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8740. //                $client[0]->setRegion($region->getRegion());
  8741.             }
  8742.             if (is_numeric($client[0]->getCountry())) {
  8743.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8744. //                $client[0]->setCountry($country->getCountry());
  8745.             }
  8746.         }
  8747.         if (empty($client)) {
  8748.             $client[0] = new Client();
  8749.             $client[0]->setName('');
  8750.             $client[0]->setTitle('');
  8751.             $client[0]->setIdDocument('');
  8752.             $client[0]->setPopulation('');
  8753.             $client[0]->setRegion('');
  8754.             $client[0]->setCountry('');
  8755.             $clientNew = array(
  8756.                 'name' => '',
  8757.                 'title' => '',
  8758.                 'idDocument' => '',
  8759.                 'population' => '',
  8760.                 'region' => '',
  8761.                 'country' => '',
  8762.                 'address' => '',
  8763.                 'addressNumber' => '',
  8764.                 'zipCode' => '',
  8765.                 'typeDocument' => '',
  8766.             );
  8767.         } else {
  8768.             $clientNew = array(
  8769.                 'name' => $client[0]->getName(),
  8770.                 'title' => $client[0]->getTitle(),
  8771.                 'idDocument' => $client[0]->getIdDocument(),
  8772.                 'population' => '',
  8773.                 'region' => '',
  8774.                 'country' => '',
  8775.                 'address' => $client[0]->getAddress(),
  8776.                 'addressNumber' => $client[0]->getAddressNumber(),
  8777.                 'zipCode' => $client[0]->getZipCode(),
  8778.                 'typeDocument' => $client[0]->getTypeDocument(),
  8779.             );
  8780.             if (is_numeric($client[0]->getPopulation())) {
  8781.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  8782.                 $clientNew['population'] = $city->getCity();
  8783.             }
  8784.             if (is_numeric($client[0]->getRegion())) {
  8785.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  8786.                 $clientNew['region'] = $region->getRegion();
  8787.             }
  8788.             if (is_numeric($client[0]->getCountry())) {
  8789.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  8790.                 $clientNew['country'] = $country->getCountry();
  8791.             }
  8792.         }
  8793.         // Acumuladores de los calculos
  8794.         $totales_neto_all 0;
  8795.         $data_iva = array(
  8796.             'iva' => 21,
  8797.             'ivaMontoVeintiUno' => 0,
  8798.             'ivaMontoDiez' => 0,
  8799.             'ivaMontoCero' => null,
  8800.         );
  8801.         //INICIO: Determinamos el numero de factura o proforma
  8802.         if ($typeBase == 'I') {
  8803.             // Es una Factura
  8804.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  8805.             $dateDocument $number->getDateAt();
  8806.             $number $number->getNumber();
  8807.             $type 'Invoice';
  8808.         } else {
  8809.             if ($typeBase == 'R') {
  8810.                 // Es una factura rectificativa
  8811.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  8812.                 $dateDocument $number->getDateAt();
  8813.                 $type 'Invoice Rec';
  8814.             } else {
  8815.                 // Es una Proforma
  8816.                 //                $number = $em->getRepository('DevelupBundle:ReservationProforma')->findOneById($invoiceId);
  8817.                 //                $number = $number->getNumber();
  8818.                 $number $invoiceId;
  8819.                 //                $number = $number->getPrefix().$number->getReservationId();
  8820.                 $type 'Proforma';
  8821.             }
  8822.         }
  8823.         //FIN: Determinamos el numero de factura o proforma
  8824.         // Buscamos las salas reservadas, pagos y servicios para el evento
  8825.         $arrayItems = array();
  8826.         $fileProducts = array();
  8827.         $payments = array();
  8828.         $services = array();
  8829.         if (!empty($items)) {
  8830.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  8831.                 foreach ($items as $item) {
  8832.                     switch ($item->getItemType()) {
  8833.                         case 'PRODUCT'// Salon
  8834.                             $fileProducts[] = $item;
  8835.                             break;
  8836.                         case 'PAYMENT'// Pago
  8837.                             $payments[] = $item;
  8838.                             break;
  8839.                         case 'SERVICE'// Servicio
  8840.                             $services[] = $item;
  8841.                             break;
  8842.                         default:
  8843.                             break;
  8844.                     }
  8845.                 }
  8846.             } else {
  8847.                 // Es una proforma
  8848.                 foreach ($items as $item) {
  8849.                     switch ($item->getType()) {
  8850.                         case 'PRODUCT'// Producto
  8851.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  8852.                             if (!empty($productPro)) {
  8853.                                 $fileProducts[] = $productPro;
  8854.                             }
  8855.                             break;
  8856.                         case 'PAYMENT'// Pago
  8857.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  8858.                             if (!empty($paymentPro)) {
  8859.                                 $payments[] = $paymentPro;
  8860.                             }
  8861.                             break;
  8862.                         case 'SERVICE'// Servicio
  8863.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  8864.                             if (!empty($servicePro)) {
  8865.                                 $services[] = $servicePro;
  8866.                             }
  8867.                             break;
  8868.                         default:
  8869.                             break;
  8870.                     }
  8871.                 }
  8872.             }
  8873.         }
  8874.         $data_supplier = array();
  8875.         $i 0;
  8876.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  8877.         $pax '1';
  8878.         $qty '1';
  8879.         $product = array(
  8880.             'neto' => 0,
  8881.             'sumSubT' => 0,
  8882.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  8883.         $service = array(
  8884.             'neto' => 0,
  8885.             'sumSubT' => 0,
  8886.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  8887.         foreach ($fileProducts as $item) {
  8888.             //            $days = '1';
  8889.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  8890.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  8891.                 if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
  8892.                     $subtotal 0;
  8893.                     $neto 0;
  8894.                     $subnetoMounting 0;
  8895.                     $subtotalLounge 0;
  8896.                     $subnetoRemoval 0;
  8897.                 } else {
  8898.                     if ($item->getIva() == '21') {
  8899.                         $subtotalLounge $item->getSubTotalPrice() * 1.21;
  8900.                     }
  8901.                     if ($item->getIva() == '10') {
  8902.                         $subtotalLounge $item->getSubTotalPrice() * 1.1;
  8903.                     }
  8904.                     if ($item->getIva() == '0') {
  8905.                         $subtotalLounge $item->getSubTotalPrice() * 1;
  8906.                     }
  8907.                     $subneto $item->getSubTotalPrice();
  8908.                     $subtotal =  $subtotalLounge;
  8909.                     $neto =  $subneto;
  8910.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8911.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8912.                     $neto round($neto2PHP_ROUND_HALF_UP);
  8913.                     $arrayItems[] = array(
  8914.                         'type' => 'Product',
  8915.                         'name' => $item->getLngLoungeName(),
  8916.                         'amount' => $item->getServicePrice(),
  8917.                         'iva' => $item->getIva(),
  8918.                         'amountSubTotal' => $neto,
  8919.                         //                        'iva' => '21',
  8920.                         'total' => $subtotal,
  8921.                     );
  8922.                 }
  8923.             } else {
  8924.                 // Es proforma
  8925.                 if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
  8926.                     $subtotal 0;
  8927.                     $neto 0;
  8928.                     $subtotalProduct 0;
  8929.                 } else {
  8930.                     if ($item->getIva() == '21') {
  8931.                         $subtotalProduct $item->getSubTotalPrice() * 1.21;
  8932.                     }
  8933.                     if ($item->getIva() == '10') {
  8934.                         $subtotalProduct $item->getSubTotalPrice() * 1.1;
  8935.                     }
  8936.                     if ($item->getIva() == '0') {
  8937.                         $subtotalProduct $item->getSubTotalPrice() * 1;
  8938.                     }
  8939.                     $subneto $item->getSubTotalPrice();
  8940.                     $subtotal =  $subtotalProduct;
  8941.                     $neto =  $subneto;
  8942.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  8943.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  8944.                     $neto round($neto2PHP_ROUND_HALF_UP);
  8945.                     $arrayItems[] = array(
  8946.                         'type' => 'Product',
  8947.                         'name' => $item->getProductName(),
  8948.                         'amount' => $item->getServicePrice(),
  8949.                         'amountSubTotal' => $neto,
  8950.                         //                        'iva' => '21',
  8951.                         'iva' => $item->getIva(),
  8952.                         'total' => $subtotal,
  8953.                     );
  8954.                 }
  8955.             }
  8956.             // Acumula netos totales e IVA
  8957.             $totales_neto_all $totales_neto_all $neto;
  8958.             if ($item->getIva() == '21') {
  8959.                 $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  8960.             }
  8961.             if ($item->getIva() == '10') {
  8962.                 $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  8963.             }
  8964.             if ($item->getIva() == '0') {
  8965.                 $data_iva['ivaMontoCero'] = $neto 0;
  8966.             }
  8967.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8968.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  8969.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  8970.             // Acumula netos totales e IVA
  8971.             $product['neto'] = $product['neto'] + $neto;
  8972.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  8973.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  8974.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  8975.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  8976.             $pax $item->getPax();
  8977.             $qty $item->getUnits();
  8978.             if (!empty($item->getDays())) {
  8979.                 $days $item->getDays();
  8980.             }
  8981.             // Calculo del precio unitario despues de aplicar Over y Comision
  8982.             $multiplo = (float)$qty * (float)$days;
  8983.             $item->setServicePrice($item->getSubTotalPrice() / $multiplo);
  8984.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  8985.                 $data_supplier['product'][$i] = array(
  8986.                     'id' => $item->getId(),
  8987.                     'loungeName' => $item->getLngLoungeName(),
  8988.                     'idLounge' => $item->getLngIdLounge(),
  8989.                     'dateStart' => $item->getLngDateStart(),
  8990.                     'dateEnd' => $item->getLngDateEnd(),
  8991.                     //                    'servicePrice' => $item->getLngServicePrice(),
  8992.                     'servicePrice' => $item->getServicePrice(),
  8993.                     'serviceSubTotalPrice' => $item->getSubTotalPrice(),
  8994.                     'subtotalLounge' => $subtotalLounge,
  8995.                     // 'iva' => $iva,
  8996.                     'iva' => $item->getIva(),
  8997.                     'pax' => $pax,
  8998.                     'qty' => $qty,
  8999.                     'days' => $days,
  9000.                     'type' => $item->getLngType(),
  9001.                     'subtotal' => $subtotal,
  9002.                 );
  9003.             } else {
  9004.                 // Es proforma
  9005.                 $data_supplier['product'][$i] = array(
  9006.                     'id' => $item->getId(),
  9007.                     'productName' => $item->getProductName(),
  9008.                     'productId' => $item->getProductId(),
  9009.                     'dateStart' => $item->getDateStart(),
  9010.                     'dateEnd' => $item->getDateEnd(),
  9011.                     'location' => $item->getLocation(),
  9012.                     //                    'servicePrice' => $item->getServicePrice(),
  9013.                     'servicePrice' => $item->getServicePrice(),
  9014.                     'serviceSubTotalPrice' => $item->getSubTotalPrice(),
  9015.                     'subtotalProduct' => $subtotalProduct,
  9016.                     // 'iva' => $iva,
  9017.                     'iva' => $item->getIva(),
  9018.                     'pax' => $pax,
  9019.                     'qty' => $qty,
  9020.                     'days' => $days,
  9021.                     'type' => $item->getType(),
  9022.                     'subtotal' => $subtotal,
  9023.                 );
  9024.             }
  9025.             $i++;
  9026.         }
  9027.         $data_supplier['productSubTotal'] = array(
  9028.             'neto' => $product['neto'],
  9029.             'sumSubT' => $product['sumSubT'],
  9030.         );
  9031.         $payment = array(
  9032.             'sumSubT' => 0,
  9033.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  9034.         $i 0;
  9035.         foreach ($payments as $item) {
  9036.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9037.                 //                $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmount();
  9038.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  9039.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9040.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  9041.                 $data_supplier['payment'][$i] = array(
  9042.                     'id' => $item->getId(),
  9043.                     'amount' => $item->getPayAmount(),
  9044.                     'amountTotal' => $item->getPayAmountTotal(),
  9045.                     'vat' => $item->getPayVat(),
  9046.                     'datePayAt' => $item->getPayDatePayAt(),
  9047.                     'wayToPay' => $item->getPayWayToPay(),
  9048.                 );
  9049.                 $arrayItems[] = array(
  9050.                     'type' => 'Payment',
  9051.                     'name' => $item->getPayWayToPay(),
  9052.                     'amount' => $item->getPayAmount(),
  9053.                     'total' => $item->getPayAmountTotal(),
  9054.                     'iva' => $item->getPayVat(),
  9055.                     //                    'iva' => '',
  9056.                     //                    'total' => $item->getPayAmount(),
  9057.                 );
  9058.             } else {
  9059.                 // Es una proforma
  9060.                 //                $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmount();
  9061.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  9062.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  9063.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  9064.                 $data_supplier['payment'][$i] = array(
  9065.                     'id' => $item->getId(),
  9066.                     'amount' => $item->getAmount(),
  9067.                     'amountTotal' => $item->getAmountTotal(),
  9068.                     'vat' => $item->getVat(),
  9069.                     'datePayAt' => $item->getDatePayAt(),
  9070.                     'wayToPay' => $item->getWayToPay(),
  9071.                 );
  9072.                 $arrayItems[] = array(
  9073.                     'type' => 'Payment',
  9074.                     'name' => $item->getWayToPay(),
  9075.                     'amount' => $item->getAmount(),
  9076.                     'total' => $item->getAmountTotal(),
  9077.                     'iva' => $item->getVat(),
  9078.                     //                    'iva' => '',
  9079.                     //                    'total' => $item->getAmount(),
  9080.                 );
  9081.             }
  9082.             $i++;
  9083.         }
  9084.         if (!empty($payments)) {
  9085.             $data_supplier['paymentSubTotal'] = array(
  9086.                 'sumSubT' => $payment['sumSubT'],
  9087.             );
  9088.         }
  9089.         foreach ($services as $item) {
  9090.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  9091.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  9092.                     $subtotal 0;
  9093.                     $neto 0;
  9094.                     $subtotalService 0;
  9095.                 } else {
  9096.                     $subtotalService $item->getSrvPrice();
  9097.                     $subneto $item->getSrvPrice();
  9098.                     // Commission
  9099.                     if ($item->getSrvOpCommission() == '1') {
  9100.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  9101.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  9102.                     } else {
  9103.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  9104.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  9105.                     }
  9106.                     // Over
  9107.                     if ($item->getSrvOpOver() == '1') {
  9108.                         $subtotalService $subtotalService $item->getSrvOver();
  9109.                         $subneto $subneto $item->getSrvOver();
  9110.                     } else {
  9111.                         $subtotalService $subtotalService $item->getSrvOver();
  9112.                         $subneto $subneto $item->getSrvOver();
  9113.                     }
  9114.                     // IVA
  9115.                     if ($item->getSrvOpIva() == '1') {
  9116.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  9117.                     } else {
  9118.                         $subtotalService $item->getSrvPrice();
  9119.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  9120.                     }
  9121.                     switch ($item->getSrvServiceCatId()) {
  9122.                         case 1// Alojamiento
  9123.                             // el numero de noches $numNoches; precio unitario $subneto
  9124.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  9125.                             // La personas no afectan este calculo
  9126.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  9127.                             $subnetoUnit $subneto;
  9128.                             $subneto $subneto $numNoches $item->getSrvUnits();
  9129.                             $data_supplier['service'][$i] = array(
  9130.                                 'id' => $item->getId(),
  9131.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9132.                                 'serviceName' => $item->getSrvName(),
  9133.                                 'serviceType' => 'Hotel',
  9134.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  9135.                                 'qty' => $item->getSrvUnits(),
  9136.                                 'iva' => $item->getSrvIva(),
  9137.                                 'pax' => '-',
  9138.                                 'precioUnit' => $subnetoUnit,
  9139.                                 'subneto' => $subneto,
  9140.                                 'subtotal' => $subtotal,
  9141.                             );
  9142.                             break;
  9143.                         case 2//Actividades
  9144.                             // El nĂºmero de personas es considerado en el calculo
  9145.                             $pax $item->getSrvPax();
  9146.                             if (empty($pax) or $pax == "0") {
  9147.                                 $pax 1;
  9148.                             }
  9149.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9150.                             if ($days 1) {
  9151.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9152.                             } else {
  9153.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9154.                             }
  9155.                             $subtotal $subtotalService $days $item->getSrvUnits();
  9156.                             $subnetoUnit $subneto;
  9157.                             $subneto $subneto $days $item->getSrvUnits();
  9158.                             $data_supplier['service'][$i] = array(
  9159.                                 'id' => $item->getId(),
  9160.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9161.                                 'serviceName' => $item->getSrvName(),
  9162.                                 'serviceType' => 'Actividad',
  9163.                                 'date' => $dateServ,
  9164.                                 'qty' => $item->getSrvUnits(),
  9165.                                 'iva' => $item->getSrvIva(),
  9166.                                 'pax' => $item->getSrvPax(),
  9167.                                 'precioUnit' => $subnetoUnit,
  9168.                                 'subneto' => $subneto,
  9169.                                 'subtotal' => $subtotal,
  9170.                             );
  9171.                             break;
  9172.                         case 3// AV
  9173.                             $pax $item->getSrvPax();
  9174.                             if (empty($pax) or $pax == "0") {
  9175.                                 $pax 1;
  9176.                             }
  9177.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9178.                             if ($days 1) {
  9179.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9180.                             } else {
  9181.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9182.                             }
  9183.                             $unitsServ $item->getSrvUnits();
  9184.                             if (empty($unitsServ) or $unitsServ == "0") {
  9185.                                 $unitsServ 1;
  9186.                             }
  9187.                             $subtotal $subtotalService $days $unitsServ $pax;
  9188.                             $subnetoUnit $subneto;
  9189.                             $subneto $subneto $days $unitsServ $pax;
  9190.                             $data_supplier['service'][$i] = array(
  9191.                                 'id' => $item->getId(),
  9192.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9193.                                 'serviceName' => $item->getSrvName(),
  9194.                                 'serviceType' => 'AV',
  9195.                                 'date' => $dateServ,
  9196.                                 'qty' => $unitsServ,
  9197.                                 'iva' => $item->getSrvIva(),
  9198.                                 'pax' => $item->getSrvPax(),
  9199.                                 'precioUnit' => $subnetoUnit,
  9200.                                 'subneto' => $subneto,
  9201.                                 'subtotal' => $subtotal,
  9202.                             );
  9203.                             break;
  9204.                         case 4//Creative
  9205.                             $pax $item->getSrvPax();
  9206.                             if (empty($pax) or $pax == "0") {
  9207.                                 $pax 1;
  9208.                             }
  9209.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9210.                             if ($days 1) {
  9211.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9212.                             } else {
  9213.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9214.                             }
  9215.                             $unitsServ $item->getSrvUnits();
  9216.                             if (empty($unitsServ) or $unitsServ == "0") {
  9217.                                 $unitsServ 1;
  9218.                             }
  9219.                             $subtotal $subtotalService $days $unitsServ $pax;
  9220.                             $subnetoUnit $subneto;
  9221.                             $subneto $subneto $days $unitsServ $pax;
  9222.                             $data_supplier['service'][$i] = array(
  9223.                                 'id' => $item->getId(),
  9224.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9225.                                 'serviceName' => $item->getSrvName(),
  9226.                                 'serviceType' => 'Creativo',
  9227.                                 'date' => $dateServ,
  9228.                                 'qty' => $unitsServ,
  9229.                                 'iva' => $item->getSrvIva(),
  9230.                                 'pax' => $item->getSrvPax(),
  9231.                                 'precioUnit' => $subnetoUnit,
  9232.                                 'subneto' => $subneto,
  9233.                                 'subtotal' => $subtotal,
  9234.                             );
  9235.                             break;
  9236.                         case 5//Cruise
  9237.                             $pax $item->getSrvPax();
  9238.                             if (empty($pax) or $pax == "0") {
  9239.                                 $pax 1;
  9240.                             }
  9241.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  9242.                             if ($days 1) {
  9243.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9244.                             } else {
  9245.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9246.                             }
  9247.                             $unitsServ $item->getSrvUnits();
  9248.                             if (empty($unitsServ) or $unitsServ == "0") {
  9249.                                 $unitsServ 1;
  9250.                             }
  9251.                             $subtotal $subtotalService $days $unitsServ $pax;
  9252.                             $subnetoUnit $subneto;
  9253.                             $subneto $subneto $days $unitsServ $pax;
  9254.                             $data_supplier['service'][$i] = array(
  9255.                                 'id' => $item->getId(),
  9256.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9257.                                 'serviceName' => $item->getSrvName(),
  9258.                                 'serviceType' => 'Crucero',
  9259.                                 'date' => $dateServ,
  9260.                                 'qty' => $unitsServ,
  9261.                                 'iva' => $item->getSrvIva(),
  9262.                                 'pax' => $item->getSrvPax(),
  9263.                                 'precioUnit' => $subnetoUnit,
  9264.                                 'subneto' => $subneto,
  9265.                                 'subtotal' => $subtotal,
  9266.                             );
  9267.                             break;
  9268.                         case 6//Entertaiment
  9269.                             $pax $item->getSrvPax();
  9270.                             if (empty($pax) or $pax == "0") {
  9271.                                 $pax 1;
  9272.                             }
  9273.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9274.                             if ($days 1) {
  9275.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9276.                             } else {
  9277.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9278.                             }
  9279.                             $unitsServ $item->getSrvUnits();
  9280.                             if (empty($unitsServ) or $unitsServ == "0") {
  9281.                                 $unitsServ 1;
  9282.                             }
  9283.                             $subtotal $subtotalService $days $unitsServ $pax;
  9284.                             $subnetoUnit $subneto;
  9285.                             $subneto $subneto $days $unitsServ $pax;
  9286.                             $data_supplier['service'][$i] = array(
  9287.                                 'id' => $item->getId(),
  9288.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9289.                                 'serviceName' => $item->getSrvName(),
  9290.                                 'serviceType' => 'Entretenimiento',
  9291.                                 'date' => $dateServ,
  9292.                                 'qty' => $unitsServ,
  9293.                                 'iva' => $item->getSrvIva(),
  9294.                                 'pax' => $item->getSrvPax(),
  9295.                                 'precioUnit' => $subnetoUnit,
  9296.                                 'subneto' => $subneto,
  9297.                                 'subtotal' => $subtotal,
  9298.                             );
  9299.                             break;
  9300.                         case 7// Gifts
  9301.                             $pax $item->getSrvPax();
  9302.                             if (empty($pax) or $pax == "0") {
  9303.                                 $pax 1;
  9304.                             }
  9305.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9306.                             $days 1;
  9307.                             if ($days 1) {
  9308.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9309.                             } else {
  9310.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9311.                             }
  9312.                             $unitsServ $item->getSrvUnits();
  9313.                             if (empty($unitsServ) or $unitsServ == "0") {
  9314.                                 $unitsServ 1;
  9315.                             }
  9316.                             $subtotal $subtotalService $days $unitsServ $pax;
  9317.                             $subnetoUnit $subneto;
  9318.                             $subneto $subneto $days $unitsServ $pax;
  9319.                             $data_supplier['service'][$i] = array(
  9320.                                 'id' => $item->getId(),
  9321.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9322.                                 'serviceName' => $item->getSrvName(),
  9323.                                 'serviceType' => 'Regalos',
  9324.                                 'date' => $dateServ,
  9325.                                 'qty' => $unitsServ,
  9326.                                 'iva' => $item->getSrvIva(),
  9327.                                 'pax' => $item->getSrvPax(),
  9328.                                 'precioUnit' => $subnetoUnit,
  9329.                                 'subneto' => $subneto,
  9330.                                 'subtotal' => $subtotal,
  9331.                             );
  9332.                             break;
  9333.                         case 8//Guide
  9334.                             $pax $item->getSrvPax();
  9335.                             if (empty($pax) or $pax == "0") {
  9336.                                 $pax 1;
  9337.                             }
  9338.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9339.                             if ($days 1) {
  9340.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9341.                             } else {
  9342.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9343.                             }
  9344.                             $unitsServ $item->getSrvUnits();
  9345.                             if (empty($unitsServ) or $unitsServ == "0") {
  9346.                                 $unitsServ 1;
  9347.                             }
  9348.                             $subtotal $subtotalService $days $unitsServ $pax;
  9349.                             $subnetoUnit $subneto;
  9350.                             $subneto $subneto $days $unitsServ $pax;
  9351.                             $data_supplier['service'][$i] = array(
  9352.                                 'id' => $item->getId(),
  9353.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9354.                                 'serviceName' => $item->getSrvName(),
  9355.                                 'serviceType' => 'Regalos',
  9356.                                 'date' => $dateServ,
  9357.                                 'qty' => $unitsServ,
  9358.                                 'iva' => $item->getSrvIva(),
  9359.                                 'pax' => $item->getSrvPax(),
  9360.                                 'precioUnit' => $subnetoUnit,
  9361.                                 'subneto' => $subneto,
  9362.                                 'subtotal' => $subtotal,
  9363.                             );
  9364.                             break;
  9365.                         case 9//Itineraries
  9366.                             $pax $item->getSrvPax();
  9367.                             if (empty($pax) or $pax == "0") {
  9368.                                 $pax 1;
  9369.                             }
  9370.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9371.                             if ($days 1) {
  9372.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9373.                             } else {
  9374.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9375.                             }
  9376.                             $unitsServ $item->getSrvUnits();
  9377.                             if (empty($unitsServ) or $unitsServ == "0") {
  9378.                                 $unitsServ 1;
  9379.                             }
  9380.                             $subtotal $subtotalService $days $unitsServ $pax;
  9381.                             $subnetoUnit $subneto;
  9382.                             $subneto $subneto $days $unitsServ $pax;
  9383.                             $data_supplier['service'][$i] = array(
  9384.                                 'id' => $item->getId(),
  9385.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9386.                                 'serviceName' => $item->getSrvName(),
  9387.                                 'serviceType' => 'Itinerarios',
  9388.                                 'date' => $dateServ,
  9389.                                 'qty' => $unitsServ,
  9390.                                 'iva' => $item->getSrvIva(),
  9391.                                 'pax' => $item->getSrvPax(),
  9392.                                 'precioUnit' => $subnetoUnit,
  9393.                                 'subneto' => $subneto,
  9394.                                 'subtotal' => $subtotal,
  9395.                             );
  9396.                             break;
  9397.                         case 10//Lounge  -- No Aplica
  9398.                             //                        $pax = $item->getPax();
  9399.                             //                        if (empty($pax) or $pax == "0") {
  9400.                             //                            $pax = 1;
  9401.                             //                        }
  9402.                             //
  9403.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9404.                             //                        if ($days > 1){
  9405.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9406.                             //                        } else {
  9407.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9408.                             //                        }
  9409.                             //
  9410.                             //                        $unitsServ = $item->getUnits();
  9411.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  9412.                             //                            $unitsServ = 1;
  9413.                             //                        }
  9414.                             //
  9415.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  9416.                             //                        $subnetoUnit = $subneto;
  9417.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  9418.                             //
  9419.                             //                        $data_supplier['service'][$i] = array (
  9420.                             //                            'id' => $item->getId(),
  9421.                             //                            'serviceCatId' => $item->getServiceCatId(),
  9422.                             //                            'serviceName' => $item->getName(),
  9423.                             //                            'serviceType' => 'Itinerarios',
  9424.                             //                            'date' => $dateServ,
  9425.                             //                            'qty' => $unitsServ,
  9426.                             //                            'iva' => $item->getIva(),
  9427.                             //                            'pax' => $item->getPax(),
  9428.                             //                            'precioUnit' => $subnetoUnit,
  9429.                             //                            'subneto' => $subneto,
  9430.                             //                            'subtotal' => $subtotal,
  9431.                             //                        );
  9432.                             break;
  9433.                         case 11//Menu
  9434.                             $pax $item->getSrvPax();
  9435.                             if (empty($pax) or $pax == "0") {
  9436.                                 $pax 1;
  9437.                             }
  9438.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9439.                             if ($days 1) {
  9440.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9441.                             } else {
  9442.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9443.                             }
  9444.                             $unitsServ $item->getSrvUnits();
  9445.                             if (empty($unitsServ) or $unitsServ == "0") {
  9446.                                 $unitsServ 1;
  9447.                             }
  9448.                             $subtotal $subtotalService $days $unitsServ $pax;
  9449.                             $subnetoUnit $subneto;
  9450.                             $subneto $subneto $days $unitsServ $pax;
  9451.                             $data_supplier['service'][$i] = array(
  9452.                                 'id' => $item->getId(),
  9453.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9454.                                 'serviceName' => $item->getSrvName(),
  9455.                                 'serviceType' => 'MenĂº',
  9456.                                 'date' => $dateServ,
  9457.                                 'qty' => $unitsServ,
  9458.                                 'iva' => $item->getSrvIva(),
  9459.                                 'pax' => $item->getSrvPax(),
  9460.                                 'precioUnit' => $subnetoUnit,
  9461.                                 'subneto' => $subneto,
  9462.                                 'subtotal' => $subtotal,
  9463.                             );
  9464.                             break;
  9465.                         case 12//Others
  9466.                             $pax $item->getSrvPax();
  9467.                             if (empty($pax) or $pax == "0") {
  9468.                                 $pax 1;
  9469.                             }
  9470.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9471.                             if ($days 1) {
  9472.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9473.                             } else {
  9474.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9475.                             }
  9476.                             $unitsServ $item->getSrvUnits();
  9477.                             if (empty($unitsServ) or $unitsServ == "0") {
  9478.                                 $unitsServ 1;
  9479.                             }
  9480.                             $subtotal $subtotalService $days $unitsServ $pax;
  9481.                             $subnetoUnit $subneto;
  9482.                             $subneto $subneto $days $unitsServ $pax;
  9483.                             $data_supplier['service'][$i] = array(
  9484.                                 'id' => $item->getId(),
  9485.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9486.                                 'serviceName' => $item->getSrvName(),
  9487.                                 'serviceType' => 'Otros',
  9488.                                 'date' => $dateServ,
  9489.                                 'qty' => $unitsServ,
  9490.                                 'iva' => $item->getSrvIva(),
  9491.                                 'pax' => $item->getSrvPax(),
  9492.                                 'precioUnit' => $subnetoUnit,
  9493.                                 'subneto' => $subneto,
  9494.                                 'subtotal' => $subtotal,
  9495.                             );
  9496.                             break;
  9497.                         case 13//Transport
  9498.                             $pax $item->getSrvPax();
  9499.                             if (empty($pax) or $pax == "0") {
  9500.                                 $pax 1;
  9501.                             }
  9502.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9503.                             if ($days 1) {
  9504.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9505.                             } else {
  9506.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9507.                             }
  9508.                             $unitsServ $item->getSrvUnits();
  9509.                             if (empty($unitsServ) or $unitsServ == "0") {
  9510.                                 $unitsServ 1;
  9511.                             }
  9512.                             $subtotal $subtotalService $days $unitsServ $pax;
  9513.                             $subnetoUnit $subneto;
  9514.                             $subneto $subneto $days $unitsServ $pax;
  9515.                             $data_supplier['service'][$i] = array(
  9516.                                 'id' => $item->getId(),
  9517.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9518.                                 'serviceName' => $item->getSrvName(),
  9519.                                 'serviceType' => 'Transporte',
  9520.                                 'date' => $dateServ,
  9521.                                 'qty' => $unitsServ,
  9522.                                 'iva' => $item->getSrvIva(),
  9523.                                 'pax' => $item->getSrvPax(),
  9524.                                 'precioUnit' => $subnetoUnit,
  9525.                                 'subneto' => $subneto,
  9526.                                 'subtotal' => $subtotal,
  9527.                             );
  9528.                             break;
  9529.                         case 14//Technology
  9530.                             $pax $item->getSrvPax();
  9531.                             if (empty($pax) or $pax == "0") {
  9532.                                 $pax 1;
  9533.                             }
  9534.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9535.                             $days 1;
  9536.                             //                        if ($days > 1){
  9537.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9538.                             //                        } else {
  9539.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9540.                             //                        }
  9541.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9542.                             $unitsServ $item->getSrvUnits();
  9543.                             if (empty($unitsServ) or $unitsServ == "0") {
  9544.                                 $unitsServ 1;
  9545.                             }
  9546.                             $subtotal $subtotalService $days $unitsServ $pax;
  9547.                             $subnetoUnit $subneto;
  9548.                             $subneto $subneto $days $unitsServ $pax;
  9549.                             $data_supplier['service'][$i] = array(
  9550.                                 'id' => $item->getId(),
  9551.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9552.                                 'serviceName' => $item->getSrvName(),
  9553.                                 'serviceType' => 'TecnologĂ­a',
  9554.                                 'date' => $dateServ,
  9555.                                 'qty' => $unitsServ,
  9556.                                 'iva' => $item->getSrvIva(),
  9557.                                 'pax' => $item->getSrvPax(),
  9558.                                 'precioUnit' => $subnetoUnit,
  9559.                                 'subneto' => $subneto,
  9560.                                 'subtotal' => $subtotal,
  9561.                             );
  9562.                             break;
  9563.                         case 15//Assisstant
  9564.                             $pax $item->getSrvPax();
  9565.                             if (empty($pax) or $pax == "0") {
  9566.                                 $pax 1;
  9567.                             }
  9568.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9569.                             if ($days 1) {
  9570.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9571.                             } else {
  9572.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9573.                             }
  9574.                             $unitsServ $item->getSrvUnits();
  9575.                             if (empty($unitsServ) or $unitsServ == "0") {
  9576.                                 $unitsServ 1;
  9577.                             }
  9578.                             $subtotal $subtotalService $days $unitsServ $pax;
  9579.                             $subnetoUnit $subneto;
  9580.                             $subneto $subneto $days $unitsServ $pax;
  9581.                             $data_supplier['service'][$i] = array(
  9582.                                 'id' => $item->getId(),
  9583.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9584.                                 'serviceName' => $item->getSrvName(),
  9585.                                 'serviceType' => 'Asistente',
  9586.                                 'date' => $dateServ,
  9587.                                 'qty' => $unitsServ,
  9588.                                 'iva' => $item->getSrvIva(),
  9589.                                 'pax' => $item->getSrvPax(),
  9590.                                 'precioUnit' => $subnetoUnit,
  9591.                                 'subneto' => $subneto,
  9592.                                 'subtotal' => $subtotal,
  9593.                             );
  9594.                             break;
  9595.                         case 16//DDR
  9596.                             $pax $item->getSrvPax();
  9597.                             if (empty($pax) or $pax == "0") {
  9598.                                 $pax 1;
  9599.                             }
  9600.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  9601.                             if ($days 1) {
  9602.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  9603.                             } else {
  9604.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  9605.                             }
  9606.                             $unitsServ $item->getSrvUnits();
  9607.                             if (empty($unitsServ) or $unitsServ == "0") {
  9608.                                 $unitsServ 1;
  9609.                             }
  9610.                             $subtotal $subtotalService $days $unitsServ $pax;
  9611.                             $subnetoUnit $subneto;
  9612.                             $subneto $subneto $days $unitsServ $pax;
  9613.                             $data_supplier['service'][$i] = array(
  9614.                                 'id' => $item->getId(),
  9615.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  9616.                                 'serviceName' => $item->getSrvName(),
  9617.                                 'serviceType' => 'DDR',
  9618.                                 'date' => $dateServ,
  9619.                                 'qty' => $unitsServ,
  9620.                                 'iva' => $item->getSrvIva(),
  9621.                                 'pax' => $item->getSrvPax(),
  9622.                                 'precioUnit' => $subnetoUnit,
  9623.                                 'subneto' => $subneto,
  9624.                                 'subtotal' => $subtotal,
  9625.                             );
  9626.                             break;
  9627.                         default:
  9628.                             break;
  9629.                     }
  9630.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  9631.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  9632.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  9633.                     $arrayItems[] = array(
  9634.                         'type' => 'Service',
  9635.                         'name' => $item->getSrvName(),
  9636.                         'amount' => $neto,
  9637.                         'iva' => $item->getSrvIva(),
  9638.                         'total' => $subtotal,
  9639.                     );
  9640.                 }
  9641.                 switch ($item->getSrvIva()) {
  9642.                         // Acumula IVA
  9643.                     case 21:
  9644.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  9645.                         break;
  9646.                     case 10:
  9647.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  9648.                         break;
  9649.                     case 0:
  9650.                         break;
  9651.                     default:
  9652.                         break;
  9653.                 }
  9654.             } else {
  9655.                 // Es una proforma
  9656.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  9657.                     $subtotal 0;
  9658.                     $neto 0;
  9659.                     $subtotalService 0;
  9660.                 } else {
  9661.                     $subtotalService $item->getPrice();
  9662.                     $subneto $item->getPrice();
  9663.                     // Commission
  9664.                     if ($item->getOpCommission() == '1') {
  9665.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  9666.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  9667.                     } else {
  9668.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  9669.                         $subneto $subneto * (- ($item->getCommission() / 100));
  9670.                     }
  9671.                     // Over
  9672.                     if ($item->getOpOver() == '1') {
  9673.                         $subtotalService $subtotalService $item->getOver();
  9674.                         $subneto $subneto $item->getOver();
  9675.                     } else {
  9676.                         $subtotalService $subtotalService $item->getOver();
  9677.                         $subneto $subneto $item->getOver();
  9678.                     }
  9679.                     // IVA
  9680.                     if ($item->getOpIva() == '1') {
  9681.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  9682.                     } else {
  9683.                         $subtotalService $item->getPrice();
  9684.                         $subneto = ($subneto 100) / (100 $item->getIva());
  9685.                     }
  9686.                     switch ($item->getServiceCatId()) {
  9687.                         case 1// Alojamiento
  9688.                             // el numero de noches $numNoches; precio unitario $subneto
  9689.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  9690.                             // La personas no afectan este calculo
  9691.                             $subtotal $subtotalService $numNoches $item->getUnits();
  9692.                             $subnetoUnit $subneto;
  9693.                             $subneto $subneto $numNoches $item->getUnits();
  9694.                             $data_supplier['service'][$i] = array(
  9695.                                 'id' => $item->getId(),
  9696.                                 'serviceCatId' => $item->getServiceCatId(),
  9697.                                 'serviceName' => $item->getName(),
  9698.                                 'serviceType' => 'Hotel',
  9699.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  9700.                                 'qty' => $item->getUnits(),
  9701.                                 'iva' => $item->getIva(),
  9702.                                 'pax' => '-',
  9703.                                 'precioUnit' => $subnetoUnit,
  9704.                                 'subneto' => $subneto,
  9705.                                 'subtotal' => $subtotal,
  9706.                             );
  9707.                             break;
  9708.                         case 2//Actividades
  9709.                             // El nĂºmero de personas es considerado en el calculo
  9710.                             $pax $item->getPax();
  9711.                             if (empty($pax) or $pax == "0") {
  9712.                                 $pax 1;
  9713.                             }
  9714.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9715.                             if ($days 1) {
  9716.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9717.                             } else {
  9718.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9719.                             }
  9720.                             $subtotal $subtotalService $days $item->getUnits();
  9721.                             $subnetoUnit $subneto;
  9722.                             $subneto $subneto $days $item->getUnits();
  9723.                             $data_supplier['service'][$i] = array(
  9724.                                 'id' => $item->getId(),
  9725.                                 'serviceCatId' => $item->getServiceCatId(),
  9726.                                 'serviceName' => $item->getName(),
  9727.                                 'serviceType' => 'Actividad',
  9728.                                 'date' => $dateServ,
  9729.                                 'qty' => $item->getUnits(),
  9730.                                 'iva' => $item->getIva(),
  9731.                                 'pax' => $item->getPax(),
  9732.                                 'precioUnit' => $subnetoUnit,
  9733.                                 'subneto' => $subneto,
  9734.                                 'subtotal' => $subtotal,
  9735.                             );
  9736.                             break;
  9737.                         case 3// AV
  9738.                             $pax $item->getPax();
  9739.                             if (empty($pax) or $pax == "0") {
  9740.                                 $pax 1;
  9741.                             }
  9742.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9743.                             if ($days 1) {
  9744.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9745.                             } else {
  9746.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9747.                             }
  9748.                             $unitsServ $item->getUnits();
  9749.                             if (empty($unitsServ) or $unitsServ == "0") {
  9750.                                 $unitsServ 1;
  9751.                             }
  9752.                             $subtotal $subtotalService $days $unitsServ $pax;
  9753.                             $subnetoUnit $subneto;
  9754.                             $subneto $subneto $days $unitsServ $pax;
  9755.                             $data_supplier['service'][$i] = array(
  9756.                                 'id' => $item->getId(),
  9757.                                 'serviceCatId' => $item->getServiceCatId(),
  9758.                                 'serviceName' => $item->getName(),
  9759.                                 'serviceType' => 'AV',
  9760.                                 'date' => $dateServ,
  9761.                                 'qty' => $unitsServ,
  9762.                                 'iva' => $item->getIva(),
  9763.                                 'pax' => $item->getPax(),
  9764.                                 'precioUnit' => $subnetoUnit,
  9765.                                 'subneto' => $subneto,
  9766.                                 'subtotal' => $subtotal,
  9767.                             );
  9768.                             break;
  9769.                         case 4//Creative
  9770.                             $pax $item->getPax();
  9771.                             if (empty($pax) or $pax == "0") {
  9772.                                 $pax 1;
  9773.                             }
  9774.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9775.                             if ($days 1) {
  9776.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9777.                             } else {
  9778.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9779.                             }
  9780.                             $unitsServ $item->getUnits();
  9781.                             if (empty($unitsServ) or $unitsServ == "0") {
  9782.                                 $unitsServ 1;
  9783.                             }
  9784.                             $subtotal $subtotalService $days $unitsServ $pax;
  9785.                             $subnetoUnit $subneto;
  9786.                             $subneto $subneto $days $unitsServ $pax;
  9787.                             $data_supplier['service'][$i] = array(
  9788.                                 'id' => $item->getId(),
  9789.                                 'serviceCatId' => $item->getServiceCatId(),
  9790.                                 'serviceName' => $item->getName(),
  9791.                                 'serviceType' => 'Creativo',
  9792.                                 'date' => $dateServ,
  9793.                                 'qty' => $unitsServ,
  9794.                                 'iva' => $item->getIva(),
  9795.                                 'pax' => $item->getPax(),
  9796.                                 'precioUnit' => $subnetoUnit,
  9797.                                 'subneto' => $subneto,
  9798.                                 'subtotal' => $subtotal,
  9799.                             );
  9800.                             break;
  9801.                         case 5//Cruise
  9802.                             $pax $item->getPax();
  9803.                             if (empty($pax) or $pax == "0") {
  9804.                                 $pax 1;
  9805.                             }
  9806.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  9807.                             if ($days 1) {
  9808.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9809.                             } else {
  9810.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9811.                             }
  9812.                             $unitsServ $item->getUnits();
  9813.                             if (empty($unitsServ) or $unitsServ == "0") {
  9814.                                 $unitsServ 1;
  9815.                             }
  9816.                             $subtotal $subtotalService $days $unitsServ $pax;
  9817.                             $subnetoUnit $subneto;
  9818.                             $subneto $subneto $days $unitsServ $pax;
  9819.                             $data_supplier['service'][$i] = array(
  9820.                                 'id' => $item->getId(),
  9821.                                 'serviceCatId' => $item->getServiceCatId(),
  9822.                                 'serviceName' => $item->getName(),
  9823.                                 'serviceType' => 'Crucero',
  9824.                                 'date' => $dateServ,
  9825.                                 'qty' => $unitsServ,
  9826.                                 'iva' => $item->getIva(),
  9827.                                 'pax' => $item->getPax(),
  9828.                                 'precioUnit' => $subnetoUnit,
  9829.                                 'subneto' => $subneto,
  9830.                                 'subtotal' => $subtotal,
  9831.                             );
  9832.                             break;
  9833.                         case 6//Entertaiment
  9834.                             $pax $item->getPax();
  9835.                             if (empty($pax) or $pax == "0") {
  9836.                                 $pax 1;
  9837.                             }
  9838.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9839.                             if ($days 1) {
  9840.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9841.                             } else {
  9842.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9843.                             }
  9844.                             $unitsServ $item->getUnits();
  9845.                             if (empty($unitsServ) or $unitsServ == "0") {
  9846.                                 $unitsServ 1;
  9847.                             }
  9848.                             $subtotal $subtotalService $days $unitsServ $pax;
  9849.                             $subnetoUnit $subneto;
  9850.                             $subneto $subneto $days $unitsServ $pax;
  9851.                             $data_supplier['service'][$i] = array(
  9852.                                 'id' => $item->getId(),
  9853.                                 'serviceCatId' => $item->getServiceCatId(),
  9854.                                 'serviceName' => $item->getName(),
  9855.                                 'serviceType' => 'Entretenimiento',
  9856.                                 'date' => $dateServ,
  9857.                                 'qty' => $unitsServ,
  9858.                                 'iva' => $item->getIva(),
  9859.                                 'pax' => $item->getPax(),
  9860.                                 'precioUnit' => $subnetoUnit,
  9861.                                 'subneto' => $subneto,
  9862.                                 'subtotal' => $subtotal,
  9863.                             );
  9864.                             break;
  9865.                         case 7// Gifts
  9866.                             $pax $item->getPax();
  9867.                             if (empty($pax) or $pax == "0") {
  9868.                                 $pax 1;
  9869.                             }
  9870.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9871.                             $days 1;
  9872.                             if ($days 1) {
  9873.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9874.                             } else {
  9875.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9876.                             }
  9877.                             $unitsServ $item->getUnits();
  9878.                             if (empty($unitsServ) or $unitsServ == "0") {
  9879.                                 $unitsServ 1;
  9880.                             }
  9881.                             $subtotal $subtotalService $days $unitsServ $pax;
  9882.                             $subnetoUnit $subneto;
  9883.                             $subneto $subneto $days $unitsServ $pax;
  9884.                             $data_supplier['service'][$i] = array(
  9885.                                 'id' => $item->getId(),
  9886.                                 'serviceCatId' => $item->getServiceCatId(),
  9887.                                 'serviceName' => $item->getName(),
  9888.                                 'serviceType' => 'Regalos',
  9889.                                 'date' => $dateServ,
  9890.                                 'qty' => $unitsServ,
  9891.                                 'iva' => $item->getIva(),
  9892.                                 'pax' => $item->getPax(),
  9893.                                 'precioUnit' => $subnetoUnit,
  9894.                                 'subneto' => $subneto,
  9895.                                 'subtotal' => $subtotal,
  9896.                             );
  9897.                             break;
  9898.                         case 8//Guide
  9899.                             $pax $item->getPax();
  9900.                             if (empty($pax) or $pax == "0") {
  9901.                                 $pax 1;
  9902.                             }
  9903.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9904.                             if ($days 1) {
  9905.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9906.                             } else {
  9907.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9908.                             }
  9909.                             $unitsServ $item->getUnits();
  9910.                             if (empty($unitsServ) or $unitsServ == "0") {
  9911.                                 $unitsServ 1;
  9912.                             }
  9913.                             $subtotal $subtotalService $days $unitsServ $pax;
  9914.                             $subnetoUnit $subneto;
  9915.                             $subneto $subneto $days $unitsServ $pax;
  9916.                             $data_supplier['service'][$i] = array(
  9917.                                 'id' => $item->getId(),
  9918.                                 'serviceCatId' => $item->getServiceCatId(),
  9919.                                 'serviceName' => $item->getName(),
  9920.                                 'serviceType' => 'Regalos',
  9921.                                 'date' => $dateServ,
  9922.                                 'qty' => $unitsServ,
  9923.                                 'iva' => $item->getIva(),
  9924.                                 'pax' => $item->getPax(),
  9925.                                 'precioUnit' => $subnetoUnit,
  9926.                                 'subneto' => $subneto,
  9927.                                 'subtotal' => $subtotal,
  9928.                             );
  9929.                             break;
  9930.                         case 9//Itineraries
  9931.                             $pax $item->getPax();
  9932.                             if (empty($pax) or $pax == "0") {
  9933.                                 $pax 1;
  9934.                             }
  9935.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  9936.                             if ($days 1) {
  9937.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  9938.                             } else {
  9939.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9940.                             }
  9941.                             $unitsServ $item->getUnits();
  9942.                             if (empty($unitsServ) or $unitsServ == "0") {
  9943.                                 $unitsServ 1;
  9944.                             }
  9945.                             $subtotal $subtotalService $days $unitsServ $pax;
  9946.                             $subnetoUnit $subneto;
  9947.                             $subneto $subneto $days $unitsServ $pax;
  9948.                             $data_supplier['service'][$i] = array(
  9949.                                 'id' => $item->getId(),
  9950.                                 'serviceCatId' => $item->getServiceCatId(),
  9951.                                 'serviceName' => $item->getName(),
  9952.                                 'serviceType' => 'Itinerarios',
  9953.                                 'date' => $dateServ,
  9954.                                 'qty' => $unitsServ,
  9955.                                 'iva' => $item->getIva(),
  9956.                                 'pax' => $item->getPax(),
  9957.                                 'precioUnit' => $subnetoUnit,
  9958.                                 'subneto' => $subneto,
  9959.                                 'subtotal' => $subtotal,
  9960.                             );
  9961.                             break;
  9962.                         case 10//Lounge  -- No Aplica
  9963.                             //                        $pax = $item->getPax();
  9964.                             //                        if (empty($pax) or $pax == "0") {
  9965.                             //                            $pax = 1;
  9966.                             //                        }
  9967.                             //
  9968.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  9969.                             //                        if ($days > 1){
  9970.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  9971.                             //                        } else {
  9972.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  9973.                             //                        }
  9974.                             //
  9975.                             //                        $unitsServ = $item->getUnits();
  9976.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  9977.                             //                            $unitsServ = 1;
  9978.                             //                        }
  9979.                             //
  9980.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  9981.                             //                        $subnetoUnit = $subneto;
  9982.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  9983.                             //
  9984.                             //                        $data_supplier['service'][$i] = array (
  9985.                             //                            'id' => $item->getId(),
  9986.                             //                            'serviceCatId' => $item->getServiceCatId(),
  9987.                             //                            'serviceName' => $item->getName(),
  9988.                             //                            'serviceType' => 'Itinerarios',
  9989.                             //                            'date' => $dateServ,
  9990.                             //                            'qty' => $unitsServ,
  9991.                             //                            'iva' => $item->getIva(),
  9992.                             //                            'pax' => $item->getPax(),
  9993.                             //                            'precioUnit' => $subnetoUnit,
  9994.                             //                            'subneto' => $subneto,
  9995.                             //                            'subtotal' => $subtotal,
  9996.                             //                        );
  9997.                             break;
  9998.                         case 11//Menu
  9999.                             $pax $item->getPax();
  10000.                             if (empty($pax) or $pax == "0") {
  10001.                                 $pax 1;
  10002.                             }
  10003.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10004.                             if ($days 1) {
  10005.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10006.                             } else {
  10007.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10008.                             }
  10009.                             $unitsServ $item->getUnits();
  10010.                             if (empty($unitsServ) or $unitsServ == "0") {
  10011.                                 $unitsServ 1;
  10012.                             }
  10013.                             $subtotal $subtotalService $days $unitsServ $pax;
  10014.                             $subnetoUnit $subneto;
  10015.                             $subneto $subneto $days $unitsServ $pax;
  10016.                             $data_supplier['service'][$i] = array(
  10017.                                 'id' => $item->getId(),
  10018.                                 'serviceCatId' => $item->getServiceCatId(),
  10019.                                 'serviceName' => $item->getName(),
  10020.                                 'serviceType' => 'MenĂº',
  10021.                                 'date' => $dateServ,
  10022.                                 'qty' => $unitsServ,
  10023.                                 'iva' => $item->getIva(),
  10024.                                 'pax' => $item->getPax(),
  10025.                                 'precioUnit' => $subnetoUnit,
  10026.                                 'subneto' => $subneto,
  10027.                                 'subtotal' => $subtotal,
  10028.                             );
  10029.                             break;
  10030.                         case 12//Others
  10031.                             $pax $item->getPax();
  10032.                             if (empty($pax) or $pax == "0") {
  10033.                                 $pax 1;
  10034.                             }
  10035.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10036.                             if ($days 1) {
  10037.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10038.                             } else {
  10039.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10040.                             }
  10041.                             $unitsServ $item->getUnits();
  10042.                             if (empty($unitsServ) or $unitsServ == "0") {
  10043.                                 $unitsServ 1;
  10044.                             }
  10045.                             $subtotal $subtotalService $days $unitsServ $pax;
  10046.                             $subnetoUnit $subneto;
  10047.                             $subneto $subneto $days $unitsServ $pax;
  10048.                             $data_supplier['service'][$i] = array(
  10049.                                 'id' => $item->getId(),
  10050.                                 'serviceCatId' => $item->getServiceCatId(),
  10051.                                 'serviceName' => $item->getName(),
  10052.                                 'serviceType' => 'Otros',
  10053.                                 'date' => $dateServ,
  10054.                                 'qty' => $unitsServ,
  10055.                                 'iva' => $item->getIva(),
  10056.                                 'pax' => $item->getPax(),
  10057.                                 'precioUnit' => $subnetoUnit,
  10058.                                 'subneto' => $subneto,
  10059.                                 'subtotal' => $subtotal,
  10060.                             );
  10061.                             break;
  10062.                         case 13//Transport
  10063.                             $pax $item->getPax();
  10064.                             if (empty($pax) or $pax == "0") {
  10065.                                 $pax 1;
  10066.                             }
  10067.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10068.                             if ($days 1) {
  10069.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10070.                             } else {
  10071.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10072.                             }
  10073.                             $unitsServ $item->getUnits();
  10074.                             if (empty($unitsServ) or $unitsServ == "0") {
  10075.                                 $unitsServ 1;
  10076.                             }
  10077.                             $subtotal $subtotalService $days $unitsServ $pax;
  10078.                             $subnetoUnit $subneto;
  10079.                             $subneto $subneto $days $unitsServ $pax;
  10080.                             $data_supplier['service'][$i] = array(
  10081.                                 'id' => $item->getId(),
  10082.                                 'serviceCatId' => $item->getServiceCatId(),
  10083.                                 'serviceName' => $item->getName(),
  10084.                                 'serviceType' => 'Transporte',
  10085.                                 'date' => $dateServ,
  10086.                                 'qty' => $unitsServ,
  10087.                                 'iva' => $item->getIva(),
  10088.                                 'pax' => $item->getPax(),
  10089.                                 'precioUnit' => $subnetoUnit,
  10090.                                 'subneto' => $subneto,
  10091.                                 'subtotal' => $subtotal,
  10092.                             );
  10093.                             break;
  10094.                         case 14//Technology
  10095.                             $pax $item->getPax();
  10096.                             if (empty($pax) or $pax == "0") {
  10097.                                 $pax 1;
  10098.                             }
  10099.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  10100.                             $days 1;
  10101.                             //                        if ($days > 1){
  10102.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  10103.                             //                        } else {
  10104.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10105.                             //                        }
  10106.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10107.                             $unitsServ $item->getUnits();
  10108.                             if (empty($unitsServ) or $unitsServ == "0") {
  10109.                                 $unitsServ 1;
  10110.                             }
  10111.                             $subtotal $subtotalService $days $unitsServ $pax;
  10112.                             $subnetoUnit $subneto;
  10113.                             $subneto $subneto $days $unitsServ $pax;
  10114.                             $data_supplier['service'][$i] = array(
  10115.                                 'id' => $item->getId(),
  10116.                                 'serviceCatId' => $item->getServiceCatId(),
  10117.                                 'serviceName' => $item->getName(),
  10118.                                 'serviceType' => 'TecnologĂ­a',
  10119.                                 'date' => $dateServ,
  10120.                                 'qty' => $unitsServ,
  10121.                                 'iva' => $item->getIva(),
  10122.                                 'pax' => $item->getPax(),
  10123.                                 'precioUnit' => $subnetoUnit,
  10124.                                 'subneto' => $subneto,
  10125.                                 'subtotal' => $subtotal,
  10126.                             );
  10127.                             break;
  10128.                         case 15//Assisstant
  10129.                             $pax $item->getPax();
  10130.                             if (empty($pax) or $pax == "0") {
  10131.                                 $pax 1;
  10132.                             }
  10133.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10134.                             if ($days 1) {
  10135.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10136.                             } else {
  10137.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10138.                             }
  10139.                             $unitsServ $item->getUnits();
  10140.                             if (empty($unitsServ) or $unitsServ == "0") {
  10141.                                 $unitsServ 1;
  10142.                             }
  10143.                             $subtotal $subtotalService $days $unitsServ $pax;
  10144.                             $subnetoUnit $subneto;
  10145.                             $subneto $subneto $days $unitsServ $pax;
  10146.                             $data_supplier['service'][$i] = array(
  10147.                                 'id' => $item->getId(),
  10148.                                 'serviceCatId' => $item->getServiceCatId(),
  10149.                                 'serviceName' => $item->getName(),
  10150.                                 'serviceType' => 'Asistente',
  10151.                                 'date' => $dateServ,
  10152.                                 'qty' => $unitsServ,
  10153.                                 'iva' => $item->getIva(),
  10154.                                 'pax' => $item->getPax(),
  10155.                                 'precioUnit' => $subnetoUnit,
  10156.                                 'subneto' => $subneto,
  10157.                                 'subtotal' => $subtotal,
  10158.                             );
  10159.                             break;
  10160.                         case 16//DDR
  10161.                             $pax $item->getPax();
  10162.                             if (empty($pax) or $pax == "0") {
  10163.                                 $pax 1;
  10164.                             }
  10165.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  10166.                             if ($days 1) {
  10167.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  10168.                             } else {
  10169.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  10170.                             }
  10171.                             $unitsServ $item->getUnits();
  10172.                             if (empty($unitsServ) or $unitsServ == "0") {
  10173.                                 $unitsServ 1;
  10174.                             }
  10175.                             $subtotal $subtotalService $days $unitsServ $pax;
  10176.                             $subnetoUnit $subneto;
  10177.                             $subneto $subneto $days $unitsServ $pax;
  10178.                             $data_supplier['service'][$i] = array(
  10179.                                 'id' => $item->getId(),
  10180.                                 'serviceCatId' => $item->getServiceCatId(),
  10181.                                 'serviceName' => $item->getName(),
  10182.                                 'serviceType' => 'DDR',
  10183.                                 'date' => $dateServ,
  10184.                                 'qty' => $unitsServ,
  10185.                                 'iva' => $item->getIva(),
  10186.                                 'pax' => $item->getPax(),
  10187.                                 'precioUnit' => $subnetoUnit,
  10188.                                 'subneto' => $subneto,
  10189.                                 'subtotal' => $subtotal,
  10190.                             );
  10191.                             break;
  10192.                         default:
  10193.                             break;
  10194.                     }
  10195.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10196.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10197.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  10198.                     $arrayItems[] = array(
  10199.                         'type' => 'Service',
  10200.                         'name' => $item->getName(),
  10201.                         'amount' => $neto,
  10202.                         'iva' => $item->getIva(),
  10203.                         'total' => $subtotal,
  10204.                     );
  10205.                 }
  10206.                 switch ($item->getIva()) {
  10207.                         // Acumula IVA
  10208.                     case 21:
  10209.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  10210.                         break;
  10211.                     case 10:
  10212.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  10213.                         break;
  10214.                     case 0:
  10215.                         break;
  10216.                     default:
  10217.                         break;
  10218.                 }
  10219.             }
  10220.             $totales_neto_all $totales_neto_all $neto;
  10221.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10222.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  10223.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10224.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10225.             // Acumula netos totales e IVA
  10226.             $service['neto'] = $service['neto'] + $neto;
  10227.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  10228.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10229.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  10230.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  10231.             $i++;
  10232.         }
  10233.         $data_supplier['serviceSubTotal'] = array(
  10234.             'neto' => $service['neto'],
  10235.             'sumSubT' => $service['sumSubT'],
  10236.         );
  10237.         $currency '€';
  10238.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  10239.         if (!empty($payments)) {
  10240.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  10241.         } else {
  10242.             $amount_pay 0;
  10243.         }
  10244.         $totales_all $totales_total $amount_pay;
  10245.         if (empty($dateDocument)) {
  10246.             $dateDocument = new DateTime('now');
  10247.         }
  10248.         $data = array(
  10249.             'id' => $fileId,
  10250.             'type' => $type,
  10251.             'number' => $number,
  10252.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $fileId,
  10253.             'date' => $dateDocument,
  10254.             'file' => $file,
  10255.             'company' => $company,
  10256.             'clients' => $clientNew,
  10257.             'arrayItems' => $arrayItems,
  10258.             'datasupplier' => $data_supplier,
  10259.             'currency' => $currency,
  10260.             'totales_neto' => $totales_neto_all,
  10261.             'bases_imponibles' => $data_iva,
  10262.             'totales' => $totales_total,
  10263.             'balance' => $totales_all,
  10264.             'paymentInvoice' => $amount_pay,
  10265.         );
  10266.         return $data;
  10267.     }
  10268.     private function baseInvoiceDoneFile($fileId$invoiceId$typeBase)
  10269.     {
  10270.         $em $this->getDoctrine()->getManager();
  10271.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  10272.         $dateDocument null;                                                                           //Fecha final del documento
  10273.         $subneto 0;
  10274.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  10275.             if ($typeBase == 'I') {
  10276.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  10277.                 $arrayLocation = array();
  10278.                 $arrayLocationWithNull false;
  10279.                 foreach ($items as $item) {
  10280.                     if (!empty($item->getLocation())) {
  10281.                         $arrayLocation[$item->getLocation()] = $item->getLocation();
  10282.                     } else {
  10283.                         $arrayLocationWithNull true;
  10284.                     }
  10285.                 }
  10286.                 if ($arrayLocationWithNull) {
  10287.                     $arrayLocation['null'] = 'null';
  10288.                 }
  10289.                 $productsInFile = array();
  10290.                 foreach ($arrayLocation as $item) {
  10291.                     // VIDEO
  10292.                     $parameters = array(
  10293.                         'fileId' => $fileId,
  10294.                         'type' => 'VĂ­deo',
  10295.                         'location' => $item,
  10296.                         'invoiceId' => $invoiceId,
  10297.                     );
  10298.                     $dql 'SELECT i
  10299.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10300.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10301.                             ORDER BY i.rankAv ASC';
  10302.                     $query $em->createQuery($dql)->setParameters($parameters);
  10303.                     $productsInFileVid $query->getResult();
  10304.                     // SONIDO
  10305.                     $parameters = array(
  10306.                         'fileId' => $fileId,
  10307.                         'type' => 'Sonido',
  10308.                         'location' => $item,
  10309.                         'invoiceId' => $invoiceId,
  10310.                     );
  10311.                     $dql 'SELECT i
  10312.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10313.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10314.                             ORDER BY i.rankAv ASC';
  10315.                     $query $em->createQuery($dql)->setParameters($parameters);
  10316.                     $productsInFileSound $query->getResult();
  10317.                     // ILUMINACION
  10318.                     $parameters = array(
  10319.                         'fileId' => $fileId,
  10320.                         'type' => 'IluminaciĂ³n',
  10321.                         'location' => $item,
  10322.                         'invoiceId' => $invoiceId,
  10323.                     );
  10324.                     $dql 'SELECT i
  10325.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10326.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
  10327.                             ORDER BY i.rankAv ASC';
  10328.                     $query $em->createQuery($dql)->setParameters($parameters);
  10329.                     $productsInFileLights $query->getResult();
  10330.                     // OTROS
  10331.                     $parameters = array(
  10332.                         'fileId' => $fileId,
  10333.                         'typeV' => 'VĂ­deo',
  10334.                         'typeS' => 'Sonido',
  10335.                         'typeI' => 'IluminaciĂ³n',
  10336.                         'location' => $item,
  10337.                         'invoiceId' => $invoiceId,
  10338.                     );
  10339.                     $dql 'SELECT i
  10340.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10341.                             WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceId = :invoiceId)
  10342.                             ORDER BY i.rankAv ASC';
  10343.                     $query $em->createQuery($dql)->setParameters($parameters);
  10344.                     $productsInFileOther $query->getResult();
  10345.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10346.                     $parameters = array(
  10347.                         'fileId' => $fileId,
  10348.                         'location' => $item,
  10349.                         'invoiceId' => $invoiceId,
  10350.                     );
  10351.                     $dql 'SELECT i
  10352.                             FROM AvexpressBundle:AveDocInvoiceItems i
  10353.                             WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceId = :invoiceId)
  10354.                             ORDER BY i.rankAv ASC';
  10355.                     $query $em->createQuery($dql)->setParameters($parameters);
  10356.                     $productsInFileNull $query->getResult();
  10357.                     // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  10358.                     if ($item == 'null') {
  10359.                         // VIDEO
  10360.                         $parameters = array(
  10361.                             'fileId' => $fileId,
  10362.                             'type' => 'VĂ­deo',
  10363.                             'invoiceId' => $invoiceId,
  10364.                         );
  10365.                         $dql 'SELECT i
  10366.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10367.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10368.                                 ORDER BY i.rankAv ASC';
  10369.                         $query $em->createQuery($dql)->setParameters($parameters);
  10370.                         $productsInFileVid $query->getResult();
  10371.                         // SONIDO
  10372.                         $parameters = array(
  10373.                             'fileId' => $fileId,
  10374.                             'type' => 'Sonido',
  10375.                             'invoiceId' => $invoiceId,
  10376.                         );
  10377.                         $dql 'SELECT i
  10378.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10379.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10380.                                 ORDER BY i.rankAv ASC';
  10381.                         $query $em->createQuery($dql)->setParameters($parameters);
  10382.                         $productsInFileSound $query->getResult();
  10383.                         // ILUMINACION
  10384.                         $parameters = array(
  10385.                             'fileId' => $fileId,
  10386.                             'type' => 'IluminaciĂ³n',
  10387.                             'invoiceId' => $invoiceId,
  10388.                         );
  10389.                         $dql 'SELECT i
  10390.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10391.                                 WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
  10392.                                 ORDER BY i.rankAv ASC';
  10393.                         $query $em->createQuery($dql)->setParameters($parameters);
  10394.                         $productsInFileLights $query->getResult();
  10395.                         // OTROS
  10396.                         $parameters = array(
  10397.                             'fileId' => $fileId,
  10398.                             'typeV' => 'VĂ­deo',
  10399.                             'typeS' => 'Sonido',
  10400.                             'typeI' => 'IluminaciĂ³n',
  10401.                             'invoiceId' => $invoiceId,
  10402.                         );
  10403.                         $dql 'SELECT i
  10404.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10405.                                 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)
  10406.                                 ORDER BY i.rankAv ASC';
  10407.                         $query $em->createQuery($dql)->setParameters($parameters);
  10408.                         $productsInFileOther $query->getResult();
  10409.                         // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10410.                         $parameters = array(
  10411.                             'fileId' => $fileId,
  10412.                             'invoiceId' => $invoiceId,
  10413.                         );
  10414.                         $dql 'SELECT i
  10415.                                 FROM AvexpressBundle:AveDocInvoiceItems i
  10416.                                 WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceId = :invoiceId)
  10417.                                 ORDER BY i.rankAv ASC';
  10418.                         $query $em->createQuery($dql)->setParameters($parameters);
  10419.                         $productsInFileNull $query->getResult();
  10420.                     }
  10421.                     $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  10422.                 }
  10423.                 $items $productsInFile;       // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
  10424.             } else {
  10425.                 // Es factura ni proforma
  10426.                 $items $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId'proformaId' => $invoiceId));
  10427.             }
  10428.         } else {
  10429.             // No es factura ni proforma, es una rectificativa
  10430.             $items $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  10431.             $arrayLocation = array();
  10432.             $arrayLocationWithNull false;
  10433.             foreach ($items as $item) {
  10434.                 if (!empty($item->getLocation())) {
  10435.                     $arrayLocation[$item->getLocation()] = $item->getLocation();
  10436.                 } else {
  10437.                     $arrayLocationWithNull true;
  10438.                 }
  10439.             }
  10440.             if ($arrayLocationWithNull) {
  10441.                 $arrayLocation['null'] = 'null';
  10442.             }
  10443.             $productsInFile = array();
  10444.             foreach ($arrayLocation as $item) {
  10445.                 // VIDEO
  10446.                 $parameters = array(
  10447.                     'fileId' => $fileId,
  10448.                     'type' => 'VĂ­deo',
  10449.                     'location' => $item,
  10450.                     'invoiceId' => $invoiceId,
  10451.                 );
  10452.                 $dql 'SELECT i
  10453.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10454.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10455.                         ORDER BY i.rankAv ASC';
  10456.                 $query $em->createQuery($dql)->setParameters($parameters);
  10457.                 $productsInFileVid $query->getResult();
  10458.                 // SONIDO
  10459.                 $parameters = array(
  10460.                     'fileId' => $fileId,
  10461.                     'type' => 'Sonido',
  10462.                     'location' => $item,
  10463.                     'invoiceId' => $invoiceId,
  10464.                 );
  10465.                 $dql 'SELECT i
  10466.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10467.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10468.                         ORDER BY i.rankAv ASC';
  10469.                 $query $em->createQuery($dql)->setParameters($parameters);
  10470.                 $productsInFileSound $query->getResult();
  10471.                 // ILUMINACION
  10472.                 $parameters = array(
  10473.                     'fileId' => $fileId,
  10474.                     'type' => 'IluminaciĂ³n',
  10475.                     'location' => $item,
  10476.                     'invoiceId' => $invoiceId,
  10477.                 );
  10478.                 $dql 'SELECT i
  10479.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10480.                         WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
  10481.                         ORDER BY i.rankAv ASC';
  10482.                 $query $em->createQuery($dql)->setParameters($parameters);
  10483.                 $productsInFileLights $query->getResult();
  10484.                 // OTROS
  10485.                 $parameters = array(
  10486.                     'fileId' => $fileId,
  10487.                     'typeV' => 'VĂ­deo',
  10488.                     'typeS' => 'Sonido',
  10489.                     'typeI' => 'IluminaciĂ³n',
  10490.                     'location' => $item,
  10491.                     'invoiceId' => $invoiceId,
  10492.                 );
  10493.                 $dql 'SELECT i
  10494.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10495.                         WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceRecId = :invoiceId)
  10496.                         ORDER BY i.rankAv ASC';
  10497.                 $query $em->createQuery($dql)->setParameters($parameters);
  10498.                 $productsInFileOther $query->getResult();
  10499.                 // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10500.                 $parameters = array(
  10501.                     'fileId' => $fileId,
  10502.                     'location' => $item,
  10503.                     'invoiceId' => $invoiceId,
  10504.                 );
  10505.                 $dql 'SELECT i
  10506.                         FROM AvexpressBundle:AveDocInvoiceRecItems i
  10507.                         WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceRecId = :invoiceId)
  10508.                         ORDER BY i.rankAv ASC';
  10509.                 $query $em->createQuery($dql)->setParameters($parameters);
  10510.                 $productsInFileNull $query->getResult();
  10511.                 // Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
  10512.                 if ($item == 'null') {
  10513.                     // VIDEO
  10514.                     $parameters = array(
  10515.                         'fileId' => $fileId,
  10516.                         'type' => 'VĂ­deo',
  10517.                         'invoiceId' => $invoiceId,
  10518.                     );
  10519.                     $dql 'SELECT i
  10520.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10521.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10522.                             ORDER BY i.rankAv ASC';
  10523.                     $query $em->createQuery($dql)->setParameters($parameters);
  10524.                     $productsInFileVid $query->getResult();
  10525.                     // SONIDO
  10526.                     $parameters = array(
  10527.                         'fileId' => $fileId,
  10528.                         'type' => 'Sonido',
  10529.                         'invoiceId' => $invoiceId,
  10530.                     );
  10531.                     $dql 'SELECT i
  10532.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10533.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10534.                             ORDER BY i.rankAv ASC';
  10535.                     $query $em->createQuery($dql)->setParameters($parameters);
  10536.                     $productsInFileSound $query->getResult();
  10537.                     // ILUMINACION
  10538.                     $parameters = array(
  10539.                         'fileId' => $fileId,
  10540.                         'type' => 'IluminaciĂ³n',
  10541.                         'invoiceId' => $invoiceId,
  10542.                     );
  10543.                     $dql 'SELECT i
  10544.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10545.                             WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
  10546.                             ORDER BY i.rankAv ASC';
  10547.                     $query $em->createQuery($dql)->setParameters($parameters);
  10548.                     $productsInFileLights $query->getResult();
  10549.                     // OTROS
  10550.                     $parameters = array(
  10551.                         'fileId' => $fileId,
  10552.                         'typeV' => 'VĂ­deo',
  10553.                         'typeS' => 'Sonido',
  10554.                         'typeI' => 'IluminaciĂ³n',
  10555.                         'invoiceId' => $invoiceId,
  10556.                     );
  10557.                     $dql 'SELECT i
  10558.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10559.                             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)
  10560.                             ORDER BY i.rankAv ASC';
  10561.                     $query $em->createQuery($dql)->setParameters($parameters);
  10562.                     $productsInFileOther $query->getResult();
  10563.                     // CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
  10564.                     $parameters = array(
  10565.                         'fileId' => $fileId,
  10566.                         'invoiceId' => $invoiceId,
  10567.                     );
  10568.                     $dql 'SELECT i
  10569.                             FROM AvexpressBundle:AveDocInvoiceRecItems i
  10570.                             WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceRecId = :invoiceId)
  10571.                             ORDER BY i.rankAv ASC';
  10572.                     $query $em->createQuery($dql)->setParameters($parameters);
  10573.                     $productsInFileNull $query->getResult();
  10574.                 }
  10575.                 $productsInFile array_merge($productsInFile$productsInFileVid$productsInFileSound$productsInFileLights$productsInFileOther$productsInFileNull);
  10576.             }
  10577.             $items $productsInFile;       // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
  10578.         }
  10579.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority(4);
  10580.         $client $em->getRepository(Client::class)->findById($file->getClient());
  10581.         if (empty($client)) {
  10582.             $client[0] = new Client();
  10583.             $client[0]->setName('');
  10584.             $client[0]->setTitle('');
  10585.             $client[0]->setIdDocument('');
  10586.             $client[0]->setPopulation('');
  10587.             $client[0]->setRegion('');
  10588.             $client[0]->setCountry('');
  10589.         } else {
  10590.             if (is_numeric($client[0]->getPopulation())) {
  10591.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  10592. //                $client[0]->setPopulation($city->getCity());
  10593.             }
  10594.             if (is_numeric($client[0]->getRegion())) {
  10595.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  10596. //                $client[0]->setRegion($region->getRegion());
  10597.             }
  10598.             if (is_numeric($client[0]->getCountry())) {
  10599.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  10600. //                $client[0]->setCountry($country->getCountry());
  10601.             }
  10602.         }
  10603.         if (empty($client)) {
  10604.             $client[0] = new Client();
  10605.             $client[0]->setName('');
  10606.             $client[0]->setTitle('');
  10607.             $client[0]->setIdDocument('');
  10608.             $client[0]->setPopulation('');
  10609.             $client[0]->setRegion('');
  10610.             $client[0]->setCountry('');
  10611.             $clientNew = array(
  10612.                 'name' => '',
  10613.                 'title' => '',
  10614.                 'idDocument' => '',
  10615.                 'population' => '',
  10616.                 'region' => '',
  10617.                 'country' => '',
  10618.                 'address' => '',
  10619.                 'addressNumber' => '',
  10620.                 'zipCode' => '',
  10621.                 'typeDocument' => '',
  10622.             );
  10623.         } else {
  10624.             $clientNew = array(
  10625.                 'name' => $client[0]->getName(),
  10626.                 'title' => $client[0]->getTitle(),
  10627.                 'idDocument' => $client[0]->getIdDocument(),
  10628.                 'population' => '',
  10629.                 'region' => '',
  10630.                 'country' => '',
  10631.                 'address' => $client[0]->getAddress(),
  10632.                 'addressNumber' => $client[0]->getAddressNumber(),
  10633.                 'zipCode' => $client[0]->getZipCode(),
  10634.                 'typeDocument' => $client[0]->getTypeDocument(),
  10635.             );
  10636.             if (is_numeric($client[0]->getPopulation())) {
  10637.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  10638.                 $clientNew['population'] = $city->getCity();
  10639.             }
  10640.             if (is_numeric($client[0]->getRegion())) {
  10641.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  10642.                 $clientNew['region'] = $region->getRegion();
  10643.             }
  10644.             if (is_numeric($client[0]->getCountry())) {
  10645.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  10646.                 $clientNew['country'] = $country->getCountry();
  10647.             }
  10648.         }
  10649.         // Acumuladores de los calculos
  10650.         $totales_neto_all 0;
  10651.         $data_iva = array(
  10652.             'iva' => 21,
  10653.             'ivaMontoVeintiUno' => 0,
  10654.             'ivaMontoDiez' => 0,
  10655.             'ivaMontoCero' => null,
  10656.         );
  10657.         //INICIO: Determinamos el numero de factura o proforma
  10658.         if ($typeBase == 'I') {
  10659.             // Es una Factura
  10660.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  10661.             $dateDocument $number->getDateAt();
  10662.             $number $number->getNumber();
  10663.             $type 'Invoice';
  10664.         } else {
  10665.             if ($typeBase == 'R') {
  10666.                 // Es una factura rectificativa
  10667.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  10668.                 $dateDocument $number->getDateAt();
  10669.                 $type 'Invoice Rec';
  10670.             } else {
  10671.                 // Es una Proforma
  10672.                 $number $invoiceId;
  10673.                 $type 'Proforma';
  10674.             }
  10675.         }
  10676.         //FIN: Determinamos el numero de factura o proforma
  10677.         // Buscamos los productos, pagos y servicios
  10678.         $arrayItems = array();
  10679.         $fileProducts = array();
  10680.         $payments = array();
  10681.         $services = array();
  10682.         if (!empty($items)) {
  10683.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10684.                 foreach ($items as $item) {
  10685.                     switch ($item->getItemType()) {
  10686.                         case 'PRODUCT'// Producto
  10687.                             $fileProducts[] = $item;
  10688.                             break;
  10689.                         case 'PAYMENT'// Pago
  10690.                             $payments[] = $item;
  10691.                             break;
  10692.                         case 'SERVICE'// Servicio
  10693.                             $services[] = $item;
  10694.                             break;
  10695.                         default:
  10696.                             break;
  10697.                     }
  10698.                 }
  10699.             } else {
  10700.                 // Es una proforma
  10701.                 foreach ($items as $item) {
  10702.                     switch ($item->getType()) {
  10703.                         case 'PRODUCT'// Producto
  10704.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  10705.                             if (!empty($productPro)) {
  10706.                                 $fileProducts[] = $productPro;
  10707.                             }
  10708.                             break;
  10709.                         case 'PAYMENT'// Pago
  10710.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  10711.                             if (!empty($paymentPro)) {
  10712.                                 $payments[] = $paymentPro;
  10713.                             }
  10714.                             break;
  10715.                         case 'SERVICE'// Servicio
  10716.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  10717.                             if (!empty($servicePro)) {
  10718.                                 $services[] = $servicePro;
  10719.                             }
  10720.                             break;
  10721.                         default:
  10722.                             break;
  10723.                     }
  10724.                 }
  10725.             }
  10726.         }
  10727.         $data_supplier = array();
  10728.         $i 0;
  10729.         $pax '1';
  10730.         $qty '1';
  10731.         $product = array(
  10732.             'neto' => 0,
  10733.             'sumSubT' => 0,
  10734.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10735.         $service = array(
  10736.             'neto' => 0,
  10737.             'sumSubT' => 0,
  10738.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10739.         foreach ($fileProducts as $item) {
  10740.             $days = ((($item->getPrdDateEnd())->diff($item->getPrdDateStart()))->days 1);
  10741.             if (!is_null($item->getPrdDays()) or !empty($item->getPrdDays())) {
  10742.                 $days $item->getPrdDays();
  10743.             }
  10744.             if (!is_null($item->getPrdQty()) or !empty($item->getPrdQty())) {
  10745.                 $qty $item->getPrdQty();
  10746.             }
  10747.             if (!empty($item->getPrdDays())) {
  10748.                 $days $item->getPrdDays();
  10749.             }
  10750.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10751.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
  10752.                     $subtotal 0;
  10753.                     $neto 0;
  10754.                     $subtotalProduct 0;
  10755.                 } else {
  10756.                     //Buscamos el iva
  10757.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10758.                     if (empty($zProductFile)) {
  10759.                         $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId());
  10760.                     }
  10761.                     if (empty($zProductFile)) {
  10762.                         $zProductFile = new AveProductFile;
  10763.                         $zProductFile->setIva(21);
  10764.                     }             // No se consigue el iva, se obliga a 21%
  10765.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  10766.                     
  10767.                     if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)) {
  10768.                         $ivaFactor = ($item->getPrdIva()) / 100;
  10769.                     }        // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
  10770.                     $subtotalProduct $item->getPrdSubTotalPrice() * ($ivaFactor);
  10771.                     $subneto $item->getPrdSubTotalPrice();
  10772.                     $subtotal =  $subtotalProduct;
  10773.                     $neto =  $subneto;
  10774.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10775.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10776.                     $neto round($neto2PHP_ROUND_HALF_UP);
  10777.                     $arrayItems[] = array(
  10778.                         'type' => 'Product',
  10779.                         'name' => $item->getPrdName(),
  10780.                         'amount' => $neto,
  10781.                         'iva' => $zProductFile->getIva(),
  10782.                         'total' => $subtotal,
  10783.                     );
  10784.                     $ivaFactor = ($ivaFactor 100);
  10785.                     switch ($ivaFactor){
  10786.                         case 21:
  10787.                             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  10788.                             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10789.                             break;
  10790.                         case 10:
  10791.                             $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  10792.                             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10793.                             break;
  10794.                         case 0:
  10795.                             $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  10796.                             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  10797.                             break;
  10798.                         default:
  10799.                             $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  10800.                             $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  10801.                             break;
  10802.                     }
  10803.                 }
  10804.             } else {
  10805.                 // Es proforma
  10806.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  10807.                     $subtotal 0;
  10808.                     $neto 0;
  10809.                     $subtotalProduct 0;
  10810.                 } else {
  10811.                     //Buscamos el iva
  10812.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10813.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  10814.                     $ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
  10815.                     $subtotalProduct $item->getSubTotalPrice() * ($ivaFactor);
  10816.                     $subneto $item->getSubTotalPrice();
  10817.                     $subtotal =  $subtotalProduct;
  10818.                     $neto =  $subneto;
  10819.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  10820.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  10821.                     $neto round($neto2PHP_ROUND_HALF_UP);
  10822.                     $arrayItems[] = array(
  10823.                         'type' => 'Product',
  10824.                         'name' => $item->getProductName(),
  10825.                         'amount' => $neto,
  10826.                         'iva' => $zProductFile->getIva(),
  10827.                         'total' => $subtotal,
  10828.                     );
  10829.                     switch ($zProductFile->getIva()) {
  10830.                         case 21:
  10831.                             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  10832.                             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  10833.                             break;
  10834.                         case 10:
  10835.                             $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1);
  10836.                             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  10837.                             break;
  10838.                         case 0:
  10839.                             $data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto 0);
  10840.                             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  10841.                             break;
  10842.                         default:
  10843.                             $data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
  10844.                             $data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2PHP_ROUND_HALF_UP);
  10845.                             break;
  10846.                     }
  10847.                 }
  10848.             }
  10849.             // Acumula netos totales e IVA
  10850.             $totales_neto_all $totales_neto_all $neto;
  10851.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10852.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  10853.             // Acumula netos totales e IVA
  10854.             $product['neto'] = $product['neto'] + $neto;
  10855.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  10856.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10857.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  10858.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  10859.             // Calculo del precio unitario despues de aplicar Over y Comision
  10860.             $multiplo $qty * (float)$days;
  10861.             $item->setPrdServicePrice($subneto $multiplo);
  10862.             //Buscamos el iva
  10863.             $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  10864.             if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  10865.             $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  10866.             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
  10867.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10868.                 $data_supplier['product'][$i] = array(
  10869.                     'id' => $item->getId(),
  10870.                     'productName' => $item->getPrdName(),
  10871.                     'productId' => $item->getPrdProductId(),
  10872.                     'dateStart' => $item->getPrdDateStart(),
  10873.                     'dateEnd' => $item->getPrdDateEnd(),
  10874.                     'location' => $item->getLocation(),
  10875.                     'servicePrice' => $item->getPrdServicePrice(),
  10876.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  10877.                     'subtotalProduct' => $subtotalProduct,
  10878.                     'iva' => $ivaFactor,
  10879.                     'pax' => $pax,
  10880.                     'qty' => $qty,
  10881.                     'days' => $days,
  10882.                     'type' => $item->getPrdType(),
  10883.                     'subtotal' => $subtotal,
  10884.                 );
  10885.             } else {
  10886.                 // Es proforma
  10887.                 $data_supplier['product'][$i] = array(
  10888.                     'id' => $item->getId(),
  10889.                     'productName' => $item->getProductName(),
  10890.                     'productId' => $item->getProductId(),
  10891.                     'dateStart' => $item->getDateStart(),
  10892.                     'dateEnd' => $item->getDateEnd(),
  10893.                     'servicePrice' => $item->getServicePrice(),
  10894.                     'subtotalProduct' => $subtotalProduct,
  10895.                     'iva' => $ivaFactor,
  10896.                     'pax' => $pax,
  10897.                     'qty' => $qty,
  10898.                     'days' => $days,
  10899.                     'type' => $item->getType(),
  10900.                     'subtotal' => $subtotal,
  10901.                 );
  10902.             }
  10903.             $i++;
  10904.         }
  10905.         $data_supplier['productSubTotal'] = array(
  10906.             'neto' => $product['neto'],
  10907.             'sumSubT' => $product['sumSubT'],
  10908.         );
  10909.         $payment = array(
  10910.             'sumSubT' => 0,
  10911.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  10912.         $i 0;
  10913.         foreach ($payments as $item) {
  10914.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10915.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  10916.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10917.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  10918.                 $data_supplier['payment'][$i] = array(
  10919.                     'id' => $item->getId(),
  10920.                     'amount' => $item->getPayAmount(),
  10921.                     'amountTotal' => $item->getPayAmountTotal(),
  10922.                     'vat' => $item->getPayVat(),
  10923.                     'datePayAt' => $item->getPayDatePayAt(),
  10924.                     'wayToPay' => $item->getPayWayToPay(),
  10925.                 );
  10926.                 $arrayItems[] = array(
  10927.                     'type' => 'Payment',
  10928.                     'name' => $item->getPayWayToPay(),
  10929.                     'amount' => $item->getPayAmount(),
  10930.                     'total' => $item->getPayAmountTotal(),
  10931.                     'iva' => $item->getPayVat(),
  10932.                 );
  10933.             } else {
  10934.                 // Es una proforma
  10935.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  10936.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  10937.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  10938.                 $data_supplier['payment'][$i] = array(
  10939.                     'id' => $item->getId(),
  10940.                     'amount' => $item->getAmount(),
  10941.                     'amountTotal' => $item->getAmountTotal(),
  10942.                     'vat' => $item->getVat(),
  10943.                     'datePayAt' => $item->getDatePayAt(),
  10944.                     'wayToPay' => $item->getWayToPay(),
  10945.                 );
  10946.                 $arrayItems[] = array(
  10947.                     'type' => 'Payment',
  10948.                     'name' => $item->getWayToPay(),
  10949.                     'amount' => $item->getAmount(),
  10950.                     'total' => $item->getAmountTotal(),
  10951.                     'iva' => $item->getVat(),
  10952.                 );
  10953.             }
  10954.             $i++;
  10955.         }
  10956.         if (!empty($payments)) {
  10957.             $data_supplier['paymentSubTotal'] = array(
  10958.                 'sumSubT' => $payment['sumSubT'],
  10959.             );
  10960.         }
  10961.         foreach ($services as $item) {
  10962.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  10963.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  10964.                     $subtotal 0;
  10965.                     $neto 0;
  10966.                     $subtotalService 0;
  10967.                 } else {
  10968.                     $subtotalService $item->getSrvPrice();
  10969.                     $subneto $item->getSrvPrice();
  10970.                     // Commission
  10971.                     if ($item->getSrvOpCommission() == '1') {
  10972.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  10973.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  10974.                     } else {
  10975.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  10976.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  10977.                     }
  10978.                     // Over
  10979.                     if ($item->getSrvOpOver() == '1') {
  10980.                         $subtotalService $subtotalService $item->getSrvOver();
  10981.                         $subneto $subneto $item->getSrvOver();
  10982.                     } else {
  10983.                         $subtotalService $subtotalService $item->getSrvOver();
  10984.                         $subneto $subneto $item->getSrvOver();
  10985.                     }
  10986.                     // IVA
  10987.                     if ($item->getSrvOpIva() == '1') {
  10988.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  10989.                     } else {
  10990.                         $subtotalService $item->getSrvPrice();
  10991.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  10992.                     }
  10993.                     switch ($item->getSrvServiceCatId()) {
  10994.                         case 1// Alojamiento
  10995.                             // el numero de noches $numNoches; precio unitario $subneto
  10996.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  10997.                             // La personas no afectan este calculo
  10998.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  10999.                             $subnetoUnit $subneto;
  11000.                             $subneto $subneto $numNoches $item->getSrvUnits();
  11001.                             $data_supplier['service'][$i] = array(
  11002.                                 'id' => $item->getId(),
  11003.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11004.                                 'serviceName' => $item->getSrvName(),
  11005.                                 'serviceType' => 'Hotel',
  11006.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  11007.                                 'qty' => $item->getSrvUnits(),
  11008.                                 'iva' => $item->getSrvIva(),
  11009.                                 'pax' => '-',
  11010.                                 'precioUnit' => $subnetoUnit,
  11011.                                 'subneto' => $subneto,
  11012.                                 'subtotal' => $subtotal,
  11013.                             );
  11014.                             break;
  11015.                         case 2//Actividades
  11016.                             // El nĂºmero de personas es considerado en el calculo
  11017.                             $pax $item->getSrvPax();
  11018.                             if (empty($pax) or $pax == "0") {
  11019.                                 $pax 1;
  11020.                             }
  11021.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11022.                             if ($days 1) {
  11023.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11024.                             } else {
  11025.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11026.                             }
  11027.                             $subtotal $subtotalService $days $item->getSrvUnits();
  11028.                             $subnetoUnit $subneto;
  11029.                             $subneto $subneto $days $item->getSrvUnits();
  11030.                             $data_supplier['service'][$i] = array(
  11031.                                 'id' => $item->getId(),
  11032.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11033.                                 'serviceName' => $item->getSrvName(),
  11034.                                 'serviceType' => 'Actividad',
  11035.                                 'date' => $dateServ,
  11036.                                 'qty' => $item->getSrvUnits(),
  11037.                                 'iva' => $item->getSrvIva(),
  11038.                                 'pax' => $item->getSrvPax(),
  11039.                                 'precioUnit' => $subnetoUnit,
  11040.                                 'subneto' => $subneto,
  11041.                                 'subtotal' => $subtotal,
  11042.                             );
  11043.                             break;
  11044.                         case 3// AV
  11045.                             $pax $item->getSrvPax();
  11046.                             if (empty($pax) or $pax == "0") {
  11047.                                 $pax 1;
  11048.                             }
  11049.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11050.                             if ($days 1) {
  11051.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11052.                             } else {
  11053.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11054.                             }
  11055.                             $unitsServ $item->getSrvUnits();
  11056.                             if (empty($unitsServ) or $unitsServ == "0") {
  11057.                                 $unitsServ 1;
  11058.                             }
  11059.                             $subtotal $subtotalService $days $unitsServ $pax;
  11060.                             $subnetoUnit $subneto;
  11061.                             $subneto $subneto $days $unitsServ $pax;
  11062.                             $data_supplier['service'][$i] = array(
  11063.                                 'id' => $item->getId(),
  11064.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11065.                                 'serviceName' => $item->getSrvName(),
  11066.                                 'serviceType' => 'AV',
  11067.                                 'date' => $dateServ,
  11068.                                 'qty' => $unitsServ,
  11069.                                 'iva' => $item->getSrvIva(),
  11070.                                 'pax' => $item->getSrvPax(),
  11071.                                 'precioUnit' => $subnetoUnit,
  11072.                                 'subneto' => $subneto,
  11073.                                 'subtotal' => $subtotal,
  11074.                             );
  11075.                             break;
  11076.                         case 4//Creative
  11077.                             $pax $item->getSrvPax();
  11078.                             if (empty($pax) or $pax == "0") {
  11079.                                 $pax 1;
  11080.                             }
  11081.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11082.                             if ($days 1) {
  11083.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11084.                             } else {
  11085.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11086.                             }
  11087.                             $unitsServ $item->getSrvUnits();
  11088.                             if (empty($unitsServ) or $unitsServ == "0") {
  11089.                                 $unitsServ 1;
  11090.                             }
  11091.                             $subtotal $subtotalService $days $unitsServ $pax;
  11092.                             $subnetoUnit $subneto;
  11093.                             $subneto $subneto $days $unitsServ $pax;
  11094.                             $data_supplier['service'][$i] = array(
  11095.                                 'id' => $item->getId(),
  11096.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11097.                                 'serviceName' => $item->getSrvName(),
  11098.                                 'serviceType' => 'Creativo',
  11099.                                 'date' => $dateServ,
  11100.                                 'qty' => $unitsServ,
  11101.                                 'iva' => $item->getSrvIva(),
  11102.                                 'pax' => $item->getSrvPax(),
  11103.                                 'precioUnit' => $subnetoUnit,
  11104.                                 'subneto' => $subneto,
  11105.                                 'subtotal' => $subtotal,
  11106.                             );
  11107.                             break;
  11108.                         case 5//Cruise
  11109.                             $pax $item->getSrvPax();
  11110.                             if (empty($pax) or $pax == "0") {
  11111.                                 $pax 1;
  11112.                             }
  11113.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  11114.                             if ($days 1) {
  11115.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11116.                             } else {
  11117.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11118.                             }
  11119.                             $unitsServ $item->getSrvUnits();
  11120.                             if (empty($unitsServ) or $unitsServ == "0") {
  11121.                                 $unitsServ 1;
  11122.                             }
  11123.                             $subtotal $subtotalService $days $unitsServ $pax;
  11124.                             $subnetoUnit $subneto;
  11125.                             $subneto $subneto $days $unitsServ $pax;
  11126.                             $data_supplier['service'][$i] = array(
  11127.                                 'id' => $item->getId(),
  11128.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11129.                                 'serviceName' => $item->getSrvName(),
  11130.                                 'serviceType' => 'Crucero',
  11131.                                 'date' => $dateServ,
  11132.                                 'qty' => $unitsServ,
  11133.                                 'iva' => $item->getSrvIva(),
  11134.                                 'pax' => $item->getSrvPax(),
  11135.                                 'precioUnit' => $subnetoUnit,
  11136.                                 'subneto' => $subneto,
  11137.                                 'subtotal' => $subtotal,
  11138.                             );
  11139.                             break;
  11140.                         case 6//Entertaiment
  11141.                             $pax $item->getSrvPax();
  11142.                             if (empty($pax) or $pax == "0") {
  11143.                                 $pax 1;
  11144.                             }
  11145.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11146.                             if ($days 1) {
  11147.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11148.                             } else {
  11149.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11150.                             }
  11151.                             $unitsServ $item->getSrvUnits();
  11152.                             if (empty($unitsServ) or $unitsServ == "0") {
  11153.                                 $unitsServ 1;
  11154.                             }
  11155.                             $subtotal $subtotalService $days $unitsServ $pax;
  11156.                             $subnetoUnit $subneto;
  11157.                             $subneto $subneto $days $unitsServ $pax;
  11158.                             $data_supplier['service'][$i] = array(
  11159.                                 'id' => $item->getId(),
  11160.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11161.                                 'serviceName' => $item->getSrvName(),
  11162.                                 'serviceType' => 'Entretenimiento',
  11163.                                 'date' => $dateServ,
  11164.                                 'qty' => $unitsServ,
  11165.                                 'iva' => $item->getSrvIva(),
  11166.                                 'pax' => $item->getSrvPax(),
  11167.                                 'precioUnit' => $subnetoUnit,
  11168.                                 'subneto' => $subneto,
  11169.                                 'subtotal' => $subtotal,
  11170.                             );
  11171.                             break;
  11172.                         case 7// Gifts
  11173.                             $pax $item->getSrvPax();
  11174.                             if (empty($pax) or $pax == "0") {
  11175.                                 $pax 1;
  11176.                             }
  11177.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11178.                             $days 1;
  11179.                             if ($days 1) {
  11180.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11181.                             } else {
  11182.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11183.                             }
  11184.                             $unitsServ $item->getSrvUnits();
  11185.                             if (empty($unitsServ) or $unitsServ == "0") {
  11186.                                 $unitsServ 1;
  11187.                             }
  11188.                             $subtotal $subtotalService $days $unitsServ $pax;
  11189.                             $subnetoUnit $subneto;
  11190.                             $subneto $subneto $days $unitsServ $pax;
  11191.                             $data_supplier['service'][$i] = array(
  11192.                                 'id' => $item->getId(),
  11193.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11194.                                 'serviceName' => $item->getSrvName(),
  11195.                                 'serviceType' => 'Regalos',
  11196.                                 'date' => $dateServ,
  11197.                                 'qty' => $unitsServ,
  11198.                                 'iva' => $item->getSrvIva(),
  11199.                                 'pax' => $item->getSrvPax(),
  11200.                                 'precioUnit' => $subnetoUnit,
  11201.                                 'subneto' => $subneto,
  11202.                                 'subtotal' => $subtotal,
  11203.                             );
  11204.                             break;
  11205.                         case 8//Guide
  11206.                             $pax $item->getSrvPax();
  11207.                             if (empty($pax) or $pax == "0") {
  11208.                                 $pax 1;
  11209.                             }
  11210.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11211.                             if ($days 1) {
  11212.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11213.                             } else {
  11214.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11215.                             }
  11216.                             $unitsServ $item->getSrvUnits();
  11217.                             if (empty($unitsServ) or $unitsServ == "0") {
  11218.                                 $unitsServ 1;
  11219.                             }
  11220.                             $subtotal $subtotalService $days $unitsServ $pax;
  11221.                             $subnetoUnit $subneto;
  11222.                             $subneto $subneto $days $unitsServ $pax;
  11223.                             $data_supplier['service'][$i] = array(
  11224.                                 'id' => $item->getId(),
  11225.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11226.                                 'serviceName' => $item->getSrvName(),
  11227.                                 'serviceType' => 'Regalos',
  11228.                                 'date' => $dateServ,
  11229.                                 'qty' => $unitsServ,
  11230.                                 'iva' => $item->getSrvIva(),
  11231.                                 'pax' => $item->getSrvPax(),
  11232.                                 'precioUnit' => $subnetoUnit,
  11233.                                 'subneto' => $subneto,
  11234.                                 'subtotal' => $subtotal,
  11235.                             );
  11236.                             break;
  11237.                         case 9//Itineraries
  11238.                             $pax $item->getSrvPax();
  11239.                             if (empty($pax) or $pax == "0") {
  11240.                                 $pax 1;
  11241.                             }
  11242.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11243.                             if ($days 1) {
  11244.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11245.                             } else {
  11246.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11247.                             }
  11248.                             $unitsServ $item->getSrvUnits();
  11249.                             if (empty($unitsServ) or $unitsServ == "0") {
  11250.                                 $unitsServ 1;
  11251.                             }
  11252.                             $subtotal $subtotalService $days $unitsServ $pax;
  11253.                             $subnetoUnit $subneto;
  11254.                             $subneto $subneto $days $unitsServ $pax;
  11255.                             $data_supplier['service'][$i] = array(
  11256.                                 'id' => $item->getId(),
  11257.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11258.                                 'serviceName' => $item->getSrvName(),
  11259.                                 'serviceType' => 'Itinerarios',
  11260.                                 'date' => $dateServ,
  11261.                                 'qty' => $unitsServ,
  11262.                                 'iva' => $item->getSrvIva(),
  11263.                                 'pax' => $item->getSrvPax(),
  11264.                                 'precioUnit' => $subnetoUnit,
  11265.                                 'subneto' => $subneto,
  11266.                                 'subtotal' => $subtotal,
  11267.                             );
  11268.                             break;
  11269.                         case 10//Lounge  -- No Aplica
  11270.                             break;
  11271.                         case 11//Menu
  11272.                             $pax $item->getSrvPax();
  11273.                             if (empty($pax) or $pax == "0") {
  11274.                                 $pax 1;
  11275.                             }
  11276.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11277.                             if ($days 1) {
  11278.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11279.                             } else {
  11280.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11281.                             }
  11282.                             $unitsServ $item->getSrvUnits();
  11283.                             if (empty($unitsServ) or $unitsServ == "0") {
  11284.                                 $unitsServ 1;
  11285.                             }
  11286.                             $subtotal $subtotalService $days $unitsServ $pax;
  11287.                             $subnetoUnit $subneto;
  11288.                             $subneto $subneto $days $unitsServ $pax;
  11289.                             $data_supplier['service'][$i] = array(
  11290.                                 'id' => $item->getId(),
  11291.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11292.                                 'serviceName' => $item->getSrvName(),
  11293.                                 'serviceType' => 'MenĂº',
  11294.                                 'date' => $dateServ,
  11295.                                 'qty' => $unitsServ,
  11296.                                 'iva' => $item->getSrvIva(),
  11297.                                 'pax' => $item->getSrvPax(),
  11298.                                 'precioUnit' => $subnetoUnit,
  11299.                                 'subneto' => $subneto,
  11300.                                 'subtotal' => $subtotal,
  11301.                             );
  11302.                             break;
  11303.                         case 12//Others
  11304.                             $pax $item->getSrvPax();
  11305.                             if (empty($pax) or $pax == "0") {
  11306.                                 $pax 1;
  11307.                             }
  11308.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11309.                             if ($days 1) {
  11310.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11311.                             } else {
  11312.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11313.                             }
  11314.                             $unitsServ $item->getSrvUnits();
  11315.                             if (empty($unitsServ) or $unitsServ == "0") {
  11316.                                 $unitsServ 1;
  11317.                             }
  11318.                             $subtotal $subtotalService $days $unitsServ $pax;
  11319.                             $subnetoUnit $subneto;
  11320.                             $subneto $subneto $days $unitsServ $pax;
  11321.                             $data_supplier['service'][$i] = array(
  11322.                                 'id' => $item->getId(),
  11323.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11324.                                 'serviceName' => $item->getSrvName(),
  11325.                                 'serviceType' => 'Otros',
  11326.                                 'date' => $dateServ,
  11327.                                 'qty' => $unitsServ,
  11328.                                 'iva' => $item->getSrvIva(),
  11329.                                 'pax' => $item->getSrvPax(),
  11330.                                 'precioUnit' => $subnetoUnit,
  11331.                                 'subneto' => $subneto,
  11332.                                 'subtotal' => $subtotal,
  11333.                             );
  11334.                             break;
  11335.                         case 13//Transport
  11336.                             $pax $item->getSrvPax();
  11337.                             if (empty($pax) or $pax == "0") {
  11338.                                 $pax 1;
  11339.                             }
  11340.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11341.                             if ($days 1) {
  11342.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11343.                             } else {
  11344.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11345.                             }
  11346.                             $unitsServ $item->getSrvUnits();
  11347.                             if (empty($unitsServ) or $unitsServ == "0") {
  11348.                                 $unitsServ 1;
  11349.                             }
  11350.                             $subtotal $subtotalService $days $unitsServ $pax;
  11351.                             $subnetoUnit $subneto;
  11352.                             $subneto $subneto $days $unitsServ $pax;
  11353.                             $data_supplier['service'][$i] = array(
  11354.                                 'id' => $item->getId(),
  11355.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11356.                                 'serviceName' => $item->getSrvName(),
  11357.                                 'serviceType' => 'Transporte',
  11358.                                 'date' => $dateServ,
  11359.                                 'qty' => $unitsServ,
  11360.                                 'iva' => $item->getSrvIva(),
  11361.                                 'pax' => $item->getSrvPax(),
  11362.                                 'precioUnit' => $subnetoUnit,
  11363.                                 'subneto' => $subneto,
  11364.                                 'subtotal' => $subtotal,
  11365.                             );
  11366.                             break;
  11367.                         case 14//Technology
  11368.                             $pax $item->getSrvPax();
  11369.                             if (empty($pax) or $pax == "0") {
  11370.                                 $pax 1;
  11371.                             }
  11372.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11373.                             $days 1;
  11374.                             //                        if ($days > 1){
  11375.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  11376.                             //                        } else {
  11377.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11378.                             //                        }
  11379.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11380.                             $unitsServ $item->getSrvUnits();
  11381.                             if (empty($unitsServ) or $unitsServ == "0") {
  11382.                                 $unitsServ 1;
  11383.                             }
  11384.                             $subtotal $subtotalService $days $unitsServ $pax;
  11385.                             $subnetoUnit $subneto;
  11386.                             $subneto $subneto $days $unitsServ $pax;
  11387.                             $data_supplier['service'][$i] = array(
  11388.                                 'id' => $item->getId(),
  11389.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11390.                                 'serviceName' => $item->getSrvName(),
  11391.                                 'serviceType' => 'TecnologĂ­a',
  11392.                                 'date' => $dateServ,
  11393.                                 'qty' => $unitsServ,
  11394.                                 'iva' => $item->getSrvIva(),
  11395.                                 'pax' => $item->getSrvPax(),
  11396.                                 'precioUnit' => $subnetoUnit,
  11397.                                 'subneto' => $subneto,
  11398.                                 'subtotal' => $subtotal,
  11399.                             );
  11400.                             break;
  11401.                         case 15//Assisstant
  11402.                             $pax $item->getSrvPax();
  11403.                             if (empty($pax) or $pax == "0") {
  11404.                                 $pax 1;
  11405.                             }
  11406.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11407.                             if ($days 1) {
  11408.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11409.                             } else {
  11410.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11411.                             }
  11412.                             $unitsServ $item->getSrvUnits();
  11413.                             if (empty($unitsServ) or $unitsServ == "0") {
  11414.                                 $unitsServ 1;
  11415.                             }
  11416.                             $subtotal $subtotalService $days $unitsServ $pax;
  11417.                             $subnetoUnit $subneto;
  11418.                             $subneto $subneto $days $unitsServ $pax;
  11419.                             $data_supplier['service'][$i] = array(
  11420.                                 'id' => $item->getId(),
  11421.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11422.                                 'serviceName' => $item->getSrvName(),
  11423.                                 'serviceType' => 'Asistente',
  11424.                                 'date' => $dateServ,
  11425.                                 'qty' => $unitsServ,
  11426.                                 'iva' => $item->getSrvIva(),
  11427.                                 'pax' => $item->getSrvPax(),
  11428.                                 'precioUnit' => $subnetoUnit,
  11429.                                 'subneto' => $subneto,
  11430.                                 'subtotal' => $subtotal,
  11431.                             );
  11432.                             break;
  11433.                         case 16//DDR
  11434.                             $pax $item->getSrvPax();
  11435.                             if (empty($pax) or $pax == "0") {
  11436.                                 $pax 1;
  11437.                             }
  11438.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  11439.                             if ($days 1) {
  11440.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  11441.                             } else {
  11442.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  11443.                             }
  11444.                             $unitsServ $item->getSrvUnits();
  11445.                             if (empty($unitsServ) or $unitsServ == "0") {
  11446.                                 $unitsServ 1;
  11447.                             }
  11448.                             $subtotal $subtotalService $days $unitsServ $pax;
  11449.                             $subnetoUnit $subneto;
  11450.                             $subneto $subneto $days $unitsServ $pax;
  11451.                             $data_supplier['service'][$i] = array(
  11452.                                 'id' => $item->getId(),
  11453.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  11454.                                 'serviceName' => $item->getSrvName(),
  11455.                                 'serviceType' => 'DDR',
  11456.                                 'date' => $dateServ,
  11457.                                 'qty' => $unitsServ,
  11458.                                 'iva' => $item->getSrvIva(),
  11459.                                 'pax' => $item->getSrvPax(),
  11460.                                 'precioUnit' => $subnetoUnit,
  11461.                                 'subneto' => $subneto,
  11462.                                 'subtotal' => $subtotal,
  11463.                             );
  11464.                             break;
  11465.                         default:
  11466.                             break;
  11467.                     }
  11468.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  11469.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  11470.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  11471.                     $arrayItems[] = array(
  11472.                         'type' => 'Service',
  11473.                         'name' => $item->getSrvName(),
  11474.                         'amount' => $neto,
  11475.                         'iva' => $item->getSrvIva(),
  11476.                         'total' => $subtotal,
  11477.                     );
  11478.                 }
  11479.                 switch ($item->getSrvIva()) {
  11480.                         // Acumula IVA
  11481.                     case 21:
  11482.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  11483.                         break;
  11484.                     case 10:
  11485.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  11486.                         break;
  11487.                     case 0:
  11488.                         $data_iva['ivaMontoCero'] = 0;
  11489.                         break;
  11490.                     default:
  11491.                         break;
  11492.                 }
  11493.             } else {
  11494.                 // Es una proforma
  11495.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  11496.                     $subtotal 0;
  11497.                     $neto 0;
  11498.                     $subtotalService 0;
  11499.                 } else {
  11500.                     $subtotalService $item->getPrice();
  11501.                     $subneto $item->getPrice();
  11502.                     // Commission
  11503.                     if ($item->getOpCommission() == '1') {
  11504.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  11505.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  11506.                     } else {
  11507.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  11508.                         $subneto $subneto * (- ($item->getCommission() / 100));
  11509.                     }
  11510.                     // Over
  11511.                     if ($item->getOpOver() == '1') {
  11512.                         $subtotalService $subtotalService $item->getOver();
  11513.                         $subneto $subneto $item->getOver();
  11514.                     } else {
  11515.                         $subtotalService $subtotalService $item->getOver();
  11516.                         $subneto $subneto $item->getOver();
  11517.                     }
  11518.                     // IVA
  11519.                     if ($item->getOpIva() == '1') {
  11520.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  11521.                     } else {
  11522.                         $subtotalService $item->getPrice();
  11523.                         $subneto = ($subneto 100) / (100 $item->getIva());
  11524.                     }
  11525.                     switch ($item->getServiceCatId()) {
  11526.                         case 1// Alojamiento
  11527.                             // el numero de noches $numNoches; precio unitario $subneto
  11528.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  11529.                             // La personas no afectan este calculo
  11530.                             $subtotal $subtotalService $numNoches $item->getUnits();
  11531.                             $subnetoUnit $subneto;
  11532.                             $subneto $subneto $numNoches $item->getUnits();
  11533.                             $data_supplier['service'][$i] = array(
  11534.                                 'id' => $item->getId(),
  11535.                                 'serviceCatId' => $item->getServiceCatId(),
  11536.                                 'serviceName' => $item->getName(),
  11537.                                 'serviceType' => 'Hotel',
  11538.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  11539.                                 'qty' => $item->getUnits(),
  11540.                                 'iva' => $item->getIva(),
  11541.                                 'pax' => '-',
  11542.                                 'precioUnit' => $subnetoUnit,
  11543.                                 'subneto' => $subneto,
  11544.                                 'subtotal' => $subtotal,
  11545.                             );
  11546.                             break;
  11547.                         case 2//Actividades
  11548.                             // El nĂºmero de personas es considerado en el calculo
  11549.                             $pax $item->getPax();
  11550.                             if (empty($pax) or $pax == "0") {
  11551.                                 $pax 1;
  11552.                             }
  11553.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11554.                             if ($days 1) {
  11555.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11556.                             } else {
  11557.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11558.                             }
  11559.                             $subtotal $subtotalService $days $item->getUnits();
  11560.                             $subnetoUnit $subneto;
  11561.                             $subneto $subneto $days $item->getUnits();
  11562.                             $data_supplier['service'][$i] = array(
  11563.                                 'id' => $item->getId(),
  11564.                                 'serviceCatId' => $item->getServiceCatId(),
  11565.                                 'serviceName' => $item->getName(),
  11566.                                 'serviceType' => 'Actividad',
  11567.                                 'date' => $dateServ,
  11568.                                 'qty' => $item->getUnits(),
  11569.                                 'iva' => $item->getIva(),
  11570.                                 'pax' => $item->getPax(),
  11571.                                 'precioUnit' => $subnetoUnit,
  11572.                                 'subneto' => $subneto,
  11573.                                 'subtotal' => $subtotal,
  11574.                             );
  11575.                             break;
  11576.                         case 3// AV
  11577.                             $pax $item->getPax();
  11578.                             if (empty($pax) or $pax == "0") {
  11579.                                 $pax 1;
  11580.                             }
  11581.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11582.                             if ($days 1) {
  11583.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11584.                             } else {
  11585.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11586.                             }
  11587.                             $unitsServ $item->getUnits();
  11588.                             if (empty($unitsServ) or $unitsServ == "0") {
  11589.                                 $unitsServ 1;
  11590.                             }
  11591.                             $subtotal $subtotalService $days $unitsServ $pax;
  11592.                             $subnetoUnit $subneto;
  11593.                             $subneto $subneto $days $unitsServ $pax;
  11594.                             $data_supplier['service'][$i] = array(
  11595.                                 'id' => $item->getId(),
  11596.                                 'serviceCatId' => $item->getServiceCatId(),
  11597.                                 'serviceName' => $item->getName(),
  11598.                                 'serviceType' => 'AV',
  11599.                                 'date' => $dateServ,
  11600.                                 'qty' => $unitsServ,
  11601.                                 'iva' => $item->getIva(),
  11602.                                 'pax' => $item->getPax(),
  11603.                                 'precioUnit' => $subnetoUnit,
  11604.                                 'subneto' => $subneto,
  11605.                                 'subtotal' => $subtotal,
  11606.                             );
  11607.                             break;
  11608.                         case 4//Creative
  11609.                             $pax $item->getPax();
  11610.                             if (empty($pax) or $pax == "0") {
  11611.                                 $pax 1;
  11612.                             }
  11613.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11614.                             if ($days 1) {
  11615.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11616.                             } else {
  11617.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11618.                             }
  11619.                             $unitsServ $item->getUnits();
  11620.                             if (empty($unitsServ) or $unitsServ == "0") {
  11621.                                 $unitsServ 1;
  11622.                             }
  11623.                             $subtotal $subtotalService $days $unitsServ $pax;
  11624.                             $subnetoUnit $subneto;
  11625.                             $subneto $subneto $days $unitsServ $pax;
  11626.                             $data_supplier['service'][$i] = array(
  11627.                                 'id' => $item->getId(),
  11628.                                 'serviceCatId' => $item->getServiceCatId(),
  11629.                                 'serviceName' => $item->getName(),
  11630.                                 'serviceType' => 'Creativo',
  11631.                                 'date' => $dateServ,
  11632.                                 'qty' => $unitsServ,
  11633.                                 'iva' => $item->getIva(),
  11634.                                 'pax' => $item->getPax(),
  11635.                                 'precioUnit' => $subnetoUnit,
  11636.                                 'subneto' => $subneto,
  11637.                                 'subtotal' => $subtotal,
  11638.                             );
  11639.                             break;
  11640.                         case 5//Cruise
  11641.                             $pax $item->getPax();
  11642.                             if (empty($pax) or $pax == "0") {
  11643.                                 $pax 1;
  11644.                             }
  11645.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  11646.                             if ($days 1) {
  11647.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11648.                             } else {
  11649.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11650.                             }
  11651.                             $unitsServ $item->getUnits();
  11652.                             if (empty($unitsServ) or $unitsServ == "0") {
  11653.                                 $unitsServ 1;
  11654.                             }
  11655.                             $subtotal $subtotalService $days $unitsServ $pax;
  11656.                             $subnetoUnit $subneto;
  11657.                             $subneto $subneto $days $unitsServ $pax;
  11658.                             $data_supplier['service'][$i] = array(
  11659.                                 'id' => $item->getId(),
  11660.                                 'serviceCatId' => $item->getServiceCatId(),
  11661.                                 'serviceName' => $item->getName(),
  11662.                                 'serviceType' => 'Crucero',
  11663.                                 'date' => $dateServ,
  11664.                                 'qty' => $unitsServ,
  11665.                                 'iva' => $item->getIva(),
  11666.                                 'pax' => $item->getPax(),
  11667.                                 'precioUnit' => $subnetoUnit,
  11668.                                 'subneto' => $subneto,
  11669.                                 'subtotal' => $subtotal,
  11670.                             );
  11671.                             break;
  11672.                         case 6//Entertaiment
  11673.                             $pax $item->getPax();
  11674.                             if (empty($pax) or $pax == "0") {
  11675.                                 $pax 1;
  11676.                             }
  11677.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11678.                             if ($days 1) {
  11679.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11680.                             } else {
  11681.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11682.                             }
  11683.                             $unitsServ $item->getUnits();
  11684.                             if (empty($unitsServ) or $unitsServ == "0") {
  11685.                                 $unitsServ 1;
  11686.                             }
  11687.                             $subtotal $subtotalService $days $unitsServ $pax;
  11688.                             $subnetoUnit $subneto;
  11689.                             $subneto $subneto $days $unitsServ $pax;
  11690.                             $data_supplier['service'][$i] = array(
  11691.                                 'id' => $item->getId(),
  11692.                                 'serviceCatId' => $item->getServiceCatId(),
  11693.                                 'serviceName' => $item->getName(),
  11694.                                 'serviceType' => 'Entretenimiento',
  11695.                                 'date' => $dateServ,
  11696.                                 'qty' => $unitsServ,
  11697.                                 'iva' => $item->getIva(),
  11698.                                 'pax' => $item->getPax(),
  11699.                                 'precioUnit' => $subnetoUnit,
  11700.                                 'subneto' => $subneto,
  11701.                                 'subtotal' => $subtotal,
  11702.                             );
  11703.                             break;
  11704.                         case 7// Gifts
  11705.                             $pax $item->getPax();
  11706.                             if (empty($pax) or $pax == "0") {
  11707.                                 $pax 1;
  11708.                             }
  11709.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11710.                             $days 1;
  11711.                             if ($days 1) {
  11712.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11713.                             } else {
  11714.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11715.                             }
  11716.                             $unitsServ $item->getUnits();
  11717.                             if (empty($unitsServ) or $unitsServ == "0") {
  11718.                                 $unitsServ 1;
  11719.                             }
  11720.                             $subtotal $subtotalService $days $unitsServ $pax;
  11721.                             $subnetoUnit $subneto;
  11722.                             $subneto $subneto $days $unitsServ $pax;
  11723.                             $data_supplier['service'][$i] = array(
  11724.                                 'id' => $item->getId(),
  11725.                                 'serviceCatId' => $item->getServiceCatId(),
  11726.                                 'serviceName' => $item->getName(),
  11727.                                 'serviceType' => 'Regalos',
  11728.                                 'date' => $dateServ,
  11729.                                 'qty' => $unitsServ,
  11730.                                 'iva' => $item->getIva(),
  11731.                                 'pax' => $item->getPax(),
  11732.                                 'precioUnit' => $subnetoUnit,
  11733.                                 'subneto' => $subneto,
  11734.                                 'subtotal' => $subtotal,
  11735.                             );
  11736.                             break;
  11737.                         case 8//Guide
  11738.                             $pax $item->getPax();
  11739.                             if (empty($pax) or $pax == "0") {
  11740.                                 $pax 1;
  11741.                             }
  11742.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11743.                             if ($days 1) {
  11744.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11745.                             } else {
  11746.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11747.                             }
  11748.                             $unitsServ $item->getUnits();
  11749.                             if (empty($unitsServ) or $unitsServ == "0") {
  11750.                                 $unitsServ 1;
  11751.                             }
  11752.                             $subtotal $subtotalService $days $unitsServ $pax;
  11753.                             $subnetoUnit $subneto;
  11754.                             $subneto $subneto $days $unitsServ $pax;
  11755.                             $data_supplier['service'][$i] = array(
  11756.                                 'id' => $item->getId(),
  11757.                                 'serviceCatId' => $item->getServiceCatId(),
  11758.                                 'serviceName' => $item->getName(),
  11759.                                 'serviceType' => 'Regalos',
  11760.                                 'date' => $dateServ,
  11761.                                 'qty' => $unitsServ,
  11762.                                 'iva' => $item->getIva(),
  11763.                                 'pax' => $item->getPax(),
  11764.                                 'precioUnit' => $subnetoUnit,
  11765.                                 'subneto' => $subneto,
  11766.                                 'subtotal' => $subtotal,
  11767.                             );
  11768.                             break;
  11769.                         case 9//Itineraries
  11770.                             $pax $item->getPax();
  11771.                             if (empty($pax) or $pax == "0") {
  11772.                                 $pax 1;
  11773.                             }
  11774.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11775.                             if ($days 1) {
  11776.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11777.                             } else {
  11778.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11779.                             }
  11780.                             $unitsServ $item->getUnits();
  11781.                             if (empty($unitsServ) or $unitsServ == "0") {
  11782.                                 $unitsServ 1;
  11783.                             }
  11784.                             $subtotal $subtotalService $days $unitsServ $pax;
  11785.                             $subnetoUnit $subneto;
  11786.                             $subneto $subneto $days $unitsServ $pax;
  11787.                             $data_supplier['service'][$i] = array(
  11788.                                 'id' => $item->getId(),
  11789.                                 'serviceCatId' => $item->getServiceCatId(),
  11790.                                 'serviceName' => $item->getName(),
  11791.                                 'serviceType' => 'Itinerarios',
  11792.                                 'date' => $dateServ,
  11793.                                 'qty' => $unitsServ,
  11794.                                 'iva' => $item->getIva(),
  11795.                                 'pax' => $item->getPax(),
  11796.                                 'precioUnit' => $subnetoUnit,
  11797.                                 'subneto' => $subneto,
  11798.                                 'subtotal' => $subtotal,
  11799.                             );
  11800.                             break;
  11801.                         case 10//Lounge  -- No Aplica
  11802.                             break;
  11803.                         case 11//Menu
  11804.                             $pax $item->getPax();
  11805.                             if (empty($pax) or $pax == "0") {
  11806.                                 $pax 1;
  11807.                             }
  11808.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11809.                             if ($days 1) {
  11810.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11811.                             } else {
  11812.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11813.                             }
  11814.                             $unitsServ $item->getUnits();
  11815.                             if (empty($unitsServ) or $unitsServ == "0") {
  11816.                                 $unitsServ 1;
  11817.                             }
  11818.                             $subtotal $subtotalService $days $unitsServ $pax;
  11819.                             $subnetoUnit $subneto;
  11820.                             $subneto $subneto $days $unitsServ $pax;
  11821.                             $data_supplier['service'][$i] = array(
  11822.                                 'id' => $item->getId(),
  11823.                                 'serviceCatId' => $item->getServiceCatId(),
  11824.                                 'serviceName' => $item->getName(),
  11825.                                 'serviceType' => 'MenĂº',
  11826.                                 'date' => $dateServ,
  11827.                                 'qty' => $unitsServ,
  11828.                                 'iva' => $item->getIva(),
  11829.                                 'pax' => $item->getPax(),
  11830.                                 'precioUnit' => $subnetoUnit,
  11831.                                 'subneto' => $subneto,
  11832.                                 'subtotal' => $subtotal,
  11833.                             );
  11834.                             break;
  11835.                         case 12//Others
  11836.                             $pax $item->getPax();
  11837.                             if (empty($pax) or $pax == "0") {
  11838.                                 $pax 1;
  11839.                             }
  11840.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11841.                             if ($days 1) {
  11842.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11843.                             } else {
  11844.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11845.                             }
  11846.                             $unitsServ $item->getUnits();
  11847.                             if (empty($unitsServ) or $unitsServ == "0") {
  11848.                                 $unitsServ 1;
  11849.                             }
  11850.                             $subtotal $subtotalService $days $unitsServ $pax;
  11851.                             $subnetoUnit $subneto;
  11852.                             $subneto $subneto $days $unitsServ $pax;
  11853.                             $data_supplier['service'][$i] = array(
  11854.                                 'id' => $item->getId(),
  11855.                                 'serviceCatId' => $item->getServiceCatId(),
  11856.                                 'serviceName' => $item->getName(),
  11857.                                 'serviceType' => 'Otros',
  11858.                                 'date' => $dateServ,
  11859.                                 'qty' => $unitsServ,
  11860.                                 'iva' => $item->getIva(),
  11861.                                 'pax' => $item->getPax(),
  11862.                                 'precioUnit' => $subnetoUnit,
  11863.                                 'subneto' => $subneto,
  11864.                                 'subtotal' => $subtotal,
  11865.                             );
  11866.                             break;
  11867.                         case 13//Transport
  11868.                             $pax $item->getPax();
  11869.                             if (empty($pax) or $pax == "0") {
  11870.                                 $pax 1;
  11871.                             }
  11872.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11873.                             if ($days 1) {
  11874.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11875.                             } else {
  11876.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11877.                             }
  11878.                             $unitsServ $item->getUnits();
  11879.                             if (empty($unitsServ) or $unitsServ == "0") {
  11880.                                 $unitsServ 1;
  11881.                             }
  11882.                             $subtotal $subtotalService $days $unitsServ $pax;
  11883.                             $subnetoUnit $subneto;
  11884.                             $subneto $subneto $days $unitsServ $pax;
  11885.                             $data_supplier['service'][$i] = array(
  11886.                                 'id' => $item->getId(),
  11887.                                 'serviceCatId' => $item->getServiceCatId(),
  11888.                                 'serviceName' => $item->getName(),
  11889.                                 'serviceType' => 'Transporte',
  11890.                                 'date' => $dateServ,
  11891.                                 'qty' => $unitsServ,
  11892.                                 'iva' => $item->getIva(),
  11893.                                 'pax' => $item->getPax(),
  11894.                                 'precioUnit' => $subnetoUnit,
  11895.                                 'subneto' => $subneto,
  11896.                                 'subtotal' => $subtotal,
  11897.                             );
  11898.                             break;
  11899.                         case 14//Technology
  11900.                             $pax $item->getPax();
  11901.                             if (empty($pax) or $pax == "0") {
  11902.                                 $pax 1;
  11903.                             }
  11904.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  11905.                             $days 1;
  11906.                             //                        if ($days > 1){
  11907.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  11908.                             //                        } else {
  11909.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11910.                             //                        }
  11911.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11912.                             $unitsServ $item->getUnits();
  11913.                             if (empty($unitsServ) or $unitsServ == "0") {
  11914.                                 $unitsServ 1;
  11915.                             }
  11916.                             $subtotal $subtotalService $days $unitsServ $pax;
  11917.                             $subnetoUnit $subneto;
  11918.                             $subneto $subneto $days $unitsServ $pax;
  11919.                             $data_supplier['service'][$i] = array(
  11920.                                 'id' => $item->getId(),
  11921.                                 'serviceCatId' => $item->getServiceCatId(),
  11922.                                 'serviceName' => $item->getName(),
  11923.                                 'serviceType' => 'TecnologĂ­a',
  11924.                                 'date' => $dateServ,
  11925.                                 'qty' => $unitsServ,
  11926.                                 'iva' => $item->getIva(),
  11927.                                 'pax' => $item->getPax(),
  11928.                                 'precioUnit' => $subnetoUnit,
  11929.                                 'subneto' => $subneto,
  11930.                                 'subtotal' => $subtotal,
  11931.                             );
  11932.                             break;
  11933.                         case 15//Assisstant
  11934.                             $pax $item->getPax();
  11935.                             if (empty($pax) or $pax == "0") {
  11936.                                 $pax 1;
  11937.                             }
  11938.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11939.                             if ($days 1) {
  11940.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11941.                             } else {
  11942.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11943.                             }
  11944.                             $unitsServ $item->getUnits();
  11945.                             if (empty($unitsServ) or $unitsServ == "0") {
  11946.                                 $unitsServ 1;
  11947.                             }
  11948.                             $subtotal $subtotalService $days $unitsServ $pax;
  11949.                             $subnetoUnit $subneto;
  11950.                             $subneto $subneto $days $unitsServ $pax;
  11951.                             $data_supplier['service'][$i] = array(
  11952.                                 'id' => $item->getId(),
  11953.                                 'serviceCatId' => $item->getServiceCatId(),
  11954.                                 'serviceName' => $item->getName(),
  11955.                                 'serviceType' => 'Asistente',
  11956.                                 'date' => $dateServ,
  11957.                                 'qty' => $unitsServ,
  11958.                                 'iva' => $item->getIva(),
  11959.                                 'pax' => $item->getPax(),
  11960.                                 'precioUnit' => $subnetoUnit,
  11961.                                 'subneto' => $subneto,
  11962.                                 'subtotal' => $subtotal,
  11963.                             );
  11964.                             break;
  11965.                         case 16//DDR
  11966.                             $pax $item->getPax();
  11967.                             if (empty($pax) or $pax == "0") {
  11968.                                 $pax 1;
  11969.                             }
  11970.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  11971.                             if ($days 1) {
  11972.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  11973.                             } else {
  11974.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  11975.                             }
  11976.                             $unitsServ $item->getUnits();
  11977.                             if (empty($unitsServ) or $unitsServ == "0") {
  11978.                                 $unitsServ 1;
  11979.                             }
  11980.                             $subtotal $subtotalService $days $unitsServ $pax;
  11981.                             $subnetoUnit $subneto;
  11982.                             $subneto $subneto $days $unitsServ $pax;
  11983.                             $data_supplier['service'][$i] = array(
  11984.                                 'id' => $item->getId(),
  11985.                                 'serviceCatId' => $item->getServiceCatId(),
  11986.                                 'serviceName' => $item->getName(),
  11987.                                 'serviceType' => 'DDR',
  11988.                                 'date' => $dateServ,
  11989.                                 'qty' => $unitsServ,
  11990.                                 'iva' => $item->getIva(),
  11991.                                 'pax' => $item->getPax(),
  11992.                                 'precioUnit' => $subnetoUnit,
  11993.                                 'subneto' => $subneto,
  11994.                                 'subtotal' => $subtotal,
  11995.                             );
  11996.                             break;
  11997.                         default:
  11998.                             break;
  11999.                     }
  12000.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12001.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12002.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  12003.                     $arrayItems[] = array(
  12004.                         'type' => 'Service',
  12005.                         'name' => $item->getName(),
  12006.                         'amount' => $neto,
  12007.                         'iva' => $item->getIva(),
  12008.                         'total' => $subtotal,
  12009.                     );
  12010.                 }
  12011.                 switch ($item->getIva()) {
  12012.                         // Acumula IVA
  12013.                     case 21:
  12014.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  12015.                         break;
  12016.                     case 10:
  12017.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  12018.                         break;
  12019.                     case 0:
  12020.                         $data_iva['ivaMontoCero'] = 0;
  12021.                         break;
  12022.                     default:
  12023.                         break;
  12024.                 }
  12025.             }
  12026.             $totales_neto_all $totales_neto_all $neto;
  12027.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12028.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  12029.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  12030.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  12031.             $data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2PHP_ROUND_HALF_UP);
  12032.             // Acumula netos totales e IVA
  12033.             $service['neto'] = $service['neto'] + $neto;
  12034.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  12035.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12036.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  12037.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  12038.             $i++;
  12039.         }
  12040.         $data_supplier['serviceSubTotal'] = array(
  12041.             'neto' => $service['neto'],
  12042.             'sumSubT' => $service['sumSubT'],
  12043.         );
  12044.         $currency '€';
  12045.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  12046.         if (!empty($payments)) {
  12047.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  12048.         } else {
  12049.             $amount_pay 0;
  12050.         }
  12051.         $totales_all $totales_total $amount_pay;
  12052.         if (empty($dateDocument)) {
  12053.             $dateDocument = new DateTime('now');
  12054.         }
  12055.         $data = array(
  12056.             'id' => $fileId,
  12057.             'type' => $type,
  12058.             'number' => $number,
  12059.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $invoiceId,
  12060.             'date' => $dateDocument,
  12061.             'file' => $file,
  12062.             'token' => $file->getAccessKey(),
  12063.             'company' => $company,
  12064.             'clients' => $clientNew,
  12065.             'arrayItems' => $arrayItems,
  12066.             'datasupplier' => $data_supplier,
  12067.             'currency' => $currency,
  12068.             'totales_neto' => $totales_neto_all,
  12069.             'bases_imponibles' => $data_iva,
  12070.             'totales' => $totales_total,
  12071.             'balance' => $totales_all,
  12072.             'paymentInvoice' => $amount_pay,
  12073.         );
  12074.         return $data;
  12075.     }
  12076.     private function baseInvoiceDoneFileTwo($fileId$invoiceId$typeBase)
  12077.     {
  12078.         $em $this->getDoctrine()->getManager();
  12079.         $file $em->getRepository(AveFiles::class)->findOneById($fileId);
  12080.         $dateDocument null;                                                                           //Fecha final del documento
  12081.         $subneto 0;
  12082.         if (($typeBase == 'I') or ($typeBase == 'P')) {
  12083.             if ($typeBase == 'I') {
  12084.                 $items $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId'invoiceId' => $invoiceId));
  12085.             } else {
  12086.                 // Es factura ni proforma
  12087.                 $items $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId'proformaId' => $invoiceId));
  12088.             }
  12089.         } else {
  12090.             // No es factura ni proforma, es una rectificativa
  12091.             $items $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId'invoiceRecId' => $invoiceId));
  12092.         }
  12093.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  12094.         $client $em->getRepository(Client::class)->findById($file->getClient());
  12095.         if (empty($client)) {
  12096.             $client[0] = new Client();
  12097.             $client[0]->setName('');
  12098.             $client[0]->setTitle('');
  12099.             $client[0]->setIdDocument('');
  12100.             $client[0]->setPopulation('');
  12101.             $client[0]->setRegion('');
  12102.             $client[0]->setCountry('');
  12103.         } else {
  12104.             if (is_numeric($client[0]->getPopulation())) {
  12105.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  12106. //                $client[0]->setPopulation($city->getCity());
  12107.             }
  12108.             if (is_numeric($client[0]->getRegion())) {
  12109.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  12110. //                $client[0]->setRegion($region->getRegion());
  12111.             }
  12112.             if (is_numeric($client[0]->getCountry())) {
  12113.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  12114. //                $client[0]->setCountry($country->getCountry());
  12115.             }
  12116.         }
  12117.         if (empty($client)) {
  12118.             $client[0] = new Client();
  12119.             $client[0]->setName('');
  12120.             $client[0]->setTitle('');
  12121.             $client[0]->setIdDocument('');
  12122.             $client[0]->setPopulation('');
  12123.             $client[0]->setRegion('');
  12124.             $client[0]->setCountry('');
  12125.             $clientNew = array(
  12126.                 'name' => '',
  12127.                 'title' => '',
  12128.                 'idDocument' => '',
  12129.                 'population' => '',
  12130.                 'region' => '',
  12131.                 'country' => '',
  12132.                 'address' => '',
  12133.                 'addressNumber' => '',
  12134.                 'zipCode' => '',
  12135.                 'typeDocument' => '',
  12136.             );
  12137.         } else {
  12138.             $clientNew = array(
  12139.                 'name' => $client[0]->getName(),
  12140.                 'title' => $client[0]->getTitle(),
  12141.                 'idDocument' => $client[0]->getIdDocument(),
  12142.                 'population' => '',
  12143.                 'region' => '',
  12144.                 'country' => '',
  12145.                 'address' => $client[0]->getAddress(),
  12146.                 'addressNumber' => $client[0]->getAddressNumber(),
  12147.                 'zipCode' => $client[0]->getZipCode(),
  12148.                 'typeDocument' => $client[0]->getTypeDocument(),
  12149.             );
  12150.             if (is_numeric($client[0]->getPopulation())) {
  12151.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  12152.                 $clientNew['population'] = $city->getCity();
  12153.             }
  12154.             if (is_numeric($client[0]->getRegion())) {
  12155.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  12156.                 $clientNew['region'] = $region->getRegion();
  12157.             }
  12158.             if (is_numeric($client[0]->getCountry())) {
  12159.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  12160.                 $clientNew['country'] = $country->getCountry();
  12161.             }
  12162.         }
  12163.         // Acumuladores de los calculos
  12164.         $totales_neto_all 0;
  12165.         $data_iva = array(
  12166.             'iva' => 21,
  12167.             'ivaMontoVeintiUno' => 0,
  12168.             'ivaMontoDiez' => 0,
  12169.             'ivaMontoCero' => 0,
  12170.         );
  12171.         //INICIO: Determinamos el numero de factura o proforma
  12172.         if ($typeBase == 'I') {
  12173.             // Es una Factura
  12174.             $number $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
  12175.             $dateDocument $number->getDateAt();
  12176.             $number $number->getNumber();
  12177.             $type 'Invoice';
  12178.         } else {
  12179.             if ($typeBase == 'R') {
  12180.                 // Es una factura rectificativa
  12181.                 $number $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
  12182.                 $dateDocument $number->getDateAt();
  12183.                 $type 'Invoice Rec';
  12184.             } else {
  12185.                 // Es una Proforma
  12186.                 $number $invoiceId;
  12187.                 $type 'Proforma';
  12188.             }
  12189.         }
  12190.         //FIN: Determinamos el numero de factura o proforma
  12191.         // Buscamos los productos, pagos y servicios
  12192.         $arrayItems = array();
  12193.         $fileProducts = array();
  12194.         $payments = array();
  12195.         $services = array();
  12196.         if (!empty($items)) {
  12197.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12198.                 foreach ($items as $item) {
  12199.                     switch ($item->getItemType()) {
  12200.                         case 'PRODUCT'// Producto
  12201.                             $fileProducts[] = $item;
  12202.                             break;
  12203.                         case 'PAYMENT'// Pago
  12204.                             $payments[] = $item;
  12205.                             break;
  12206.                         case 'SERVICE'// Servicio
  12207.                             $services[] = $item;
  12208.                             break;
  12209.                         default:
  12210.                             break;
  12211.                     }
  12212.                 }
  12213.             } else {
  12214.                 // Es una proforma
  12215.                 foreach ($items as $item) {
  12216.                     switch ($item->getType()) {
  12217.                         case 'PRODUCT'// Producto
  12218.                             $productPro $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  12219.                             if (!empty($productPro)) {
  12220.                                 $fileProducts[] = $productPro;
  12221.                             }
  12222.                             break;
  12223.                         case 'PAYMENT'// Pago
  12224.                             $paymentPro $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
  12225.                             if (!empty($paymentPro)) {
  12226.                                 $payments[] = $paymentPro;
  12227.                             }
  12228.                             break;
  12229.                         case 'SERVICE'// Servicio
  12230.                             $servicePro $em->getRepository(AveServices::class)->findOneById($item->getControlId());
  12231.                             if (!empty($servicePro)) {
  12232.                                 $services[] = $servicePro;
  12233.                             }
  12234.                             break;
  12235.                         default:
  12236.                             break;
  12237.                     }
  12238.                 }
  12239.             }
  12240.         }
  12241.         $data_supplier = array();
  12242.         $i 0;
  12243.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  12244.         $pax '1';
  12245.         $qty '1';
  12246.         $product = array(
  12247.             'neto' => 0,
  12248.             'sumSubT' => 0,
  12249.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12250.         $service = array(
  12251.             'neto' => 0,
  12252.             'sumSubT' => 0,
  12253.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12254.         foreach ($fileProducts as $item) {
  12255.             if (!is_null($item->getUnits()) or !empty($item->getUnits())) {
  12256.                 $qty $item->getUnits();
  12257.             }
  12258.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12259.                 if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
  12260.                     $subtotal 0;
  12261.                     $neto 0;
  12262.                     $subtotalProduct 0;
  12263.                     $ivaFactor 0;
  12264.                 } else {
  12265.                         
  12266.                     //Buscamos el iva
  12267.                     $zProductFile $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  12268.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  12269. //                    $subtotalProduct = $item->getPrdServicePrice() * 1.21;
  12270.                     $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  12271.                     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
  12272.                     $ivaFactor = (+ ($ivaFactor/100));
  12273.                     
  12274.                     $subtotalProduct $item->getPrdSubTotalPrice() * $ivaFactor;
  12275.                     $ivaFactor = (($ivaFactor 1) * 100);
  12276.                     $subneto $item->getPrdSubTotalPrice();
  12277.                     $subtotal =  $subtotalProduct;
  12278.                     $neto =  $subneto;
  12279.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12280.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12281.                     $neto round($neto2PHP_ROUND_HALF_UP);
  12282.                     $arrayItems[] = array(
  12283.                         'type' => 'Product',
  12284.                         'name' => $item->getPrdName(),
  12285.                         'amount' => $neto,
  12286.                         'iva' => $ivaFactor,
  12287.                         'total' => $subtotal,
  12288.                     );
  12289.                 }
  12290.             } else {
  12291.                 // Es proforma
  12292.                 if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
  12293.                     $subtotal 0;
  12294.                     $neto 0;
  12295.                     $subtotalProduct 0;
  12296.                     $ivaFactor 0;
  12297.                 } else {
  12298.                     //Buscamos el iva
  12299. //                    d($item);
  12300. //                    $zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  12301.                     $zProductFile $item;
  12302.                     if (empty($zProductFile)){ $zProductFile $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
  12303. //                    $subtotalProduct = $item->getServicePrice() * 1.21;
  12304.                     $ivaFactor = empty($zProductFile) ? 21 $zProductFile->getIva();
  12305. //                    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
  12306.                     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
  12307.                     $ivaFactor = (+ ($ivaFactor/100));
  12308.                     $subtotalProduct $item->getSubTotalPrice() * $ivaFactor;
  12309.                     $ivaFactor = (($ivaFactor 1) * 100);
  12310.                     $subneto $item->getSubTotalPrice();
  12311.                     $subtotal =  $subtotalProduct;
  12312.                     $neto =  $subneto;
  12313.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12314.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12315.                     $neto round($neto2PHP_ROUND_HALF_UP);
  12316.                     $arrayItems[] = array(
  12317.                         'type' => 'Product',
  12318.                         'name' => $item->getProductName(),
  12319.                         'amount' => $neto,
  12320.                         'iva' => '21',
  12321.                         'total' => $subtotal,
  12322.                     );
  12323.                 }
  12324.             }
  12325.             // Acumula netos totales e IVA
  12326.             $totales_neto_all $totales_neto_all $neto;
  12327.             switch ($ivaFactor) {
  12328.                 case 21$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21); break;
  12329.                 case 10$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto 0.1); break;
  12330.                 case 0$data_iva['ivaMontoCero'] = 0; break;
  12331.                 default: break;
  12332.             }
  12333.             
  12334.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12335.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  12336.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  12337.             // Acumula netos totales e IVA
  12338.             $product['neto'] = $product['neto'] + $neto;
  12339.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  12340.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12341.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  12342.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  12343.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12344.                 $data_supplier['product'][$i] = array(
  12345.                     'id' => $item->getId(),
  12346.                     'productName' => $item->getPrdName(),
  12347.                     'productId' => $item->getPrdProductId(),
  12348.                     'dateStart' => $item->getPrdDateStart(),
  12349.                     'dateEnd' => $item->getPrdDateEnd(),
  12350.                     'servicePrice' => $item->getPrdServicePrice(),
  12351.                     'serviceSubTotalPrice' => $subneto,     //antes de IVA
  12352.                     'subtotalProduct' => $subtotalProduct,
  12353.                     'iva' => $iva,
  12354.                     'pax' => $pax,
  12355.                     'qty' => $qty,
  12356.                     'type' => $item->getPrdType(),
  12357.                     'subtotal' => $subtotal,
  12358.                 );
  12359.             } else {
  12360.                 // Es proforma
  12361.                 $data_supplier['product'][$i] = array(
  12362.                     'id' => $item->getId(),
  12363.                     'productName' => $item->getProductName(),
  12364.                     'productId' => $item->getProductId(),
  12365.                     'dateStart' => $item->getDateStart(),
  12366.                     'dateEnd' => $item->getDateEnd(),
  12367.                     'servicePrice' => $item->getServicePrice(),
  12368.                     'subtotalProduct' => $subtotalProduct,
  12369.                     'iva' => $iva,
  12370.                     'pax' => $pax,
  12371.                     'qty' => $qty,
  12372.                     'type' => $item->getType(),
  12373.                     'subtotal' => $subtotal,
  12374.                 );
  12375.             }
  12376.             $i++;
  12377.         }
  12378.         $data_supplier['productSubTotal'] = array(
  12379.             'neto' => $product['neto'],
  12380.             'sumSubT' => $product['sumSubT'],
  12381.         );
  12382.         $payment = array(
  12383.             'sumSubT' => 0,
  12384.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  12385.         $i 0;
  12386.         foreach ($payments as $item) {
  12387.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12388.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getPayAmountTotal();
  12389.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12390.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  12391.                 $data_supplier['payment'][$i] = array(
  12392.                     'id' => $item->getId(),
  12393.                     'amount' => $item->getPayAmount(),
  12394.                     'amountTotal' => $item->getPayAmountTotal(),
  12395.                     'vat' => $item->getPayVat(),
  12396.                     'datePayAt' => $item->getPayDatePayAt(),
  12397.                     'wayToPay' => $item->getPayWayToPay(),
  12398.                 );
  12399.                 $arrayItems[] = array(
  12400.                     'type' => 'Payment',
  12401.                     'name' => $item->getPayWayToPay(),
  12402.                     'amount' => $item->getPayAmount(),
  12403.                     'total' => $item->getPayAmountTotal(),
  12404.                     'iva' => $item->getPayVat(),
  12405.                 );
  12406.             } else {
  12407.                 // Es una proforma
  12408.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  12409.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  12410.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  12411.                 $data_supplier['payment'][$i] = array(
  12412.                     'id' => $item->getId(),
  12413.                     'amount' => $item->getAmount(),
  12414.                     'amountTotal' => $item->getAmountTotal(),
  12415.                     'vat' => $item->getVat(),
  12416.                     'datePayAt' => $item->getDatePayAt(),
  12417.                     'wayToPay' => $item->getWayToPay(),
  12418.                 );
  12419.                 $arrayItems[] = array(
  12420.                     'type' => 'Payment',
  12421.                     'name' => $item->getWayToPay(),
  12422.                     'amount' => $item->getAmount(),
  12423.                     'total' => $item->getAmountTotal(),
  12424.                     'iva' => $item->getVat(),
  12425.                 );
  12426.             }
  12427.             $i++;
  12428.         }
  12429.         if (!empty($payments)) {
  12430.             $data_supplier['paymentSubTotal'] = array(
  12431.                 'sumSubT' => $payment['sumSubT'],
  12432.             );
  12433.         }
  12434.         foreach ($services as $item) {
  12435.             if (($typeBase == 'I') or ($typeBase == 'R')) {
  12436.                 if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
  12437.                     $subtotal 0;
  12438.                     $neto 0;
  12439.                     $subtotalService 0;
  12440.                 } else {
  12441.                     $subtotalService $item->getSrvPrice();
  12442.                     $subneto $item->getSrvPrice();
  12443.                     // Commission
  12444.                     if ($item->getSrvOpCommission() == '1') {
  12445.                         $subtotalService $subtotalService * (+ ($item->getSrvCommission() / 100));
  12446.                         $subneto $subneto * (+ ($item->getSrvCommission() / 100));
  12447.                     } else {
  12448.                         $subtotalService $subtotalService * (- ($item->getSrvCommission() / 100));
  12449.                         $subneto $subneto * (- ($item->getSrvCommission() / 100));
  12450.                     }
  12451.                     // Over
  12452.                     if ($item->getSrvOpOver() == '1') {
  12453.                         $subtotalService $subtotalService $item->getSrvOver();
  12454.                         $subneto $subneto $item->getSrvOver();
  12455.                     } else {
  12456.                         $subtotalService $subtotalService $item->getSrvOver();
  12457.                         $subneto $subneto $item->getSrvOver();
  12458.                     }
  12459.                     // IVA
  12460.                     if ($item->getSrvOpIva() == '1') {
  12461.                         $subtotalService $subtotalService * (+ ($item->getSrvIva() / 100));
  12462.                     } else {
  12463.                         $subtotalService $item->getSrvPrice();
  12464.                         $subneto = ($subneto 100) / (100 $item->getSrvIva());
  12465.                     }
  12466.                     switch ($item->getSrvServiceCatId()) {
  12467.                         case 1// Alojamiento
  12468.                             // el numero de noches $numNoches; precio unitario $subneto
  12469.                             $numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
  12470.                             // La personas no afectan este calculo
  12471.                             $subtotal $subtotalService $numNoches $item->getSrvUnits();
  12472.                             $subnetoUnit $subneto;
  12473.                             $subneto $subneto $numNoches $item->getSrvUnits();
  12474.                             $data_supplier['service'][$i] = array(
  12475.                                 'id' => $item->getId(),
  12476.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12477.                                 'serviceName' => $item->getSrvName(),
  12478.                                 'serviceType' => 'Hotel',
  12479.                                 'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
  12480.                                 'qty' => $item->getSrvUnits(),
  12481.                                 'iva' => $item->getSrvIva(),
  12482.                                 'pax' => '-',
  12483.                                 'precioUnit' => $subnetoUnit,
  12484.                                 'subneto' => $subneto,
  12485.                                 'subtotal' => $subtotal,
  12486.                             );
  12487.                             break;
  12488.                         case 2//Actividades
  12489.                             // El nĂºmero de personas es considerado en el calculo
  12490.                             $pax $item->getSrvPax();
  12491.                             if (empty($pax) or $pax == "0") {
  12492.                                 $pax 1;
  12493.                             }
  12494.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12495.                             if ($days 1) {
  12496.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12497.                             } else {
  12498.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12499.                             }
  12500.                             $subtotal $subtotalService $days $item->getSrvUnits();
  12501.                             $subnetoUnit $subneto;
  12502.                             $subneto $subneto $days $item->getSrvUnits();
  12503.                             $data_supplier['service'][$i] = array(
  12504.                                 'id' => $item->getId(),
  12505.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12506.                                 'serviceName' => $item->getSrvName(),
  12507.                                 'serviceType' => 'Actividad',
  12508.                                 'date' => $dateServ,
  12509.                                 'qty' => $item->getSrvUnits(),
  12510.                                 'iva' => $item->getSrvIva(),
  12511.                                 'pax' => $item->getSrvPax(),
  12512.                                 'precioUnit' => $subnetoUnit,
  12513.                                 'subneto' => $subneto,
  12514.                                 'subtotal' => $subtotal,
  12515.                             );
  12516.                             break;
  12517.                         case 3// AV
  12518.                             $pax $item->getSrvPax();
  12519.                             if (empty($pax) or $pax == "0") {
  12520.                                 $pax 1;
  12521.                             }
  12522.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12523.                             if ($days 1) {
  12524.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12525.                             } else {
  12526.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12527.                             }
  12528.                             $unitsServ $item->getSrvUnits();
  12529.                             if (empty($unitsServ) or $unitsServ == "0") {
  12530.                                 $unitsServ 1;
  12531.                             }
  12532.                             $subtotal $subtotalService $days $unitsServ $pax;
  12533.                             $subnetoUnit $subneto;
  12534.                             $subneto $subneto $days $unitsServ $pax;
  12535.                             $data_supplier['service'][$i] = array(
  12536.                                 'id' => $item->getId(),
  12537.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12538.                                 'serviceName' => $item->getSrvName(),
  12539.                                 'serviceType' => 'AV',
  12540.                                 'date' => $dateServ,
  12541.                                 'qty' => $unitsServ,
  12542.                                 'iva' => $item->getSrvIva(),
  12543.                                 'pax' => $item->getSrvPax(),
  12544.                                 'precioUnit' => $subnetoUnit,
  12545.                                 'subneto' => $subneto,
  12546.                                 'subtotal' => $subtotal,
  12547.                             );
  12548.                             break;
  12549.                         case 4//Creative
  12550.                             $pax $item->getSrvPax();
  12551.                             if (empty($pax) or $pax == "0") {
  12552.                                 $pax 1;
  12553.                             }
  12554.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12555.                             if ($days 1) {
  12556.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12557.                             } else {
  12558.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12559.                             }
  12560.                             $unitsServ $item->getSrvUnits();
  12561.                             if (empty($unitsServ) or $unitsServ == "0") {
  12562.                                 $unitsServ 1;
  12563.                             }
  12564.                             $subtotal $subtotalService $days $unitsServ $pax;
  12565.                             $subnetoUnit $subneto;
  12566.                             $subneto $subneto $days $unitsServ $pax;
  12567.                             $data_supplier['service'][$i] = array(
  12568.                                 'id' => $item->getId(),
  12569.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12570.                                 'serviceName' => $item->getSrvName(),
  12571.                                 'serviceType' => 'Creativo',
  12572.                                 'date' => $dateServ,
  12573.                                 'qty' => $unitsServ,
  12574.                                 'iva' => $item->getSrvIva(),
  12575.                                 'pax' => $item->getSrvPax(),
  12576.                                 'precioUnit' => $subnetoUnit,
  12577.                                 'subneto' => $subneto,
  12578.                                 'subtotal' => $subtotal,
  12579.                             );
  12580.                             break;
  12581.                         case 5//Cruise
  12582.                             $pax $item->getSrvPax();
  12583.                             if (empty($pax) or $pax == "0") {
  12584.                                 $pax 1;
  12585.                             }
  12586.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
  12587.                             if ($days 1) {
  12588.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12589.                             } else {
  12590.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12591.                             }
  12592.                             $unitsServ $item->getSrvUnits();
  12593.                             if (empty($unitsServ) or $unitsServ == "0") {
  12594.                                 $unitsServ 1;
  12595.                             }
  12596.                             $subtotal $subtotalService $days $unitsServ $pax;
  12597.                             $subnetoUnit $subneto;
  12598.                             $subneto $subneto $days $unitsServ $pax;
  12599.                             $data_supplier['service'][$i] = array(
  12600.                                 'id' => $item->getId(),
  12601.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12602.                                 'serviceName' => $item->getSrvName(),
  12603.                                 'serviceType' => 'Crucero',
  12604.                                 'date' => $dateServ,
  12605.                                 'qty' => $unitsServ,
  12606.                                 'iva' => $item->getSrvIva(),
  12607.                                 'pax' => $item->getSrvPax(),
  12608.                                 'precioUnit' => $subnetoUnit,
  12609.                                 'subneto' => $subneto,
  12610.                                 'subtotal' => $subtotal,
  12611.                             );
  12612.                             break;
  12613.                         case 6//Entertaiment
  12614.                             $pax $item->getSrvPax();
  12615.                             if (empty($pax) or $pax == "0") {
  12616.                                 $pax 1;
  12617.                             }
  12618.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12619.                             if ($days 1) {
  12620.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12621.                             } else {
  12622.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12623.                             }
  12624.                             $unitsServ $item->getSrvUnits();
  12625.                             if (empty($unitsServ) or $unitsServ == "0") {
  12626.                                 $unitsServ 1;
  12627.                             }
  12628.                             $subtotal $subtotalService $days $unitsServ $pax;
  12629.                             $subnetoUnit $subneto;
  12630.                             $subneto $subneto $days $unitsServ $pax;
  12631.                             $data_supplier['service'][$i] = array(
  12632.                                 'id' => $item->getId(),
  12633.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12634.                                 'serviceName' => $item->getSrvName(),
  12635.                                 'serviceType' => 'Entretenimiento',
  12636.                                 'date' => $dateServ,
  12637.                                 'qty' => $unitsServ,
  12638.                                 'iva' => $item->getSrvIva(),
  12639.                                 'pax' => $item->getSrvPax(),
  12640.                                 'precioUnit' => $subnetoUnit,
  12641.                                 'subneto' => $subneto,
  12642.                                 'subtotal' => $subtotal,
  12643.                             );
  12644.                             break;
  12645.                         case 7// Gifts
  12646.                             $pax $item->getSrvPax();
  12647.                             if (empty($pax) or $pax == "0") {
  12648.                                 $pax 1;
  12649.                             }
  12650.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12651.                             $days 1;
  12652.                             if ($days 1) {
  12653.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12654.                             } else {
  12655.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12656.                             }
  12657.                             $unitsServ $item->getSrvUnits();
  12658.                             if (empty($unitsServ) or $unitsServ == "0") {
  12659.                                 $unitsServ 1;
  12660.                             }
  12661.                             $subtotal $subtotalService $days $unitsServ $pax;
  12662.                             $subnetoUnit $subneto;
  12663.                             $subneto $subneto $days $unitsServ $pax;
  12664.                             $data_supplier['service'][$i] = array(
  12665.                                 'id' => $item->getId(),
  12666.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12667.                                 'serviceName' => $item->getSrvName(),
  12668.                                 'serviceType' => 'Regalos',
  12669.                                 'date' => $dateServ,
  12670.                                 'qty' => $unitsServ,
  12671.                                 'iva' => $item->getSrvIva(),
  12672.                                 'pax' => $item->getSrvPax(),
  12673.                                 'precioUnit' => $subnetoUnit,
  12674.                                 'subneto' => $subneto,
  12675.                                 'subtotal' => $subtotal,
  12676.                             );
  12677.                             break;
  12678.                         case 8//Guide
  12679.                             $pax $item->getSrvPax();
  12680.                             if (empty($pax) or $pax == "0") {
  12681.                                 $pax 1;
  12682.                             }
  12683.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12684.                             if ($days 1) {
  12685.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12686.                             } else {
  12687.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12688.                             }
  12689.                             $unitsServ $item->getSrvUnits();
  12690.                             if (empty($unitsServ) or $unitsServ == "0") {
  12691.                                 $unitsServ 1;
  12692.                             }
  12693.                             $subtotal $subtotalService $days $unitsServ $pax;
  12694.                             $subnetoUnit $subneto;
  12695.                             $subneto $subneto $days $unitsServ $pax;
  12696.                             $data_supplier['service'][$i] = array(
  12697.                                 'id' => $item->getId(),
  12698.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12699.                                 'serviceName' => $item->getSrvName(),
  12700.                                 'serviceType' => 'Regalos',
  12701.                                 'date' => $dateServ,
  12702.                                 'qty' => $unitsServ,
  12703.                                 'iva' => $item->getSrvIva(),
  12704.                                 'pax' => $item->getSrvPax(),
  12705.                                 'precioUnit' => $subnetoUnit,
  12706.                                 'subneto' => $subneto,
  12707.                                 'subtotal' => $subtotal,
  12708.                             );
  12709.                             break;
  12710.                         case 9//Itineraries
  12711.                             $pax $item->getSrvPax();
  12712.                             if (empty($pax) or $pax == "0") {
  12713.                                 $pax 1;
  12714.                             }
  12715.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12716.                             if ($days 1) {
  12717.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12718.                             } else {
  12719.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12720.                             }
  12721.                             $unitsServ $item->getSrvUnits();
  12722.                             if (empty($unitsServ) or $unitsServ == "0") {
  12723.                                 $unitsServ 1;
  12724.                             }
  12725.                             $subtotal $subtotalService $days $unitsServ $pax;
  12726.                             $subnetoUnit $subneto;
  12727.                             $subneto $subneto $days $unitsServ $pax;
  12728.                             $data_supplier['service'][$i] = array(
  12729.                                 'id' => $item->getId(),
  12730.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12731.                                 'serviceName' => $item->getSrvName(),
  12732.                                 'serviceType' => 'Itinerarios',
  12733.                                 'date' => $dateServ,
  12734.                                 'qty' => $unitsServ,
  12735.                                 'iva' => $item->getSrvIva(),
  12736.                                 'pax' => $item->getSrvPax(),
  12737.                                 'precioUnit' => $subnetoUnit,
  12738.                                 'subneto' => $subneto,
  12739.                                 'subtotal' => $subtotal,
  12740.                             );
  12741.                             break;
  12742.                         case 10//Lounge  -- No Aplica
  12743.                             //                        $pax = $item->getPax();
  12744.                             //                        if (empty($pax) or $pax == "0") {
  12745.                             //                            $pax = 1;
  12746.                             //                        }
  12747.                             //
  12748.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12749.                             //                        if ($days > 1){
  12750.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  12751.                             //                        } else {
  12752.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12753.                             //                        }
  12754.                             //
  12755.                             //                        $unitsServ = $item->getUnits();
  12756.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  12757.                             //                            $unitsServ = 1;
  12758.                             //                        }
  12759.                             //
  12760.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  12761.                             //                        $subnetoUnit = $subneto;
  12762.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  12763.                             //
  12764.                             //                        $data_supplier['service'][$i] = array (
  12765.                             //                            'id' => $item->getId(),
  12766.                             //                            'serviceCatId' => $item->getServiceCatId(),
  12767.                             //                            'serviceName' => $item->getName(),
  12768.                             //                            'serviceType' => 'Itinerarios',
  12769.                             //                            'date' => $dateServ,
  12770.                             //                            'qty' => $unitsServ,
  12771.                             //                            'iva' => $item->getIva(),
  12772.                             //                            'pax' => $item->getPax(),
  12773.                             //                            'precioUnit' => $subnetoUnit,
  12774.                             //                            'subneto' => $subneto,
  12775.                             //                            'subtotal' => $subtotal,
  12776.                             //                        );
  12777.                             break;
  12778.                         case 11//Menu
  12779.                             $pax $item->getSrvPax();
  12780.                             if (empty($pax) or $pax == "0") {
  12781.                                 $pax 1;
  12782.                             }
  12783.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12784.                             if ($days 1) {
  12785.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12786.                             } else {
  12787.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12788.                             }
  12789.                             $unitsServ $item->getSrvUnits();
  12790.                             if (empty($unitsServ) or $unitsServ == "0") {
  12791.                                 $unitsServ 1;
  12792.                             }
  12793.                             $subtotal $subtotalService $days $unitsServ $pax;
  12794.                             $subnetoUnit $subneto;
  12795.                             $subneto $subneto $days $unitsServ $pax;
  12796.                             $data_supplier['service'][$i] = array(
  12797.                                 'id' => $item->getId(),
  12798.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12799.                                 'serviceName' => $item->getSrvName(),
  12800.                                 'serviceType' => 'MenĂº',
  12801.                                 'date' => $dateServ,
  12802.                                 'qty' => $unitsServ,
  12803.                                 'iva' => $item->getSrvIva(),
  12804.                                 'pax' => $item->getSrvPax(),
  12805.                                 'precioUnit' => $subnetoUnit,
  12806.                                 'subneto' => $subneto,
  12807.                                 'subtotal' => $subtotal,
  12808.                             );
  12809.                             break;
  12810.                         case 12//Others
  12811.                             $pax $item->getSrvPax();
  12812.                             if (empty($pax) or $pax == "0") {
  12813.                                 $pax 1;
  12814.                             }
  12815.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12816.                             if ($days 1) {
  12817.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12818.                             } else {
  12819.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12820.                             }
  12821.                             $unitsServ $item->getSrvUnits();
  12822.                             if (empty($unitsServ) or $unitsServ == "0") {
  12823.                                 $unitsServ 1;
  12824.                             }
  12825.                             $subtotal $subtotalService $days $unitsServ $pax;
  12826.                             $subnetoUnit $subneto;
  12827.                             $subneto $subneto $days $unitsServ $pax;
  12828.                             $data_supplier['service'][$i] = array(
  12829.                                 'id' => $item->getId(),
  12830.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12831.                                 'serviceName' => $item->getSrvName(),
  12832.                                 'serviceType' => 'Otros',
  12833.                                 'date' => $dateServ,
  12834.                                 'qty' => $unitsServ,
  12835.                                 'iva' => $item->getSrvIva(),
  12836.                                 'pax' => $item->getSrvPax(),
  12837.                                 'precioUnit' => $subnetoUnit,
  12838.                                 'subneto' => $subneto,
  12839.                                 'subtotal' => $subtotal,
  12840.                             );
  12841.                             break;
  12842.                         case 13//Transport
  12843.                             $pax $item->getSrvPax();
  12844.                             if (empty($pax) or $pax == "0") {
  12845.                                 $pax 1;
  12846.                             }
  12847.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12848.                             if ($days 1) {
  12849.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12850.                             } else {
  12851.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12852.                             }
  12853.                             $unitsServ $item->getSrvUnits();
  12854.                             if (empty($unitsServ) or $unitsServ == "0") {
  12855.                                 $unitsServ 1;
  12856.                             }
  12857.                             $subtotal $subtotalService $days $unitsServ $pax;
  12858.                             $subnetoUnit $subneto;
  12859.                             $subneto $subneto $days $unitsServ $pax;
  12860.                             $data_supplier['service'][$i] = array(
  12861.                                 'id' => $item->getId(),
  12862.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12863.                                 'serviceName' => $item->getSrvName(),
  12864.                                 'serviceType' => 'Transporte',
  12865.                                 'date' => $dateServ,
  12866.                                 'qty' => $unitsServ,
  12867.                                 'iva' => $item->getSrvIva(),
  12868.                                 'pax' => $item->getSrvPax(),
  12869.                                 'precioUnit' => $subnetoUnit,
  12870.                                 'subneto' => $subneto,
  12871.                                 'subtotal' => $subtotal,
  12872.                             );
  12873.                             break;
  12874.                         case 14//Technology
  12875.                             $pax $item->getSrvPax();
  12876.                             if (empty($pax) or $pax == "0") {
  12877.                                 $pax 1;
  12878.                             }
  12879.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  12880.                             $days 1;
  12881.                             //                        if ($days > 1){
  12882.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  12883.                             //                        } else {
  12884.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  12885.                             //                        }
  12886.                             $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12887.                             $unitsServ $item->getSrvUnits();
  12888.                             if (empty($unitsServ) or $unitsServ == "0") {
  12889.                                 $unitsServ 1;
  12890.                             }
  12891.                             $subtotal $subtotalService $days $unitsServ $pax;
  12892.                             $subnetoUnit $subneto;
  12893.                             $subneto $subneto $days $unitsServ $pax;
  12894.                             $data_supplier['service'][$i] = array(
  12895.                                 'id' => $item->getId(),
  12896.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12897.                                 'serviceName' => $item->getSrvName(),
  12898.                                 'serviceType' => 'TecnologĂ­a',
  12899.                                 'date' => $dateServ,
  12900.                                 'qty' => $unitsServ,
  12901.                                 'iva' => $item->getSrvIva(),
  12902.                                 'pax' => $item->getSrvPax(),
  12903.                                 'precioUnit' => $subnetoUnit,
  12904.                                 'subneto' => $subneto,
  12905.                                 'subtotal' => $subtotal,
  12906.                             );
  12907.                             break;
  12908.                         case 15//Assisstant
  12909.                             $pax $item->getSrvPax();
  12910.                             if (empty($pax) or $pax == "0") {
  12911.                                 $pax 1;
  12912.                             }
  12913.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12914.                             if ($days 1) {
  12915.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12916.                             } else {
  12917.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12918.                             }
  12919.                             $unitsServ $item->getSrvUnits();
  12920.                             if (empty($unitsServ) or $unitsServ == "0") {
  12921.                                 $unitsServ 1;
  12922.                             }
  12923.                             $subtotal $subtotalService $days $unitsServ $pax;
  12924.                             $subnetoUnit $subneto;
  12925.                             $subneto $subneto $days $unitsServ $pax;
  12926.                             $data_supplier['service'][$i] = array(
  12927.                                 'id' => $item->getId(),
  12928.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12929.                                 'serviceName' => $item->getSrvName(),
  12930.                                 'serviceType' => 'Asistente',
  12931.                                 'date' => $dateServ,
  12932.                                 'qty' => $unitsServ,
  12933.                                 'iva' => $item->getSrvIva(),
  12934.                                 'pax' => $item->getSrvPax(),
  12935.                                 'precioUnit' => $subnetoUnit,
  12936.                                 'subneto' => $subneto,
  12937.                                 'subtotal' => $subtotal,
  12938.                             );
  12939.                             break;
  12940.                         case 16//DDR
  12941.                             $pax $item->getSrvPax();
  12942.                             if (empty($pax) or $pax == "0") {
  12943.                                 $pax 1;
  12944.                             }
  12945.                             $days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days 1);
  12946.                             if ($days 1) {
  12947.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
  12948.                             } else {
  12949.                                 $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
  12950.                             }
  12951.                             $unitsServ $item->getSrvUnits();
  12952.                             if (empty($unitsServ) or $unitsServ == "0") {
  12953.                                 $unitsServ 1;
  12954.                             }
  12955.                             $subtotal $subtotalService $days $unitsServ $pax;
  12956.                             $subnetoUnit $subneto;
  12957.                             $subneto $subneto $days $unitsServ $pax;
  12958.                             $data_supplier['service'][$i] = array(
  12959.                                 'id' => $item->getId(),
  12960.                                 'serviceCatId' => $item->getSrvServiceCatId(),
  12961.                                 'serviceName' => $item->getSrvName(),
  12962.                                 'serviceType' => 'DDR',
  12963.                                 'date' => $dateServ,
  12964.                                 'qty' => $unitsServ,
  12965.                                 'iva' => $item->getSrvIva(),
  12966.                                 'pax' => $item->getSrvPax(),
  12967.                                 'precioUnit' => $subnetoUnit,
  12968.                                 'subneto' => $subneto,
  12969.                                 'subtotal' => $subtotal,
  12970.                             );
  12971.                             break;
  12972.                         default:
  12973.                             break;
  12974.                     }
  12975.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  12976.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  12977.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  12978.                     $arrayItems[] = array(
  12979.                         'type' => 'Service',
  12980.                         'name' => $item->getSrvName(),
  12981.                         'amount' => $neto,
  12982.                         'iva' => $item->getSrvIva(),
  12983.                         'total' => $subtotal,
  12984.                     );
  12985.                 }
  12986.                 switch ($item->getSrvIva()) {
  12987.                         // Acumula IVA
  12988.                     case 21:
  12989.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100));
  12990.                         break;
  12991.                     case 10:
  12992.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100));
  12993.                         break;
  12994.                     case 0:
  12995.                         break;
  12996.                     default:
  12997.                         break;
  12998.                 }
  12999.             } else {
  13000.                 // Es una proforma
  13001.                 if (is_null($item->getPrice()) or empty($item->getPrice())) {
  13002.                     $subtotal 0;
  13003.                     $neto 0;
  13004.                     $subtotalService 0;
  13005.                 } else {
  13006.                     $subtotalService $item->getPrice();
  13007.                     $subneto $item->getPrice();
  13008.                     // Commission
  13009.                     if ($item->getOpCommission() == '1') {
  13010.                         $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  13011.                         $subneto $subneto * (+ ($item->getCommission() / 100));
  13012.                     } else {
  13013.                         $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  13014.                         $subneto $subneto * (- ($item->getCommission() / 100));
  13015.                     }
  13016.                     // Over
  13017.                     if ($item->getOpOver() == '1') {
  13018.                         $subtotalService $subtotalService $item->getOver();
  13019.                         $subneto $subneto $item->getOver();
  13020.                     } else {
  13021.                         $subtotalService $subtotalService $item->getOver();
  13022.                         $subneto $subneto $item->getOver();
  13023.                     }
  13024.                     // IVA
  13025.                     if ($item->getOpIva() == '1') {
  13026.                         $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  13027.                     } else {
  13028.                         $subtotalService $item->getPrice();
  13029.                         $subneto = ($subneto 100) / (100 $item->getIva());
  13030.                     }
  13031.                     switch ($item->getServiceCatId()) {
  13032.                         case 1// Alojamiento
  13033.                             // el numero de noches $numNoches; precio unitario $subneto
  13034.                             $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  13035.                             // La personas no afectan este calculo
  13036.                             $subtotal $subtotalService $numNoches $item->getUnits();
  13037.                             $subnetoUnit $subneto;
  13038.                             $subneto $subneto $numNoches $item->getUnits();
  13039.                             $data_supplier['service'][$i] = array(
  13040.                                 'id' => $item->getId(),
  13041.                                 'serviceCatId' => $item->getServiceCatId(),
  13042.                                 'serviceName' => $item->getName(),
  13043.                                 'serviceType' => 'Hotel',
  13044.                                 'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  13045.                                 'qty' => $item->getUnits(),
  13046.                                 'iva' => $item->getIva(),
  13047.                                 'pax' => '-',
  13048.                                 'precioUnit' => $subnetoUnit,
  13049.                                 'subneto' => $subneto,
  13050.                                 'subtotal' => $subtotal,
  13051.                             );
  13052.                             break;
  13053.                         case 2//Actividades
  13054.                             // El nĂºmero de personas es considerado en el calculo
  13055.                             $pax $item->getPax();
  13056.                             if (empty($pax) or $pax == "0") {
  13057.                                 $pax 1;
  13058.                             }
  13059.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13060.                             if ($days 1) {
  13061.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13062.                             } else {
  13063.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13064.                             }
  13065.                             $subtotal $subtotalService $days $item->getUnits();
  13066.                             $subnetoUnit $subneto;
  13067.                             $subneto $subneto $days $item->getUnits();
  13068.                             $data_supplier['service'][$i] = array(
  13069.                                 'id' => $item->getId(),
  13070.                                 'serviceCatId' => $item->getServiceCatId(),
  13071.                                 'serviceName' => $item->getName(),
  13072.                                 'serviceType' => 'Actividad',
  13073.                                 'date' => $dateServ,
  13074.                                 'qty' => $item->getUnits(),
  13075.                                 'iva' => $item->getIva(),
  13076.                                 'pax' => $item->getPax(),
  13077.                                 'precioUnit' => $subnetoUnit,
  13078.                                 'subneto' => $subneto,
  13079.                                 'subtotal' => $subtotal,
  13080.                             );
  13081.                             break;
  13082.                         case 3// AV
  13083.                             $pax $item->getPax();
  13084.                             if (empty($pax) or $pax == "0") {
  13085.                                 $pax 1;
  13086.                             }
  13087.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13088.                             if ($days 1) {
  13089.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13090.                             } else {
  13091.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13092.                             }
  13093.                             $unitsServ $item->getUnits();
  13094.                             if (empty($unitsServ) or $unitsServ == "0") {
  13095.                                 $unitsServ 1;
  13096.                             }
  13097.                             $subtotal $subtotalService $days $unitsServ $pax;
  13098.                             $subnetoUnit $subneto;
  13099.                             $subneto $subneto $days $unitsServ $pax;
  13100.                             $data_supplier['service'][$i] = array(
  13101.                                 'id' => $item->getId(),
  13102.                                 'serviceCatId' => $item->getServiceCatId(),
  13103.                                 'serviceName' => $item->getName(),
  13104.                                 'serviceType' => 'AV',
  13105.                                 'date' => $dateServ,
  13106.                                 'qty' => $unitsServ,
  13107.                                 'iva' => $item->getIva(),
  13108.                                 'pax' => $item->getPax(),
  13109.                                 'precioUnit' => $subnetoUnit,
  13110.                                 'subneto' => $subneto,
  13111.                                 'subtotal' => $subtotal,
  13112.                             );
  13113.                             break;
  13114.                         case 4//Creative
  13115.                             $pax $item->getPax();
  13116.                             if (empty($pax) or $pax == "0") {
  13117.                                 $pax 1;
  13118.                             }
  13119.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13120.                             if ($days 1) {
  13121.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13122.                             } else {
  13123.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13124.                             }
  13125.                             $unitsServ $item->getUnits();
  13126.                             if (empty($unitsServ) or $unitsServ == "0") {
  13127.                                 $unitsServ 1;
  13128.                             }
  13129.                             $subtotal $subtotalService $days $unitsServ $pax;
  13130.                             $subnetoUnit $subneto;
  13131.                             $subneto $subneto $days $unitsServ $pax;
  13132.                             $data_supplier['service'][$i] = array(
  13133.                                 'id' => $item->getId(),
  13134.                                 'serviceCatId' => $item->getServiceCatId(),
  13135.                                 'serviceName' => $item->getName(),
  13136.                                 'serviceType' => 'Creativo',
  13137.                                 'date' => $dateServ,
  13138.                                 'qty' => $unitsServ,
  13139.                                 'iva' => $item->getIva(),
  13140.                                 'pax' => $item->getPax(),
  13141.                                 'precioUnit' => $subnetoUnit,
  13142.                                 'subneto' => $subneto,
  13143.                                 'subtotal' => $subtotal,
  13144.                             );
  13145.                             break;
  13146.                         case 5//Cruise
  13147.                             $pax $item->getPax();
  13148.                             if (empty($pax) or $pax == "0") {
  13149.                                 $pax 1;
  13150.                             }
  13151.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  13152.                             if ($days 1) {
  13153.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13154.                             } else {
  13155.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13156.                             }
  13157.                             $unitsServ $item->getUnits();
  13158.                             if (empty($unitsServ) or $unitsServ == "0") {
  13159.                                 $unitsServ 1;
  13160.                             }
  13161.                             $subtotal $subtotalService $days $unitsServ $pax;
  13162.                             $subnetoUnit $subneto;
  13163.                             $subneto $subneto $days $unitsServ $pax;
  13164.                             $data_supplier['service'][$i] = array(
  13165.                                 'id' => $item->getId(),
  13166.                                 'serviceCatId' => $item->getServiceCatId(),
  13167.                                 'serviceName' => $item->getName(),
  13168.                                 'serviceType' => 'Crucero',
  13169.                                 'date' => $dateServ,
  13170.                                 'qty' => $unitsServ,
  13171.                                 'iva' => $item->getIva(),
  13172.                                 'pax' => $item->getPax(),
  13173.                                 'precioUnit' => $subnetoUnit,
  13174.                                 'subneto' => $subneto,
  13175.                                 'subtotal' => $subtotal,
  13176.                             );
  13177.                             break;
  13178.                         case 6//Entertaiment
  13179.                             $pax $item->getPax();
  13180.                             if (empty($pax) or $pax == "0") {
  13181.                                 $pax 1;
  13182.                             }
  13183.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13184.                             if ($days 1) {
  13185.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13186.                             } else {
  13187.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13188.                             }
  13189.                             $unitsServ $item->getUnits();
  13190.                             if (empty($unitsServ) or $unitsServ == "0") {
  13191.                                 $unitsServ 1;
  13192.                             }
  13193.                             $subtotal $subtotalService $days $unitsServ $pax;
  13194.                             $subnetoUnit $subneto;
  13195.                             $subneto $subneto $days $unitsServ $pax;
  13196.                             $data_supplier['service'][$i] = array(
  13197.                                 'id' => $item->getId(),
  13198.                                 'serviceCatId' => $item->getServiceCatId(),
  13199.                                 'serviceName' => $item->getName(),
  13200.                                 'serviceType' => 'Entretenimiento',
  13201.                                 'date' => $dateServ,
  13202.                                 'qty' => $unitsServ,
  13203.                                 'iva' => $item->getIva(),
  13204.                                 'pax' => $item->getPax(),
  13205.                                 'precioUnit' => $subnetoUnit,
  13206.                                 'subneto' => $subneto,
  13207.                                 'subtotal' => $subtotal,
  13208.                             );
  13209.                             break;
  13210.                         case 7// Gifts
  13211.                             $pax $item->getPax();
  13212.                             if (empty($pax) or $pax == "0") {
  13213.                                 $pax 1;
  13214.                             }
  13215.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13216.                             $days 1;
  13217.                             if ($days 1) {
  13218.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13219.                             } else {
  13220.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13221.                             }
  13222.                             $unitsServ $item->getUnits();
  13223.                             if (empty($unitsServ) or $unitsServ == "0") {
  13224.                                 $unitsServ 1;
  13225.                             }
  13226.                             $subtotal $subtotalService $days $unitsServ $pax;
  13227.                             $subnetoUnit $subneto;
  13228.                             $subneto $subneto $days $unitsServ $pax;
  13229.                             $data_supplier['service'][$i] = array(
  13230.                                 'id' => $item->getId(),
  13231.                                 'serviceCatId' => $item->getServiceCatId(),
  13232.                                 'serviceName' => $item->getName(),
  13233.                                 'serviceType' => 'Regalos',
  13234.                                 'date' => $dateServ,
  13235.                                 'qty' => $unitsServ,
  13236.                                 'iva' => $item->getIva(),
  13237.                                 'pax' => $item->getPax(),
  13238.                                 'precioUnit' => $subnetoUnit,
  13239.                                 'subneto' => $subneto,
  13240.                                 'subtotal' => $subtotal,
  13241.                             );
  13242.                             break;
  13243.                         case 8//Guide
  13244.                             $pax $item->getPax();
  13245.                             if (empty($pax) or $pax == "0") {
  13246.                                 $pax 1;
  13247.                             }
  13248.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13249.                             if ($days 1) {
  13250.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13251.                             } else {
  13252.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13253.                             }
  13254.                             $unitsServ $item->getUnits();
  13255.                             if (empty($unitsServ) or $unitsServ == "0") {
  13256.                                 $unitsServ 1;
  13257.                             }
  13258.                             $subtotal $subtotalService $days $unitsServ $pax;
  13259.                             $subnetoUnit $subneto;
  13260.                             $subneto $subneto $days $unitsServ $pax;
  13261.                             $data_supplier['service'][$i] = array(
  13262.                                 'id' => $item->getId(),
  13263.                                 'serviceCatId' => $item->getServiceCatId(),
  13264.                                 'serviceName' => $item->getName(),
  13265.                                 'serviceType' => 'Regalos',
  13266.                                 'date' => $dateServ,
  13267.                                 'qty' => $unitsServ,
  13268.                                 'iva' => $item->getIva(),
  13269.                                 'pax' => $item->getPax(),
  13270.                                 'precioUnit' => $subnetoUnit,
  13271.                                 'subneto' => $subneto,
  13272.                                 'subtotal' => $subtotal,
  13273.                             );
  13274.                             break;
  13275.                         case 9//Itineraries
  13276.                             $pax $item->getPax();
  13277.                             if (empty($pax) or $pax == "0") {
  13278.                                 $pax 1;
  13279.                             }
  13280.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13281.                             if ($days 1) {
  13282.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13283.                             } else {
  13284.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13285.                             }
  13286.                             $unitsServ $item->getUnits();
  13287.                             if (empty($unitsServ) or $unitsServ == "0") {
  13288.                                 $unitsServ 1;
  13289.                             }
  13290.                             $subtotal $subtotalService $days $unitsServ $pax;
  13291.                             $subnetoUnit $subneto;
  13292.                             $subneto $subneto $days $unitsServ $pax;
  13293.                             $data_supplier['service'][$i] = array(
  13294.                                 'id' => $item->getId(),
  13295.                                 'serviceCatId' => $item->getServiceCatId(),
  13296.                                 'serviceName' => $item->getName(),
  13297.                                 'serviceType' => 'Itinerarios',
  13298.                                 'date' => $dateServ,
  13299.                                 'qty' => $unitsServ,
  13300.                                 'iva' => $item->getIva(),
  13301.                                 'pax' => $item->getPax(),
  13302.                                 'precioUnit' => $subnetoUnit,
  13303.                                 'subneto' => $subneto,
  13304.                                 'subtotal' => $subtotal,
  13305.                             );
  13306.                             break;
  13307.                         case 10//Lounge  -- No Aplica
  13308.                             //                        $pax = $item->getPax();
  13309.                             //                        if (empty($pax) or $pax == "0") {
  13310.                             //                            $pax = 1;
  13311.                             //                        }
  13312.                             //
  13313.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13314.                             //                        if ($days > 1){
  13315.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  13316.                             //                        } else {
  13317.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13318.                             //                        }
  13319.                             //
  13320.                             //                        $unitsServ = $item->getUnits();
  13321.                             //                        if (empty($unitsServ) or $unitsServ == "0") {
  13322.                             //                            $unitsServ = 1;
  13323.                             //                        }
  13324.                             //
  13325.                             //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  13326.                             //                        $subnetoUnit = $subneto;
  13327.                             //                        $subneto = $subneto * $days * $unitsServ * $pax;
  13328.                             //
  13329.                             //                        $data_supplier['service'][$i] = array (
  13330.                             //                            'id' => $item->getId(),
  13331.                             //                            'serviceCatId' => $item->getServiceCatId(),
  13332.                             //                            'serviceName' => $item->getName(),
  13333.                             //                            'serviceType' => 'Itinerarios',
  13334.                             //                            'date' => $dateServ,
  13335.                             //                            'qty' => $unitsServ,
  13336.                             //                            'iva' => $item->getIva(),
  13337.                             //                            'pax' => $item->getPax(),
  13338.                             //                            'precioUnit' => $subnetoUnit,
  13339.                             //                            'subneto' => $subneto,
  13340.                             //                            'subtotal' => $subtotal,
  13341.                             //                        );
  13342.                             break;
  13343.                         case 11//Menu
  13344.                             $pax $item->getPax();
  13345.                             if (empty($pax) or $pax == "0") {
  13346.                                 $pax 1;
  13347.                             }
  13348.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13349.                             if ($days 1) {
  13350.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13351.                             } else {
  13352.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13353.                             }
  13354.                             $unitsServ $item->getUnits();
  13355.                             if (empty($unitsServ) or $unitsServ == "0") {
  13356.                                 $unitsServ 1;
  13357.                             }
  13358.                             $subtotal $subtotalService $days $unitsServ $pax;
  13359.                             $subnetoUnit $subneto;
  13360.                             $subneto $subneto $days $unitsServ $pax;
  13361.                             $data_supplier['service'][$i] = array(
  13362.                                 'id' => $item->getId(),
  13363.                                 'serviceCatId' => $item->getServiceCatId(),
  13364.                                 'serviceName' => $item->getName(),
  13365.                                 'serviceType' => 'MenĂº',
  13366.                                 'date' => $dateServ,
  13367.                                 'qty' => $unitsServ,
  13368.                                 'iva' => $item->getIva(),
  13369.                                 'pax' => $item->getPax(),
  13370.                                 'precioUnit' => $subnetoUnit,
  13371.                                 'subneto' => $subneto,
  13372.                                 'subtotal' => $subtotal,
  13373.                             );
  13374.                             break;
  13375.                         case 12//Others
  13376.                             $pax $item->getPax();
  13377.                             if (empty($pax) or $pax == "0") {
  13378.                                 $pax 1;
  13379.                             }
  13380.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13381.                             if ($days 1) {
  13382.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13383.                             } else {
  13384.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13385.                             }
  13386.                             $unitsServ $item->getUnits();
  13387.                             if (empty($unitsServ) or $unitsServ == "0") {
  13388.                                 $unitsServ 1;
  13389.                             }
  13390.                             $subtotal $subtotalService $days $unitsServ $pax;
  13391.                             $subnetoUnit $subneto;
  13392.                             $subneto $subneto $days $unitsServ $pax;
  13393.                             $data_supplier['service'][$i] = array(
  13394.                                 'id' => $item->getId(),
  13395.                                 'serviceCatId' => $item->getServiceCatId(),
  13396.                                 'serviceName' => $item->getName(),
  13397.                                 'serviceType' => 'Otros',
  13398.                                 'date' => $dateServ,
  13399.                                 'qty' => $unitsServ,
  13400.                                 'iva' => $item->getIva(),
  13401.                                 'pax' => $item->getPax(),
  13402.                                 'precioUnit' => $subnetoUnit,
  13403.                                 'subneto' => $subneto,
  13404.                                 'subtotal' => $subtotal,
  13405.                             );
  13406.                             break;
  13407.                         case 13//Transport
  13408.                             $pax $item->getPax();
  13409.                             if (empty($pax) or $pax == "0") {
  13410.                                 $pax 1;
  13411.                             }
  13412.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13413.                             if ($days 1) {
  13414.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13415.                             } else {
  13416.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13417.                             }
  13418.                             $unitsServ $item->getUnits();
  13419.                             if (empty($unitsServ) or $unitsServ == "0") {
  13420.                                 $unitsServ 1;
  13421.                             }
  13422.                             $subtotal $subtotalService $days $unitsServ $pax;
  13423.                             $subnetoUnit $subneto;
  13424.                             $subneto $subneto $days $unitsServ $pax;
  13425.                             $data_supplier['service'][$i] = array(
  13426.                                 'id' => $item->getId(),
  13427.                                 'serviceCatId' => $item->getServiceCatId(),
  13428.                                 'serviceName' => $item->getName(),
  13429.                                 'serviceType' => 'Transporte',
  13430.                                 'date' => $dateServ,
  13431.                                 'qty' => $unitsServ,
  13432.                                 'iva' => $item->getIva(),
  13433.                                 'pax' => $item->getPax(),
  13434.                                 'precioUnit' => $subnetoUnit,
  13435.                                 'subneto' => $subneto,
  13436.                                 'subtotal' => $subtotal,
  13437.                             );
  13438.                             break;
  13439.                         case 14//Technology
  13440.                             $pax $item->getPax();
  13441.                             if (empty($pax) or $pax == "0") {
  13442.                                 $pax 1;
  13443.                             }
  13444.                             //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13445.                             $days 1;
  13446.                             //                        if ($days > 1){
  13447.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  13448.                             //                        } else {
  13449.                             //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13450.                             //                        }
  13451.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13452.                             $unitsServ $item->getUnits();
  13453.                             if (empty($unitsServ) or $unitsServ == "0") {
  13454.                                 $unitsServ 1;
  13455.                             }
  13456.                             $subtotal $subtotalService $days $unitsServ $pax;
  13457.                             $subnetoUnit $subneto;
  13458.                             $subneto $subneto $days $unitsServ $pax;
  13459.                             $data_supplier['service'][$i] = array(
  13460.                                 'id' => $item->getId(),
  13461.                                 'serviceCatId' => $item->getServiceCatId(),
  13462.                                 'serviceName' => $item->getName(),
  13463.                                 'serviceType' => 'TecnologĂ­a',
  13464.                                 'date' => $dateServ,
  13465.                                 'qty' => $unitsServ,
  13466.                                 'iva' => $item->getIva(),
  13467.                                 'pax' => $item->getPax(),
  13468.                                 'precioUnit' => $subnetoUnit,
  13469.                                 'subneto' => $subneto,
  13470.                                 'subtotal' => $subtotal,
  13471.                             );
  13472.                             break;
  13473.                         case 15//Assisstant
  13474.                             $pax $item->getPax();
  13475.                             if (empty($pax) or $pax == "0") {
  13476.                                 $pax 1;
  13477.                             }
  13478.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13479.                             if ($days 1) {
  13480.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13481.                             } else {
  13482.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13483.                             }
  13484.                             $unitsServ $item->getUnits();
  13485.                             if (empty($unitsServ) or $unitsServ == "0") {
  13486.                                 $unitsServ 1;
  13487.                             }
  13488.                             $subtotal $subtotalService $days $unitsServ $pax;
  13489.                             $subnetoUnit $subneto;
  13490.                             $subneto $subneto $days $unitsServ $pax;
  13491.                             $data_supplier['service'][$i] = array(
  13492.                                 'id' => $item->getId(),
  13493.                                 'serviceCatId' => $item->getServiceCatId(),
  13494.                                 'serviceName' => $item->getName(),
  13495.                                 'serviceType' => 'Asistente',
  13496.                                 'date' => $dateServ,
  13497.                                 'qty' => $unitsServ,
  13498.                                 'iva' => $item->getIva(),
  13499.                                 'pax' => $item->getPax(),
  13500.                                 'precioUnit' => $subnetoUnit,
  13501.                                 'subneto' => $subneto,
  13502.                                 'subtotal' => $subtotal,
  13503.                             );
  13504.                             break;
  13505.                         case 16//DDR
  13506.                             $pax $item->getPax();
  13507.                             if (empty($pax) or $pax == "0") {
  13508.                                 $pax 1;
  13509.                             }
  13510.                             $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13511.                             if ($days 1) {
  13512.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13513.                             } else {
  13514.                                 $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13515.                             }
  13516.                             $unitsServ $item->getUnits();
  13517.                             if (empty($unitsServ) or $unitsServ == "0") {
  13518.                                 $unitsServ 1;
  13519.                             }
  13520.                             $subtotal $subtotalService $days $unitsServ $pax;
  13521.                             $subnetoUnit $subneto;
  13522.                             $subneto $subneto $days $unitsServ $pax;
  13523.                             $data_supplier['service'][$i] = array(
  13524.                                 'id' => $item->getId(),
  13525.                                 'serviceCatId' => $item->getServiceCatId(),
  13526.                                 'serviceName' => $item->getName(),
  13527.                                 'serviceType' => 'DDR',
  13528.                                 'date' => $dateServ,
  13529.                                 'qty' => $unitsServ,
  13530.                                 'iva' => $item->getIva(),
  13531.                                 'pax' => $item->getPax(),
  13532.                                 'precioUnit' => $subnetoUnit,
  13533.                                 'subneto' => $subneto,
  13534.                                 'subtotal' => $subtotal,
  13535.                             );
  13536.                             break;
  13537.                         default:
  13538.                             break;
  13539.                     }
  13540.                     // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  13541.                     $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  13542.                     $neto round($subneto2PHP_ROUND_HALF_UP);
  13543.                     $arrayItems[] = array(
  13544.                         'type' => 'Service',
  13545.                         'name' => $item->getName(),
  13546.                         'amount' => $neto,
  13547.                         'iva' => $item->getIva(),
  13548.                         'total' => $subtotal,
  13549.                     );
  13550.                 }
  13551.                 switch ($item->getIva()) {
  13552.                         // Acumula IVA
  13553.                     case 21:
  13554.                         $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  13555.                         break;
  13556.                     case 10:
  13557.                         $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  13558.                         break;
  13559.                     case 0:
  13560.                         break;
  13561.                     default:
  13562.                         break;
  13563.                 }
  13564.             }
  13565.             $totales_neto_all $totales_neto_all $neto;
  13566.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13567.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  13568.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  13569.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  13570.             // Acumula netos totales e IVA
  13571.             $service['neto'] = $service['neto'] + $neto;
  13572.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  13573.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13574.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  13575.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  13576.             $i++;
  13577.         }
  13578.         $data_supplier['serviceSubTotal'] = array(
  13579.             'neto' => $service['neto'],
  13580.             'sumSubT' => $service['sumSubT'],
  13581.         );
  13582.         $currency '€';
  13583.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  13584.         if (!empty($payments)) {
  13585.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  13586.         } else {
  13587.             $amount_pay 0;
  13588.         }
  13589.         $totales_all $totales_total $amount_pay;
  13590.         if (empty($dateDocument)) {
  13591.             $dateDocument = new DateTime('now');
  13592.         }
  13593.         $data = array(
  13594.             'id' => $fileId,
  13595.             'type' => $type,
  13596.             'number' => $number,
  13597.             'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' $invoiceId,
  13598.             'date' => $dateDocument,
  13599.             'file' => $file,
  13600.             'token' => $file->getAccessKey(),
  13601.             'company' => $company,
  13602.             'clients' => $clientNew,
  13603.             'arrayItems' => $arrayItems,
  13604.             'datasupplier' => $data_supplier,
  13605.             'currency' => $currency,
  13606.             'totales_neto' => $totales_neto_all,
  13607.             'bases_imponibles' => $data_iva,
  13608.             'totales' => $totales_total,
  13609.             'balance' => $totales_all,
  13610.             'paymentInvoice' => $amount_pay,
  13611.         );
  13612.         return $data;
  13613.     }
  13614.     private function sendTelegram($id$text)
  13615.     {
  13616.         $em $this->getDoctrine()->getManager();
  13617.         $telegUser $em->getRepository(MdvTelegramUser::class)->findOneByUserId($id);
  13618.         if (empty($telegUser)) {
  13619.             return true;
  13620.         }
  13621.         $parameters = array(
  13622.             'chat_id' => $telegUser->getChatId(),
  13623.             'text' => $text,
  13624.         );
  13625.         $bot_token $telegUser->getBotToken();
  13626.         $url "https://api.telegram.org/bot$bot_token/sendMessage";
  13627.         if (!$curl curl_init()) {
  13628.             exit();
  13629.         }
  13630.         curl_setopt($curlCURLOPT_POSTtrue);
  13631.         curl_setopt($curlCURLOPT_POSTFIELDS$parameters);
  13632.         curl_setopt($curlCURLOPT_URL$url);
  13633.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  13634.         $output curl_exec($curl);
  13635.         curl_close($curl);
  13636.         return true;
  13637.     }
  13638.     private function baseProformaSelect($id$type$number$prefix$date$proformaId)
  13639.     {
  13640.         $em $this->getDoctrine()->getManager();
  13641.         $file $em->getRepository(AveFiles::class)->findOneById($id);
  13642.         $company $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
  13643.         $client $em->getRepository(Client::class)->findById($file->getClient());
  13644.         if (empty($client)) {
  13645.             $client[0] = new Client();
  13646.             $client[0]->setName('');
  13647.             $client[0]->setTitle('');
  13648.             $client[0]->setIdDocument('');
  13649.             $client[0]->setPopulation('');
  13650.             $client[0]->setRegion('');
  13651.             $client[0]->setCountry('');
  13652.         } else {
  13653.             if (is_numeric($client[0]->getPopulation())) {
  13654.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  13655. //                $client[0]->setPopulation($city->getCity());
  13656.             }
  13657.             if (is_numeric($client[0]->getRegion())) {
  13658.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  13659. //                $client[0]->setRegion($region->getRegion());
  13660.             }
  13661.             if (is_numeric($client[0]->getCountry())) {
  13662.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  13663. //                $client[0]->setCountry($country->getCountry());
  13664.             }
  13665.         }
  13666.         if (empty($client)) {
  13667.             $client[0] = new Client();
  13668.             $client[0]->setName('');
  13669.             $client[0]->setTitle('');
  13670.             $client[0]->setIdDocument('');
  13671.             $client[0]->setPopulation('');
  13672.             $client[0]->setRegion('');
  13673.             $client[0]->setCountry('');
  13674.             $clientNew = array(
  13675.                 'name' => '',
  13676.                 'title' => '',
  13677.                 'idDocument' => '',
  13678.                 'population' => '',
  13679.                 'region' => '',
  13680.                 'country' => '',
  13681.                 'address' => '',
  13682.                 'addressNumber' => '',
  13683.                 'zipCode' => '',
  13684.                 'typeDocument' => '',
  13685.             );
  13686.         } else {
  13687.             $clientNew = array(
  13688.                 'name' => $client[0]->getName(),
  13689.                 'title' => $client[0]->getTitle(),
  13690.                 'idDocument' => $client[0]->getIdDocument(),
  13691.                 'population' => '',
  13692.                 'region' => '',
  13693.                 'country' => '',
  13694.                 'address' => $client[0]->getAddress(),
  13695.                 'addressNumber' => $client[0]->getAddressNumber(),
  13696.                 'zipCode' => $client[0]->getZipCode(),
  13697.                 'typeDocument' => $client[0]->getTypeDocument(),
  13698.             );
  13699.             if (is_numeric($client[0]->getPopulation())) {
  13700.                 $city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
  13701.                 $clientNew['population'] = $city->getCity();
  13702.             }
  13703.             if (is_numeric($client[0]->getRegion())) {
  13704.                 $region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
  13705.                 $clientNew['region'] = $region->getRegion();
  13706.             }
  13707.             if (is_numeric($client[0]->getCountry())) {
  13708.                 $country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
  13709.                 $clientNew['country'] = $country->getCountry();
  13710.             }
  13711.         }
  13712.         // Acumuladores de los calculos
  13713.         $totales_neto_all 0;
  13714.         $data_iva = array(
  13715.             'iva' => 21,
  13716.             'ivaMontoVeintiUno' => 0,
  13717.             'ivaMontoDiez' => 0,
  13718.             'ivaMontoCero' => null,
  13719.         );
  13720.         // Buscamos las salas reservadas, pagos y servicios para el evento
  13721.         // Buscamos los productos de la proforma
  13722.         $productsInProforma $em->getRepository(AveDocProformaItems::class)->findByProformaId($proformaId);
  13723.         $productsInFile = array();
  13724.         foreach ($productsInProforma as $item) {
  13725.             $producto $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
  13726.             if (!empty($producto)) {
  13727.                 $productsInFile[] = $producto;
  13728.             }
  13729.         }
  13730.         //        $productsInFile = $em->getRepository(AveProductFile::class)->findByFileId($id);
  13731.         $payments $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
  13732.         $services $em->getRepository(AveServices::class)->findByFileId($id);
  13733.         $data_supplier = array();
  13734.         $i 0;
  13735.         $iva '21';            // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
  13736.         $pax '1';
  13737.         $qty '1';
  13738.         $product = array(
  13739.             'neto' => 0,
  13740.             'sumSubT' => 0,
  13741.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13742.         $service = array(
  13743.             'neto' => 0,
  13744.             'sumSubT' => 0,
  13745.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13746.         foreach ($productsInFile as $item) {
  13747.             //            $days = '1';
  13748.             //            $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  13749.             $days = ((($item->getDateEnd())->diff($item->getDateStart()))->days 1);
  13750.             // Verificamos que el producto no se encuentre ya en una factura
  13751.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
  13752.             $pax $item->getPax();
  13753.             $qty $item->getUnits();
  13754.             if (!empty($item->getDays())) {
  13755.                 $days $item->getDays();
  13756.             }
  13757.             if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
  13758.                 $subtotal 0;
  13759.                 $neto 0;
  13760.                 $subtotalProduct 0;
  13761.             } else {
  13762.                 //                $subtotalProduct = $item->getServicePrice() * 1.21;
  13763.                 $subtotalProduct $item->getSubTotalPrice() * 1.21;
  13764.                 //                $subneto = $item->getServicePrice();
  13765.                 $subneto $item->getSubTotalPrice();
  13766.                 $subtotal =  $subtotalProduct;
  13767.                 $neto =  $subneto;
  13768.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  13769.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  13770.                 $neto round($neto2PHP_ROUND_HALF_UP);
  13771.             }
  13772.             // Acumula netos totales e IVA
  13773.             $totales_neto_all $totales_neto_all $neto;
  13774.             $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto 0.21);
  13775.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13776.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  13777.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  13778.             // Acumula netos totales e IVA
  13779.             $product['neto'] = $product['neto'] + $neto;
  13780.             $product['sumSubT'] = $product['sumSubT'] + $subtotal;
  13781.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13782.             $product['neto'] = round($product['neto'], 2PHP_ROUND_HALF_UP);
  13783.             $product['sumSubT'] = round($product['sumSubT'], 2PHP_ROUND_HALF_UP);
  13784.             $data_supplier['product'][$i] = array(
  13785.                 'id' => $item->getId(),
  13786.                 'productName' => $item->getProductName(),
  13787.                 'productId' => $item->getProductId(),
  13788.                 'dateStart' => $item->getDateStart(),
  13789.                 'dateEnd' => $item->getDateEnd(),
  13790.                 'servicePrice' => $item->getServicePrice(),
  13791.                 'subTotalPrice' => $item->getSubTotalPrice(),
  13792.                 'subtotalProduct' => $subtotalProduct,
  13793.                 'iva' => $iva,
  13794.                 'pax' => $pax,
  13795.                 'qty' => $qty,
  13796.                 'days' => $days,
  13797.                 'type' => $item->getType(),
  13798.                 'subtotal' => $subtotal,
  13799.             );
  13800.             $i++;
  13801.         }
  13802.         $data_supplier['productSubTotal'] = array(
  13803.             'neto' => $product['neto'],
  13804.             'sumSubT' => $product['sumSubT'],
  13805.         );
  13806.         $payment = array(
  13807.             'sumSubT' => 0,
  13808.         ); // Acumula sumatoria de netos y sumantoria de subtotales
  13809.         $i 0;
  13810.         foreach ($payments as $item) {
  13811.             // Verificamos que el pago no se encuentre ya en una factura
  13812.             $existe $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
  13813.             if (!empty($existe)) {
  13814.                 $payment['sumSubT'] = $payment['sumSubT'] + 0;
  13815.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13816.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  13817.             } else {
  13818.                 $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
  13819.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  13820.                 $payment['sumSubT'] = round($payment['sumSubT'], 2PHP_ROUND_HALF_UP);
  13821.             }
  13822.             $data_supplier['payment'][$i] = array(
  13823.                 'id' => $item->getId(),
  13824.                 'amount' => $item->getAmount(),
  13825.                 'datePayAt' => $item->getDatePayAt(),
  13826.                 'wayToPay' => $item->getWayToPay(),
  13827.                 'amountTotal' => $item->getAmountTotal(),
  13828.                 'vat' => $item->getVat(),
  13829.             );
  13830.             $i++;
  13831.         }
  13832.         if (!empty($payments)) {
  13833.             $data_supplier['paymentSubTotal'] = array(
  13834.                 'sumSubT' => $payment['sumSubT'],
  13835.             );
  13836.         }
  13837.         foreach ($services as $item) {
  13838.             // Verificamos que el servicio no se encuentre ya en una factura
  13839.             $existe $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
  13840.             if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
  13841.                 $subtotal 0;
  13842.                 $neto 0;
  13843.                 $subtotalService 0;
  13844.                 $subneto 0;
  13845.                 switch ($item->getServiceCatId()) {
  13846.                     case 1// Alojamiento
  13847.                         // el numero de noches $numNoches; precio unitario $subneto
  13848.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  13849.                         // La personas no afectan este calculo
  13850.                         $subtotal $subtotalService $numNoches $item->getUnits();
  13851.                         $subnetoUnit $subneto;
  13852.                         $subneto $subneto $numNoches $item->getUnits();
  13853.                         $data_supplier['service'][$i] = array(
  13854.                             'id' => $item->getId(),
  13855.                             'serviceCatId' => $item->getServiceCatId(),
  13856.                             'serviceName' => $item->getName(),
  13857.                             'serviceType' => 'Hotel',
  13858.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  13859.                             'qty' => $item->getUnits(),
  13860.                             'iva' => $item->getIva(),
  13861.                             'pax' => '-',
  13862.                             'precioUnit' => $subnetoUnit,
  13863.                             'subneto' => $subneto,
  13864.                             'subtotal' => $subtotal,
  13865.                         );
  13866.                         break;
  13867.                     case 2//Actividades
  13868.                         // El nĂºmero de personas es considerado en el calculo
  13869.                         $pax $item->getPax();
  13870.                         if (empty($pax) or $pax == "0") {
  13871.                             $pax 1;
  13872.                         }
  13873.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13874.                         if ($days 1) {
  13875.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13876.                         } else {
  13877.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13878.                         }
  13879.                         $subtotal $subtotalService $days $item->getUnits();
  13880.                         $subnetoUnit $subneto;
  13881.                         $subneto $subneto $days $item->getUnits();
  13882.                         $data_supplier['service'][$i] = array(
  13883.                             'id' => $item->getId(),
  13884.                             'serviceCatId' => $item->getServiceCatId(),
  13885.                             'serviceName' => $item->getName(),
  13886.                             'serviceType' => 'Actividad',
  13887.                             'date' => $dateServ,
  13888.                             'qty' => $item->getUnits(),
  13889.                             'iva' => $item->getIva(),
  13890.                             'pax' => $item->getPax(),
  13891.                             'precioUnit' => $subnetoUnit,
  13892.                             'subneto' => $subneto,
  13893.                             'subtotal' => $subtotal,
  13894.                         );
  13895.                         break;
  13896.                     case 3// AV
  13897.                         $pax $item->getPax();
  13898.                         if (empty($pax) or $pax == "0") {
  13899.                             $pax 1;
  13900.                         }
  13901.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13902.                         if ($days 1) {
  13903.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13904.                         } else {
  13905.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13906.                         }
  13907.                         $unitsServ $item->getUnits();
  13908.                         if (empty($unitsServ) or $unitsServ == "0") {
  13909.                             $unitsServ 1;
  13910.                         }
  13911.                         $subtotal $subtotalService $days $unitsServ $pax;
  13912.                         $subnetoUnit $subneto;
  13913.                         $subneto $subneto $days $unitsServ $pax;
  13914.                         $data_supplier['service'][$i] = array(
  13915.                             'id' => $item->getId(),
  13916.                             'serviceCatId' => $item->getServiceCatId(),
  13917.                             'serviceName' => $item->getName(),
  13918.                             'serviceType' => 'AV',
  13919.                             'date' => $dateServ,
  13920.                             'qty' => $unitsServ,
  13921.                             'iva' => $item->getIva(),
  13922.                             'pax' => $item->getPax(),
  13923.                             'precioUnit' => $subnetoUnit,
  13924.                             'subneto' => $subneto,
  13925.                             'subtotal' => $subtotal,
  13926.                         );
  13927.                         break;
  13928.                     case 4//Creative
  13929.                         $pax $item->getPax();
  13930.                         if (empty($pax) or $pax == "0") {
  13931.                             $pax 1;
  13932.                         }
  13933.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13934.                         if ($days 1) {
  13935.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13936.                         } else {
  13937.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13938.                         }
  13939.                         $unitsServ $item->getUnits();
  13940.                         if (empty($unitsServ) or $unitsServ == "0") {
  13941.                             $unitsServ 1;
  13942.                         }
  13943.                         $subtotal $subtotalService $days $unitsServ $pax;
  13944.                         $subnetoUnit $subneto;
  13945.                         $subneto $subneto $days $unitsServ $pax;
  13946.                         $data_supplier['service'][$i] = array(
  13947.                             'id' => $item->getId(),
  13948.                             'serviceCatId' => $item->getServiceCatId(),
  13949.                             'serviceName' => $item->getName(),
  13950.                             'serviceType' => 'Creativo',
  13951.                             'date' => $dateServ,
  13952.                             'qty' => $unitsServ,
  13953.                             'iva' => $item->getIva(),
  13954.                             'pax' => $item->getPax(),
  13955.                             'precioUnit' => $subnetoUnit,
  13956.                             'subneto' => $subneto,
  13957.                             'subtotal' => $subtotal,
  13958.                         );
  13959.                         break;
  13960.                     case 5//Cruise
  13961.                         $pax $item->getPax();
  13962.                         if (empty($pax) or $pax == "0") {
  13963.                             $pax 1;
  13964.                         }
  13965.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  13966.                         if ($days 1) {
  13967.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  13968.                         } else {
  13969.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  13970.                         }
  13971.                         $unitsServ $item->getUnits();
  13972.                         if (empty($unitsServ) or $unitsServ == "0") {
  13973.                             $unitsServ 1;
  13974.                         }
  13975.                         $subtotal $subtotalService $days $unitsServ $pax;
  13976.                         $subnetoUnit $subneto;
  13977.                         $subneto $subneto $days $unitsServ $pax;
  13978.                         $data_supplier['service'][$i] = array(
  13979.                             'id' => $item->getId(),
  13980.                             'serviceCatId' => $item->getServiceCatId(),
  13981.                             'serviceName' => $item->getName(),
  13982.                             'serviceType' => 'Crucero',
  13983.                             'date' => $dateServ,
  13984.                             'qty' => $unitsServ,
  13985.                             'iva' => $item->getIva(),
  13986.                             'pax' => $item->getPax(),
  13987.                             'precioUnit' => $subnetoUnit,
  13988.                             'subneto' => $subneto,
  13989.                             'subtotal' => $subtotal,
  13990.                         );
  13991.                         break;
  13992.                     case 6//Entertaiment
  13993.                         $pax $item->getPax();
  13994.                         if (empty($pax) or $pax == "0") {
  13995.                             $pax 1;
  13996.                         }
  13997.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  13998.                         if ($days 1) {
  13999.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14000.                         } else {
  14001.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14002.                         }
  14003.                         $unitsServ $item->getUnits();
  14004.                         if (empty($unitsServ) or $unitsServ == "0") {
  14005.                             $unitsServ 1;
  14006.                         }
  14007.                         $subtotal $subtotalService $days $unitsServ $pax;
  14008.                         $subnetoUnit $subneto;
  14009.                         $subneto $subneto $days $unitsServ $pax;
  14010.                         $data_supplier['service'][$i] = array(
  14011.                             'id' => $item->getId(),
  14012.                             'serviceCatId' => $item->getServiceCatId(),
  14013.                             'serviceName' => $item->getName(),
  14014.                             'serviceType' => 'Entretenimiento',
  14015.                             'date' => $dateServ,
  14016.                             'qty' => $unitsServ,
  14017.                             'iva' => $item->getIva(),
  14018.                             'pax' => $item->getPax(),
  14019.                             'precioUnit' => $subnetoUnit,
  14020.                             'subneto' => $subneto,
  14021.                             'subtotal' => $subtotal,
  14022.                         );
  14023.                         break;
  14024.                     case 7// Gifts
  14025.                         $pax $item->getPax();
  14026.                         if (empty($pax) or $pax == "0") {
  14027.                             $pax 1;
  14028.                         }
  14029.                         $days 1;
  14030.                         if ($days 1) {
  14031.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14032.                         } else {
  14033.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14034.                         }
  14035.                         $unitsServ $item->getUnits();
  14036.                         if (empty($unitsServ) or $unitsServ == "0") {
  14037.                             $unitsServ 1;
  14038.                         }
  14039.                         $subtotal $subtotalService $days $unitsServ $pax;
  14040.                         $subnetoUnit $subneto;
  14041.                         $subneto $subneto $days $unitsServ $pax;
  14042.                         $data_supplier['service'][$i] = array(
  14043.                             'id' => $item->getId(),
  14044.                             'serviceCatId' => $item->getServiceCatId(),
  14045.                             'serviceName' => $item->getName(),
  14046.                             'serviceType' => 'Regalos',
  14047.                             'date' => $dateServ,
  14048.                             'qty' => $unitsServ,
  14049.                             'iva' => $item->getIva(),
  14050.                             'pax' => $item->getPax(),
  14051.                             'precioUnit' => $subnetoUnit,
  14052.                             'subneto' => $subneto,
  14053.                             'subtotal' => $subtotal,
  14054.                         );
  14055.                         break;
  14056.                     case 8//Guide
  14057.                         $pax $item->getPax();
  14058.                         if (empty($pax) or $pax == "0") {
  14059.                             $pax 1;
  14060.                         }
  14061.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14062.                         if ($days 1) {
  14063.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14064.                         } else {
  14065.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14066.                         }
  14067.                         $unitsServ $item->getUnits();
  14068.                         if (empty($unitsServ) or $unitsServ == "0") {
  14069.                             $unitsServ 1;
  14070.                         }
  14071.                         $subtotal $subtotalService $days $unitsServ $pax;
  14072.                         $subnetoUnit $subneto;
  14073.                         $subneto $subneto $days $unitsServ $pax;
  14074.                         $data_supplier['service'][$i] = array(
  14075.                             'id' => $item->getId(),
  14076.                             'serviceCatId' => $item->getServiceCatId(),
  14077.                             'serviceName' => $item->getName(),
  14078.                             'serviceType' => 'Regalos',
  14079.                             'date' => $dateServ,
  14080.                             'qty' => $unitsServ,
  14081.                             'iva' => $item->getIva(),
  14082.                             'pax' => $item->getPax(),
  14083.                             'precioUnit' => $subnetoUnit,
  14084.                             'subneto' => $subneto,
  14085.                             'subtotal' => $subtotal,
  14086.                         );
  14087.                         break;
  14088.                     case 9//Itineraries
  14089.                         $pax $item->getPax();
  14090.                         if (empty($pax) or $pax == "0") {
  14091.                             $pax 1;
  14092.                         }
  14093.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14094.                         if ($days 1) {
  14095.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14096.                         } else {
  14097.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14098.                         }
  14099.                         $unitsServ $item->getUnits();
  14100.                         if (empty($unitsServ) or $unitsServ == "0") {
  14101.                             $unitsServ 1;
  14102.                         }
  14103.                         $subtotal $subtotalService $days $unitsServ $pax;
  14104.                         $subnetoUnit $subneto;
  14105.                         $subneto $subneto $days $unitsServ $pax;
  14106.                         $data_supplier['service'][$i] = array(
  14107.                             'id' => $item->getId(),
  14108.                             'serviceCatId' => $item->getServiceCatId(),
  14109.                             'serviceName' => $item->getName(),
  14110.                             'serviceType' => 'Itinerarios',
  14111.                             'date' => $dateServ,
  14112.                             'qty' => $unitsServ,
  14113.                             'iva' => $item->getIva(),
  14114.                             'pax' => $item->getPax(),
  14115.                             'precioUnit' => $subnetoUnit,
  14116.                             'subneto' => $subneto,
  14117.                             'subtotal' => $subtotal,
  14118.                         );
  14119.                         break;
  14120.                     case 10//Lounge  -- No Aplica
  14121.                         //                        $pax = $item->getPax();
  14122.                         //                        if (empty($pax) or $pax == "0") {
  14123.                         //                            $pax = 1;
  14124.                         //                        }
  14125.                         //
  14126.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  14127.                         //                        if ($days > 1){
  14128.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  14129.                         //                        } else {
  14130.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14131.                         //                        }
  14132.                         //
  14133.                         //                        $unitsServ = $item->getUnits();
  14134.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  14135.                         //                            $unitsServ = 1;
  14136.                         //                        }
  14137.                         //
  14138.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  14139.                         //                        $subnetoUnit = $subneto;
  14140.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  14141.                         //
  14142.                         //                        $data_supplier['service'][$i] = array (
  14143.                         //                            'id' => $item->getId(),
  14144.                         //                            'serviceCatId' => $item->getServiceCatId(),
  14145.                         //                            'serviceName' => $item->getName(),
  14146.                         //                            'serviceType' => 'Itinerarios',
  14147.                         //                            'date' => $dateServ,
  14148.                         //                            'qty' => $unitsServ,
  14149.                         //                            'iva' => $item->getIva(),
  14150.                         //                            'pax' => $item->getPax(),
  14151.                         //                            'precioUnit' => $subnetoUnit,
  14152.                         //                            'subneto' => $subneto,
  14153.                         //                            'subtotal' => $subtotal,
  14154.                         //                        );
  14155.                         break;
  14156.                     case 11//Menu
  14157.                         $pax $item->getPax();
  14158.                         if (empty($pax) or $pax == "0") {
  14159.                             $pax 1;
  14160.                         }
  14161.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14162.                         if ($days 1) {
  14163.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14164.                         } else {
  14165.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14166.                         }
  14167.                         $unitsServ $item->getUnits();
  14168.                         if (empty($unitsServ) or $unitsServ == "0") {
  14169.                             $unitsServ 1;
  14170.                         }
  14171.                         $subtotal $subtotalService $days $unitsServ $pax;
  14172.                         $subnetoUnit $subneto;
  14173.                         $subneto $subneto $days $unitsServ $pax;
  14174.                         $data_supplier['service'][$i] = array(
  14175.                             'id' => $item->getId(),
  14176.                             'serviceCatId' => $item->getServiceCatId(),
  14177.                             'serviceName' => $item->getName(),
  14178.                             'serviceType' => 'MenĂº',
  14179.                             'date' => $dateServ,
  14180.                             'qty' => $unitsServ,
  14181.                             'iva' => $item->getIva(),
  14182.                             'pax' => $item->getPax(),
  14183.                             'precioUnit' => $subnetoUnit,
  14184.                             'subneto' => $subneto,
  14185.                             'subtotal' => $subtotal,
  14186.                         );
  14187.                         break;
  14188.                     case 12//Others
  14189.                         $pax $item->getPax();
  14190.                         if (empty($pax) or $pax == "0") {
  14191.                             $pax 1;
  14192.                         }
  14193.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14194.                         if ($days 1) {
  14195.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14196.                         } else {
  14197.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14198.                         }
  14199.                         $unitsServ $item->getUnits();
  14200.                         if (empty($unitsServ) or $unitsServ == "0") {
  14201.                             $unitsServ 1;
  14202.                         }
  14203.                         $subtotal $subtotalService $days $unitsServ $pax;
  14204.                         $subnetoUnit $subneto;
  14205.                         $subneto $subneto $days $unitsServ $pax;
  14206.                         $data_supplier['service'][$i] = array(
  14207.                             'id' => $item->getId(),
  14208.                             'serviceCatId' => $item->getServiceCatId(),
  14209.                             'serviceName' => $item->getName(),
  14210.                             'serviceType' => 'Otros',
  14211.                             'date' => $dateServ,
  14212.                             'qty' => $unitsServ,
  14213.                             'iva' => $item->getIva(),
  14214.                             'pax' => $item->getPax(),
  14215.                             'precioUnit' => $subnetoUnit,
  14216.                             'subneto' => $subneto,
  14217.                             'subtotal' => $subtotal,
  14218.                         );
  14219.                         break;
  14220.                     case 13//Transport
  14221.                         $pax $item->getPax();
  14222.                         if (empty($pax) or $pax == "0") {
  14223.                             $pax 1;
  14224.                         }
  14225.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14226.                         if ($days 1) {
  14227.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14228.                         } else {
  14229.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14230.                         }
  14231.                         $unitsServ $item->getUnits();
  14232.                         if (empty($unitsServ) or $unitsServ == "0") {
  14233.                             $unitsServ 1;
  14234.                         }
  14235.                         $subtotal $subtotalService $days $unitsServ $pax;
  14236.                         $subnetoUnit $subneto;
  14237.                         $subneto $subneto $days $unitsServ $pax;
  14238.                         $data_supplier['service'][$i] = array(
  14239.                             'id' => $item->getId(),
  14240.                             'serviceCatId' => $item->getServiceCatId(),
  14241.                             'serviceName' => $item->getName(),
  14242.                             'serviceType' => 'Transporte',
  14243.                             'date' => $dateServ,
  14244.                             'qty' => $unitsServ,
  14245.                             'iva' => $item->getIva(),
  14246.                             'pax' => $item->getPax(),
  14247.                             'precioUnit' => $subnetoUnit,
  14248.                             'subneto' => $subneto,
  14249.                             'subtotal' => $subtotal,
  14250.                         );
  14251.                         break;
  14252.                     case 14//Technology
  14253.                         $pax $item->getPax();
  14254.                         if (empty($pax) or $pax == "0") {
  14255.                             $pax 1;
  14256.                         }
  14257.                         $days 1;
  14258.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14259.                         $unitsServ $item->getUnits();
  14260.                         if (empty($unitsServ) or $unitsServ == "0") {
  14261.                             $unitsServ 1;
  14262.                         }
  14263.                         $subtotal $subtotalService $days $unitsServ $pax;
  14264.                         $subnetoUnit $subneto;
  14265.                         $subneto $subneto $days $unitsServ $pax;
  14266.                         $data_supplier['service'][$i] = array(
  14267.                             'id' => $item->getId(),
  14268.                             'serviceCatId' => $item->getServiceCatId(),
  14269.                             'serviceName' => $item->getName(),
  14270.                             'serviceType' => 'TecnologĂ­a',
  14271.                             'date' => $dateServ,
  14272.                             'qty' => $unitsServ,
  14273.                             'iva' => $item->getIva(),
  14274.                             'pax' => $item->getPax(),
  14275.                             'precioUnit' => $subnetoUnit,
  14276.                             'subneto' => $subneto,
  14277.                             'subtotal' => $subtotal,
  14278.                         );
  14279.                         break;
  14280.                     case 15//Assisstant
  14281.                         $pax $item->getPax();
  14282.                         if (empty($pax) or $pax == "0") {
  14283.                             $pax 1;
  14284.                         }
  14285.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14286.                         if ($days 1) {
  14287.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14288.                         } else {
  14289.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14290.                         }
  14291.                         $unitsServ $item->getUnits();
  14292.                         if (empty($unitsServ) or $unitsServ == "0") {
  14293.                             $unitsServ 1;
  14294.                         }
  14295.                         $subtotal $subtotalService $days $unitsServ $pax;
  14296.                         $subnetoUnit $subneto;
  14297.                         $subneto $subneto $days $unitsServ $pax;
  14298.                         $data_supplier['service'][$i] = array(
  14299.                             'id' => $item->getId(),
  14300.                             'serviceCatId' => $item->getServiceCatId(),
  14301.                             'serviceName' => $item->getName(),
  14302.                             'serviceType' => 'Asistente',
  14303.                             'date' => $dateServ,
  14304.                             'qty' => $unitsServ,
  14305.                             'iva' => $item->getIva(),
  14306.                             'pax' => $item->getPax(),
  14307.                             'precioUnit' => $subnetoUnit,
  14308.                             'subneto' => $subneto,
  14309.                             'subtotal' => $subtotal,
  14310.                         );
  14311.                         break;
  14312.                     case 16//DDR
  14313.                         $pax $item->getPax();
  14314.                         if (empty($pax) or $pax == "0") {
  14315.                             $pax 1;
  14316.                         }
  14317.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14318.                         if ($days 1) {
  14319.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14320.                         } else {
  14321.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14322.                         }
  14323.                         $unitsServ $item->getUnits();
  14324.                         if (empty($unitsServ) or $unitsServ == "0") {
  14325.                             $unitsServ 1;
  14326.                         }
  14327.                         $subtotal $subtotalService $days $unitsServ $pax;
  14328.                         $subnetoUnit $subneto;
  14329.                         $subneto $subneto $days $unitsServ $pax;
  14330.                         $data_supplier['service'][$i] = array(
  14331.                             'id' => $item->getId(),
  14332.                             'serviceCatId' => $item->getServiceCatId(),
  14333.                             'serviceName' => $item->getName(),
  14334.                             'serviceType' => 'DDR',
  14335.                             'date' => $dateServ,
  14336.                             'qty' => $unitsServ,
  14337.                             'iva' => $item->getIva(),
  14338.                             'pax' => $item->getPax(),
  14339.                             'precioUnit' => $subnetoUnit,
  14340.                             'subneto' => $subneto,
  14341.                             'subtotal' => $subtotal,
  14342.                         );
  14343.                         break;
  14344.                     default:
  14345.                         break;
  14346.                 }
  14347.             } else {
  14348.                 $subtotalService $item->getPrice();
  14349.                 $subneto $item->getPrice();
  14350.                 // Commission
  14351.                 if ($item->getOpCommission() == '1') {
  14352.                     $subtotalService $subtotalService * (+ ($item->getCommission() / 100));
  14353.                     $subneto $subneto  * (+ ($item->getCommission() / 100));
  14354.                 } else {
  14355.                     $subtotalService $subtotalService * (- ($item->getCommission() / 100));
  14356.                     $subneto $subneto * (- ($item->getCommission() / 100));
  14357.                 }
  14358.                 // Over
  14359.                 if ($item->getOpOver() == '1') {
  14360.                     $subtotalService $subtotalService $item->getOver();
  14361.                     $subneto $subneto $item->getOver();
  14362.                 } else {
  14363.                     $subtotalService $subtotalService $item->getOver();
  14364.                     $subneto $subneto $item->getOver();
  14365.                 }
  14366.                 // IVA
  14367.                 if ($item->getOpIva() == '1') {
  14368.                     $subtotalService $subtotalService * (+ ($item->getIva() / 100));
  14369.                 } else {
  14370.                     $subtotalService $item->getPrice();
  14371.                     $subneto = ($subneto 100) / (100 $item->getIva());
  14372.                 }
  14373.                 switch ($item->getServiceCatId()) {
  14374.                     case 1// Alojamiento
  14375.                         // el numero de noches $numNoches; precio unitario $subneto
  14376.                         $numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
  14377.                         // La personas no afectan este calculo
  14378.                         $subtotal $subtotalService $numNoches $item->getUnits();
  14379.                         $subnetoUnit $subneto;
  14380.                         $subneto $subneto $numNoches $item->getUnits();
  14381.                         $data_supplier['service'][$i] = array(
  14382.                             'id' => $item->getId(),
  14383.                             'serviceCatId' => $item->getServiceCatId(),
  14384.                             'serviceName' => $item->getName(),
  14385.                             'serviceType' => 'Hotel',
  14386.                             'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
  14387.                             'qty' => $item->getUnits(),
  14388.                             'iva' => $item->getIva(),
  14389.                             'pax' => '-',
  14390.                             'precioUnit' => $subnetoUnit,
  14391.                             'subneto' => $subneto,
  14392.                             'subtotal' => $subtotal,
  14393.                         );
  14394.                         break;
  14395.                     case 2//Actividades
  14396.                         // El nĂºmero de personas es considerado en el calculo
  14397.                         $pax $item->getPax();
  14398.                         if (empty($pax) or $pax == "0") {
  14399.                             $pax 1;
  14400.                         }
  14401.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14402.                         if ($days 1) {
  14403.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14404.                         } else {
  14405.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14406.                         }
  14407.                         $subtotal $subtotalService $days $item->getUnits();
  14408.                         $subnetoUnit $subneto;
  14409.                         $subneto $subneto $days $item->getUnits();
  14410.                         $data_supplier['service'][$i] = array(
  14411.                             'id' => $item->getId(),
  14412.                             'serviceCatId' => $item->getServiceCatId(),
  14413.                             'serviceName' => $item->getName(),
  14414.                             'serviceType' => 'Actividad',
  14415.                             'date' => $dateServ,
  14416.                             'qty' => $item->getUnits(),
  14417.                             'iva' => $item->getIva(),
  14418.                             'pax' => $item->getPax(),
  14419.                             'precioUnit' => $subnetoUnit,
  14420.                             'subneto' => $subneto,
  14421.                             'subtotal' => $subtotal,
  14422.                         );
  14423.                         break;
  14424.                     case 3// AV
  14425.                         $pax $item->getPax();
  14426.                         if (empty($pax) or $pax == "0") {
  14427.                             $pax 1;
  14428.                         }
  14429.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14430.                         if ($days 1) {
  14431.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14432.                         } else {
  14433.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14434.                         }
  14435.                         $unitsServ $item->getUnits();
  14436.                         if (empty($unitsServ) or $unitsServ == "0") {
  14437.                             $unitsServ 1;
  14438.                         }
  14439.                         $subtotal $subtotalService $days $unitsServ $pax;
  14440.                         $subnetoUnit $subneto;
  14441.                         $subneto $subneto $days $unitsServ $pax;
  14442.                         $data_supplier['service'][$i] = array(
  14443.                             'id' => $item->getId(),
  14444.                             'serviceCatId' => $item->getServiceCatId(),
  14445.                             'serviceName' => $item->getName(),
  14446.                             'serviceType' => 'AV',
  14447.                             'date' => $dateServ,
  14448.                             'qty' => $unitsServ,
  14449.                             'iva' => $item->getIva(),
  14450.                             'pax' => $item->getPax(),
  14451.                             'precioUnit' => $subnetoUnit,
  14452.                             'subneto' => $subneto,
  14453.                             'subtotal' => $subtotal,
  14454.                         );
  14455.                         break;
  14456.                     case 4//Creative
  14457.                         $pax $item->getPax();
  14458.                         if (empty($pax) or $pax == "0") {
  14459.                             $pax 1;
  14460.                         }
  14461.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14462.                         if ($days 1) {
  14463.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14464.                         } else {
  14465.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14466.                         }
  14467.                         $unitsServ $item->getUnits();
  14468.                         if (empty($unitsServ) or $unitsServ == "0") {
  14469.                             $unitsServ 1;
  14470.                         }
  14471.                         $subtotal $subtotalService $days $unitsServ $pax;
  14472.                         $subnetoUnit $subneto;
  14473.                         $subneto $subneto $days $unitsServ $pax;
  14474.                         $data_supplier['service'][$i] = array(
  14475.                             'id' => $item->getId(),
  14476.                             'serviceCatId' => $item->getServiceCatId(),
  14477.                             'serviceName' => $item->getName(),
  14478.                             'serviceType' => 'Creativo',
  14479.                             'date' => $dateServ,
  14480.                             'qty' => $unitsServ,
  14481.                             'iva' => $item->getIva(),
  14482.                             'pax' => $item->getPax(),
  14483.                             'precioUnit' => $subnetoUnit,
  14484.                             'subneto' => $subneto,
  14485.                             'subtotal' => $subtotal,
  14486.                         );
  14487.                         break;
  14488.                     case 5//Cruise
  14489.                         $pax $item->getPax();
  14490.                         if (empty($pax) or $pax == "0") {
  14491.                             $pax 1;
  14492.                         }
  14493.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
  14494.                         if ($days 1) {
  14495.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14496.                         } else {
  14497.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14498.                         }
  14499.                         $unitsServ $item->getUnits();
  14500.                         if (empty($unitsServ) or $unitsServ == "0") {
  14501.                             $unitsServ 1;
  14502.                         }
  14503.                         $subtotal $subtotalService $days $unitsServ $pax;
  14504.                         $subnetoUnit $subneto;
  14505.                         $subneto $subneto $days $unitsServ $pax;
  14506.                         $data_supplier['service'][$i] = array(
  14507.                             'id' => $item->getId(),
  14508.                             'serviceCatId' => $item->getServiceCatId(),
  14509.                             'serviceName' => $item->getName(),
  14510.                             'serviceType' => 'Crucero',
  14511.                             'date' => $dateServ,
  14512.                             'qty' => $unitsServ,
  14513.                             'iva' => $item->getIva(),
  14514.                             'pax' => $item->getPax(),
  14515.                             'precioUnit' => $subnetoUnit,
  14516.                             'subneto' => $subneto,
  14517.                             'subtotal' => $subtotal,
  14518.                         );
  14519.                         break;
  14520.                     case 6//Entertaiment
  14521.                         $pax $item->getPax();
  14522.                         if (empty($pax) or $pax == "0") {
  14523.                             $pax 1;
  14524.                         }
  14525.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14526.                         if ($days 1) {
  14527.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14528.                         } else {
  14529.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14530.                         }
  14531.                         $unitsServ $item->getUnits();
  14532.                         if (empty($unitsServ) or $unitsServ == "0") {
  14533.                             $unitsServ 1;
  14534.                         }
  14535.                         $subtotal $subtotalService $days $unitsServ $pax;
  14536.                         $subnetoUnit $subneto;
  14537.                         $subneto $subneto $days $unitsServ $pax;
  14538.                         $data_supplier['service'][$i] = array(
  14539.                             'id' => $item->getId(),
  14540.                             'serviceCatId' => $item->getServiceCatId(),
  14541.                             'serviceName' => $item->getName(),
  14542.                             'serviceType' => 'Entretenimiento',
  14543.                             'date' => $dateServ,
  14544.                             'qty' => $unitsServ,
  14545.                             'iva' => $item->getIva(),
  14546.                             'pax' => $item->getPax(),
  14547.                             'precioUnit' => $subnetoUnit,
  14548.                             'subneto' => $subneto,
  14549.                             'subtotal' => $subtotal,
  14550.                         );
  14551.                         break;
  14552.                     case 7// Gifts
  14553.                         $pax $item->getPax();
  14554.                         if (empty($pax) or $pax == "0") {
  14555.                             $pax 1;
  14556.                         }
  14557.                         $days 1;
  14558.                         if ($days 1) {
  14559.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14560.                         } else {
  14561.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14562.                         }
  14563.                         $unitsServ $item->getUnits();
  14564.                         if (empty($unitsServ) or $unitsServ == "0") {
  14565.                             $unitsServ 1;
  14566.                         }
  14567.                         $subtotal $subtotalService $days $unitsServ $pax;
  14568.                         $subnetoUnit $subneto;
  14569.                         $subneto $subneto $days $unitsServ $pax;
  14570.                         $data_supplier['service'][$i] = array(
  14571.                             'id' => $item->getId(),
  14572.                             'serviceCatId' => $item->getServiceCatId(),
  14573.                             'serviceName' => $item->getName(),
  14574.                             'serviceType' => 'Regalos',
  14575.                             'date' => $dateServ,
  14576.                             'qty' => $unitsServ,
  14577.                             'iva' => $item->getIva(),
  14578.                             'pax' => $item->getPax(),
  14579.                             'precioUnit' => $subnetoUnit,
  14580.                             'subneto' => $subneto,
  14581.                             'subtotal' => $subtotal,
  14582.                         );
  14583.                         break;
  14584.                     case 8//Guide
  14585.                         $pax $item->getPax();
  14586.                         if (empty($pax) or $pax == "0") {
  14587.                             $pax 1;
  14588.                         }
  14589.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14590.                         if ($days 1) {
  14591.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14592.                         } else {
  14593.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14594.                         }
  14595.                         $unitsServ $item->getUnits();
  14596.                         if (empty($unitsServ) or $unitsServ == "0") {
  14597.                             $unitsServ 1;
  14598.                         }
  14599.                         $subtotal $subtotalService $days $unitsServ $pax;
  14600.                         $subnetoUnit $subneto;
  14601.                         $subneto $subneto $days $unitsServ $pax;
  14602.                         $data_supplier['service'][$i] = array(
  14603.                             'id' => $item->getId(),
  14604.                             'serviceCatId' => $item->getServiceCatId(),
  14605.                             'serviceName' => $item->getName(),
  14606.                             'serviceType' => 'Regalos',
  14607.                             'date' => $dateServ,
  14608.                             'qty' => $unitsServ,
  14609.                             'iva' => $item->getIva(),
  14610.                             'pax' => $item->getPax(),
  14611.                             'precioUnit' => $subnetoUnit,
  14612.                             'subneto' => $subneto,
  14613.                             'subtotal' => $subtotal,
  14614.                         );
  14615.                         break;
  14616.                     case 9//Itineraries
  14617.                         $pax $item->getPax();
  14618.                         if (empty($pax) or $pax == "0") {
  14619.                             $pax 1;
  14620.                         }
  14621.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14622.                         if ($days 1) {
  14623.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14624.                         } else {
  14625.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14626.                         }
  14627.                         $unitsServ $item->getUnits();
  14628.                         if (empty($unitsServ) or $unitsServ == "0") {
  14629.                             $unitsServ 1;
  14630.                         }
  14631.                         $subtotal $subtotalService $days $unitsServ $pax;
  14632.                         $subnetoUnit $subneto;
  14633.                         $subneto $subneto $days $unitsServ $pax;
  14634.                         $data_supplier['service'][$i] = array(
  14635.                             'id' => $item->getId(),
  14636.                             'serviceCatId' => $item->getServiceCatId(),
  14637.                             'serviceName' => $item->getName(),
  14638.                             'serviceType' => 'Itinerarios',
  14639.                             'date' => $dateServ,
  14640.                             'qty' => $unitsServ,
  14641.                             'iva' => $item->getIva(),
  14642.                             'pax' => $item->getPax(),
  14643.                             'precioUnit' => $subnetoUnit,
  14644.                             'subneto' => $subneto,
  14645.                             'subtotal' => $subtotal,
  14646.                         );
  14647.                         break;
  14648.                     case 10//Lounge  -- No Aplica
  14649.                         //                        $pax = $item->getPax();
  14650.                         //                        if (empty($pax) or $pax == "0") {
  14651.                         //                            $pax = 1;
  14652.                         //                        }
  14653.                         //
  14654.                         //                        $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
  14655.                         //                        if ($days > 1){
  14656.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
  14657.                         //                        } else {
  14658.                         //                            $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14659.                         //                        }
  14660.                         //
  14661.                         //                        $unitsServ = $item->getUnits();
  14662.                         //                        if (empty($unitsServ) or $unitsServ == "0") {
  14663.                         //                            $unitsServ = 1;
  14664.                         //                        }
  14665.                         //
  14666.                         //                        $subtotal = $subtotalService * $days * $unitsServ * $pax;
  14667.                         //                        $subnetoUnit = $subneto;
  14668.                         //                        $subneto = $subneto * $days * $unitsServ * $pax;
  14669.                         //
  14670.                         //                        $data_supplier['service'][$i] = array (
  14671.                         //                            'id' => $item->getId(),
  14672.                         //                            'serviceCatId' => $item->getServiceCatId(),
  14673.                         //                            'serviceName' => $item->getName(),
  14674.                         //                            'serviceType' => 'Itinerarios',
  14675.                         //                            'date' => $dateServ,
  14676.                         //                            'qty' => $unitsServ,
  14677.                         //                            'iva' => $item->getIva(),
  14678.                         //                            'pax' => $item->getPax(),
  14679.                         //                            'precioUnit' => $subnetoUnit,
  14680.                         //                            'subneto' => $subneto,
  14681.                         //                            'subtotal' => $subtotal,
  14682.                         //                        );
  14683.                         break;
  14684.                     case 11//Menu
  14685.                         $pax $item->getPax();
  14686.                         if (empty($pax) or $pax == "0") {
  14687.                             $pax 1;
  14688.                         }
  14689.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14690.                         if ($days 1) {
  14691.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14692.                         } else {
  14693.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14694.                         }
  14695.                         $unitsServ $item->getUnits();
  14696.                         if (empty($unitsServ) or $unitsServ == "0") {
  14697.                             $unitsServ 1;
  14698.                         }
  14699.                         $subtotal $subtotalService $days $unitsServ $pax;
  14700.                         $subnetoUnit $subneto;
  14701.                         $subneto $subneto $days $unitsServ $pax;
  14702.                         $data_supplier['service'][$i] = array(
  14703.                             'id' => $item->getId(),
  14704.                             'serviceCatId' => $item->getServiceCatId(),
  14705.                             'serviceName' => $item->getName(),
  14706.                             'serviceType' => 'MenĂº',
  14707.                             'date' => $dateServ,
  14708.                             'qty' => $unitsServ,
  14709.                             'iva' => $item->getIva(),
  14710.                             'pax' => $item->getPax(),
  14711.                             'precioUnit' => $subnetoUnit,
  14712.                             'subneto' => $subneto,
  14713.                             'subtotal' => $subtotal,
  14714.                         );
  14715.                         break;
  14716.                     case 12//Others
  14717.                         $pax $item->getPax();
  14718.                         if (empty($pax) or $pax == "0") {
  14719.                             $pax 1;
  14720.                         }
  14721.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14722.                         if ($days 1) {
  14723.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14724.                         } else {
  14725.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14726.                         }
  14727.                         $unitsServ $item->getUnits();
  14728.                         if (empty($unitsServ) or $unitsServ == "0") {
  14729.                             $unitsServ 1;
  14730.                         }
  14731.                         $subtotal $subtotalService $days $unitsServ $pax;
  14732.                         $subnetoUnit $subneto;
  14733.                         $subneto $subneto $days $unitsServ $pax;
  14734.                         $data_supplier['service'][$i] = array(
  14735.                             'id' => $item->getId(),
  14736.                             'serviceCatId' => $item->getServiceCatId(),
  14737.                             'serviceName' => $item->getName(),
  14738.                             'serviceType' => 'Otros',
  14739.                             'date' => $dateServ,
  14740.                             'qty' => $unitsServ,
  14741.                             'iva' => $item->getIva(),
  14742.                             'pax' => $item->getPax(),
  14743.                             'precioUnit' => $subnetoUnit,
  14744.                             'subneto' => $subneto,
  14745.                             'subtotal' => $subtotal,
  14746.                         );
  14747.                         break;
  14748.                     case 13//Transport
  14749.                         $pax $item->getPax();
  14750.                         if (empty($pax) or $pax == "0") {
  14751.                             $pax 1;
  14752.                         }
  14753.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14754.                         if ($days 1) {
  14755.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14756.                         } else {
  14757.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14758.                         }
  14759.                         $unitsServ $item->getUnits();
  14760.                         if (empty($unitsServ) or $unitsServ == "0") {
  14761.                             $unitsServ 1;
  14762.                         }
  14763.                         $subtotal $subtotalService $days $unitsServ $pax;
  14764.                         $subnetoUnit $subneto;
  14765.                         $subneto $subneto $days $unitsServ $pax;
  14766.                         $data_supplier['service'][$i] = array(
  14767.                             'id' => $item->getId(),
  14768.                             'serviceCatId' => $item->getServiceCatId(),
  14769.                             'serviceName' => $item->getName(),
  14770.                             'serviceType' => 'Transporte',
  14771.                             'date' => $dateServ,
  14772.                             'qty' => $unitsServ,
  14773.                             'iva' => $item->getIva(),
  14774.                             'pax' => $item->getPax(),
  14775.                             'precioUnit' => $subnetoUnit,
  14776.                             'subneto' => $subneto,
  14777.                             'subtotal' => $subtotal,
  14778.                         );
  14779.                         break;
  14780.                     case 14//Technology
  14781.                         $pax $item->getPax();
  14782.                         if (empty($pax) or $pax == "0") {
  14783.                             $pax 1;
  14784.                         }
  14785.                         $days 1;
  14786.                         $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14787.                         $unitsServ $item->getUnits();
  14788.                         if (empty($unitsServ) or $unitsServ == "0") {
  14789.                             $unitsServ 1;
  14790.                         }
  14791.                         $subtotal $subtotalService $days $unitsServ $pax;
  14792.                         $subnetoUnit $subneto;
  14793.                         $subneto $subneto $days $unitsServ $pax;
  14794.                         $data_supplier['service'][$i] = array(
  14795.                             'id' => $item->getId(),
  14796.                             'serviceCatId' => $item->getServiceCatId(),
  14797.                             'serviceName' => $item->getName(),
  14798.                             'serviceType' => 'TecnologĂ­a',
  14799.                             'date' => $dateServ,
  14800.                             'qty' => $unitsServ,
  14801.                             'iva' => $item->getIva(),
  14802.                             'pax' => $item->getPax(),
  14803.                             'precioUnit' => $subnetoUnit,
  14804.                             'subneto' => $subneto,
  14805.                             'subtotal' => $subtotal,
  14806.                         );
  14807.                         break;
  14808.                     case 15//Assisstant
  14809.                         $pax $item->getPax();
  14810.                         if (empty($pax) or $pax == "0") {
  14811.                             $pax 1;
  14812.                         }
  14813.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14814.                         if ($days 1) {
  14815.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14816.                         } else {
  14817.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14818.                         }
  14819.                         $unitsServ $item->getUnits();
  14820.                         if (empty($unitsServ) or $unitsServ == "0") {
  14821.                             $unitsServ 1;
  14822.                         }
  14823.                         $subtotal $subtotalService $days $unitsServ $pax;
  14824.                         $subnetoUnit $subneto;
  14825.                         $subneto $subneto $days $unitsServ $pax;
  14826.                         $data_supplier['service'][$i] = array(
  14827.                             'id' => $item->getId(),
  14828.                             'serviceCatId' => $item->getServiceCatId(),
  14829.                             'serviceName' => $item->getName(),
  14830.                             'serviceType' => 'Asistente',
  14831.                             'date' => $dateServ,
  14832.                             'qty' => $unitsServ,
  14833.                             'iva' => $item->getIva(),
  14834.                             'pax' => $item->getPax(),
  14835.                             'precioUnit' => $subnetoUnit,
  14836.                             'subneto' => $subneto,
  14837.                             'subtotal' => $subtotal,
  14838.                         );
  14839.                         break;
  14840.                     case 16//DDR
  14841.                         $pax $item->getPax();
  14842.                         if (empty($pax) or $pax == "0") {
  14843.                             $pax 1;
  14844.                         }
  14845.                         $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days 1);
  14846.                         if ($days 1) {
  14847.                             $dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
  14848.                         } else {
  14849.                             $dateServ = ($item->getDateInAt())->format('d/m/Y');
  14850.                         }
  14851.                         $unitsServ $item->getUnits();
  14852.                         if (empty($unitsServ) or $unitsServ == "0") {
  14853.                             $unitsServ 1;
  14854.                         }
  14855.                         $subtotal $subtotalService $days $unitsServ $pax;
  14856.                         $subnetoUnit $subneto;
  14857.                         $subneto $subneto $days $unitsServ $pax;
  14858.                         $data_supplier['service'][$i] = array(
  14859.                             'id' => $item->getId(),
  14860.                             'serviceCatId' => $item->getServiceCatId(),
  14861.                             'serviceName' => $item->getName(),
  14862.                             'serviceType' => 'DDR',
  14863.                             'date' => $dateServ,
  14864.                             'qty' => $unitsServ,
  14865.                             'iva' => $item->getIva(),
  14866.                             'pax' => $item->getPax(),
  14867.                             'precioUnit' => $subnetoUnit,
  14868.                             'subneto' => $subneto,
  14869.                             'subtotal' => $subtotal,
  14870.                         );
  14871.                         break;
  14872.                     default:
  14873.                         break;
  14874.                 }
  14875.                 // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
  14876.                 $subtotal round($subtotal2PHP_ROUND_HALF_UP);
  14877.                 $neto round($subneto2PHP_ROUND_HALF_UP);
  14878.             }
  14879.             switch ($item->getIva()) {
  14880.                     // Acumula IVA
  14881.                 case 21:
  14882.                     $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100));
  14883.                     break;
  14884.                 case 10:
  14885.                     $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
  14886.                     break;
  14887.                 case 0:
  14888.                     break;
  14889.                 default:
  14890.                     break;
  14891.             }
  14892.             $totales_neto_all $totales_neto_all $neto;
  14893.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  14894.             $totales_neto_all round($totales_neto_all2PHP_ROUND_HALF_UP);
  14895.             $data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2PHP_ROUND_HALF_UP);
  14896.             $data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2PHP_ROUND_HALF_UP);
  14897.             // Acumula netos totales e IVA
  14898.             $service['neto'] = $service['neto'] + $neto;
  14899.             $service['sumSubT'] = $service['sumSubT'] + $subtotal;
  14900.             // Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
  14901.             $service['neto'] = round($service['neto'], 2PHP_ROUND_HALF_UP);
  14902.             $service['sumSubT'] = round($service['sumSubT'], 2PHP_ROUND_HALF_UP);
  14903.             $i++;
  14904.         }
  14905.         $data_supplier['serviceSubTotal'] = array(
  14906.             'neto' => $service['neto'],
  14907.             'sumSubT' => $service['sumSubT'],
  14908.         );
  14909.         $currency '€';
  14910.         $totales_total $totales_neto_all $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
  14911.         if (!empty($payments)) {
  14912.             $amount_pay $data_supplier['paymentSubTotal']['sumSubT'];
  14913.         } else {
  14914.             $amount_pay 0;
  14915.         }
  14916.         $totales_all $totales_total $amount_pay;
  14917.         $data = array(
  14918.             'id' => $id,
  14919.             'type' => $type,
  14920.             'number' => $number,
  14921.             'prefix' => $prefix,
  14922.             'date' => $date,
  14923.             'file' => $file,
  14924.             'token' => ''// $file->getAccessKey(),
  14925.             'company' => $company,
  14926.             'clients' => $clientNew,
  14927.             'datasupplier' => $data_supplier,
  14928.             'currency' => $currency,
  14929.             'totales_neto' => $totales_neto_all,
  14930.             'bases_imponibles' => $data_iva,
  14931.             'totales' => $totales_total,
  14932.             'balance' => $totales_all,
  14933.             'paymentInvoice' => $amount_pay,
  14934.         );
  14935.         return $data;
  14936.     }
  14937.     private function sendMailLot($mailAddressFrom$mailArrayTo$mailSubject$mailBody)
  14938.     {
  14939.         $em $this->getDoctrine()->getManager();
  14940.         $agent $em->getRepository(User::class)->findOneByEmail($mailAddressFrom);
  14941.         //        $client = $em->getRepository(User::class)->findOneByEmail($mailAddressTo);
  14942.         $replyTo = array();
  14943.         foreach ($mailArrayTo as $item) {
  14944.             // Verificamos que los correos sean validos
  14945.             if (filter_var($itemFILTER_VALIDATE_EMAIL)) {
  14946.                 $replyTo[$item] = $item;
  14947.             }
  14948.         }
  14949.         $agentMail $mailAddressFrom;
  14950.         $mailAgent $agentMail;
  14951.         //Se prepara el correo con los agentes a notificar
  14952.         $firmGmail $agent->getFirmGmail();
  14953.         $data = array(
  14954.             'body' => $mailBody,
  14955.             'firm' => $firmGmail,
  14956.         );
  14957.         // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  14958.         $transporter = new Swift_SmtpTransport();
  14959.         $transporter->setHost('smtp.gmail.com')
  14960.             ->setEncryption('ssl'//ssl / tls
  14961.             ->setPort(465// 465 / 587
  14962.             ->setUsername('desarrollo@develup.solutions')
  14963.             ->setPassword('utvh hzoi wfdo ztjs');
  14964.         $mailer = new Swift_Mailer($transporter);
  14965.         $message = new Swift_Message();
  14966.         $message->setSubject($mailSubject)
  14967.             ->setSender($agentMail)
  14968.             ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  14969.             ->setReplyTo($agentMail)
  14970.             ->setTo($replyTo)
  14971.             ->setBody(
  14972.                 $this->renderView(
  14973.                     'mail/structure-mail.html.twig',
  14974.                     array('data' => $data)
  14975.                 ),
  14976.                 'text/html'
  14977.             );
  14978.         $mailer->send($message);
  14979.         return true;
  14980.     }
  14981.     private function calculoBeneficiosDocumento($id$typeDoc)
  14982.     {
  14983.         // Funcion para registrar los beneficios al crear facturas o facturas rectificativas
  14984.         $em $this->getDoctrine()->getManager();
  14985.         if ($typeDoc == 'Invoice') {
  14986.             // Es factura
  14987.             $invoice $em->getRepository(AveDocInvoice::class)->findOneById($id);
  14988.             $invoiceItems $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
  14989.             // ComisiĂ³n de AV a GreenPatio
  14990.             $aveFile $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  14991.             $reserva $em->getRepository(Reservation::class)->findOneById($aveFile->getReservation());
  14992.             if (!empty($reserva)){
  14993.                 if (!is_null($reserva->getComAvGp())) {
  14994.                     $supplierNet $invoice->getTotalNet() * ($reserva->getComAvGp()/100);
  14995.                 } else {
  14996.                     // Valor por defecto de la Comision de Av 10%
  14997.                     $supplierNet $invoice->getTotalNet() * (10/100);
  14998.                 }
  14999.                 $description $id.' - ComisiĂ³n MANTE de Green Patio (Generado automaticamente)';
  15000.                 $supplier $em->getRepository(Supplier::class)->findOneById(2028);     // Green Patio como proveedor
  15001.                 $benSup = new AveBenefitsSupplier();
  15002.                 $benSup->setFileId($aveFile->getId());
  15003.                 $benSup->setDocId(0);
  15004.                 $benSup->setDocType('.');
  15005.                 $benSup->setSupplierId(2028);
  15006.                 $benSup->setSupplierName($supplier->getCompany() . ' | ' $supplier->getName());
  15007.                 $benSup->setDescription($description);
  15008.                 $benSup->setBenefitSupplier($supplierNet);
  15009.                 $em->persist($benSup);
  15010.                 $em->flush();
  15011.             }
  15012.         } else {
  15013.             // Es factura rectificativa
  15014.             // Se busca la entrada de los beneficios de la factura y se genera su contraparte. Tambien se necesita el ID de la factura rectificativa
  15015.             $invoiceRec $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
  15016.             if (empty($invoiceRec)) { return true; }
  15017.             $ben $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByDocId($invoiceRec->getInvoiceToRec());
  15018.             $benefits = new AveBenefitsInvoiceInvoiceRec();
  15019.             $benefits->setDocId($invoiceRec->getId());
  15020.             $benefits->setFileId($ben->getFileId());
  15021.             $benefits->setDocType('Invoice Rec');
  15022.             $benefits->setDateAt($invoiceRec->getDateAt());
  15023.             $benefits->setFileName($ben->getFileName());
  15024.             $benefits->setClientId($ben->getClientId());
  15025.             $benefits->setClientName($ben->getClientName());
  15026.             $benefits->setBenefitEuro($ben->getBenefitEuro() * (-1));
  15027.             $benefits->setBenefitPerc($ben->getBenefitPerc());
  15028.             $benefits->setNetSale($ben->getNetSale() * (-1));
  15029.             $benefits->setTotalSale($ben->getTotalSale() * (-1));
  15030.             $em->persist($benefits);
  15031.             $em->flush();
  15032.             return true;
  15033.         }
  15034.         $productsItems = array();
  15035.         // Buscamos los productos de la factura para determinar el proveedor
  15036.         foreach ($invoiceItems as $item) {
  15037.             $prdItem $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
  15038.             $sup = (empty($prdItem) or empty($prdItem->getSupplierExt())) ? 'AV EXPRESS S.L.' $prdItem->getSupplierExt();
  15039.             $iva = (empty($prdItem) or empty($prdItem->getIva())) ? '21' $prdItem->getSupplierExt();
  15040.             switch ($iva) {
  15041.                 case '21':
  15042.                     if (empty($prdItem)) {
  15043.                         $ivaxPlus 1.21;
  15044.                     } else {
  15045.                         $ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.83 1.21;  // 100/121 = 0.826
  15046.                     }
  15047.                     break;
  15048.                 case '10':
  15049.                     if (empty($prdItem)) {
  15050.                         $ivaxPlus 1.10;
  15051.                     } else {
  15052.                         $ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.91 1.10;  // 100/110 = 0.909
  15053.                     }
  15054.                     break;
  15055.                 case '0':
  15056.                     $ivaxPlus 1;
  15057.                     break;
  15058.                 default:
  15059.                     $ivaxPlus 1.21;
  15060.                     break;
  15061.             }
  15062.             $productsItems[] = array(
  15063.                 'invoiceItemOrInvoiceRecItem' => $item,
  15064.                 'productFile' => $prdItem,
  15065.                 'supplier' => $sup,
  15066.                 'iva' => $ivaxPlus,
  15067.                 'typeDoc' => $typeDoc
  15068.             );
  15069.         }
  15070.         $data = array();
  15071.         foreach ($productsItems as $elem) {
  15072.             if (empty($data[$invoice->getFileId()])) {
  15073.                 $data[$invoice->getFileId()] = array(
  15074.                     'id' => $invoice->getFileId(),
  15075.                     'benefitEuro' => 0,
  15076.                     'benefitPerc' => 0,
  15077.                     'netSale' => 0,
  15078.                     'totalSale' => 0,
  15079.                 );
  15080.             }
  15081.             $benefitEuro $data[$invoice->getFileId()]['benefitEuro'];
  15082.             $benefitPerc $data[$invoice->getFileId()]['benefitPerc'];
  15083.             $netSale $data[$invoice->getFileId()]['netSale'];
  15084.             $totalSale $data[$invoice->getFileId()]['totalSale'];
  15085.             // Con los factores se sumarĂ¡ o restarĂ¡ el beneficio
  15086.             // Se verifica si es una factura o factura rectificativa
  15087.             if ($typeDoc == 'Invoice') {
  15088.                 $indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? $elem['productFile']->getOpOver();
  15089.                 $indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? $elem['productFile']->getOpCommission();
  15090.                 $indicePax $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
  15091.                 $indiceQty $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
  15092.                 $indiceDays $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
  15093.                 $indicePriceProduct $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
  15094.                 $indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? $elem['productFile']->getOver();
  15095.                 $indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? $elem['productFile']->getCommission();
  15096.             } else {
  15097.                 $indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? $elem['productFile']->getOpOver();
  15098.                 $indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? $elem['productFile']->getOpCommission();
  15099.                 $indicePax $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
  15100.                 $indiceQty $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
  15101.                 $indiceDays $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
  15102.                 $indicePriceProduct $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
  15103.                 $indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? $elem['productFile']->getOver();
  15104.                 $indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? $elem['productFile']->getCommission();
  15105.             }
  15106.             // Se verifica el proveedor
  15107.             if ($elem['supplier'] == 'AV EXPRESS S.L.') { $factorSupp 0; } else { $factorSupp 1; }
  15108.             // Se verifica si es ganancia o perdida segun OVER (- o +)
  15109.             if ($indiceOpOver == 0) { $factorOver = -1; } else { $factorOver 1; }
  15110.             // Se verifica si es ganancia o perdida segun COMISION (- o +)
  15111.             if ($indiceOpComission == 0) { $factorCommission = -1; } else { $factorCommission 1; }
  15112.             // Pax
  15113.             if ($indicePax == or empty($indicePax)) { $pax 1; } else { $pax $indicePax; }
  15114.             // Qty
  15115.             if ($indiceQty == or empty($indiceQty)) { $qty 1; } else { $qty $indiceQty; }
  15116.             // Days
  15117.             if ($indiceDays == or empty($indiceDays)) { $days 1; } else { $days $indiceDays; }
  15118.             // Precio base
  15119.             $priceBase $indicePriceProduct $pax $qty $days;
  15120.             // Agregamos el over (se consideran over + o -)
  15121.             $price $priceBase + ($factorOver $indiceOver);
  15122.             // Agregamos la comision (se consideran comision + o -)
  15123.             $price $price + ((($factorCommission $indiceCommission) * $price) / 100);
  15124.             // Agregamos el factor proveedor
  15125.             $benefitEuroItem $price - ($priceBase $factorSupp);
  15126.             // Agregamos al porcentaje el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
  15127.             //                $benefitEuroItem = $benefitEuroItem * $factorTypeDoc;
  15128.             // Agregamos al precio el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
  15129.             //                $price = $price * $factorTypeDoc;
  15130.             // Agregamos el precio a la venta neta
  15131.             $netSale $netSale $price;
  15132.             // Agregamos al precio el IVA para la venta total
  15133.             $totalSale $totalSale + ($price $elem['iva']);
  15134.             $benefitPercItem = (empty($invoice) or ($invoice->getTotalNet() == 0)) ? round((($benefitEuroItem 100) / $invoice->getTotalNet()), 2PHP_ROUND_HALF_UP);
  15135.             $data[$invoice->getFileId()] = array(
  15136.                 'id' => $invoice->getFileId(),
  15137.                 'benefitEuro' => $benefitEuro $benefitEuroItem,
  15138.                 'benefitPerc' => $benefitPerc $benefitPercItem,
  15139.                 'netSale' => $netSale,
  15140.                 'totalSale' => $totalSale,
  15141.             );
  15142.         }
  15143.         foreach ($data as $key => $elem) {
  15144.             // Verificamos beneficios simplificados de proveedores
  15145.             $simplyBen $em->getRepository(AveBenefitsSupplier::class)->findByFileId($elem['id']);
  15146.             $benefitEuro $elem['benefitEuro'];
  15147.             foreach ($simplyBen as $item) { $benefitEuro $benefitEuro $item->getBenefitSupplier(); }
  15148.             $data[$key]['benefitEuro'] = $benefitEuro;
  15149.             $newBenefitPerc = (($benefitEuro 100) / $elem['netSale']);
  15150.             $newBenefitPerc round($newBenefitPerc2PHP_ROUND_HALF_UP);
  15151.             $data[$key]['benefitPerc'] = $newBenefitPerc;
  15152.         }
  15153.         // Los $benefitPercItem de 99.97 o 100.01 lo llevamos a 100
  15154. //        if ($data[$invoice->getFileId()]['benefitEuro'] == $data[$invoice->getFileId()]['netSale']) { $data[$invoice->getFileId()]['benefitPerc'] = 100; }
  15155.         $fileId $invoice->getFileId();
  15156.         if (isset($data[$fileId]) && $data[$fileId]['benefitEuro'] == $data[$fileId]['netSale']) {
  15157.             $data[$fileId]['benefitPerc'] = 100;
  15158.         }
  15159.         // Buscamos los datos del cliente
  15160.         if (!empty($invoice)) {
  15161.             $file $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
  15162.             $clientId = empty($file) ? null $file->getClient();
  15163.             $clientName = empty($clientId) ? null $em->getRepository(Client::class)->findOneById($clientId);
  15164.             $clientName = empty($clientName) ? null $clientName->getName();
  15165.         } else {
  15166.             $clientId null;
  15167.             $clientName null;
  15168.         }
  15169.         if (!empty($data)) {
  15170.             $benefits = new AveBenefitsInvoiceInvoiceRec();
  15171.             $benefits->setDocId($invoice->getId());
  15172.             $benefits->setFileId($invoice->getFileId());
  15173.             $benefits->setDocType($typeDoc);
  15174.             $benefits->setDateAt($invoice->getDateAt());
  15175.             $benefits->setFileName($file->getTitle());
  15176.             $benefits->setClientId($clientId);
  15177.             $benefits->setClientName($clientName);
  15178.             $benefits->setBenefitEuro($data[$invoice->getFileId()]['benefitEuro']);
  15179.             $benefits->setBenefitPerc($data[$invoice->getFileId()]['benefitPerc']);
  15180.             $benefits->setNetSale($data[$invoice->getFileId()]['netSale']);
  15181.             $benefits->setTotalSale($data[$invoice->getFileId()]['totalSale']);
  15182.             $em->persist($benefits);
  15183.             $em->flush();
  15184.         }
  15185.         //Llamamos al servicio del gestor de comisiones internas entre empresas
  15186.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  15187.         $user_id $user_logueado->getId();
  15188.         $dataService $this->commisionEnterpriseService->commissionAvExpressGreenPatio($invoice->getId(), $user_id);
  15189.         return true;
  15190.     }
  15191. };